├── Arrays ├── ComArray.java ├── IterateArray.java └── MultiDimArray.java ├── Basic Programs ├── Arithmatic.java ├── Armstrong.java ├── Factorial.java ├── HelloWorld.java ├── InputMethods.java ├── Primitive.java ├── StudentImp.java ├── TpeCast.java └── TryWithResources.java ├── Control Statements ├── Conditional Statements │ ├── Conditional.java │ ├── ConditionalScanner.java │ ├── README.md │ └── SwitchCase.java ├── Jumping Statements │ ├── JumpingStatementsDemo.java │ └── README.md ├── Looping Statments │ ├── DoWhileLoop.java │ ├── ForLoop.java │ ├── README.md │ └── WhileLoop.java └── README.md ├── Exception Handling ├── ChekExcep.java └── DefExcepHandler.java ├── Inheritance ├── Area.java ├── Hierarchichal.java ├── Overrid.java └── TransMul.java ├── Java Programs ├── Arithmetic.java ├── ArithmeticOperations.java ├── Armstrong.java ├── ArrayIndexExample.java ├── ClassObject.java ├── Comparision.java ├── Concatenation.java ├── CustomException.java ├── ExceptionHandling.java ├── ExceptionHandlingExample.java ├── FactorialExample.java ├── Final.java ├── InputMethods.java ├── Main.java ├── MethodOverLoad.java ├── MethodOverRid.java ├── MultiLevel.java ├── Mutiple.java ├── MyRun.java ├── MyRunnable.java ├── OneDimensionalArrayExample.java ├── PreventInheritanceExample.java ├── ScannerMethods.java ├── SingleLevel.java ├── StringConcatenationExample.java ├── StringMethods.java ├── SuperClass.java ├── ThreadClass.java ├── TwoDArray.java ├── TypeCasting.java └── VariableTypesExample.java ├── LICENSE ├── README.md └── Strings ├── String Tokenizers ├── StringFirst.java ├── StringSecond.java └── StringThird.java ├── StringBuff.java ├── StringBuil.java └── Strings.java /Arrays/ComArray.java: -------------------------------------------------------------------------------- 1 | public class ComArray { 2 | int[] arr3 = {14,7,3,9,2}; 3 | public static void main(String[] args) { 4 | int[] arr1 = {14,7,3,9,2}; 5 | int[] arr2 = {3,89,5,78,7,3,9,2}; 6 | for (int i=0; i num2 && num1 > num3) { 7 | System.out.printf(" %d is Greater", num1); 8 | } else if (num2 > num1 && num2 > num3) { 9 | System.out.printf(" %d is Greater", num2); 10 | } else { 11 | System.out.printf(" %d is Greater", num3); 12 | } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /Control Statements/Conditional Statements/ConditionalScanner.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | public class ConditionalScanner { 4 | public static void main(String[] args) { 5 | Scanner input = new Scanner(System.in); 6 | System.out.println("What is your Name? "); 7 | String name = input.next(); 8 | System.out.printf("HI %s ", name); 9 | System.out.println("Please Enter Number 1: "); 10 | int num1 = input.nextInt(); 11 | System.out.println("Please Enter Number 2: "); 12 | int num2 = input.nextInt(); 13 | System.out.println("Please Enter Number 3: "); 14 | int num3 = input.nextInt(); 15 | if (num1 > num2 && num1 > num3) { 16 | System.out.printf("%d is Greatest", num1); 17 | } else if (num2 > num1 && num2 > num3) { 18 | System.out.printf("%d is Greatest", num2); 19 | } else { 20 | System.out.printf("%d is Greatest", num3); 21 | } 22 | input.close(); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /Control Statements/Conditional Statements/README.md: -------------------------------------------------------------------------------- 1 | # Java Conditional Statements 2 | 3 | In Java programming, conditional statements are used to perform different actions based on different conditions. There are mainly three types of conditional statements in Java: `if`, `else if`, and `else`. 4 | 5 | ## 1. `if` Statement 6 | 7 | The `if` statement checks a condition and executes a block of code if the condition is true. 8 | 9 | ### Syntax: 10 | ```java 11 | if (condition) { 12 | // Code to be executed if condition is true 13 | } 14 | 15 | ## 2. `else if` Statement 16 | 17 | The `else if` statement allows you to check multiple conditions after the initial `if` statement. If the first `if` condition is false, it evaluates the next condition. 18 | 19 | ### Syntax: 20 | ```java 21 | else if (condition) { 22 | // Code to be executed if condition is true 23 | } 24 | 25 | ## 3. `else` Statement 26 | 27 | The `else` statement is used to execute a block of code if none of the preceding conditions are true. 28 | 29 | ### Syntax: 30 | ```java 31 | else { 32 | // Code to be executed if no condition is true 33 | } 34 | -------------------------------------------------------------------------------- /Control Statements/Conditional Statements/SwitchCase.java: -------------------------------------------------------------------------------- 1 | public class SwitchCase { 2 | public static void main(String[] args) { 3 | int choice = 2; 4 | 5 | switch (choice) { 6 | case 1: 7 | System.out.println("You chose option 1"); 8 | break; 9 | case 2: 10 | System.out.println("You chose option 2"); 11 | break; 12 | case 3: 13 | System.out.println("You chose option 3"); 14 | break; 15 | default: 16 | System.out.println("Invalid choice"); 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /Control Statements/Jumping Statements/JumpingStatementsDemo.java: -------------------------------------------------------------------------------- 1 | public class JumpingStatementsDemo { 2 | public static void main(String[] args) { 3 | // Using break statement 4 | System.out.println("Using break statement:"); 5 | for (int i = 1; i <= 10; i++) { 6 | if (i == 5) { 7 | break; // exit the loop when i is 5 8 | } 9 | System.out.println(i); 10 | } 11 | 12 | // Using continue statement 13 | System.out.println("\nUsing continue statement:"); 14 | for (int i = 1; i <= 10; i++) { 15 | if (i % 2 == 0) { 16 | continue; // skip the rest of the loop body for even numbers 17 | } 18 | System.out.println(i); 19 | } 20 | 21 | // Using return statement 22 | System.out.println("\nUsing return statement:"); 23 | printNumbersUntil(5); // method will return when i equals 5 24 | } 25 | 26 | public static void printNumbersUntil(int limit) { 27 | for (int i = 1; i <= 10; i++) { 28 | if (i == limit) { 29 | return; // exit the method when i equals the limit 30 | } 31 | System.out.println(i); 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /Control Statements/Jumping Statements/README.md: -------------------------------------------------------------------------------- 1 | ## Jumping Statements in Java 2 | 3 | Jumping statements in Java control the flow of execution by allowing you to jump to different parts of your code. The primary jumping statements are `break`, `continue`, and `return`. 4 | 5 | ### `break` Statement 6 | 7 | The `break` statement is used to exit a loop or switch statement prematurely. When a `break` statement is encountered, the control flow jumps out of the current loop or switch block. 8 | 9 | **Example:** 10 | 11 | ```java 12 | for (int i = 1; i <= 10; i++) { 13 | if (i == 5) { 14 | break; // exit the loop when i is 5 15 | } 16 | System.out.println(i); 17 | } 18 | // Output: 1 2 3 4 19 | ``` 20 | 21 | ### `continue` Statement 22 | 23 | The `continue` statement is used to skip the current iteration of a loop and proceed with the next iteration. When a `continue` statement is encountered, the remaining code inside the loop is skipped for the current iteration. 24 | 25 | **Example:** 26 | 27 | ```java 28 | for (int i = 1; i <= 10; i++) { 29 | if (i % 2 == 0) { 30 | continue; // skip the rest of the loop body for even numbers 31 | } 32 | System.out.println(i); 33 | } 34 | // Output: 1 3 5 7 9 35 | ``` 36 | -------------------------------------------------------------------------------- /Control Statements/Looping Statments/DoWhileLoop.java: -------------------------------------------------------------------------------- 1 | public class DoWhileLoop { 2 | public static void main(String[] args) { 3 | int i = 10; 4 | do { // This block will execute first before checking the condition. 5 | System.out.println("This is do Block"); 6 | } while (i != 10); // Condition becomes False. 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /Control Statements/Looping Statments/ForLoop.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | public class ForLoop { 4 | public static void main(String[] args) { 5 | Scanner input = new Scanner(System.in); 6 | System.out.println("Enter a number for which you want a table: "); 7 | int number = input.nextInt(); 8 | for (int i = 1; i <= 10; i++) { 9 | System.out.println(number + "*" + i + "=" + number * i); 10 | } 11 | input.close(); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /Control Statements/Looping Statments/README.md: -------------------------------------------------------------------------------- 1 | 2 | # Java Looping Statements 3 | 4 | In Java, looping statements are used to execute a block of code repeatedly based on a specified condition. There are mainly three types of looping statements in Java: `for`, `while`, and `do-while`. 5 | 6 | 7 | ## 1. `for` Loop 8 | 9 | The `for` loop is used when the number of iterations is known beforehand. 10 | 11 | ### Syntax: 12 | ```java 13 | for (initialization; condition; update) { 14 | // Code to be executed 15 | } 16 | ``` 17 | 18 | ### Example: 19 | ```java 20 | for (int i = 1; i <= 10; i++) { 21 | System.out.println(number + "*" + i + "=" + number * i); 22 | } 23 | ``` 24 | 25 | ## 2. `while` Loop 26 | 27 | The `while` loop is used when the number of iterations is not known beforehand, and the loop continues as long as a specified condition is true. 28 | 29 | ### Syntax: 30 | ```java 31 | while (condition) { 32 | // Code to be executed 33 | } 34 | ``` 35 | 36 | ### Example: 37 | ```java 38 | int i = 1; 39 | while (i <= 10) { 40 | System.out.println(number + "*" + i + "=" + number * i); 41 | i += 1; 42 | } 43 | ``` 44 | 45 | ## 3. `do-while` Loop 46 | 47 | The `do-while` loop is similar to the `while` loop, but the condition is checked after executing the code block, so it always executes at least once. 48 | 49 | ### Syntax: 50 | ```java 51 | do { 52 | // Code to be executed 53 | } while (condition); 54 | ``` 55 | 56 | ### Example: 57 | ```java 58 | int i = 1; 59 | do { 60 | System.out.println("This is Do block: "); 61 | i++; 62 | } while (i <= 10); 63 | ``` 64 | 65 | These looping statements provide flexibility in controlling the flow of execution in Java programs and are essential for repetitive tasks. 66 | ``` 67 | -------------------------------------------------------------------------------- /Control Statements/Looping Statments/WhileLoop.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | public class WhileLoop { 4 | public static void main(String[] args) { 5 | Scanner input = new Scanner(System.in); 6 | System.out.println("Enter a number for which you want a table: "); 7 | int number = input.nextInt(); 8 | int i = 1; 9 | while (i <= 10) { 10 | System.out.println(number + "*" + i + "=" + number * i); 11 | i += 1; 12 | } 13 | input.close(); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Control Statements/README.md: -------------------------------------------------------------------------------- 1 | In Java, there are generally three types of control statements: 2 | 3 | Control statements are programming constructs that dictate the flow of execution within a program. They allow you to make decisions, repeat blocks of code, and alter the normal sequence of program execution. In essence, control statements enable you to control the flow of your program based on various conditions and requirements# Java Control Statements 4 | 5 | ## Selection Statements/Conditional Statements 6 | 7 | Conditional statements are used to make decisions based on certain conditions. 8 | 9 | - **if statement** 10 | - **if-else statement** 11 | - **if-else if-else statement** (also known as nested if-else) 12 | - **switch statement** 13 | 14 | ## Looping Statements (Iteration) 15 | 16 | Iteration statements are used to repeatedly execute a block of code. 17 | 18 | - **for loop** 19 | - **while loop** 20 | - **do-while loop** 21 | 22 | ## Jump Statements 23 | 24 | Jumping statements are used to alter the normal flow of control. 25 | 26 | - **break statement** 27 | - **continue statement** 28 | - **return statement** 29 | - **throw statement** 30 | 31 | These control statements provide various ways to control the flow of execution in Java programs. 32 | -------------------------------------------------------------------------------- /Exception Handling/ChekExcep.java: -------------------------------------------------------------------------------- 1 | class ChekExcep { 2 | public static void main(String[] args){ 3 | String className = "ChekdExcep"; 4 | 5 | try { 6 | Class clz = Class.forName(className); 7 | System.out.println("Class loaded successfully: " +clz.getName()); 8 | } 9 | catch(ClassNotFoundException e){ 10 | System.err.println("class not found: "+ className); 11 | } 12 | } 13 | } -------------------------------------------------------------------------------- /Exception Handling/DefExcepHandler.java: -------------------------------------------------------------------------------- 1 | class DefExcepHandler{ 2 | public static void main(String[] args){ 3 | try{ 4 | 5 | int data=50/0; 6 | System.out.println(data); 7 | } 8 | catch(ArithmeticException ae){ 9 | System.out.println(ae); 10 | } 11 | catch(Exception e){ 12 | System.out.println(e); 13 | System.out.println("parent class exceptionhandles"+e); 14 | } 15 | } 16 | } -------------------------------------------------------------------------------- /Inheritance/Area.java: -------------------------------------------------------------------------------- 1 | public class Area{ 2 | public void calculate(){ 3 | System.out.println("Nothng to calculate"); 4 | } 5 | public void calculate(int x){ 6 | System.out.println("Circle area: "+Math.PI*Math.pow(x,2)); 7 | } 8 | 9 | public void calculate(double x){ 10 | System.out.println("Circle Perimeter"+2*Math.PI*x); 11 | } 12 | 13 | public void calculate(int x,int y){ 14 | System.out.println("Rectangle Area"+x*y); 15 | } 16 | public static void main(String[] args){ 17 | Area a1=new Area(); 18 | a1.calculate(); 19 | a1.calculate(10,20); 20 | a1.calculate(10.5); 21 | a1.calculate(10); 22 | } 23 | } -------------------------------------------------------------------------------- /Inheritance/Hierarchichal.java: -------------------------------------------------------------------------------- 1 | class SuperHero { 2 | String name; 3 | String power; 4 | public SuperHero(String name, String power) { 5 | this.name = name; 6 | this.power = power; 7 | } 8 | public void usePower() { 9 | System.out.println(name + " users " + power); 10 | } 11 | } 12 | 13 | class IronMan extends SuperHero { 14 | public IronMan(String name) { 15 | super(name, " advanced technoloogy "); 16 | } 17 | } 18 | 19 | class SpiderMan extends SuperHero { 20 | public SpiderMan(String name) { 21 | super(name, "Web-slinging ans spuider-like abilities"); 22 | 23 | } 24 | } 25 | 26 | public class Hierarchichal { 27 | public static void main(String[] args) { 28 | IronMan ironMan = new IronMan(" Iron man "); 29 | SpiderMan spiderMan = new SpiderMan("Spider man"); 30 | 31 | ironMan.usePower(); 32 | spiderMan.usePower(); 33 | } 34 | } -------------------------------------------------------------------------------- /Inheritance/Overrid.java: -------------------------------------------------------------------------------- 1 | class Shape { 2 | public int x,y; 3 | void printArea(){ 4 | System.out.println("Prints the area of the shape"); 5 | } 6 | } 7 | 8 | class Rectangle extends Shape { 9 | void printArea() { 10 | System.out.println("Area of rectangle is "+x*y); 11 | } 12 | } 13 | 14 | public class Overrid { 15 | public static void main(String[] args){ 16 | Rectangle r=new Rectangle(); 17 | r.x = 5; 18 | r.y = 10; 19 | r.printArea(); 20 | } 21 | } -------------------------------------------------------------------------------- /Inheritance/TransMul.java: -------------------------------------------------------------------------------- 1 | class Bicycle { 2 | void displayFeatures() { 3 | System.out.println("Features: Pedals, Manual power"); 4 | } 5 | } 6 | 7 | class Motorbike extends Bicycle { 8 | void displayFeatures() { 9 | super.displayFeatures(); 10 | System.out.println("Added feature by Motorbike: Engine"); 11 | } 12 | } 13 | 14 | class ElectricBike extends Motorbike { 15 | void displayFeatures() { 16 | super.displayFeatures(); 17 | System.out.println("New Feature by Electric Nike: electric power and battery"); 18 | } 19 | } 20 | class TransMul{ 21 | public static void main(String args[]) { 22 | ElectricBike myEbike = new ElectricBike(); 23 | myEbike.displayFeatures(); 24 | } 25 | } -------------------------------------------------------------------------------- /Java Programs/Arithmetic.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | public class Arithmetic { 4 | public static void main(String[] args) { 5 | Scanner sc = new Scanner(System.in); 6 | 7 | System.out.print("Enter first number: "); 8 | double num1 = sc.nextDouble(); 9 | System.out.print("Enter second number: "); 10 | double num2 = sc.nextDouble(); 11 | 12 | System.out.println("Choose operation:"); 13 | System.out.println("1. Addition (+)"); 14 | System.out.println("2. Subtraction (-)"); 15 | System.out.println("3. Multiplication (*)"); 16 | System.out.println("4. Division (/)"); 17 | System.out.print("Enter your choice (1-4): "); 18 | int choice = sc.nextInt(); 19 | 20 | 21 | double result = 0; 22 | switch (choice) { 23 | case 1: 24 | result = num1 + num2; 25 | System.out.println(num1 + " + " + num2 + " = " + result); 26 | break; 27 | case 2: 28 | result = num1 - num2; 29 | System.out.println(num1 + " - " + num2 + " = " + result); 30 | break; 31 | case 3: 32 | result = num1 * num2; 33 | System.out.println(num1 + " * " + num2 + " = " + result); 34 | break; 35 | case 4: 36 | if (num2 != 0) { 37 | result = num1 / num2; 38 | System.out.println(num1 + " / " + num2 + " = " + result); 39 | } else { 40 | System.out.println("Error: Division by zero is not allowed."); 41 | } 42 | break; 43 | default: 44 | System.out.println("Invalid choice. Please choose a number between 1 and 4."); 45 | } 46 | 47 | sc.close(); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /Java Programs/ArithmeticOperations.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | public class ArithmeticOperations { 4 | public static void main(String[] args) { 5 | Scanner scanner = new Scanner(System.in); 6 | 7 | // Input first number 8 | System.out.print("Enter the first number: "); 9 | double num1 = scanner.nextDouble(); 10 | 11 | // Input second number 12 | System.out.print("Enter the second number: "); 13 | double num2 = scanner.nextDouble(); 14 | 15 | // Perform arithmetic operations 16 | double sum = num1 + num2; 17 | double difference = num1 - num2; 18 | double product = num1 * num2; 19 | double quotient = num1 / num2; 20 | 21 | // Display results 22 | System.out.println("Sum: " + num1 + " + " + num2 + " = " + sum); 23 | System.out.println("Difference: " + num1 + " - " + num2 + " = " + difference); 24 | System.out.println("Product: " + num1 + " * " + num2 + " = " + product); 25 | System.out.println("Quotient: " + num1 + " / " + num2 + " = " + quotient); 26 | 27 | // Close the scanner 28 | scanner.close(); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /Java Programs/Armstrong.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | public class Armstrong { 4 | public static void main(String[] args) { 5 | Scanner sc = new Scanner(System.in); 6 | System.out.print("Enter a number: "); 7 | int number = sc.nextInt(); 8 | sc.close(); 9 | 10 | // Calculate sum of cubes of digits 11 | int originalNumber = number; 12 | int sum = 0; 13 | int digits = String.valueOf(number).length(); 14 | 15 | while (number != 0) { 16 | int digit = number % 10; 17 | sum += Math.pow(digit, digits); 18 | number /= 10; 19 | } 20 | 21 | // Check if number is Armstrong 22 | if (sum == originalNumber) { 23 | System.out.println(originalNumber + " is an Armstrong number."); 24 | } else { 25 | System.out.println(originalNumber + " is not an Armstrong number."); 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /Java Programs/ArrayIndexExample.java: -------------------------------------------------------------------------------- 1 | public class ArrayIndexExample { 2 | public static void main(String[] args) { 3 | int[] numbers = {1, 2, 3, 4, 5}; 4 | 5 | try { 6 | // Trying to access an index beyond the array length 7 | System.out.println("Accessing element at index 10: " + numbers[10]); 8 | } catch (ArrayIndexOutOfBoundsException e) { 9 | // Catching and handling the exception 10 | System.out.println("ArrayIndexOutOfBoundsException caught: " + e.getMessage()); 11 | } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /Java Programs/ClassObject.java: -------------------------------------------------------------------------------- 1 | class Student{ 2 | //Instance variables 3 | String name; 4 | int rollno; 5 | String branch; 6 | 7 | //Object initializing 8 | Student(String name, int rollno, String branch){ 9 | this.name = name; 10 | this.rollno = rollno; 11 | this.branch = branch; 12 | } 13 | 14 | //method to display info 15 | void displayInfo() { 16 | System.out.println("Name: "+name); 17 | System.out.println("Roll Number: "+rollno); 18 | System.out.println("Branch: "+branch); 19 | } 20 | } 21 | 22 | public class ClassObject { 23 | public static void main(String[] args){ 24 | Student s1 = new Student("Yethishwar", 97, "Ai&DS"); 25 | Student s2 = new Student("Chintu", 100, "CSE"); 26 | s1.displayInfo(); 27 | s2.displayInfo(); 28 | } 29 | } 30 | 31 | -------------------------------------------------------------------------------- /Java Programs/Comparision.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | class Comparision{ 3 | public static void main(String[] args){ 4 | Scanner sc = new Scanner(System.in); 5 | System.out.println("Enter a programming language that you know"); 6 | String input_string = sc.next(); 7 | String predefined_string = "Java"; 8 | if(input_string.equals(predefined_string)) 9 | { 10 | System.out.println("You strings are matched"); } 11 | else 12 | { 13 | System.out.println("Sorry Your strings aren't matched"); 14 | } 15 | 16 | sc.close(); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Java Programs/Concatenation.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | class Concatenation { 3 | public static void main(String[] args){ 4 | String str1 = "My name is "; 5 | String str2 = "I am studying in "; 6 | Scanner sc = new Scanner(System.in); 7 | System.out.println("Enter Your name:"); 8 | String name = sc.next(); 9 | String my_name = str1.concat(name); 10 | System.out.println("Enter your college name:"); 11 | String college = sc.next(); 12 | String result = str2 + " " + college; 13 | System.out.printf("Here is %s Details",+name); 14 | System.out.println(my_name); 15 | System.out.println(result); 16 | } 17 | } 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /Java Programs/CustomException.java: -------------------------------------------------------------------------------- 1 | class MyCustomException extends Exception { 2 | public MyCustomException(String message) { 3 | super(message); 4 | } 5 | } 6 | 7 | class CustomExceptionExample { 8 | public void validateAge(int age) throws MyCustomException { 9 | if (age < 18) { 10 | throw new MyCustomException("Age should be greater than or equal to 18."); 11 | } else { 12 | System.out.println("Age is valid."); 13 | } 14 | } 15 | } 16 | 17 | public class CustomException { 18 | public static void main(String[] args) { 19 | CustomExceptionExample example = new CustomExceptionExample(); 20 | 21 | try { 22 | example.validateAge(15); 23 | } catch (MyCustomException e) { 24 | System.out.println("Custom Exception caught: " + e.getMessage()); 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /Java Programs/ExceptionHandling.java: -------------------------------------------------------------------------------- 1 | public class ExceptionHandling { 2 | 3 | public static void main(String[] args) { 4 | try { 5 | int[] numbers = {1, 2, 3}; 6 | System.out.println("Element at index 3: " + numbers[3]); // Accessing index 3 which doesn't exist 7 | } catch (ArrayIndexOutOfBoundsException e) { 8 | System.out.println("Error: Index out of bounds."); 9 | } catch (NullPointerException e) { 10 | System.out.println("Error: Array is null."); 11 | } finally { 12 | System.out.println("Finally block executed."); 13 | } 14 | 15 | System.out.println("Program continues..."); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Java Programs/ExceptionHandlingExample.java: -------------------------------------------------------------------------------- 1 | public class ExceptionHandlingExample { 2 | public static void main(String[] args) { 3 | // Example for ArithmeticException 4 | try { 5 | int result = 10 / 0; // Attempting to divide by zero 6 | } catch (ArithmeticException e) { 7 | System.out.println("ArithmeticException occurred: " + e.getMessage()); 8 | } 9 | 10 | // Example for ArrayIndexOutOfBoundsException 11 | int[] numbers = {1, 2, 3}; 12 | try { 13 | System.out.println("Accessing element at index 3: " + numbers[3]); // Accessing out-of-bounds index 14 | } catch (ArrayIndexOutOfBoundsException e) { 15 | System.out.println("ArrayIndexOutOfBoundsException occurred: " + e.getMessage()); 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Java Programs/FactorialExample.java: -------------------------------------------------------------------------------- 1 | public class FactorialExample { 2 | public static void main(String[] args) { 3 | int number = 5; // Change this number to calculate factorial for a different number 4 | long factorial = 1; 5 | 6 | // Calculate factorial 7 | for (int i = 1; i <= number; ++i) { 8 | factorial *= i; 9 | } 10 | 11 | // Display the factorial 12 | System.out.println("Factorial of " + number + " = " + factorial); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /Java Programs/Final.java: -------------------------------------------------------------------------------- 1 | // Parent class with final method 2 | class Parent { 3 | // Final method that cannot be overridden 4 | final void display() { 5 | System.out.println("This method cannot be overridden."); 6 | } 7 | } 8 | 9 | // Main class to test the program 10 | public class Main { 11 | public static void main(String[] args) { 12 | // Create an object of Parent class 13 | Parent parent = new Parent(); 14 | 15 | // Call final method 16 | parent.display(); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Java Programs/InputMethods.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | public class InputMethods { 4 | public static void main(String[] args) { 5 | Scanner scanner = new Scanner(System.in); 6 | 7 | // Basic Input methods 8 | System.out.println("Enter your name: "); 9 | String name = scanner.next(); 10 | scanner.nextLine(); 11 | System.out.println("Enter your college name: "); 12 | String college = scanner.nextLine(); // Read the whole line 13 | System.out.println("Enter your Roll number: "); 14 | int rollNumber = scanner.nextInt(); 15 | System.out.println("Enter your 1st Year marks Percentage: "); 16 | float marks = scanner.nextFloat(); // variable declaration 17 | scanner.close(); 18 | 19 | System.out.println("--------- Your Details ---------\n"); 20 | System.out.println("Name :" + name); 21 | System.out.println("\nCollege : " + college); 22 | System.out.println("\nRoll No : " + rollNumber); 23 | System.out.println("\nPercentage : " + marks); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /Java Programs/Main.java: -------------------------------------------------------------------------------- 1 | final class BaseClass { 2 | 3 | public void display() { 4 | System.out.println("This is a final class."); 5 | } 6 | } 7 | 8 | 9 | public class Main { 10 | public static void main(String[] args) { 11 | BaseClass obj = new BaseClass(); 12 | obj.display(); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /Java Programs/MethodOverLoad.java: -------------------------------------------------------------------------------- 1 | class MethodOverLoad { 2 | // Method to add two integers 3 | public int add(int a, int b) { 4 | return a + b; 5 | } 6 | 7 | // Method to add three integers 8 | public int add(int a, int b, int c) { 9 | return a + b + c; 10 | } 11 | 12 | // Method to add two floats 13 | public float add(float a, float b) { 14 | return a + b; 15 | } 16 | 17 | // Method to add two doubles 18 | public double add(double a, double b) { 19 | return a + b; 20 | } 21 | 22 | // Method to add three doubles (return type should be double) 23 | public double add(double a, double b, double c) { 24 | return a + b + c; 25 | } 26 | 27 | public static void main(String[] args) { 28 | MethodOverLoad math = new MethodOverLoad(); 29 | System.out.println("Sum of 2 and 3: " + math.add(2, 3)); 30 | System.out.println("Sum of 2, 3 and 4: " + math.add(2, 3, 4)); 31 | System.out.println("Sum of 2.5 and 3.5: " + math.add(2.5, 3.5)); 32 | System.out.println("Sum of 2.5, 3.5, and 4.5: " + math.add(2.5, 3.5, 4.5)); 33 | System.out.println("Sum of 2.0f and 3.0f: " + math.add(2.0f, 3.0f)); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /Java Programs/MethodOverRid.java: -------------------------------------------------------------------------------- 1 | class Animal { 2 | public void makeSound(){ 3 | System.out.println("Animals barks very loudly"); 4 | } 5 | } 6 | 7 | class Dog extends Animal{ 8 | @Override 9 | public void makeSound(){ 10 | System.out.println("Dog Barks"); 11 | } 12 | } 13 | 14 | class MethodOverRid { 15 | public static void main(String[] args){ 16 | Dog dogobj = new Dog(); 17 | Animal animalobj = new Animal(); 18 | dogobj.makeSound(); 19 | 20 | animalobj.makeSound(); 21 | } 22 | } -------------------------------------------------------------------------------- /Java Programs/MultiLevel.java: -------------------------------------------------------------------------------- 1 | // Parent class 2 | class Parent { 3 | void displayParent() { 4 | System.out.println("Hey Programmer, I'm in the Parent Class"); 5 | } 6 | } 7 | 8 | // Child class inheriting from Parent 9 | class Child extends Parent { 10 | void displayChild() { 11 | System.out.println("Hey Programmer, I'm in the Child Class"); 12 | } 13 | } 14 | 15 | // GrandChild class inheriting from Child 16 | class GrandChild extends Child { 17 | void displayGrandChild() { 18 | System.out.println("Hey Programmer, I'm in the GrandChild Class"); 19 | } 20 | } 21 | 22 | public class MultiLevel { 23 | public static void main(String[] args) { 24 | GrandChild obj = new GrandChild(); 25 | obj.displayGrandChild(); // Method from GrandChild class 26 | obj.displayChild(); // Method from Child class (inherited) 27 | obj.displayParent(); // Method from Parent class (inherited) 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /Java Programs/Mutiple.java: -------------------------------------------------------------------------------- 1 | // Interface defining methods related to a vehicle 2 | interface Vehicle { 3 | void start(); 4 | void stop(); 5 | } 6 | 7 | // Interface defining methods related to a camera 8 | interface Camera { 9 | void capturePhoto(); 10 | void recordVideo(); 11 | } 12 | 13 | // Class implementing both Vehicle and Camera interfaces 14 | 15 | class Car implements Vehicle, Camera { 16 | // Vehicle interface methods 17 | public void start() { 18 | System.out.println("Car started."); 19 | } 20 | 21 | public void stop() { 22 | System.out.println("Car stopped."); 23 | } 24 | 25 | // Camera interface methods 26 | public void capturePhoto() { 27 | System.out.println("Photo captured."); 28 | } 29 | 30 | public void recordVideo() { 31 | System.out.println("Video recording started."); 32 | } 33 | 34 | // Additional method specific to Car class 35 | void drive() { 36 | System.out.println("Car is being driven."); 37 | } 38 | } 39 | 40 | public class Mutiple { 41 | public static void main(String[] args) { 42 | Car myCar = new Car(); 43 | 44 | // Using methods from Vehicle interface 45 | myCar.start(); 46 | myCar.stop(); 47 | 48 | // Using methods from Camera interface 49 | myCar.capturePhoto(); 50 | myCar.recordVideo(); 51 | 52 | // Using method specific to Car class 53 | myCar.drive(); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /Java Programs/MyRun.java: -------------------------------------------------------------------------------- 1 | // Implementing the Runnable interface 2 | class MyRunnable implements Runnable { 3 | public void run() { 4 | System.out.println("Thread using Runnable is running..."); 5 | } 6 | } 7 | 8 | public class MyRun { 9 | public static void main(String[] args) { 10 | // Creating an instance of MyRunnable 11 | MyRunnable myRunnable = new MyRunnable(); 12 | 13 | // Creating a Thread object with MyRunnable instance 14 | Thread thread = new Thread(myRunnable); 15 | 16 | // Starting the thread 17 | thread.start(); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /Java Programs/MyRunnable.java: -------------------------------------------------------------------------------- 1 | // Implementing the Runnable interface 2 | class MyRunnable implements Runnable { 3 | public void run() { 4 | System.out.println("Thread using Runnable is running..."); 5 | } 6 | } 7 | 8 | public class MyRunnable { 9 | public static void main(String[] args) { 10 | // Creating an instance of MyRunnable 11 | MyRunnable myRunnable = new MyRunnable(); 12 | 13 | // Creating a Thread object with MyRunnable instance 14 | Thread thread = new Thread(myRunnable); 15 | 16 | // Starting the thread 17 | thread.start(); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /Java Programs/OneDimensionalArrayExample.java: -------------------------------------------------------------------------------- 1 | public class OneDimensionalArrayExample { 2 | public static void main(String[] args) { 3 | // Declaration and initialization of an array 4 | int[] numbers = {1, 2, 3, 4, 5}; 5 | 6 | // Accessing elements of the array and printing them 7 | System.out.println("Elements of the array:"); 8 | for (int i = 0; i < numbers.length; i++) { 9 | System.out.println("Element at index " + i + ": " + numbers[i]); 10 | } 11 | 12 | // Modifying an element of the array 13 | numbers[2] = 30; 14 | 15 | // Accessing and printing the modified array 16 | System.out.println("\nModified elements of the array:"); 17 | for (int i = 0; i < numbers.length; i++) { 18 | System.out.println("Element at index " + i + ": " + numbers[i]); 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /Java Programs/PreventInheritanceExample.java: -------------------------------------------------------------------------------- 1 | final class BaseClass { 2 | void displayMessage() { 3 | System.out.println("This method cannot be overridden."); 4 | } 5 | } 6 | 7 | // Uncommenting the below line will result in compilation error 8 | // class DerivedClass extends BaseClass {} 9 | 10 | public class PreventInheritanceExample { 11 | public static void main(String[] args) { 12 | BaseClass obj = new BaseClass(); 13 | obj.displayMessage(); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Java Programs/ScannerMethods.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | public class ScannerMethods { 4 | public static void main(String[] args) { 5 | Scanner sc = new Scanner(System.in); 6 | 7 | System.out.println("Enter input suitable for nextLine() method"); 8 | String my_string = sc.nextLine(); 9 | 10 | System.out.println("Enter input suitable for next() method"); 11 | String my_word = sc.next(); 12 | 13 | System.out.println("Enter input suitable for nextInt() method"); 14 | int my_integer = sc.nextInt(); 15 | 16 | System.out.println("Enter input suitable for nextFloat() method"); 17 | float my_float = sc.nextFloat(); 18 | 19 | System.out.println("Enter input suitable for nextDouble() method"); 20 | double my_double = sc.nextDouble(); 21 | 22 | // Consume the leftover newline 23 | 24 | 25 | System.out.println("Your word is " + my_word); 26 | System.out.println("Your integer is " + my_integer); 27 | System.out.println("Your float is " + my_float); 28 | System.out.println("Your double is " + my_double); 29 | System.out.println("Your string is " + my_string); 30 | 31 | sc.close(); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /Java Programs/SingleLevel.java: -------------------------------------------------------------------------------- 1 | class Parent { 2 | void displayParent(){ 3 | System.out.println("Hey Programmer i'am in the Parent Class"); 4 | } 5 | } 6 | 7 | class Child extends Parent { 8 | void displayChild() { 9 | System.out.println("Hey Programmer i'am in the Child Class"); 10 | } 11 | } 12 | 13 | public class SingleLevel { 14 | public static void main(String[] args){ 15 | Child obj = new Child(); 16 | obj.displayChild(); 17 | obj.displayParent(); 18 | } 19 | } 20 | 21 | -------------------------------------------------------------------------------- /Java Programs/StringConcatenationExample.java: -------------------------------------------------------------------------------- 1 | public class StringConcatenationExample { 2 | public static void main(String[] args) { 3 | // Example strings 4 | String firstName = "John"; 5 | String lastName = "Doe"; 6 | 7 | // Concatenating strings using the + operator 8 | String fullName = firstName + " " + lastName; 9 | 10 | // Displaying the concatenated string 11 | System.out.println("Full Name: " + fullName); 12 | 13 | // Concatenating strings using the concat() method 14 | String message = "Hello, ".concat(firstName).concat("!"); 15 | 16 | // Displaying the concatenated message 17 | System.out.println(message); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /Java Programs/StringMethods.java: -------------------------------------------------------------------------------- 1 | public class StringMethods { 2 | 3 | public static void main(String[] args) { 4 | // Creating a string 5 | String str = "Hello, World!"; 6 | 7 | // Length of the string 8 | int length = str.length(); 9 | System.out.println("Length of the string: " + length); 10 | 11 | // Character at specific index 12 | char charAt5 = str.charAt(5); 13 | System.out.println("Character at index 5: " + charAt5); 14 | 15 | // Substring from index 7 to end 16 | String substring = str.substring(7); 17 | System.out.println("Substring from index 7: " + substring); 18 | 19 | // Concatenation with another string 20 | String concatStr = str.concat(" Welcome!"); 21 | System.out.println("Concatenated string: " + concatStr); 22 | 23 | // Index of a character or substring 24 | int indexOfWorld = str.indexOf("World"); 25 | System.out.println("Index of 'World': " + indexOfWorld); 26 | 27 | // Replace characters or substring 28 | String replacedStr = str.replace("Hello", "Hi"); 29 | System.out.println("String after replacement: " + replacedStr); 30 | 31 | // Convert to uppercase 32 | String uppercase = str.toUpperCase(); 33 | System.out.println("Uppercase: " + uppercase); 34 | 35 | // Convert to lowercase 36 | String lowercase = str.toLowerCase(); 37 | System.out.println("Lowercase: " + lowercase); 38 | 39 | // Check if starts with a substring 40 | boolean startsWithHello = str.startsWith("Hello"); 41 | System.out.println("Starts with 'Hello': " + startsWithHello); 42 | 43 | // Check if ends with a substring 44 | boolean endsWithWorld = str.endsWith("World!"); 45 | System.out.println("Ends with 'World!': " + endsWithWorld); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /Java Programs/SuperClass.java: -------------------------------------------------------------------------------- 1 | class Parent { 2 | void display() { // Changed method name from display to show 3 | System.out.println("Parent class method"); 4 | } 5 | } 6 | 7 | class Child extends Parent { 8 | void display() { // Changed method name from display to show 9 | super.display(); // Calling method from immediate parent class 10 | System.out.println("Child class method"); 11 | } 12 | 13 | void anotherMethod() { 14 | super.display(); // Also possible to call from another method 15 | } 16 | } 17 | 18 | public class SuperClass { 19 | public static void main(String[] args) { 20 | Child child = new Child(); 21 | child.display(); // Calls Child's overridden show method 22 | child.anotherMethod(); // Calls Parent's show method through Child's method 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /Java Programs/ThreadClass.java: -------------------------------------------------------------------------------- 1 | // Extending Thread class 2 | class MyThread extends Thread { 3 | public void run() { 4 | System.out.println("Thread using Thread class is running..."); 5 | } 6 | } 7 | 8 | public class ThreadClass { 9 | public static void main(String[] args) { 10 | // Creating an instance of MyThread 11 | MyThread myThread = new MyThread(); 12 | 13 | // Starting the thread 14 | myThread.start(); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Java Programs/TwoDArray.java: -------------------------------------------------------------------------------- 1 | public class TwoDArray { 2 | public static void main(String[] args) { 3 | // Declaring a 2D array with 3 rows and 4 columns 4 | int[][] twoDArray = new int[3][4]; 5 | 6 | // Initializing elements of the 2D array 7 | for (int i = 0; i < 3; i++) { 8 | for (int j = 0; j < 4; j++) { 9 | twoDArray[i][j] = i + j; // Assigning values based on row and column indices 10 | } 11 | } 12 | 13 | // Accessing and printing elements of the 2D array 14 | System.out.println("Printing 2D Array:"); 15 | for (int i = 0; i < 3; i++) { 16 | for (int j = 0; j < 4; j++) { 17 | System.out.print(twoDArray[i][j] + " "); 18 | } 19 | System.out.println(); // Move to the next line after printing each row 20 | 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /Java Programs/TypeCasting.java: -------------------------------------------------------------------------------- 1 | public class TypeCasting { 2 | public static void main(String[] args) { 3 | // Implicit Typecasting (Widening Conversion) 4 | int myInt = 100; 5 | long myLong = myInt; // Implicit casting from int to long 6 | float myFloat = myInt; // Implicit casting from int to float 7 | double myDouble = myFloat; // Implicit casting from float to double 8 | 9 | System.out.println("Implicit Typecasting:"); 10 | System.out.println("int to long: " + myLong); 11 | System.out.println("int to float: " + myFloat); 12 | System.out.println("float to double: " + myDouble); 13 | 14 | // Explicit Typecasting (Narrowing Conversion) 15 | double myDouble2 = 123.456; 16 | float myFloat2 = (float) myDouble2; // Explicit casting from double to float 17 | long myLong2 = (long) myDouble2; // Explicit casting from double to long 18 | int myInt2 = (int) myDouble2; // Explicit casting from double to int 19 | 20 | System.out.println("\nExplicit Typecasting:"); 21 | System.out.println("double to float: " + myFloat2); 22 | System.out.println("double to long: " + myLong2); 23 | System.out.println("double to int: " + myInt2); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /Java Programs/VariableTypesExample.java: -------------------------------------------------------------------------------- 1 | public class VariableTypesExample { 2 | 3 | // Instance variable (or non-static variable) 4 | int instanceVar = 10; 5 | 6 | // Class variable (or static variable) 7 | static String classVar = "Hello"; 8 | 9 | public void methodWithLocalVariable() { 10 | // Local variable 11 | double localVar = 3.14; 12 | 13 | System.out.println("Instance Variable: " + instanceVar); 14 | System.out.println("Class Variable: " + classVar); 15 | System.out.println("Local Variable: " + localVar); 16 | } 17 | 18 | public static void main(String[] args) { 19 | VariableTypesExample obj = new VariableTypesExample(); 20 | 21 | // Accessing instance variable through object 22 | System.out.println("Instance Variable accessed through object: " + obj.instanceVar); 23 | 24 | // Accessing class variable directly using class name 25 | System.out.println("Class Variable accessed directly: " + VariableTypesExample.classVar); 26 | 27 | // Calling method with local variable 28 | obj.methodWithLocalVariable(); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2024 Madavaram Yethishwar 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Java Programming Language 2 | Java is a high-level, class-based, object-oriented programming language that is designed to have as few implementation dependencies as possible. It is a general-purpose programming language intended to let application developers write once, run anywhere (WORA), meaning that compiled Java code can run on all platforms that support Java without the need for recompilation. Java applications are typically compiled to bytecode that can run on any Java virtual machine (JVM) regardless of the underlying computer architecture. The syntax of Java is similar to C and C++, but it has fewer low-level facilities than either of them. The language was first released by Sun Microsystems in 1995 and later acquired by Oracle Corporation. 3 | 4 | ## Java Features 5 | + Object Oriented 6 | + Robust 7 | + Platform Independent 8 | + Architecture Neutral 9 | + Portable 10 | + High Performance 11 | + Distributing 12 | + MultiThreaded 13 | + Dynamic 14 | + Reliable 15 | + Interpreted 16 | -------------------------------------------------------------------------------- /Strings/String Tokenizers/StringFirst.java: -------------------------------------------------------------------------------- 1 | //Java Program using first Constructor(using Single parameter). 2 | 3 | import java.util.StringTokenizer; 4 | class StringFirst { 5 | public static void main(String[] args) { 6 | StringTokenizer st = new StringTokenizer("This statement is passed directly inside the class."); 7 | System.out.println("Tokens extracted from the string using StringTokenizer: "); 8 | while (st.hasMoreTokens()) { 9 | System.out.println(st.nextToken()); 10 | } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /Strings/String Tokenizers/StringSecond.java: -------------------------------------------------------------------------------- 1 | //Java Program using Second Constructor(using input string and delimiter). 2 | //Syntax: StringTokenizer(String str, String delim) 3 | 4 | import java.util.StringTokenizer; 5 | import java.util.Scanner; 6 | 7 | class StringSecond { 8 | public static void main(String[] args) { 9 | Scanner sc = new Scanner(System.in); 10 | System.out.println("Enter the string: "); 11 | String s1 = sc.nextLine(); 12 | StringTokenizer st = new StringTokenizer(s1," "); 13 | System.out.println("Tokens extracted from the string using StringTokenizer: "); 14 | while (st.hasMoreTokens()) { 15 | System.out.println(st.nextToken()); 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Strings/String Tokenizers/StringThird.java: -------------------------------------------------------------------------------- 1 | //Java Program using Third Construtor. 2 | //Syntax: StringTokenizer(String str, String delim, boolean returnDelims) 3 | 4 | 5 | import java.util.StringTokenizer; 6 | import java.util.Scanner; 7 | 8 | class StringThird { 9 | public static void main(String[] args) { 10 | Scanner sc = new Scanner(System.in); 11 | System.out.println("Enter the string separated by commas: "); 12 | String s1 = sc.nextLine(); 13 | /*When we pass true as the third parameter to the StringTokenizer constructor, 14 | it indicates that the delimiters should be treated as tokens and included in the result.*/ 15 | StringTokenizer st = new StringTokenizer(s1, ",", true); 16 | 17 | System.out.println("Tokens extracted from the string using StringTokenizer: "); 18 | while (st.hasMoreTokens()) { 19 | System.out.println(st.nextToken()); 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /Strings/StringBuff.java: -------------------------------------------------------------------------------- 1 | public class StringBuff { 2 | 3 | } 4 | -------------------------------------------------------------------------------- /Strings/StringBuil.java: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MYethishwar/JavaLabCraft/d13015f74f0723b520e564e623c0dde0f78cbd5d/Strings/StringBuil.java -------------------------------------------------------------------------------- /Strings/Strings.java: -------------------------------------------------------------------------------- 1 | public class Strings { 2 | public static void main(String[] args) { 3 | 4 | int Myinteger = 97; 5 | 6 | String text = "Hello"; 7 | String blank = " "; 8 | String name = "Yethishwar"; 9 | String greeting = text + blank + name; 10 | 11 | System.out.println(greeting); 12 | System.out.println("Hello" + " " + name); // Concatenation 13 | 14 | System.out.println("Thi is Integer value:" + " " + Myinteger); 15 | 16 | } 17 | } --------------------------------------------------------------------------------