├── 1. Variables.txt ├── 10. Control_Flow_Statement_IF_ELSE_IF.txt ├── 11. Control_Flow_Statement_SWITCH_CASE.txt ├── 12. Looping_While.txt ├── 13. Loop_do_while.txt ├── 14. Loop_for.txt ├── 15. Loop_for_each.txt ├── 16. Loop_Nested.txt ├── 16.1 Loop_Nested.txt ├── 17. Break_Statement.txt ├── 18. Continue_Statement.txt ├── 19. Labelled_Break.txt ├── 2. Explicit_type_conversion.txt ├── 20. Labelled_Continue.txt ├── 21. Arrays.txt ├── 22. Jagged_Array.txt ├── 23. String_Methods.txt ├── 24. Classes and Objects.txt ├── 25. Inheritance.txt ├── 25.1 Single Inheritance.txt ├── 25.2 Multilevel Inheritance.txt ├── 25.2.1 Inheritance.txt ├── 25.3 Polymorphism.txt ├── 25.4 final keyword.txt ├── 25.5 Abstraction.txt ├── 25.6 Abstraction.txt ├── 26. File Path.txt ├── 26.1 Creating File.txt ├── 26.2 Deleting File.txt ├── 26.3 Copying File.txt ├── 26.4 Moving File.txt ├── 27. Exception Handling.txt ├── 27.1 try and catch.txt ├── 27.2 Multiple Catch.txt ├── 27.3 Throw.txt ├── 27.4 throws.txt ├── 27.5 finally.txt ├── 27.6 User defined Exception.txt ├── 28. Anonymous Class.txt ├── 28.1 Lambda Functions.txt ├── 29. Date Time API.txt ├── 3. Implicit_type_conversion.txt ├── 30. MultiThreading.txt ├── 30. Multithreading Synchronization.txt ├── 30.2 Multithreading Join.txt ├── 31. Generics.txt ├── 31.1 Generic methods.txt ├── 32. Collections - Set.txt ├── 32. Collections List.txt ├── 32.2 Collections - queue.txt ├── 32.3 Collections - Map.txt ├── 33. Jdbc.txt ├── 4. Type_promotion.txt ├── 5. Scanner_Class.txt ├── 6. Scanner_Class_number.txt ├── 7. Commandline_Arguments.txt ├── 7. Control_Flow_Statement_IF.txt ├── 8. Control_Flow_Statement_ELSE_IF.txt ├── 8. Control_Flow_Statement_IF.txt ├── 9. Control_Flow_Statement_ELSE_IF.txt ├── 9. Control_Flow_Statement_NESTED_IF.txt └── README.md /1. Variables.txt: -------------------------------------------------------------------------------- 1 | class VariableApp {     2 | int mark = 95 ;//instance variable 3 | static char grade = ‘S’; // static variable 4 | public static void main(String[] args) {          5 | float average=95.0 // local variable    6 |   } 7 | } 8 | -------------------------------------------------------------------------------- /10. Control_Flow_Statement_IF_ELSE_IF.txt: -------------------------------------------------------------------------------- 1 | class IfElseIFControlStructure{     2 |   public static void main(String[] args){          3 | int colorValue=2; 4 | if(colorValue==1) 5 | System.out.println(“Color Blue!”); 6 | else if(colorValue==2) 7 | System.out.println(“Color Red!”); 8 | else 9 | System.out.println(“Color Green!”);  10 | } 11 | } 12 | 13 | -------------------------------------------------------------------------------- /11. Control_Flow_Statement_SWITCH_CASE.txt: -------------------------------------------------------------------------------- 1 | class SwitchControlStructure{     2 |   public static void main(String[] args){ 3 | int letter='A'; 4 | switch(letter){ 5 | case 'a': 6 | System.out.println("Lowercase Letter"); 7 | break; 8 | case 'A': 9 | System.out.println("Uppercase Letter"); 10 | break; 11 | 12 | default: 13 | System.out.println("Invalid Letter"); 14 | break; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /12. Looping_While.txt: -------------------------------------------------------------------------------- 1 | class WhileStructure{     2 |   public static void main(String[] args){   3 | int counter = 1; 4 | while (counter < 11) 5 | { 6 | System.out.println("Count is: " + counter); 7 | counter++; 8 | } 9 |        } 10 | } 11 | -------------------------------------------------------------------------------- /13. Loop_do_while.txt: -------------------------------------------------------------------------------- 1 | class DoWhileStructure{     2 |   public static void main(String[] args){   3 | int counter = 1; 4 | do { 5 | System.out.println("Count is: " + counter); 6 | counter++; 7 | } while (counter < 11) ; 8 |        } 9 | } 10 | -------------------------------------------------------------------------------- /14. Loop_for.txt: -------------------------------------------------------------------------------- 1 | class ForStructure{     2 |   public static void main(String[] args) { 3 | for(int count = 1; count<10; count++) { 4 | System.out.println("Count is: " + count); 5 | } 6 | } 7 | 8 | -------------------------------------------------------------------------------- /15. Loop_for_each.txt: -------------------------------------------------------------------------------- 1 | class ForEachApp{ 2 | public static void main (String args[]){ 3 | int[] marks = { 125, 132, 95, 116, 110 }; 4 | int maxSoFar = marks[0]; 5 |         for (int indexValue : marks){ //for each loop 6 |              if (indexValue > maxSoFar){ 7 |                   maxSoFar = indexValue; 8 |              } 9 |          } 10 | System.out.println("The highest score is " +maxSoFar); 11 | }} 12 | -------------------------------------------------------------------------------- /16. Loop_Nested.txt: -------------------------------------------------------------------------------- 1 | class NestedWhileAPP{ 2 | public static void main (String args[]){ 3 | int outerLoop=1,innerLoop=1; 4 | whlie(outerLoop<=5){ 5 | while(innerLoop<=5){ 6 | System.out.print(“*”); 7 | innerLoop++; 8 | } 9 | System.out.println(“ “); 10 | outerLoop++; 11 | innerLoop=1; 12 | } 13 | } 14 | } 15 | 16 | -------------------------------------------------------------------------------- /16.1 Loop_Nested.txt: -------------------------------------------------------------------------------- 1 | class NestedForApp 2 | { 3 | public static void main (String args[]) 4 | { 5 | int rows = 5; 6 | for (int i = 1; i <= rows; ++i){ // outer loop 7 | for (int j = 1; j <= i; ++j) { // inner loop to print the numbers 8 | System.out.print(j + " "); 9 | } 10 | System.out.println(""); 11 | } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /17. Break_Statement.txt: -------------------------------------------------------------------------------- 1 | class BreakApp{ 2 | public static void main (String args[]){ 3 | for(int count = 1;count<10;count++) { 4 | if(count ==5) 5 | break; //exit from the current loop 6 | System.out.println("Count is: " + count); 7 | } 8 | } 9 | 10 | -------------------------------------------------------------------------------- /18. Continue_Statement.txt: -------------------------------------------------------------------------------- 1 | class ContinueApp { 2 | public static void main (String args[]) { 3 | for(int count = 1;count<10;count++) { 4 | if(count ==5) 5 | continue; 6 | System.out.println("Count is: " + count); 7 | } 8 | } 9 | 10 | -------------------------------------------------------------------------------- /19. Labelled_Break.txt: -------------------------------------------------------------------------------- 1 | class LabeledBreakApp{ 2 | public static void main(String args[]){ 3 | first: // First label 4 | for (int i = 0; i < 3; i++) { 5 | second: // Second label 6 | for (int j = 0; j < 3; j++) { 7 | if (1== i && 1 == j) { 8 | break first; // Using break statement with label 9 | } 10 | System.out.println(i + " " + j); 11 | } 12 | } 13 | } 14 | } 15 | 16 | -------------------------------------------------------------------------------- /2. Explicit_type_conversion.txt: -------------------------------------------------------------------------------- 1 | class ConversionExplicit {     2 |   public static void main(String[] args) {          3 | double d = 100.04; 4 | long l = (long)d; //convert double into long 5 | int i = (int)l; // long convert into int 6 | System.out.println("Double value "+d); 7 | System.out.println("Long value "+l); 8 | System.out.println("Int value "+i); 9 |   } 10 | } 11 | -------------------------------------------------------------------------------- /20. Labelled_Continue.txt: -------------------------------------------------------------------------------- 1 | class LabeledContinueApp { 2 | public static void main(String args[]){ 3 | first: // First label 4 | for (int i = 0 ; i < 3; i++) { 5 | second: // Second label 6 | for (int j = 0; j < 3; j++) { 7 | if (1 == i && 1 == j) { 8 | continue second; // Using continue statement with label 9 | } 10 | System.out.println(i + " " + j); 11 | } 12 | } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /21. Arrays.txt: -------------------------------------------------------------------------------- 1 | public static void main(String[] args) { 2 | int arr[] = {23,67,84,75,95,34,54,6,4,6,86}; 3 | System.out.println("Length: "+arr.length); 4 | System.out.println("Elements are:"); 5 | for (int i = arr.length-1 ;i >= 0 ; i--) 6 | { 7 | System.out.print(arr[i] + " "); 8 | } 9 | } 10 | 11 | public static void main(String[] args) { 12 | int a[][] = new int[3][2]; 13 | a[0][0] = 56; 14 | a[0][1] = 74; 15 | a[1][0] = 88; 16 | a[1][1] = 34; 17 | a[2][0] = 24; 18 | a[2][1] = 43; 19 | for (int i = 0; i < 3 ; i ++){ 20 | for (int j = 0; j < 2 ; j ++){ 21 | System.out.print(a[i][j]+ " "); 22 | } System.out.println(); } 23 | }} 24 | -------------------------------------------------------------------------------- /22. Jagged_Array.txt: -------------------------------------------------------------------------------- 1 | public static void main(String[] args) { 2 | // Declaring 2-D array with 4 rows 3 | int arr[][] = new int[4][]; 4 | // Making the above array Jagged 5 | // First row has 3 columns 6 | arr[0] = new int[3]; 7 | // Second row has 2 columns 8 | arr[1] = new int[2]; 9 | arr[2] = new int[1]; 10 | arr[3] = new int[4]; 11 | // Initializing array 12 | int count = 5; 13 | for (int i = 0; i < arr.length; i++) 14 | for (int j = 0; j < arr[i].length; j++) { 15 | arr[i][j] = count; 16 | count+=5; 17 | } 18 | // Displaying the values of 2D Jagged array 19 | System.out.println("Contents of 2D Jagged Array"); 20 | for (int i = 0; i < arr.length; i++) { 21 | for (int j = 0; j < arr[i].length; j++) 22 | System.out.print(arr[i][j] + " "); 23 | System.out.println(); 24 | } 25 | } 26 | } 27 | 28 | -------------------------------------------------------------------------------- /23. String_Methods.txt: -------------------------------------------------------------------------------- 1 | public static void main(String[] args) { 2 | System.out.println("Vy Technical Carrer Development Center"); 3 | System.out.println("Length = "+"VyTCDC".length()); 4 | System.out.println("Vy".concat("TcDc")); 5 | System.out.println("Vy Technical Carrer".substring(3, 12)); 6 | System.out.println("Vy".toUpperCase()); 7 | System.out.println("Vy".toLowerCase()); 8 | System.out.println(" Vy TCDC ".trim()); 9 | System.out.println("Vy".equals("Vy")); 10 | System.out.println("Vy".equals("VY")); 11 | System.out.println("Vy".equalsIgnoreCase("VY")); 12 | System.out.println("VyTCDC".startsWith("Vy")); 13 | System.out.println("VyTCDC".endsWith("dc")); 14 | System.out.println("VyTCDC".toCharArray()); } 15 | -------------------------------------------------------------------------------- /24. Classes and Objects.txt: -------------------------------------------------------------------------------- 1 | public class Employee { 2 | String name = “Ram Kumar"; 3 | int empID = 1205; 4 | int age; 5 | 6 | public void displayEmployee() { 7 | System.out.println(“Employee Name: "+name); 8 | System.out.println(“Employee Id:”+empID); 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /25. Inheritance.txt: -------------------------------------------------------------------------------- 1 | public class Shirt extends Clothing { 2 | private int _neckSize; 3 | public int getNeckSize(){ 4 | return _neckSize; 5 | } 6 | public void setNeckSize(int nSize){ 7 | this.neckSize = nSize; 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /25.1 Single Inheritance.txt: -------------------------------------------------------------------------------- 1 | class Employee { //parent class 2 | String empName; 3 | int empId; 4 | void setData(String name, int id){ // base class method 5 | empName=name; 6 | empId=id; 7 | } 8 | void displayData(){ // base class method 9 | System.out.println(“Employee Name:”+empName); 10 | System.out.println(“ID:”+empId); 11 | } 12 | } 13 | class Manager extends Employee { //child class 14 | String empDept; 15 | void setDept(String dept) { //sub class method 16 | empDept = dept; 17 | } 18 | void displayDept(){ //sub class method 19 | System.out.println(“Department:”+dept); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /25.2 Multilevel Inheritance.txt: -------------------------------------------------------------------------------- 1 | class Person { //Level 1:Base class 2 | String name; 3 | int age; 4 | void setPersonData(String name, int age){ 5 | this.name=name; 6 | this.age=age; 7 | } 8 | void displayPersonData() { 9 | System.out.println(“Name:”+name); 10 | System.out.println(“Age:”+age); 11 | } 12 | } 13 | class Employee extends Person{ //Level 2:Base class 14 | int empId; 15 | void setEmpData(String id){ 16 | empId=id; 17 | } 18 | void displayEmpData(){ 19 | System.out.println(“ID:”+empID); 20 | } 21 | } 22 | 23 | 24 | 25 | class Manager extends Employee { //child class 26 | String dept; 27 | float sal; 28 | void setManagerData(String depart, float salary){ 29 | dept = depart; 30 | sal=salary; 31 | } 32 | void displayManagerData(){ 33 | System.out.println(“Department:”+dept); 34 | System.out.println(“Salary :”+ sal); 35 | } 36 | } 37 | public class MlevelInherDemo{ 38 | public static void main(String args[]) { 39 | Manager m=new Manager(); //child class object 40 | m.setPersonData(“Arun”, 34); 41 | m.setEmpData(“M123”); 42 | m.setManagerData(“Marketing”,60000); 43 | m.displayPersonData(); 44 | m.displayEmpData(); 45 | m.displayManagerData(); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /25.2.1 Inheritance.txt: -------------------------------------------------------------------------------- 1 | class CricketPlayer { //Base class 2 | String playerName; 3 | String teamName; 4 | void setPlayerData(String playerName, String teamName){ 5 | this.playerName=playerName; 6 | this.teamName=teamName; 7 | } 8 | void displayPlayerData() { 9 | System.out.println(“ Player Name:”+playerName); 10 | System.out.println(“Team Name:”+teamName); 11 | } 12 | } 13 | class Batsman extends CricketPlayer { //Derived class 1 14 | int hScore; 15 | float batAvg; 16 | 17 | void setBatsmanData(int hScore, float batAvg){ 18 | this.hScore=hScore; 19 | this.batAvg=batAvg; 20 | } 21 | void displayBatsmanData(){ 22 | System.out.println(“ Highest Score:”+hScore); 23 | System.out.println(“Batting Average:”+batAvg); 24 | } 25 | } 26 | class Bowler extends CricketPlayer { //Derived class 2 27 | int wickets; 28 | float bowlAvg; 29 | void setBowlerData(int wickets, float bowlAvg){ 30 | this.wickets=wickets; 31 | this.bowlAvg=bowlAvg; 32 | } 33 | void displayBowlerData() { 34 | System.out.println(“ No. of Wickets:”+wickets); 35 | System.out.println(“Bowling Average:”+bowlAvg); 36 | } 37 | } 38 | 39 | 40 | 41 | public class HInherDemo{ 42 | public static void main(String args[]){ 43 | Batsman B1=new Batsman(); //Base Class Object 44 | Bowler B2=new Bowler(); 45 | B1.setPlayerData(“Sachin”, “India”); 46 | B1.setBatsmanData(200, 84.5); 47 | B2.setPlayerData(“Bumra”, “India”); 48 | B2.setBowlerData(140, 6.75); 49 | B1.displayPlayerData(); 50 | B1.displayBatsmanData(); 51 | B2.displayPlayerData(); 52 | B2.displayBowlerData(); 53 | } 54 | } 55 | 56 | -------------------------------------------------------------------------------- /25.3 Polymorphism.txt: -------------------------------------------------------------------------------- 1 | /*This abstract code illustrates the upcasting. */ 2 | class A {  3 | }  4 | 5 | class B extends A {  6 | } 7 | 8 |  class Demo { 9 | public static void main(String[] args) { 10 | A a = new B(); //upcasting 11 | } 12 | } 13 | /*This example demonstrates method overriding**/ 14 | class Vehicle { 15 | void run() { 16 | System.out.println(“Vehicle is running”); 17 | } 18 | } 19 | class Truck extends Vehicle { 20 | void run() { 21 | System.out.println(“Truck is running”); 22 | } 23 | } 24 | class OverrideDemo 25 | { 26 | public static void main(String args[]) 27 | { 28 | 29 | Vehicle obj = new Vehicle(); 30 | obj.run(); //Vehicle class run () method 31 | Vehicle obj = new Truck(); 32 | obj.run(); //Truck class run () method 33 | 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /25.4 final keyword.txt: -------------------------------------------------------------------------------- 1 | /*This program demonstrates the use of final keyword */ 2 | public class Sample { 3 | final double pi; 4 | public Sample() { 5 | pi = 3.14; 6 | } 7 | 8 | public Sample(double pi) { 9 | this.pi = pi; 10 | } 11 | public static void main(String[] args) { 12 | Sample obj = new Sample(22.0/7.0); 13 | System.out.println(obj.pi); 14 | } 15 | } 16 | /* This program demonstrates the use of final keyword*/ 17 | class Base { 18 | public final void display(String s) { 19 | System.out.println(s); 20 | } 21 | } 22 | 23 | class Sample extends Base { 24 | public void display(String s) { 25 | System.out.println(s); 26 | } public static void main(String args[]) { 27 | Sample obj = new Sample(); 28 | obj.display(“TRY ME”); 29 | } 30 | } 31 | /*This program demonstrates the use of final keyword */ 32 | final class Base { 33 | public final void display(String s) { 34 | System.out.println(s); 35 | } 36 | } 37 | class Sample extends Base { 38 | public void display(String s) { 39 | System.out.println(s); 40 | } 41 | public static void main(String args[]) { 42 | Sample obj = new Sample(); 43 | obj.display(“TRY ME”); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /25.5 Abstraction.txt: -------------------------------------------------------------------------------- 1 | abstract class Shape { 2 | void draw() { 3 | System.out.println("drawing..."); 4 | } 5 | abstract void area(); 6 | abstract void perimeter(); 7 | } 8 | class Rectangle extends Shape { 9 | private int length, breadth; 10 | Rectangle(int length, int breadth){ 11 | this.length = length; 12 | this.breadth = breadth; 13 | } 14 | @Override 15 | void area() { 16 | System.out.println("Area of Rectangle: " + (length * breadth)); 17 | } 18 | @Override 19 | void perimeter() { 20 | System.out.println("Perimeter of Rectangle: " + (2 * (length + breadth))); 21 | } } 22 | class Square extends Shape { 23 | private int side; 24 | Square(int side){ 25 | this.side = side; 26 | } 27 | @Override 28 | void area() { 29 | System.out.println("Area of Square: " + (side * side)); 30 | } 31 | @Override 32 | void perimeter() { 33 | System.out.println("Perimeter of Square: " + (4 * side)); 34 | } } 35 | class Circle extends Shape { 36 | private double radius; 37 | final static double PI = 3.14; 38 | 39 | Circle(double radius){ 40 | this.radius = radius; 41 | } 42 | @Override 43 | void area() { 44 | System.out.println("Area of Circle: " + (PI * radius * radius)); 45 | } 46 | 47 | @Override 48 | void perimeter() { 49 | System.out.println("Perimeter of Circle: " + (2 * PI * radius)); 50 | } } 51 | class MainTest { 52 | public static void main(String args[]) { 53 | Shape s; 54 | s = new Rectangle(3,5); 55 | s.area(); 56 | s.perimeter(); 57 | s = new Square(5); 58 | s.area(); 59 | s.perimeter(); 60 | s = new Circle(4.5); 61 | s.area(); 62 | s.perimeter(); } 63 | } 64 | -------------------------------------------------------------------------------- /25.6 Abstraction.txt: -------------------------------------------------------------------------------- 1 | interface Vehicle { 2 | void changeGear(int); 3 | void speedUp(int); 4 | void applyBrakes(int); 5 | } 6 | class Bicycle implements Vehicle{ 7 | int speed; 8 | int gear; 9 | //Abstract Method Implementation 10 | public void changeGear(int newGear){ 11 | gear = newGear; 12 | } 13 | //Abstract Method Implementation 14 | public void speedUp(int increment){ 15 | speed = speed + increment; 16 | } 17 | //Abstract Method Implementation 18 | public void applyBrakes(int decrement){ 19 | speed = speed - decrement; 20 | } 21 | 22 | public void printStates() { 23 | System.out.println("Speed: " + speed + " Gear: " + gear); 24 | } 25 | } 26 | 27 | class Bike implements Vehicle { 28 | int speed; 29 | int gear; 30 | //Abstract Method Implementation 31 | public void changeGear(int newGear){ 32 | gear = newGear; 33 | } 34 | //Abstract Method Implementation 35 | public void speedUp(int increment){ 36 | speed = speed + increment; 37 | } 38 | //Abstract Method Implementation 39 | public void applyBrakes(int decrement){ 40 | speed = speed - decrement; } 41 | public void printStates() { 42 | System.out.println("Speed: " + speed + " Gear: " + gear); 43 | } 44 | } 45 | class MainClass { 46 | public static void main (String[] args) { 47 | Bicycle bicycle = new Bicycle(); //Bicycle Class Object Creation 48 | bicycle.changeGear(3); 49 | bicycle.speedUp(2); 50 | bicycle.applyBrakes(1); 51 | System.out.println("Bicycle present state :"); 52 | bicycle.printStates(); 53 | Bike bike = new Bike(); //Bike Class Object Creation 54 | bike.changeGear(2); 55 | bike.speedUp(3); 56 | bike.applyBrakes(3); 57 | 58 | System.out.println("Bike present state :"); 59 | bike.printStates(); 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /26. File Path.txt: -------------------------------------------------------------------------------- 1 | // Java program to demonstrate the java.nio.file.Path interface methods 2 | import java.nio.file.Path; 3 | import java.nio.file.Paths; 4 | class PathMethods{ 5 | public static void main(String args[]) { 6 | Path p1 = Paths.get ("C:\\Users\\Senthil\\eclipse-workspace\\Sample\\src\\FileStream\\input.txt"); 7 | Path normalizedPath = p1.normalize(); 8 | workspace\\Sample\\src\\FileStream\\input.txt"); 9 | System.out.println("NormalizedPath: "+ normalizedPath); 10 | Path subPath = p1.subpath (1, 3); 11 | System.out.println("SubPath: "+ subPath); 12 | System.out.println("getFileName: "+ p1.getFileName()); 13 | System.out.println("getParent: "+p1.getParent()); 14 | System.out.println("getNameCount: "+p1.getNameCount()); 15 | System.out.println("getRoot: " + p1.getRoot()); 16 | System.out.println("isAbsolute: "+p1.isAbsolute()); 17 | System.out.println("toAbsolutePath: "+p1.toAbsolutePath()); 18 | System.out.println("toURI: "+p1.toUri()); 19 | if(p1.equals(p2)) 20 | System.out.println("Both are equal"); 21 | else 22 | System.out.println("Both are not equal"); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /26.1 Creating File.txt: -------------------------------------------------------------------------------- 1 | // Java program to demonstrate to create directory 2 | import java.nio.file.*; 3 | class CreateDirectory{ 4 | public static void main(String args[]) { 5 | try{ 6 | Path path = Paths.get("C:\\Users\\Senthil\\eclipse-workspace\\Sample\\src\\FileStream\\SampleDirectory"); 7 | if (!Files.exists(path)) { 8 | Files.createDirectory(path); 9 | System.out.println("Directory created"); 10 | } else { 11 | System.out.println("Directory already exists"); 12 | } 13 | }catch (IOException e) { System.out.println(e); //Exception details } 14 | } } 15 | // Java program to demonstrate to create file 16 | import java.nio.file.*; 17 | class CreateFile{ 18 | public static void main(String args[]) { 19 | try{ 20 | Path path1 = Paths.get("C:\\Users\\Senthil\\eclipse-workspace\\Sample\\src\\FileStream\\Sample.txt"); 21 | if (!Files.exists(path1)) { 22 | Files.createFile(path1); 23 | System.out.println("File created"); 24 | } else { 25 | System.out.println("File already exists"); 26 | } 27 | }catch (IOException e) { System.out.println(e); //Exception details } 28 | } } 29 | -------------------------------------------------------------------------------- /26.2 Deleting File.txt: -------------------------------------------------------------------------------- 1 | // Java program to demonstrate to delete a file 2 | class DeleteFileDirectory { 3 | public static void main(String args[]) { 4 | //File to delete 5 | Path path = Paths.get("C:\\Users\\Senthil\\eclipse-workspace\\Sample\\src\\FileStream\\Sample.txt"); 6 | //Directory to delete 7 | Path path = Paths.get("C:\\Users\\Senthil\\eclipse-workspace\\Sample\\src\\FileStream\\SampleDirectory"); 8 | try{ Files.deleteIfExists(path); 9 | } 10 | catch(NoSuchFileException e){ 11 | System.out.println("No such file/directory exists"); 12 | } 13 | 14 | catch(DirectoryNotEmptyException e){ 15 | System.out.println("Directory is not empty."); 16 | } 17 | catch(IOException e){ 18 | System.out.println("Invalid permissions."); 19 | } 20 | 21 | System.out.println("Deletion successful."); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /26.3 Copying File.txt: -------------------------------------------------------------------------------- 1 | // Java program to demonstrate to copy a file 2 | class CopyFileDirectory { 3 | public static void main(String args[]) { 4 | Path source = Paths.get("C:\\Users\\Senthil\\eclipse-workspace\\Sample\\src\\FileStream\\output.txt"); 5 | Path target = Paths.get("C:\\Users\\Senthil\\eclipse-workspace\\Sample\\src\\FileStream\\Sample.txt"); 6 | try { 7 | System.out.println(source+" "+ "Copied to:"+" "+ Files.copy(source, target,StandardCopyOption.REPLACE_EXISTING)); 8 | }catch (IOException e) { System.out.println(e); } 9 | } 10 | } 11 | 12 | -------------------------------------------------------------------------------- /26.4 Moving File.txt: -------------------------------------------------------------------------------- 1 | // Java program to demonstrate to copy a file 2 | class MoveFileDirectory { 3 | public static void main(String args[]) { 4 | Path source = Paths.get("C:\\Users\\Senthil\\eclipse-workspace\\Sample\\src\\FileStream\\output.txt"); 5 | Path target = Paths.get("C:\\Users\\Senthil\\eclipse-workspace\\Sample\\src\\FileStream\\Sample.txt"); 6 | try { 7 | System.out.println(source+" "+ “Moved to:"+" "+ Files.move(source, target,StandardCopyOption.REPLACE_EXISTING)); 8 | } // Catch block to handle the exceptions 9 | catch (IOException e) { System.out.println(e); } 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /27. Exception Handling.txt: -------------------------------------------------------------------------------- 1 | class SimpleArithmetic { 2 | public static void main(String args[]){ 3 | 4 | int result=75/0; //exception occur 5 | System.out.println(“Arithmetic Operation result: “+ result); 6 | …. 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /27.1 try and catch.txt: -------------------------------------------------------------------------------- 1 | // Java program to demonstrate exception handling. 2 | class ThrowsExecp{ 3 | public static void main(String args[]){ 4 | try{ 5 | String str = null; 6 | System.out.println(str.length()); 7 | } 8 | catch(NullPointerException e){ 9 | System.out.println(e); 10 | } 11 | System.out.println(“rest of the code”);//rest of the code 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /27.2 Multiple Catch.txt: -------------------------------------------------------------------------------- 1 | // Java program to demonstrate multiple catch block. 2 | public class ExceptionDemo{ 3 | public static void main(String args[]){ 4 | try{ 5 | int a[]=new int[5]; 6 | a[5]=30/0; 7 | } 8 | catch(ArithmeticException e){ System.out.println(e); } 9 | catch(ArrayIndexOutOfBoundsException e) { System.out.println(e); } 10 | catch(Exception e) { System.out.println(e); } 11 | System.out.println("rest of the code..."); 12 | } 13 | } 14 | 15 | -------------------------------------------------------------------------------- /27.3 Throw.txt: -------------------------------------------------------------------------------- 1 | // Java program to demonstrate the use of throw keyword. 2 | public class ExceptionDemo{ 3 | static void validate(int num){ 4 | if(num<0) 5 | throw new ArithmeticException(“Invalid value"); 6 | else 7 | System.out.println(“Valid to proceed"); 8 | } 9 | public static void main(String args[]){ 10 | try{ validate(-10); } 11 | catch(Exception e){ System.out.println(“Error:"+e); } 12 | System.out.println("rest of the code..."); 13 | } 14 | } 15 | 16 | -------------------------------------------------------------------------------- /27.4 throws.txt: -------------------------------------------------------------------------------- 1 | // Java program to demonstrate the use of throws keyword. 2 | class ExceptionDemo{ 3 | static void fun() throws IllegalAccessException { 4 | System.out.println("Inside fun(). "); 5 | throw new IllegalAccessException("demo"); 6 | } 7 | public static void main(String args[]) { 8 | try{ fun(); } 9 | catch(IllegalAccessException e) { System.out.println("caught in main."); } 10 | } 11 | } 12 | 13 | -------------------------------------------------------------------------------- /27.5 finally.txt: -------------------------------------------------------------------------------- 1 | // Java program to demonstrate finally block. 2 | class ExceptionDemo{ 3 | public static void main(String args[]) { 4 | try { 5 | int data=25/5; 6 | System.out.println(data); 7 | } 8 | catch(NullPointerException e) { System.out.println(e); } 9 | finally { 10 | System.out.println("finally block is always executed"); 11 | } 12 | System.out.println("rest of the code..."); 13 | } 14 | } 15 | 16 | -------------------------------------------------------------------------------- /27.6 User defined Exception.txt: -------------------------------------------------------------------------------- 1 | // Java program to demonstrate user defined exception. 2 | class InvalidAgeException extends Exception { 3 | InvalidAgeException(String s) { 4 | // Call constructor of parent Exception 5 | super(s); 6 | } 7 | } 8 | class ExceptionDemo{ 9 | static void validate(int age)throws InvalidAgeException { 10 | if(age<18) 11 | throw new InvalidAgeException("not eligible"); 12 | else 13 | System.out.println(“Eligible"); 14 | } 15 | -------------------------------------------------------------------------------- /28. Anonymous Class.txt: -------------------------------------------------------------------------------- 1 | abstract class Person{ 2 | abstract void eat(); 3 | } 4 | class AnonymousExample { 5 | public static void main(String args[]){ 6 | Person obj=new Person(){ 7 | void eat(){ 8 | System.out.println(“Nice Fruits"); 9 | } 10 | }; 11 | obj.eat(); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /28.1 Lambda Functions.txt: -------------------------------------------------------------------------------- 1 | interface Welcome{ 2 | public String welcomeMessage(); 3 | } 4 | public class LambdaExpressionExample{ 5 | public static void main(String[] args) { 6 | Welcome obj=()->{ 7 | return “Welcome to Learning!"; 8 | }; 9 | System.out.println(obj.welcomeMessage()); 10 | } 11 | } 12 | 13 | -------------------------------------------------------------------------------- /29. Date Time API.txt: -------------------------------------------------------------------------------- 1 | import java.time.LocalDate; 2 | import java.time.LocalTime; 3 | import java.time.LocalDateTime; 4 | import java.time.format.DateTimeFormatter; 5 | public class DateTimeExample { 6 | public static void main(String[] args) { 7 | LocalDate LD = LocalDate.now(); 8 | LocalTime LT = LocalTime.now(); 9 | LocalDateTime LDT = LocalDateTime.now(); 10 | 11 | DateTimeFormatter DTF = DateTimeFormatter.ofPattern 12 | ("dd-MM-yy"); 13 | String formatString = LDT.format(DTF); 14 | System.out.println(LD); 15 | System.out.println(LT); 16 | System.out.println(LDT); 17 | System.out.println(formatString); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /3. Implicit_type_conversion.txt: -------------------------------------------------------------------------------- 1 | class ConversionAutomatic {     2 |   public static void main(String[] args) {          3 | int i = 100; 4 | long l = i; // automatic type conversion 5 | float f = l; // automatic type conversion 6 | System.out.println("Int value "+i); 7 | System.out.println("Long value "+l); 8 | System.out.println("Float value "+f); 9 |   } 10 | } 11 | -------------------------------------------------------------------------------- /30. MultiThreading.txt: -------------------------------------------------------------------------------- 1 | public class Thread1{ 2 | public static void main(String a[]){ 3 | try { 4 | for(int j=5;j>0;j--) { 5 | System.out.println("Main Thread : "+j); 6 | Thread.sleep(1000); 7 | } 8 | }catch(InterruptedException e) { } 9 | System.out.println("Main Thread Exiting"); 10 | } 11 | } 12 | 13 | class ThreadA2 extends Thread { 14 | public void run() { 15 | try { 16 | for(int i = 0;i<5;i++) { 17 | Thread.sleep(5000); 18 | System.out.println("Executing second thread.."); 19 | } 20 | }catch(InterruptedException ex){ 21 | System.out.println("Thread Interrupted..."); 22 | } 23 | } 24 | } 25 | class demo2 26 | { 27 | public static void main(String args[]) 28 | { 29 | ThreadA1 t1 = new ThreadA1(); 30 | t1.start(); 31 | ThreadA2 t2 = new ThreadA2(); 32 | t2.start(); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /30. Multithreading Synchronization.txt: -------------------------------------------------------------------------------- 1 | package threading; 2 | class fivetable extends Thread { 3 | public synchronized void run() { 4 | for(int i =1;i<=5;i++) 5 | System.out.println(i + " Fives are" + (i * 5)); 6 | } 7 | } 8 | class seventable extends Thread { 9 | public synchronized void run() { 10 | for(int i =1;i<=5;i++) 11 | System.out.println(i + " Sevens are" + (i * 7)); 12 | } 13 | } 14 | class thirteentable extends Thread { 15 | public synchronized void run() { 16 | for(int i =1;i<=5;i++) 17 | System.out.println(i + " Thirteens are" + (i * 13)); 18 | } 19 | } 20 | class sync 21 | { public static void main(String arg[]) 22 | { 23 | fivetable f; 24 | seventable s; 25 | thirteentable t; 26 | f = new fivetable(); 27 | s = new seventable(); 28 | t = new thirteentable(); 29 | f.start(); 30 | s.start(); 31 | t.start(); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /30.2 Multithreading Join.txt: -------------------------------------------------------------------------------- 1 | class ThreadA extends Thread 2 | { public void run() { 3 | try 4 | { for(int i = 0;i<5;i++) 5 | { 6 | Thread.sleep(1000); 7 | System.out.println("Executing first thread.."); 8 | } 9 | } 10 | catch(InterruptedException ex) 11 | { 12 | System.out.println("Thread Interrupted..."); 13 | } } 14 | } 15 | class ThreadB extends Thread 16 | { public void run() { 17 | try 18 | { for(int i = 0;i<5;i++) 19 | { 20 | Thread.sleep(2000); 21 | System.out.println("Executing second thread.."); 22 | } 23 | } 24 | catch(InterruptedException ex) 25 | { 26 | System.out.println("Thread Interrupted..."); 27 | } 28 | } 29 | } 30 | class demo3 31 | { public static void main(String args[]) 32 | { 33 | ThreadA t1 = new ThreadA(); 34 | t1.start(); 35 | try 36 | { 37 | t1.join(); 38 | System.out.println("End of first thread..."); 39 | } 40 | catch(Exception e) 41 | { 42 | System.out.println("Thread Interrupted..."); 43 | } 44 | ThreadB t2 = new ThreadB(); 45 | t2.start(); 46 | try{ 47 | t2.join(); 48 | System.out.println("End of second thread..."); 49 | } 50 | catch(Exception e){ 51 | System.out.println("Thread Interrupted..."); 52 | } 53 | } 54 | } 55 | 56 | -------------------------------------------------------------------------------- /31. Generics.txt: -------------------------------------------------------------------------------- 1 | A generic type is a class or interface that is parameterized over types. We use angle brackets (<>) to specify the type parameter. 2 | class Demo { 3 | // T stands for "Type" 4 | private T t; 5 | public void set(T t) { 6 | this.t = t; 7 | } 8 | 9 | public T get() { 10 | return t; 11 | } 12 | } 13 | // Driver class 14 | class GenericDemo { 15 | public static void main (String[] args) { 16 | // instance of Integer type 17 | Demo iObj = new Demo(); 18 | iObj.set(25); 19 | System.out.println(iObj.get()); 20 | // instance of String type 21 | 22 | Demo sObj = new Demo(); 23 | sObj.set("Demo"); 24 | System.out.println(sObj.get()); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /31.1 Generic methods.txt: -------------------------------------------------------------------------------- 1 | // This example demonstrates user defined Generic methods 2 | class GenericMethod { 3 | static void genericDisplay (T element) { 4 | // A Generic method example 5 | System.out.println(element); 6 | System.out.println(element.getClass().getName() +" = " + element); 7 | } 8 | 9 | public static void main(String[] args) { 10 | // Driver method 11 | // Calling generic method with Integer argument 12 | genericDisplay(11); 13 | // Calling generic method with String argument 14 | genericDisplay(“Test"); 15 | // Calling generic method with double argument 16 | genericDisplay(1.0); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /32. Collections - Set.txt: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | public class HashSet2 { 3 | public static void main(String args[]){ 4 | HashSet set = new HashSet(); 5 | set.add("This"); 6 | set.add("is"); 7 | set.add("a"); 8 | set.add(null); 9 | set.add("test"); 10 | displaySet(set); 11 | } 12 | static void displaySet(HashSet set) { 13 | System.out.println("The size of the set is:" + set.size()); 14 | Iterator i = set.iterator(); 15 | while(i.hasNext()) { 16 | Object o = i.next(); 17 | if(o == null) 18 | System.out.println("null"); 19 | else 20 | System.out.println(o.toString()); 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /32. Collections List.txt: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | public class List { 3 | public static void main(String[] args) { 4 | // creating an empty LinkedList 5 | Collection list = new LinkedList(); 6 | // use add() method to add elements in the list 7 | list.add("Vy"); 8 | list.add("Tc"); 9 | list.add("Dc"); 10 | // Output the present list 11 | System.out.println("The list is: " + list); 12 | 13 | // Adding new elements to the end 14 | list.add("Last"); 15 | list.add("Element"); 16 | // printing the new list 17 | System.out.println("The new List is: " + list); 18 | System.out.println(); 19 | // remove a particular element 20 | list.remove("Last"); 21 | // print modified set1 22 | System.out.println("List after removing Last : " + list); 23 | // Create an iterator for the list using iterator() method 24 | Iterator iter = list.iterator(); 25 | // Displaying the values after iterating through the list 26 | System.out.println("\nThe iterator values" + " of list are: "); 27 | while (iter.hasNext()) { 28 | System.out.print(iter.next() + " "); 29 | } 30 | } 31 | } 32 | 33 | 34 | -------------------------------------------------------------------------------- /32.2 Collections - queue.txt: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | public class Queue1 { 3 | public static void main(String[] args) { 4 | Queue queue = new LinkedList<>(); 5 | // add elements to the queue 6 | queue.add("apple"); 7 | queue.add("banana"); 8 | queue.add("cherry"); 9 | // print the queue 10 | System.out.println("Queue: " + queue); 11 | // remove the element at the front of the queue 12 | String front = queue.remove(); 13 | 14 | System.out.println("Removed element: " + front); 15 | // print the updated queue 16 | System.out.println("Queue after removal: " + queue); 17 | // add another element to the queue 18 | queue.add("date"); 19 | // peek at the element at the front of the queue 20 | String peeked = queue.peek(); 21 | System.out.println("Peeked element: " + peeked); 22 | // print the updated queue 23 | System.out.println("Queue after peek: " + queue); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /32.3 Collections - Map.txt: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | public class Map2 { 3 | public static void main(String[] args) { 4 | // Creating an empty HashMap 5 | Map map = new HashMap<>(); 6 | // Inserting entries in the Map 7 | // using put() method 8 | map.put("vishal", 10); 9 | map.put("sachin", 30); 10 | map.put("vaibhav", 20); 11 | // Iterating over Map 12 | for (Map.Entry e : map.entrySet()) 13 | // Printing key-value pairs 14 | System.out.println(e.getKey() + " "+ e.getValue()); 15 | }} 16 | 17 | 18 | -------------------------------------------------------------------------------- /33. Jdbc.txt: -------------------------------------------------------------------------------- 1 | import java.sql.*; 2 | public class DBConnect { 3 | public static void main(String args[]){ 4 | try{ 5 | //step1 load the driver class 6 | Class.forName("com.mysql.cj.jdbc.Driver"); 7 | //step2 create the connection object 8 | Connection con=DriverManager.getConnection( "jdbc:mysql://localhost:3306/company", “username",“password"); 9 | //step3 create the statement object 10 | Statement stmt=con.createStatement(); 11 | 12 | //step4 execute query 13 | //ResultSet rs=stmt.executeQuery("create table employee (empid number(4), empname varchar2(25))"); 14 | //ResultSet rs=stmt.executeQuery("insert into employee values(1002, 'Rajesh')"); 15 | stmt.executeUpdate("update employee set empname=‘Aravind' where empid=120"); 16 | //ResultSet rs=stmt.executeQuery("select * from employee"); 17 | //while(rs.next()) 18 | //System.out.println(rs.getInt(1)+" "+rs.getString(2)); 19 | //ResultSet rs=stmt.executeQuery("delete from employee"); 20 | //step5 close the connection object 21 | con.close(); 22 | }catch(Exception e){ System.out.println(e);} 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /4. Type_promotion.txt: -------------------------------------------------------------------------------- 1 | class TypePromotion{     2 |   public static void main(String[] args){          3 | byte b = 50; 4 | b = (byte)(b * 2); //promote into int 5 | System.out.println(b); 6 |   } 7 | } 8 | 9 | 10 | class TypePromotion1{     11 |   public static void main(String[] args){          12 | byte b = 42; 13 | char c = 'a'; 14 | short s = 1024; 15 | int i = 50000; 16 | float f = 5.67f; 17 | double d = .1234; 18 | double result = (f * b) + (i / c) - (d * s); //promote into double 19 | System.out.println("result = " + result); 20 |   } 21 | } 22 | 23 | 24 | -------------------------------------------------------------------------------- /5. Scanner_Class.txt: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; //import Scanner class from util package 2 | public class ReadSomeInput { 3 | public static void main(String[] args) { 4 | Scanner console = new Scanner(System.in); 5 | System.out.print("Enter your Name : "); 6 | String name = console.next(); 7 | System.out.println(“Hi, ” +name+“ . Welcome to the Training Program ...”); 8 | console.close(); 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /6. Scanner_Class_number.txt: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | class r2 3 | { public static void main(String Args[]) { 4 | int a,b,c; 5 | System.out.println("Enter 2 Nums: "); 6 | Scanner inp = new Scanner(System.in); 7 | a=inp.nextInt(); 8 | b=inp.nextInt(); 9 | c=a+b; 10 | System.out.println("a+b: "+c); 11 | }} 12 | -------------------------------------------------------------------------------- /7. Commandline_Arguments.txt: -------------------------------------------------------------------------------- 1 | class sums 2 | { public static void main(String args[]) { 3 | int sum,num1,num2,num3; 4 | // args[] is a type of string. so it has to be converted into int 5 | 6 | num1= Integer.parseInt(args[0]); 7 | num2= Integer.parseInt(args[1]); 8 | num3= Integer.parseInt(args[2]); 9 | 10 | sum = num1+num2+num3; 11 | 12 | System.out.println("The sum is:" + sum); 13 | System.out.println(args[3]); 14 | }} 15 | -------------------------------------------------------------------------------- /7. Control_Flow_Statement_IF.txt: -------------------------------------------------------------------------------- 1 | class IfControlStructure{     2 |   public static void main(String[] args){          3 | boolean isMoving=true; 4 | int currentSpeed=10; 5 | if(isMoving){ 6 | System.out.println(currentSpeed); 7 | } 8 |   } 9 | } 10 | -------------------------------------------------------------------------------- /8. Control_Flow_Statement_ELSE_IF.txt: -------------------------------------------------------------------------------- 1 | class IfElseControlStructure{     2 |   public static void main(String[] args){          3 | boolean isMoving=true; 4 | int currentSpeed=10; 5 | if(isMoving){ 6 | currentSpeed--; 7 | System.out.println("The bicycle speed got reduced!"); 8 | }else{ 9 | System.out.println(“The bicycle has already stopped!”); 10 | } 11 |   } 12 | } 13 | -------------------------------------------------------------------------------- /8. Control_Flow_Statement_IF.txt: -------------------------------------------------------------------------------- 1 | class IfControlStructure{     2 |   public static void main(String[] args){          3 | boolean isMoving=true; 4 | int currentSpeed=10; 5 | if(isMoving){ 6 | System.out.println(currentSpeed); 7 | } 8 |   } 9 | } 10 | -------------------------------------------------------------------------------- /9. Control_Flow_Statement_ELSE_IF.txt: -------------------------------------------------------------------------------- 1 | class IfElseControlStructure{     2 |   public static void main(String[] args){          3 | boolean isMoving=true; 4 | int currentSpeed=10; 5 | if(isMoving){ 6 | currentSpeed--; 7 | System.out.println("The bicycle speed got reduced!"); 8 | }else{ 9 | System.out.println(“The bicycle has already stopped!”); 10 | } 11 |   } 12 | } 13 | -------------------------------------------------------------------------------- /9. Control_Flow_Statement_NESTED_IF.txt: -------------------------------------------------------------------------------- 1 | class NestedIFControlStructure{     2 |   public static void main(String[] args){          3 | int age=15; 4 | int weight=50; 5 | if(age>18) { 6 | if(weight>50) 7 | System.out.println(“You are eligible to denote blood”); 8 | else 9 | System.out.println(“Not eligible because you are under weight”); 10 | } else 11 | System.out.println(“Not eligible because you are under age”); 12 | } 13 | } 14 | 15 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # java_program --------------------------------------------------------------------------------