├── AbstractClassAndAbstractMethod ├── Example1 │ ├── ClientApp.java │ ├── DevApp.java │ └── ProjectApp.java └── Example2 │ ├── BankApp.java │ ├── BankClientApp.java │ ├── HDFCBankApp.java │ └── ICICIBankApp.java ├── ArithMeticOpsExample.java ├── Arrays └── ExampleSyntaxes.java ├── CastingInJava ├── CastingInJavaMain.java ├── ExplicitCasting.java └── ImplecityCasting.java ├── CollectionFramework ├── List │ ├── ArrayListExamples │ │ └── ArrayListExample1.java │ ├── LinkedListExamples │ │ └── LinkedListExample1.java │ ├── StackExamples │ │ └── StackExample1.java │ └── VectorExamples │ │ └── VectorExample1.java ├── Map │ ├── HashMapExamples │ │ └── HashMapExample1.java │ ├── HashTableExamples │ │ └── HashTableExample1.java │ ├── LinkedHashMapExamples │ │ └── LinkedHashMapExample1.java │ └── TreeMapExamples │ │ └── TreeMapExample.java └── Set │ ├── HashSetExamples │ └── HashSetExample1.java │ ├── LinkedHashSetExamples │ └── LinkedHashSetExample1.java │ └── TreeSetExamples │ └── TreeSetExample1.java ├── CommandlineParams.java ├── DifferenceBetweenScannerAndBuffer.java ├── Enums ├── Countries.java ├── Days.java ├── Gender.java ├── Months.java └── ProjectMain.java ├── ExceptionHandling ├── ExceptionHandlingExample1 │ ├── ProjectApp.java │ ├── ProjectAppImpl.java │ └── ProjectMain.java └── UserDefinedExceptions │ ├── BankApp.java │ ├── MainApp.java │ └── VoterId.java ├── FactoryDesignPatternExample ├── BIGCinema.java ├── Constants.java ├── INOXCinema.java ├── Movie.java ├── MovieDestributer.java ├── PVRCinema.java └── ProjectMain.java ├── FilesInJava ├── ReadOperations │ └── FileReadOperation.java └── WriteOperations │ ├── Employee.java │ └── ProjectMain.java ├── FinalClasses ├── ProjectApp.java ├── ProjectAppImpl.java ├── ProjectMain.java └── ProjectSubClass.java ├── FirstJavaApp.java ├── FirstOopsApp.java ├── GeneralizationAndSpecialization ├── GeneralizationAndSpecialization.java ├── SubClass.java └── SuperClass.java ├── Generics └── GenericsExample1 │ ├── DevApp1.java │ ├── DevApp2.java │ └── ProjectMain.java ├── InheritanceProject1 ├── Active.java ├── BeActive.java ├── CActive.java └── InheritanceDemo.java ├── InheritanceTechnique1 ├── ExistedLogic.java ├── InheritanceTechnique1Main.java └── NewLogic.java ├── InheritanceTechnique1b ├── Active.java ├── BeActive.java └── InheritanceTechnique1bMain.java ├── InheritanceTechnique2 ├── ExistedLogic.java ├── InheritanceTechnique2Main.java └── NewLogic.java ├── InnerClasses ├── AnonymousInnerClasses │ ├── MainApp.java │ └── ProjectApp.java └── NormalInnerClasses │ ├── MainClass.java │ └── OuterClass.java ├── Interfaces └── Example1 │ ├── ClientApp.java │ ├── DevApp.java │ ├── ProjectApp.java │ └── ProjectApp2.java ├── LogicalOpsExample.java ├── MethodOverloading ├── DevelopmentOveload.java └── MethodOverloadingMain.java ├── NewInstance └── NewInstanceExample.java ├── OddOrEvenNumber.java ├── OddOrEvenNumberScannerExample.java ├── OopsProject1 ├── App1.java ├── App2.java ├── App3.java └── ProjectMain.java ├── OopsProject2 ├── Employee.java └── ProjectMain.java ├── OopsProject3 ├── OOPSTech3.java ├── ParametersActualVsFormal.java └── WorkingWithSameMethodNames.java ├── OopsProject4 ├── ConstructorsExample.java └── OOPSTechnique4.java ├── OopsProject5 ├── Employee.java └── OOPSTechnique5.java ├── OverrideCases ├── PracticalCase1 │ ├── DevApp.java │ ├── MainApp.java │ └── ProjectApp.java └── PracticalCase2 │ ├── DevApp1.java │ ├── DevApp2.java │ ├── MainApp.java │ └── ProjectApp.java ├── Packages └── com │ ├── mypackage │ └── Test.java │ └── mypackage2 │ └── Test2.java ├── README.md ├── ReadInputFromBufferReader.java ├── ReadInputFromConsole.java ├── RelationalOpsExample.java ├── ReturnAndNonReturnTypeMethods ├── ProjectMain.java └── ReturnTypeAndNonReturnType.java ├── ScannerExample.java ├── ScannerExample2.java ├── ScannerExample3.java ├── ScannerExample4.java ├── ScannerExample5.java ├── SecondApp.java ├── SecondJavaApp.java ├── SetterVsGetter ├── Employee.java ├── ProjectMain.java └── Student.java ├── StringExample.java ├── StringScannerExample.java ├── TernaryOpsExample.java ├── TernaryOpsExample2.java ├── Threads ├── Example1 │ ├── MainApp.java │ ├── SBIAtm1.java │ ├── SBIAtm2.java │ └── SBIAtm3.java └── Example2 │ ├── Client1.java │ ├── Client2.java │ ├── Clinet3.java │ └── ServerMain.java ├── UnitaryOpsExample.java ├── VarArgs ├── VarArgsExample.java └── VarArgsExampleMain.java ├── Welcome.java ├── WrapperClasses ├── String │ └── StringOperations.java ├── StringTokenizer │ └── StringTokenizerExample.java └── StringVsStringBuffer │ └── StringVsStringBuffer.java └── listofemployees.ser /AbstractClassAndAbstractMethod/Example1/ClientApp.java: -------------------------------------------------------------------------------- 1 | package AbstractClassAndAbstractMethod.Example1; 2 | 3 | public class ClientApp { 4 | public ClientApp() { 5 | System.out.println("ClientApp.ClientApp()"); 6 | } 7 | 8 | public static void main(String args[]) { 9 | System.out.println("ClientApp.main()"); 10 | ProjectApp projectApp = new DevApp(); 11 | projectApp.task1(); 12 | projectApp.task2(); 13 | 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /AbstractClassAndAbstractMethod/Example1/DevApp.java: -------------------------------------------------------------------------------- 1 | package AbstractClassAndAbstractMethod.Example1; 2 | 3 | public class DevApp extends ProjectApp { 4 | 5 | public DevApp() { 6 | System.out.println("DevApp.DevApp()"); 7 | } 8 | 9 | /** 10 | * Implementation for concrete method / instance method (Optional) 11 | */ 12 | @Override 13 | public void task1() { 14 | System.out.println("DevApp.task1()"); 15 | System.out.println("Task 1 is completed"); 16 | } 17 | 18 | /** 19 | * Implementation for abstract method (Mandatory) 20 | */ 21 | @Override 22 | public void task2() { 23 | System.out.println("DevApp.task2()"); 24 | System.out.println("Task 2 is completed"); 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /AbstractClassAndAbstractMethod/Example1/ProjectApp.java: -------------------------------------------------------------------------------- 1 | package AbstractClassAndAbstractMethod.Example1; 2 | 3 | public abstract class ProjectApp { 4 | public ProjectApp() { 5 | System.out.println("ProjectApp.ProjectApp()"); 6 | } 7 | 8 | /* 9 | * Implementation for concrete/instance method (Optional) 10 | */ 11 | public void task1() { 12 | System.out.println("ProjectApp.task1()"); 13 | System.out.println("task1() completed."); 14 | } 15 | 16 | /* 17 | * Empty method waiting for implementation. 18 | */ 19 | public abstract void task2(); 20 | } 21 | -------------------------------------------------------------------------------- /AbstractClassAndAbstractMethod/Example2/BankApp.java: -------------------------------------------------------------------------------- 1 | package AbstractClassAndAbstractMethod.Example2; 2 | 3 | /** DESIGN */ 4 | public abstract class BankApp { 5 | private int regNo; 6 | private final static int tax = 3; 7 | 8 | public BankApp(int regNo) { 9 | System.out.println("BankApp.BankApp()"); 10 | this.regNo = regNo; 11 | } 12 | 13 | /** 14 | * This method is concrete method(normal method)s are good 15 | * to write logics for instance variable 16 | */ 17 | public void printRegNo() { 18 | System.out.println("BankApp.printRegNo()"); 19 | System.out.println("Reg No : " + regNo); 20 | } 21 | 22 | public abstract void openAccount(); 23 | 24 | public abstract void intrest(); 25 | 26 | /* 27 | * This is final static method and these methods are good to write 28 | * logics for final static variable 29 | */ 30 | public final static void yourTaxDetails() { 31 | System.out.println("BankApp.yourTaxDetails()"); 32 | System.out.println("You need to pay " + tax + " % of tax"); 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /AbstractClassAndAbstractMethod/Example2/BankClientApp.java: -------------------------------------------------------------------------------- 1 | package AbstractClassAndAbstractMethod.Example2; 2 | 3 | /** EXECUTION */ 4 | public class BankClientApp { 5 | public BankClientApp() { 6 | System.out.println("BankClientApp.BankClientApp()"); 7 | } 8 | 9 | public static void main(String args[]) { 10 | System.out.println("BankClientApp.main()"); 11 | System.out.println("=============== ICICI Bank Obj Creation ============="); 12 | BankApp iciciBank = new ICICIBankApp(1585); 13 | iciciBank.openAccount(); 14 | iciciBank.intrest(); 15 | iciciBank.printRegNo(); 16 | ICICIBankApp.yourTaxDetails(); 17 | 18 | System.out.println("=============== HDFC Bank Obj Creation ============="); 19 | BankApp hdfcBank = new HDFCBankApp(8899); 20 | hdfcBank.openAccount(); 21 | hdfcBank.intrest(); 22 | hdfcBank.printRegNo(); 23 | HDFCBankApp.yourTaxDetails(); 24 | 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /AbstractClassAndAbstractMethod/Example2/HDFCBankApp.java: -------------------------------------------------------------------------------- 1 | package AbstractClassAndAbstractMethod.Example2; 2 | 3 | public class HDFCBankApp extends BankApp { 4 | public HDFCBankApp(int regNo) { 5 | super(regNo); 6 | System.out.println("HDFCBankApp.HDFCBankApp()"); 7 | } 8 | 9 | @Override 10 | public void openAccount() { 11 | System.out.println("HDFCBankApp.openAccount()"); 12 | System.out.println("Welcome to HDFC Bank"); 13 | System.out.println("must open account in HDFC Bank"); 14 | } 15 | 16 | @Override 17 | public void intrest() { 18 | System.out.println("On Depostis in HDFC Bank you will get 5.5 % of intrest"); 19 | } 20 | 21 | } 22 | -------------------------------------------------------------------------------- /AbstractClassAndAbstractMethod/Example2/ICICIBankApp.java: -------------------------------------------------------------------------------- 1 | package AbstractClassAndAbstractMethod.Example2; 2 | 3 | /** IMPLEMENTATION */ 4 | public class ICICIBankApp extends BankApp { 5 | public ICICIBankApp(int regNo) { 6 | super(regNo); 7 | System.out.println("ICICIBankApp.ICICIBankApp()"); 8 | } 9 | 10 | @Override 11 | public void openAccount() { 12 | System.out.println("ICICIBankApp.openAccount()"); 13 | System.out.println("Welcome to ICICI BANK"); 14 | System.out.println("Please open your account in ICICI BANK"); 15 | } 16 | 17 | @Override 18 | public void intrest() { 19 | System.out.println("ICICIBankApp.intrest()"); 20 | System.out.println("You are eligible for 5% of intrest."); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /ArithMeticOpsExample.java: -------------------------------------------------------------------------------- 1 | public class ArithMeticOpsExample { 2 | public static void main(String args[]) { 3 | int res1, res2, res3; 4 | int a = 10, b = 30; 5 | res1 = (a + b) / 2; 6 | res2 = (a * b) % 5; 7 | res3 = a - b; 8 | System.out.println("==============================="); 9 | System.out.println("res1 is " + res1); 10 | System.out.println("res2 is " + res2); 11 | System.out.println("res3 is " + res3); 12 | System.out.println("==============================="); 13 | } 14 | } -------------------------------------------------------------------------------- /Arrays/ExampleSyntaxes.java: -------------------------------------------------------------------------------- 1 | package Arrays; 2 | 3 | import java.util.Arrays; 4 | 5 | public class ExampleSyntaxes { 6 | 7 | public ExampleSyntaxes() { 8 | System.out.println("ExampleSyntaxes.ExampleSyntaxes()"); 9 | } 10 | 11 | public static void main(String args[]) { 12 | System.out.println("ExampleSyntaxes.main()"); 13 | 14 | int array[] = new int[] { 10, 20, 30 };// valid 15 | int[] array2 = { 20, 30, 40 };// valid 16 | int[] array3 = new int[3];// valid 17 | array3[0] = 23; 18 | array3[1] = 0; 19 | array3[2] = 40; 20 | int[] array4 = new int[1];// valid 21 | array4[0] = 75; 22 | int array5[] = new int[2];// valid 23 | array5[0] = 45; 24 | array5[1] = 0; 25 | 26 | Integer arr[] = new Integer[1]; 27 | 28 | System.out.println(Arrays.toString(array)); 29 | System.out.println(Arrays.toString(array2)); 30 | System.out.println(Arrays.toString(arr)); 31 | 32 | for (int i : array5) { 33 | System.out.println(i); 34 | } 35 | 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /CastingInJava/CastingInJavaMain.java: -------------------------------------------------------------------------------- 1 | package CastingInJava; 2 | 3 | public class CastingInJavaMain { 4 | 5 | public CastingInJavaMain() { 6 | System.out.println("CastingInJavaMain.CastingInJavaMain()"); 7 | } 8 | 9 | public static void main(String args[]) { 10 | System.out.println("CastingInJavaMain.main()"); 11 | ImplecityCasting implecityCasting = new ImplecityCasting(); 12 | implecityCasting.doImplicityCasting(); 13 | 14 | ExplicitCasting explicitCasting = new ExplicitCasting(); 15 | explicitCasting.doExplicityCasting(); 16 | 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /CastingInJava/ExplicitCasting.java: -------------------------------------------------------------------------------- 1 | package CastingInJava; 2 | 3 | public class ExplicitCasting { 4 | public ExplicitCasting() { 5 | System.out.println("ExplicitCasting.ExplicitCasting()"); 6 | } 7 | 8 | public void doExplicityCasting() { 9 | System.out.println("ExplicitCasting.doExplicityCasting()"); 10 | /** 11 | * Here in explicit casting we are storing big datatypes 12 | * of requirements into small datatypes. 13 | */ 14 | double d = 778955.5566; 15 | System.out.println("value of d is " + d); 16 | int i = (int) d; 17 | System.out.println("value of i is " + i); 18 | 19 | long l = 77899566625L; 20 | System.out.println("value of l is " + l); 21 | int intValue = (int) l; 22 | System.out.println("vlaue of intValue is " + intValue); 23 | 24 | double doubleValue = 88588888.55566; 25 | System.out.println("Double value is " + doubleValue); 26 | float fvalue = (float) doubleValue; 27 | System.out.println("value of fvalue is " + fvalue); 28 | 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /CastingInJava/ImplecityCasting.java: -------------------------------------------------------------------------------- 1 | package CastingInJava; 2 | 3 | public class ImplecityCasting { 4 | 5 | public ImplecityCasting() { 6 | System.out.println("ImplecityCasting.ImplecityCasting()"); 7 | } 8 | 9 | public void doImplicityCasting() { 10 | /** 11 | * Implicti casting(Lower to Higher) 12 | */ 13 | int a = 20; // 4 bytes 14 | System.out.println("value of a is " + a); 15 | double d = a; 16 | System.out.println("value of b is " + d); 17 | 18 | float f = 20.555F; 19 | System.out.println("value of f is " + f); 20 | double g = f; 21 | System.out.println("value of g is " + g); 22 | 23 | int r = 2345; 24 | System.out.println("value of r is " + r); 25 | long l = r; 26 | System.out.println("value of l is " + l); 27 | 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /CollectionFramework/List/ArrayListExamples/ArrayListExample1.java: -------------------------------------------------------------------------------- 1 | package CollectionFramework.List.ArrayListExamples; 2 | 3 | import java.util.ArrayList; 4 | import java.util.ListIterator; 5 | 6 | public class ArrayListExample1 { 7 | 8 | public ArrayListExample1() { 9 | System.out.println("ArrayListExample1.ArrayListExample1()"); 10 | } 11 | 12 | public static void main(String[] args) { 13 | System.out.println("ArrayListExample1.main()"); 14 | ArrayList names = new ArrayList(); 15 | names.add("Srikanth"); // 0-index 16 | names.add("Raju Kumar"); // 1-index 17 | names.add("Naveen Kumar"); // 2-index 18 | names.add("Sai Kumar"); // 3-index 19 | names.add("Harish Kumar"); // 4-index 20 | names.add("Naresh"); // 5 -index 21 | names.add("Saikrishna"); // 6-index 22 | 23 | System.out.println("Size of arraylist is ::: " + names.size()); 24 | 25 | // modification 26 | names.add(5, "naresh kumar"); 27 | 28 | // removing 29 | names.remove(6); 30 | 31 | // checking availablity; 32 | System.out.println(" Name available " + (names.contains("Raju") ? "Yes" : "No")); 33 | System.out.println(" Name available " + (names.contains("Harish Kumar") ? "Yes" : "No")); 34 | 35 | // fetch data from array list 36 | ListIterator listIterator = names.listIterator(); 37 | // Forward direction 38 | System.out.println("List of names in Forward Direction "); 39 | while (listIterator.hasNext()) { 40 | System.out.println(listIterator.next()); // For dispaly Forward 41 | } 42 | System.out.println(); 43 | System.out.println("List of names in Backword Direction"); 44 | while (listIterator.hasPrevious()) { 45 | System.out.println(listIterator.previous()); // For dispaly Backward 46 | } 47 | 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /CollectionFramework/List/LinkedListExamples/LinkedListExample1.java: -------------------------------------------------------------------------------- 1 | package CollectionFramework.List.LinkedListExamples; 2 | 3 | import java.util.LinkedList; 4 | import java.util.ListIterator; 5 | 6 | public class LinkedListExample1 { 7 | 8 | public LinkedListExample1() { 9 | System.out.println("LinkedListExample1.LinkedListExample1()"); 10 | } 11 | 12 | public static void main(String[] args) { 13 | System.out.println("LinkedListExample1.main()"); 14 | LinkedList names = new LinkedList(); 15 | /** 16 | * PUSH is for adding element in the first position 17 | */ 18 | names.push("Srinivas"); 19 | names.push("Sreekanth"); 20 | names.push("ramu"); 21 | names.push("Mahansh"); 22 | /** 23 | * ADD is adding the item at last 24 | */ 25 | names.add("Vinay"); 26 | names.add("Rahul"); 27 | System.out.println(names); 28 | names.add("ranjith"); 29 | names.add("Rakesh"); 30 | names.add("Santhu"); 31 | System.out.println(names); 32 | 33 | /** 34 | * Fetching items 35 | */ 36 | System.out.println(names.peek()); 37 | System.out.println(names.peekLast()); 38 | System.out.println(); 39 | System.out.println("names list "); 40 | ListIterator listIterator = names.listIterator(); 41 | while (listIterator.hasNext()) { 42 | System.out.println(listIterator.next()); 43 | } 44 | 45 | System.out.println(); 46 | System.out.println(names); 47 | /** 48 | * removing item 49 | */ 50 | System.out.println(names.pop());// it will remove first item 51 | System.out.println(names); 52 | System.out.println(names.pollFirst()); 53 | System.out.println(names.pollLast()); 54 | System.out.println(names); 55 | System.out.println(names.remove()); // it will remove first item. 56 | System.out.println(names.removeLast()); 57 | System.out.println(names); 58 | System.out.println(names.remove("Vinay")); 59 | System.out.println(names); 60 | System.out.println(names.remove(0)); 61 | System.out.println(names); 62 | 63 | System.out.println(names.removeAll(names)); 64 | System.out.println(names); 65 | 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /CollectionFramework/List/StackExamples/StackExample1.java: -------------------------------------------------------------------------------- 1 | package CollectionFramework.List.StackExamples; 2 | 3 | import java.util.ListIterator; 4 | import java.util.Stack; 5 | 6 | public class StackExample1 { 7 | 8 | public StackExample1() { 9 | System.out.println("StackExample1.StackExample1()"); 10 | } 11 | 12 | public static void main(String[] args) { 13 | System.out.println("StackExample1.main()"); 14 | Stack menuItems = new Stack(); 15 | menuItems.push("Chiken Biryani"); 16 | menuItems.push("Mutton Biryani"); 17 | menuItems.push("Frans Biryani"); 18 | menuItems.push("vez palavo"); 19 | menuItems.add("vez biryani"); 20 | menuItems.add("Chiken 65"); 21 | 22 | System.out.println(menuItems); 23 | menuItems.pop();// removing item at last position 24 | System.out.println(menuItems); 25 | System.out.println(menuItems.peek()); 26 | System.out.println(menuItems); 27 | 28 | System.out.println(); 29 | System.out.println("List of menu items"); 30 | ListIterator menuList = menuItems.listIterator(); 31 | while (menuList.hasNext()) { 32 | System.out.println(" - " + menuList.next()); 33 | } 34 | 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /CollectionFramework/List/VectorExamples/VectorExample1.java: -------------------------------------------------------------------------------- 1 | package CollectionFramework.List.VectorExamples; 2 | 3 | import java.util.ListIterator; 4 | import java.util.Vector; 5 | 6 | public class VectorExample1 { 7 | 8 | public VectorExample1() { 9 | System.out.println("VectorExample1.VectorExample1()"); 10 | } 11 | 12 | public static void main(String args[]) { 13 | System.out.println("VectorExample1.main()"); 14 | Vector mountains = new Vector(); 15 | mountains.add("Everest"); 16 | mountains.add("kailasa"); 17 | mountains.add("kanchana ganga"); 18 | mountains.add("batura sar"); 19 | mountains.add("himalaya"); 20 | 21 | System.out.println(mountains); 22 | ListIterator iterator = mountains.listIterator(); 23 | System.out.println(); 24 | System.out.println("List of mountains"); 25 | while (iterator.hasNext()) { 26 | System.out.println(" - " + iterator.next().toUpperCase()); 27 | } 28 | 29 | System.out.println(); 30 | System.out.println(mountains.contains("himalaya")); 31 | System.out.println(mountains.get(0)); 32 | System.out.println(mountains.elementAt(2)); 33 | System.out.println(mountains.firstElement()); 34 | System.out.println(mountains.lastElement()); 35 | System.out.println(mountains.remove(2)); 36 | System.out.println(mountains); 37 | 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /CollectionFramework/Map/HashMapExamples/HashMapExample1.java: -------------------------------------------------------------------------------- 1 | package CollectionFramework.Map.HashMapExamples; 2 | 3 | import java.util.HashMap; 4 | import java.util.Iterator; 5 | import java.util.Set; 6 | import java.util.Map.Entry; 7 | 8 | public class HashMapExample1 { 9 | 10 | public HashMapExample1() { 11 | System.out.println("HashMapExample1.HashMapExample1()"); 12 | } 13 | 14 | public static void main(String args[]) { 15 | System.out.println("HashMapExample1.main()"); 16 | HashMap listOfPlayers = new HashMap(); 17 | listOfPlayers.put(101, "Sachin"); 18 | listOfPlayers.put(102, "Dhoni"); 19 | listOfPlayers.put(103, "Dravid"); 20 | listOfPlayers.put(104, "Gungoly"); 21 | listOfPlayers.put(105, "sehwag"); 22 | listOfPlayers.put(106, "Rohit"); 23 | listOfPlayers.put(107, "Rishab"); 24 | listOfPlayers.put(107, "Rahul"); 25 | System.out.println(listOfPlayers); 26 | listOfPlayers.remove(107); 27 | System.out.println(listOfPlayers); 28 | 29 | // Fetching from map 30 | System.out.println(listOfPlayers.get(106)); 31 | System.out.println(); 32 | System.out.println("List of players by using key"); 33 | Set keys = listOfPlayers.keySet(); 34 | Iterator keyIterator = keys.iterator(); 35 | while (keyIterator.hasNext()) { 36 | int key = keyIterator.next(); 37 | System.out.println(" - " + key + " " + listOfPlayers.get(key)); 38 | } 39 | 40 | System.out.println(); 41 | System.out.println("List of players by using values"); 42 | Set> entries = listOfPlayers.entrySet(); 43 | Iterator> iterator = entries.iterator(); 44 | while (iterator.hasNext()) { 45 | System.out.println(iterator.next()); 46 | } 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /CollectionFramework/Map/HashTableExamples/HashTableExample1.java: -------------------------------------------------------------------------------- 1 | package CollectionFramework.Map.HashTableExamples; 2 | 3 | import java.util.Hashtable; 4 | import java.util.Iterator; 5 | import java.util.Set; 6 | import java.util.Map.Entry; 7 | 8 | public class HashTableExample1 { 9 | 10 | public HashTableExample1() { 11 | System.out.println("HashTableExample1.HashTableExample1()"); 12 | } 13 | 14 | public static void main(String[] args) { 15 | System.out.println("HashTableExample1.main()"); 16 | Hashtable hashtable = new Hashtable(); 17 | hashtable.put(101, "HP"); 18 | hashtable.put(102, "DELL"); 19 | hashtable.put(103, "ACER"); 20 | hashtable.put(104, "REDMI"); 21 | hashtable.put(109, "ASUS"); 22 | hashtable.put(115, "MSI"); 23 | 24 | System.out.println(hashtable); 25 | System.out.println(); 26 | System.out.println("List of laptop Brands"); 27 | Set> entries = hashtable.entrySet(); 28 | Iterator> iterator = entries.iterator(); 29 | while (iterator.hasNext()) { 30 | System.out.println(iterator.next()); 31 | } 32 | 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /CollectionFramework/Map/LinkedHashMapExamples/LinkedHashMapExample1.java: -------------------------------------------------------------------------------- 1 | package CollectionFramework.Map.LinkedHashMapExamples; 2 | 3 | import java.util.Iterator; 4 | import java.util.LinkedHashMap; 5 | import java.util.Set; 6 | import java.util.Map.Entry; 7 | 8 | public class LinkedHashMapExample1 { 9 | 10 | public LinkedHashMapExample1() { 11 | System.out.println("LinkedHashMapExample1.LinkedHashMapExample1()"); 12 | } 13 | 14 | public static void main(String[] args) { 15 | System.out.println("LinkedHashMapExample1.main()"); 16 | LinkedHashMap students = new LinkedHashMap(); 17 | students.put(101, "Raju kumar"); 18 | students.put(102, "Naveen kumar"); 19 | students.put(103, "Sai kumar"); 20 | students.put(104, "Srikanth"); 21 | students.put(105, "Devaraju"); 22 | 23 | System.out.println(students); 24 | System.out.println(); 25 | System.out.println("List of students"); 26 | Set> entries = students.entrySet(); 27 | Iterator> eIterator = entries.iterator(); 28 | while (eIterator.hasNext()) { 29 | System.out.println(eIterator.next()); 30 | } 31 | 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /CollectionFramework/Map/TreeMapExamples/TreeMapExample.java: -------------------------------------------------------------------------------- 1 | package CollectionFramework.Map.TreeMapExamples; 2 | 3 | import java.util.Iterator; 4 | import java.util.Set; 5 | import java.util.TreeMap; 6 | import java.util.Map.Entry; 7 | 8 | public class TreeMapExample { 9 | public TreeMapExample() { 10 | System.out.println("TreeMapExample.TreeMapExample()"); 11 | } 12 | 13 | public static void main(String args[]) { 14 | System.out.println("TreeMapExample.main()"); 15 | TreeMap listOfColors = new TreeMap(); 16 | listOfColors.put(101, "red"); 17 | listOfColors.put(105, "green"); 18 | listOfColors.put(109, "yellow"); 19 | listOfColors.put(103, "orange"); 20 | listOfColors.put(110, "black"); 21 | listOfColors.put(104, "white"); 22 | 23 | System.out.println(listOfColors); 24 | listOfColors.put(100, "blue"); 25 | System.out.println(listOfColors); 26 | System.out.println(); 27 | System.out.println("List of colors"); 28 | Set> entries = listOfColors.entrySet(); 29 | Iterator> iterator = entries.iterator(); 30 | while (iterator.hasNext()) { 31 | System.out.println(iterator.next()); 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /CollectionFramework/Set/HashSetExamples/HashSetExample1.java: -------------------------------------------------------------------------------- 1 | package CollectionFramework.Set.HashSetExamples; 2 | 3 | import java.util.HashSet; 4 | import java.util.Iterator; 5 | 6 | public class HashSetExample1 { 7 | public HashSetExample1() { 8 | System.out.println("HashSetExample1.HashSetExample1()"); 9 | } 10 | 11 | public static void main(String args[]) { 12 | System.out.println("HashSetExample1.main()"); 13 | HashSet names = new HashSet(); 14 | // hashset will add the items based on hash code 15 | names.add("ramesh"); 16 | names.add("suresh"); 17 | names.add("mahesh"); 18 | names.add("somesh"); 19 | names.add("raju"); 20 | names.add("ranveer"); 21 | names.add("raju"); 22 | System.out.println(names); 23 | 24 | System.out.println("Size of set is " + names.size()); 25 | names.remove("raju"); 26 | System.out.println(names); 27 | 28 | // fetching data from sets is 29 | System.out.println(); 30 | System.out.println("List of names in set "); 31 | Iterator namesIterator = names.iterator(); 32 | while (namesIterator.hasNext()) { 33 | System.out.println(" - " + namesIterator.next()); 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /CollectionFramework/Set/LinkedHashSetExamples/LinkedHashSetExample1.java: -------------------------------------------------------------------------------- 1 | package CollectionFramework.Set.LinkedHashSetExamples; 2 | 3 | import java.util.Iterator; 4 | import java.util.LinkedHashSet; 5 | 6 | public class LinkedHashSetExample1 { 7 | public LinkedHashSetExample1() { 8 | System.out.println("LinkedHashSetExample1.LinkedHashSetExample1()"); 9 | } 10 | 11 | public static void main(String[] args) { 12 | System.out.println("LinkedHashSetExample1.main()"); 13 | LinkedHashSet movies = new LinkedHashSet(); 14 | movies.add("Bahubali the beginning"); 15 | movies.add("Bahubali the conclusion"); 16 | movies.add("RRR"); 17 | movies.add("KGF Chapter 1"); 18 | movies.add("KGF Chapter 2"); 19 | movies.add("Kaidhi"); 20 | movies.add("Vikram"); 21 | movies.add("Kaidhi"); 22 | 23 | System.out.println(movies); 24 | movies.remove("Vikram"); 25 | System.out.println(movies); 26 | System.out.println("List of movies"); 27 | Iterator iterator = movies.iterator(); 28 | while (iterator.hasNext()) { 29 | System.out.println(" * " + iterator.next()); 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /CollectionFramework/Set/TreeSetExamples/TreeSetExample1.java: -------------------------------------------------------------------------------- 1 | package CollectionFramework.Set.TreeSetExamples; 2 | 3 | import java.util.Iterator; 4 | import java.util.TreeSet; 5 | 6 | public class TreeSetExample1 { 7 | 8 | public TreeSetExample1() { 9 | System.out.println("TreeSetExample1.TreeSetExample1()"); 10 | } 11 | 12 | public static void main(String args[]) { 13 | System.out.println("TreeSetExample1.main()"); 14 | TreeSet fruitNames = new TreeSet(); 15 | fruitNames.add("Mango"); 16 | fruitNames.add("Orange"); 17 | fruitNames.add("Apple"); 18 | fruitNames.add("Banana"); 19 | fruitNames.add("Grapes"); 20 | System.out.println(fruitNames); 21 | System.out.println(); 22 | System.out.println("List of fruits "); 23 | Iterator fIterator = fruitNames.iterator(); 24 | while (fIterator.hasNext()) { 25 | System.out.println(" + " + fIterator.next()); 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /CommandlineParams.java: -------------------------------------------------------------------------------- 1 | public class CommandlineParams { 2 | public CommandlineParams() { 3 | System.out.println("CommandlineParams.CommandlineParams()"); 4 | } 5 | 6 | public static void main(String[] args) { 7 | if (args.length > 0 && args.length == 3) { 8 | int id = Integer.parseInt(args[0]); 9 | String name = String.valueOf(args[1]); 10 | double fee = Double.parseDouble(args[2]); 11 | System.out.println("Student Details: "); 12 | System.out.println("Student ID: " + id); 13 | System.out.println("Student Name: " + name); 14 | System.out.println("Student Fee: " + fee); 15 | } else { 16 | System.out.println("Please give 3 arguments"); 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /DifferenceBetweenScannerAndBuffer.java: -------------------------------------------------------------------------------- 1 | import java.io.BufferedReader; 2 | import java.io.InputStreamReader; 3 | import java.util.Scanner; 4 | 5 | public class DifferenceBetweenScannerAndBuffer { 6 | 7 | public DifferenceBetweenScannerAndBuffer() { 8 | System.out.println("DifferenceBetweenScannerAndBuffer.DifferenceBetweenScannerAndBuffer()"); 9 | } 10 | 11 | public static void main(String[] args) throws Exception { 12 | System.out.println("DifferenceBetweenScannerAndBuffer.main()"); 13 | Integer id; 14 | String name; 15 | Scanner scanner = new Scanner(System.in); 16 | System.out.println("Enter ID::"); 17 | id = scanner.nextInt(); 18 | System.out.println("Enter Name"); 19 | name = scanner.next(); 20 | System.out.println("-- Entered Details --"); 21 | System.out.println("ID " + id); 22 | System.out.println("Name " + name); 23 | System.out.println(); 24 | 25 | Integer id2; 26 | String name2; 27 | InputStreamReader inputStreamReader = new InputStreamReader(System.in); 28 | BufferedReader bufferedReader = new BufferedReader(inputStreamReader); 29 | System.out.println("Enter ID 2"); 30 | id2 = Integer.parseInt(bufferedReader.readLine()); 31 | System.out.println("Enter Name 2"); 32 | name2 = bufferedReader.readLine(); 33 | System.out.println("-- Entered Details 2 --"); 34 | System.out.println("ID 2: " + id2); 35 | System.out.println("Name 2: " + name2); 36 | scanner.close(); 37 | bufferedReader.close(); 38 | inputStreamReader.close(); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /Enums/Countries.java: -------------------------------------------------------------------------------- 1 | package Enums; 2 | 3 | public enum Countries { 4 | INDIA, 5 | USA, 6 | RUSSIA, 7 | UKRAIN, 8 | UK, 9 | CANADA, 10 | SWIZERLAND 11 | } 12 | -------------------------------------------------------------------------------- /Enums/Days.java: -------------------------------------------------------------------------------- 1 | package Enums; 2 | 3 | public enum Days { 4 | SUNDAY, 5 | MONDAY, 6 | TUESDAY, 7 | WEDNESDAY, 8 | THURSDAY, 9 | FRIDAY, 10 | SATURDAY, 11 | } 12 | -------------------------------------------------------------------------------- /Enums/Gender.java: -------------------------------------------------------------------------------- 1 | package Enums; 2 | 3 | public enum Gender { 4 | MALE, 5 | FEMALE, 6 | OTHERS 7 | } 8 | -------------------------------------------------------------------------------- /Enums/Months.java: -------------------------------------------------------------------------------- 1 | package Enums; 2 | 3 | public enum Months { 4 | JAN, 5 | FEB, 6 | MAR, 7 | APR, 8 | MAY, 9 | JUN, 10 | JUL, 11 | AUG, 12 | SEP, 13 | OCT, 14 | NOV, 15 | DEC 16 | } 17 | -------------------------------------------------------------------------------- /Enums/ProjectMain.java: -------------------------------------------------------------------------------- 1 | package Enums; 2 | 3 | public class ProjectMain { 4 | public ProjectMain() { 5 | System.out.println("ProjectMain.ProjectMain()"); 6 | } 7 | 8 | public static void main(String args[]) { 9 | System.out.println("ProjectMain.main()"); 10 | Months months[] = Months.values(); 11 | System.out.println("List of months"); 12 | for (Months month : months) { 13 | System.out.println(month); 14 | } 15 | 16 | Days days[] = Days.values(); 17 | System.out.println("list of days"); 18 | for (Days day : days) { 19 | System.out.println(day); 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /ExceptionHandling/ExceptionHandlingExample1/ProjectApp.java: -------------------------------------------------------------------------------- 1 | package ExceptionHandling.ExceptionHandlingExample1; 2 | 3 | /** DESIGN */ 4 | public interface ProjectApp { 5 | public void task1(); 6 | } 7 | -------------------------------------------------------------------------------- /ExceptionHandling/ExceptionHandlingExample1/ProjectAppImpl.java: -------------------------------------------------------------------------------- 1 | package ExceptionHandling.ExceptionHandlingExample1; 2 | 3 | import java.util.Scanner; 4 | 5 | public class ProjectAppImpl implements ProjectApp { 6 | 7 | public ProjectAppImpl() { 8 | System.out.println("ProjectAppImpl.ProjectAppImpl()"); 9 | } 10 | 11 | @Override 12 | public void task1() { 13 | System.out.println("ProjectAppImpl.task1()"); 14 | int a; 15 | int b; 16 | int c; 17 | int result; 18 | Scanner scanner = new Scanner(System.in); 19 | System.out.println("Enter the outputs"); 20 | System.out.println("Enter a value :"); 21 | a = scanner.nextInt(); 22 | System.out.println("Enter b value :"); 23 | b = scanner.nextInt(); 24 | System.out.println("Enter c value :"); 25 | c = scanner.nextInt(); 26 | scanner.close(); 27 | try { 28 | result = (a + b) / c; 29 | System.out.println("Result is " + result); 30 | } catch (Exception e) { 31 | System.out.println("Exception Details"); 32 | System.out.println(e.toString()); 33 | System.out.println(e.getClass()); 34 | System.out.println(e.getLocalizedMessage()); 35 | } finally { 36 | System.out.println("Exception closed"); 37 | System.out.println("Completed"); 38 | } 39 | 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /ExceptionHandling/ExceptionHandlingExample1/ProjectMain.java: -------------------------------------------------------------------------------- 1 | package ExceptionHandling.ExceptionHandlingExample1; 2 | 3 | public class ProjectMain { 4 | 5 | public ProjectMain() { 6 | System.out.println("ProjectMain.ProjectMain()"); 7 | } 8 | 9 | public static void main(String args[]) { 10 | System.out.println("ProjectMain.main()"); 11 | ProjectApp projectApp = new ProjectAppImpl(); 12 | projectApp.task1(); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /ExceptionHandling/UserDefinedExceptions/BankApp.java: -------------------------------------------------------------------------------- 1 | package ExceptionHandling.UserDefinedExceptions; 2 | 3 | import java.util.Scanner; 4 | 5 | public class BankApp extends Exception { 6 | 7 | public BankApp() { 8 | System.out.println("BankApp.BankApp()"); 9 | } 10 | 11 | public BankApp(String message) { 12 | super(message); 13 | } 14 | 15 | public void task1() { 16 | Scanner scanner = new Scanner(System.in); 17 | System.out.println("Please give inputs below"); 18 | System.out.println("Enter Account number"); 19 | int acno = scanner.nextInt(); 20 | System.out.println("Enter Name"); 21 | String name = scanner.next(); 22 | System.out.println("Enter balance"); 23 | double bal = scanner.nextDouble(); 24 | scanner.close(); 25 | if (bal < 1000) { 26 | try { 27 | BankApp bankApp = new BankApp("Please maintain minimum balance"); 28 | throw bankApp; 29 | } catch (Exception e) { 30 | System.out.println("Exception " + e.getLocalizedMessage()); 31 | } 32 | } else { 33 | System.out.println("Your Account balance is " + bal); 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /ExceptionHandling/UserDefinedExceptions/MainApp.java: -------------------------------------------------------------------------------- 1 | package ExceptionHandling.UserDefinedExceptions; 2 | 3 | public class MainApp { 4 | 5 | public MainApp() { 6 | System.out.println("MainApp.MainApp()"); 7 | } 8 | 9 | public static void main(String args[]) { 10 | System.out.println("MainApp.main()"); 11 | VoterId voterId = new VoterId(); 12 | voterId.task1(); 13 | 14 | BankApp bankApp = new BankApp(""); 15 | bankApp.task1(); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /ExceptionHandling/UserDefinedExceptions/VoterId.java: -------------------------------------------------------------------------------- 1 | package ExceptionHandling.UserDefinedExceptions; 2 | 3 | import java.util.Scanner; 4 | 5 | public class VoterId extends Exception { 6 | 7 | public VoterId() { 8 | System.out.println("VoterId.VoterId()"); 9 | } 10 | 11 | public VoterId(String exceptionMessage) { 12 | super(exceptionMessage); 13 | } 14 | 15 | public void task1() { 16 | int age; 17 | String name; 18 | Scanner scanner = new Scanner(System.in); 19 | System.out.println("Enter inputs"); 20 | System.out.println("Enter Age"); 21 | age = scanner.nextInt(); 22 | System.out.println("Enter Name"); 23 | name = scanner.next(); 24 | scanner.close(); 25 | if (age <= 18) { 26 | try { 27 | VoterId v = new VoterId(name + " not eligible for voting."); 28 | throw v; 29 | } catch (Exception e) { 30 | System.out.println("Exception" + e.getLocalizedMessage()); 31 | } 32 | } else { 33 | System.out.println(name + " eligible for voting."); 34 | } 35 | scanner.close(); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /FactoryDesignPatternExample/BIGCinema.java: -------------------------------------------------------------------------------- 1 | package FactoryDesignPatternExample; 2 | 3 | /** IMPLEMENTATION */ 4 | public class BIGCinema implements Movie { 5 | public BIGCinema() { 6 | System.out.println("BigCinema.BigCinema()"); 7 | } 8 | 9 | @Override 10 | public void selectMovie() { 11 | System.out.println("BigCinema.selectMovie()"); 12 | System.out.println("welcome to big cinema"); 13 | System.out.println("Thanks for visiting, Have a nice day."); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /FactoryDesignPatternExample/Constants.java: -------------------------------------------------------------------------------- 1 | package FactoryDesignPatternExample; 2 | 3 | public class Constants { 4 | public final static String BIG_CINEMA = "bigcinema"; 5 | public final static String INOX_CINEMA = "inoxcinema"; 6 | public final static String PVR_CINEMA = "pvrcinema"; 7 | 8 | } 9 | -------------------------------------------------------------------------------- /FactoryDesignPatternExample/INOXCinema.java: -------------------------------------------------------------------------------- 1 | package FactoryDesignPatternExample; 2 | 3 | /** IMPLEMENTATION */ 4 | public class INOXCinema implements Movie { 5 | public INOXCinema() { 6 | System.out.println("INOXCinema.INOXCinema()"); 7 | } 8 | 9 | @Override 10 | public void selectMovie() { 11 | System.out.println("INOXCinema.selectMovie()"); 12 | System.out.println("Welcome to INOXCinema"); 13 | System.out.println("Thanks for visiting INOXCinema"); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /FactoryDesignPatternExample/Movie.java: -------------------------------------------------------------------------------- 1 | package FactoryDesignPatternExample; 2 | 3 | /** DESIGN */ 4 | public interface Movie { 5 | public void selectMovie(); 6 | } 7 | -------------------------------------------------------------------------------- /FactoryDesignPatternExample/MovieDestributer.java: -------------------------------------------------------------------------------- 1 | package FactoryDesignPatternExample; 2 | 3 | /** Factory Class */ 4 | public class MovieDestributer { 5 | public MovieDestributer() { 6 | System.out.println("MovieDestributer.MovieDestributer()"); 7 | } 8 | 9 | /** Factory Method */ 10 | public static Movie bookMyShow(String theatre) { 11 | if (theatre.equals(Constants.BIG_CINEMA)) { 12 | return new BIGCinema(); 13 | } else if (theatre.equals(Constants.INOX_CINEMA)) { 14 | return new INOXCinema(); 15 | } else if (theatre.equals(Constants.PVR_CINEMA)) { 16 | return new PVRCinema(); 17 | } else { 18 | return null; 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /FactoryDesignPatternExample/PVRCinema.java: -------------------------------------------------------------------------------- 1 | package FactoryDesignPatternExample; 2 | 3 | /** IMPLEMENTATION */ 4 | public class PVRCinema implements Movie { 5 | public PVRCinema() { 6 | System.out.println("PVRCinema.PVRCinema()"); 7 | } 8 | 9 | @Override 10 | public void selectMovie() { 11 | System.out.println("PVRCinema.selectMovie()"); 12 | System.out.println("Welcome to PVRCinema"); 13 | System.out.println("Thanks for visiting PVRCinema, Have a great day.!"); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /FactoryDesignPatternExample/ProjectMain.java: -------------------------------------------------------------------------------- 1 | package FactoryDesignPatternExample; 2 | 3 | import java.util.Scanner; 4 | 5 | public class ProjectMain { 6 | public ProjectMain() { 7 | System.out.println("ProjectMain.ProjectMain()"); 8 | } 9 | 10 | public static void main(String args[]) { 11 | System.out.println("ProjectMain.main()"); 12 | String theature; 13 | Scanner scanner = new Scanner(System.in); 14 | System.out.println("welcome to bookmyshow"); 15 | System.out.println("Please select therature"); 16 | theature = scanner.nextLine(); 17 | 18 | Movie movie = MovieDestributer.bookMyShow(theature); 19 | movie.selectMovie(); 20 | scanner.close(); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /FilesInJava/ReadOperations/FileReadOperation.java: -------------------------------------------------------------------------------- 1 | package FilesInJava.ReadOperations; 2 | 3 | import java.io.FileInputStream; 4 | import java.io.ObjectInputStream; 5 | import java.util.Iterator; 6 | import java.util.Set; 7 | import java.util.TreeMap; 8 | import java.util.Map.Entry; 9 | 10 | import FilesInJava.WriteOperations.Employee; 11 | 12 | public class FileReadOperation { 13 | 14 | public FileReadOperation() { 15 | System.out.println("FileReadOperation.FileReadOperation()"); 16 | } 17 | 18 | public static void main(String args[]) { 19 | System.out.println("FileReadOperation.main()"); 20 | try { 21 | FileInputStream fileInputStream = new FileInputStream("listofemployees.ser"); 22 | ObjectInputStream objectInputStream = new ObjectInputStream(fileInputStream); 23 | TreeMap treeMap = (TreeMap) objectInputStream.readObject(); 24 | Set> sEntries = treeMap.entrySet(); 25 | Iterator> iterator = sEntries.iterator(); 26 | while (iterator.hasNext()) { 27 | System.out.println(iterator.next()); 28 | } 29 | objectInputStream.close(); 30 | fileInputStream.close(); 31 | } catch (Exception e) { 32 | System.err.println(e.getLocalizedMessage()); 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /FilesInJava/WriteOperations/Employee.java: -------------------------------------------------------------------------------- 1 | package FilesInJava.WriteOperations; 2 | 3 | import java.io.Serializable; 4 | 5 | /** 6 | * For writing operations we need to implement Serializable 7 | */ 8 | public class Employee implements Serializable { 9 | 10 | private T id; 11 | private E name; 12 | private K sal; 13 | private V company; 14 | 15 | public Employee() { 16 | System.out.println("Employee.Employee()"); 17 | } 18 | 19 | public Employee(T id, E name, K sal, V company) { 20 | this.id = id; 21 | this.name = name; 22 | this.sal = sal; 23 | this.company = company; 24 | } 25 | 26 | public void setId(T id) { 27 | this.id = id; 28 | } 29 | 30 | public void setName(E name) { 31 | this.name = name; 32 | } 33 | 34 | public void setSal(K sal) { 35 | this.sal = sal; 36 | } 37 | 38 | public void setCompany(V company) { 39 | this.company = company; 40 | } 41 | 42 | public T getId() { 43 | return id; 44 | } 45 | 46 | public E getName() { 47 | return name; 48 | } 49 | 50 | public K getSal() { 51 | return sal; 52 | } 53 | 54 | public V getCompany() { 55 | return company; 56 | } 57 | 58 | @Override 59 | public String toString() { 60 | return "Employee [id=" + id + ", name=" + name + ", sal=" + sal + ", company=" + company + "]"; 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /FilesInJava/WriteOperations/ProjectMain.java: -------------------------------------------------------------------------------- 1 | package FilesInJava.WriteOperations; 2 | 3 | import java.io.FileOutputStream; 4 | import java.io.ObjectOutputStream; 5 | import java.util.TreeMap; 6 | 7 | public class ProjectMain { 8 | 9 | public ProjectMain() { 10 | System.out.println("ProjectMain.ProjectMain()"); 11 | } 12 | 13 | public static void main(String[] args) { 14 | System.out.println("ProjectMain.main()"); 15 | 16 | try { 17 | Employee employee1 = new Employee(101, 18 | "Srikanth", 10000.00, "TCS"); 19 | Employee employee2 = new Employee(102, 20 | "Raju Kumar", 30000.00, "TCS"); 21 | Employee employee3 = new Employee(103, 22 | "Naveen Kumar", 28000.00, "TCS"); 23 | Employee employee4 = new Employee(104, 24 | "Devraju", 11000.00, "TCS"); 25 | Employee employee5 = new Employee(105, 26 | "Abhinay", 21000.00, "WIPRO"); 27 | System.out.println(employee1); 28 | System.out.println(employee2); 29 | System.out.println(employee3); 30 | System.out.println(employee4); 31 | System.out.println(employee5); 32 | 33 | TreeMap listOfEmployees = new TreeMap(); 34 | listOfEmployees.put(1, employee1); 35 | listOfEmployees.put(2, employee2); 36 | listOfEmployees.put(3, employee3); 37 | listOfEmployees.put(4, employee4); 38 | listOfEmployees.put(51, employee5); 39 | 40 | FileOutputStream fileOutputStream = new FileOutputStream("listofemployees.ser"); 41 | ObjectOutputStream objectOutputStream = new ObjectOutputStream(fileOutputStream); 42 | objectOutputStream.writeObject(listOfEmployees); 43 | objectOutputStream.close(); 44 | fileOutputStream.close();// Using this we write object data into file 45 | } catch (Exception e) { 46 | System.err.println(e.getLocalizedMessage()); 47 | } 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /FinalClasses/ProjectApp.java: -------------------------------------------------------------------------------- 1 | package FinalClasses; 2 | 3 | /** DESIGN */ 4 | public interface ProjectApp { 5 | void task1(); 6 | } 7 | -------------------------------------------------------------------------------- /FinalClasses/ProjectAppImpl.java: -------------------------------------------------------------------------------- 1 | package FinalClasses; 2 | 3 | public class ProjectAppImpl { 4 | 5 | } 6 | -------------------------------------------------------------------------------- /FinalClasses/ProjectMain.java: -------------------------------------------------------------------------------- 1 | package FinalClasses; 2 | 3 | /** EXECUTION */ 4 | public class ProjectMain { 5 | public ProjectMain() { 6 | System.out.println("ProjectMain.ProjectMain()"); 7 | } 8 | 9 | public static void main(String... args) { 10 | System.out.println("ProjectMain.main()"); 11 | ProjectApp projectApp = new ProjectSubClass(); 12 | projectApp.task1(); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /FinalClasses/ProjectSubClass.java: -------------------------------------------------------------------------------- 1 | package FinalClasses; 2 | 3 | public final class ProjectSubClass implements ProjectApp { 4 | 5 | public ProjectSubClass() { 6 | System.out.println("ProjectSubClass.ProjectSubClass()"); 7 | } 8 | 9 | @Override 10 | public void task1() { 11 | System.out.println("ProjectSubClass.task1()"); 12 | } 13 | 14 | } 15 | -------------------------------------------------------------------------------- /FirstJavaApp.java: -------------------------------------------------------------------------------- 1 | public class FirstJavaApp { 2 | 3 | public static void main(String args[]) { 4 | 5 | System.out.println("Hello Java !!!"); 6 | 7 | } 8 | } -------------------------------------------------------------------------------- /FirstOopsApp.java: -------------------------------------------------------------------------------- 1 | public class FirstOopsApp { 2 | /* 3 | * Requirements 4 | * Properties 5 | * Variables 6 | */ 7 | int a = 10; 8 | int b = 20; 9 | int c = 30; 10 | 11 | /* Constructor */ 12 | public FirstOopsApp() { 13 | System.out.println("FirstOopsApp.FirstOopsApp()"); 14 | } 15 | 16 | /* 17 | * method name hai 18 | * returntype void 19 | */ 20 | 21 | public void hai() { 22 | System.out.println("Hi Srikanth ! How are you"); 23 | System.out.println("a value is " + a); 24 | } 25 | 26 | /** 27 | * method name hello 28 | * return type void 29 | */ 30 | public void hello() { 31 | System.out.println("Hello Raju ! How are you"); 32 | System.out.println("value of b is " + b); 33 | } 34 | 35 | public void bye() { 36 | System.out.println("Bye Abhinay ! See you later"); 37 | System.out.println("value of c is " + c); 38 | } 39 | 40 | public static void main(String args[]) { 41 | /** creating object by using new keyword */ 42 | FirstOopsApp firstOopsApp = new FirstOopsApp(); 43 | /** using object reference calling the method hai */ 44 | firstOopsApp.hai(); 45 | /** using object reference calling the method hello */ 46 | firstOopsApp.hello(); 47 | /** using object reference calling the method bye */ 48 | firstOopsApp.bye(); 49 | 50 | /** same way we can create multiple objects */ 51 | 52 | /** creating object by using new keyword */ 53 | FirstOopsApp firstOopsApp1 = new FirstOopsApp(); 54 | /** using object reference calling the method hai */ 55 | firstOopsApp1.hai(); 56 | /** using object reference calling the method hello */ 57 | firstOopsApp1.hello(); 58 | /** using object reference calling the method bye */ 59 | firstOopsApp1.bye(); 60 | } 61 | } -------------------------------------------------------------------------------- /GeneralizationAndSpecialization/GeneralizationAndSpecialization.java: -------------------------------------------------------------------------------- 1 | package GeneralizationAndSpecialization; 2 | 3 | public class GeneralizationAndSpecialization { 4 | 5 | public GeneralizationAndSpecialization() { 6 | System.out.println("GeneralizationAndSpecialization.GeneralizationAndSpecialization()"); 7 | } 8 | 9 | public static void main(String args[]) { 10 | System.out.println("GeneralizationAndSpecialization.main()"); 11 | GeneralizationAndSpecialization generalizationAndSpecialization = new GeneralizationAndSpecialization(); 12 | 13 | /* Implicit Casting */ 14 | SuperClass superClass = new SubClass(); 15 | superClass.task1(); 16 | 17 | /* Explicit Casting */ 18 | SubClass subClass = (SubClass) new SuperClass(); 19 | subClass.task1(); 20 | 21 | } 22 | 23 | } -------------------------------------------------------------------------------- /GeneralizationAndSpecialization/SubClass.java: -------------------------------------------------------------------------------- 1 | package GeneralizationAndSpecialization; 2 | 3 | public class SubClass extends SuperClass { 4 | public SubClass() { 5 | System.out.println("SubClass.SubClass()"); 6 | } 7 | 8 | @Override 9 | public void task1() { 10 | int a = 10; 11 | int b = 20; 12 | int result = a - b; 13 | System.out.println(result); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /GeneralizationAndSpecialization/SuperClass.java: -------------------------------------------------------------------------------- 1 | package GeneralizationAndSpecialization; 2 | 3 | public class SuperClass { 4 | public SuperClass() { 5 | System.out.println("SuperClass.SuperClass()"); 6 | } 7 | 8 | public void task1() { 9 | System.out.println("SuperClass.task1()"); 10 | int a = 10; 11 | int b = 20; 12 | int result = a + b; 13 | System.out.println(result); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Generics/GenericsExample1/DevApp1.java: -------------------------------------------------------------------------------- 1 | package Generics.GenericsExample1; 2 | 3 | public class DevApp1 { 4 | 5 | private T id; 6 | 7 | public DevApp1(T id) { 8 | this.id = id; 9 | System.out.println("DevApp1.DevApp1()"); 10 | } 11 | 12 | public T getId() { 13 | return id; 14 | } 15 | } -------------------------------------------------------------------------------- /Generics/GenericsExample1/DevApp2.java: -------------------------------------------------------------------------------- 1 | package Generics.GenericsExample1; 2 | 3 | public class DevApp2 { 4 | private T a; 5 | private E b; 6 | 7 | public DevApp2(T a, E b) { 8 | this.a = a; 9 | this.b = b; 10 | System.out.println("DevApp2.DevApp2()"); 11 | } 12 | 13 | public String toString() { 14 | return a + " , " + b; 15 | } 16 | } -------------------------------------------------------------------------------- /Generics/GenericsExample1/ProjectMain.java: -------------------------------------------------------------------------------- 1 | package Generics.GenericsExample1; 2 | 3 | public class ProjectMain { 4 | 5 | public ProjectMain() { 6 | System.out.println("ProjectMain.ProjectMain()"); 7 | } 8 | 9 | public static void main(String... args) { 10 | DevApp1 devApp1 = new DevApp1(10); 11 | System.out.println("ID :: " + devApp1.getId()); 12 | 13 | DevApp1 devApp = new DevApp1("25"); 14 | System.out.println("ID :: " + devApp.getId()); 15 | 16 | DevApp2 devApp2 = new DevApp2(102, "Srikanth"); 17 | System.out.println(devApp2); 18 | 19 | DevApp2 devApp22 = new DevApp2("Raju", "Kumar"); 20 | System.out.println(devApp22); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /InheritanceProject1/Active.java: -------------------------------------------------------------------------------- 1 | package InheritanceProject1; 2 | 3 | public class Active { 4 | private int a = 10; 5 | 6 | public Active() { 7 | System.out.println("Active.Active()"); 8 | } 9 | 10 | public void task1() { 11 | System.out.println("value of a is " + a); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /InheritanceProject1/BeActive.java: -------------------------------------------------------------------------------- 1 | package InheritanceProject1; 2 | 3 | public class BeActive extends Active { 4 | private int b = 20; 5 | 6 | public BeActive() { 7 | System.out.println("BeActive.BeActive()"); 8 | } 9 | 10 | public void task2() { 11 | System.out.println("value of b is " + b); 12 | } 13 | 14 | } 15 | -------------------------------------------------------------------------------- /InheritanceProject1/CActive.java: -------------------------------------------------------------------------------- 1 | package InheritanceProject1; 2 | 3 | public class CActive extends BeActive { 4 | private int c = 30; 5 | 6 | public CActive() { 7 | System.out.println("CActive.CActive()"); 8 | } 9 | 10 | public void task3() { 11 | System.out.println("Value of c is " + c); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /InheritanceProject1/InheritanceDemo.java: -------------------------------------------------------------------------------- 1 | package InheritanceProject1; 2 | 3 | public class InheritanceDemo { 4 | public InheritanceDemo() { 5 | System.out.println("InheritanceDemo.InheritanceDemo()"); 6 | } 7 | 8 | public static void main(String args[]) { 9 | System.out.println("InheritanceDemo.main()"); 10 | CActive cActive = new CActive(); 11 | cActive.task1(); 12 | cActive.task2(); 13 | cActive.task3(); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /InheritanceTechnique1/ExistedLogic.java: -------------------------------------------------------------------------------- 1 | package InheritanceTechnique1; 2 | 3 | public class ExistedLogic { 4 | private int a = 5; 5 | private int b = 3; 6 | 7 | public ExistedLogic() { 8 | System.out.println("ExistedLogic.ExistedLogic()"); 9 | } 10 | 11 | public ExistedLogic(int a, int b) { 12 | System.out.println("ExistedLogic.ExistedLogic()"); 13 | this.a = a; 14 | this.b = b; 15 | } 16 | 17 | public void task1() { 18 | System.out.println("value of a is " + a); 19 | System.out.println("value of b is " + b); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /InheritanceTechnique1/InheritanceTechnique1Main.java: -------------------------------------------------------------------------------- 1 | package InheritanceTechnique1; 2 | 3 | public class InheritanceTechnique1Main { 4 | public InheritanceTechnique1Main() { 5 | System.out.println("InheritanceTechnique1Main.InheritanceTechnique1Main()"); 6 | } 7 | 8 | public static void main(String args[]) { 9 | ExistedLogic existedLogic = new ExistedLogic(10, 50); 10 | existedLogic.task1(); 11 | NewLogic newLogic = new NewLogic(20, 30); 12 | newLogic.task1(); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /InheritanceTechnique1/NewLogic.java: -------------------------------------------------------------------------------- 1 | package InheritanceTechnique1; 2 | 3 | public class NewLogic extends ExistedLogic { 4 | public NewLogic(int a, int b) { 5 | /** 6 | * Here is super is used to send the constructor parameters 7 | * of child class will pass to parent class constructor 8 | */ 9 | super(a, b); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /InheritanceTechnique1b/Active.java: -------------------------------------------------------------------------------- 1 | package InheritanceTechnique1b; 2 | 3 | public class Active { 4 | private int a, b, c; 5 | private char x; 6 | 7 | public Active() { 8 | System.out.println("Active.Active()-no args consturctor"); 9 | this.a = 10; 10 | this.b = 20; 11 | } 12 | 13 | public Active(int a, int b, int c) { 14 | System.out.println("Active.Active()-3 args consturctor"); 15 | this.a = a; 16 | this.b = b; 17 | this.c = c; 18 | } 19 | 20 | public Active(char x, int b) { 21 | System.out.println("Active.Active()-2 args consturctor"); 22 | this.x = x; 23 | this.b = b; 24 | } 25 | 26 | public void task1() { 27 | System.out.println("Active.task1()"); 28 | System.out.println("value of a is " + a); 29 | System.out.println("value of b is " + b); 30 | } 31 | 32 | public void task2() { 33 | System.out.println("Active.task2()"); 34 | System.out.println("value of a is " + a); 35 | System.out.println("value of b is " + b); 36 | System.out.println("value of c is " + c); 37 | } 38 | 39 | public void task3() { 40 | System.out.println("Active.task3()"); 41 | System.out.println("value of a is " + a); 42 | System.out.println("value of x is " + x); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /InheritanceTechnique1b/BeActive.java: -------------------------------------------------------------------------------- 1 | package InheritanceTechnique1b; 2 | 3 | public class BeActive extends Active { 4 | private int x, y; 5 | 6 | public BeActive() { 7 | super(); 8 | } 9 | 10 | public BeActive(int a, int b, int c) { 11 | super(a, b, c); 12 | } 13 | 14 | public BeActive(char x, int b) { 15 | super(x, b); 16 | } 17 | 18 | public BeActive(int x, int y) { 19 | this.x = x; 20 | this.y = y; 21 | } 22 | 23 | public void task4() { 24 | System.out.println("BeActive.task4()"); 25 | System.out.println("the value of x is " + x); 26 | System.out.println("the value of y is " + y); 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /InheritanceTechnique1b/InheritanceTechnique1bMain.java: -------------------------------------------------------------------------------- 1 | package InheritanceTechnique1b; 2 | 3 | public class InheritanceTechnique1bMain { 4 | public InheritanceTechnique1bMain() { 5 | System.out.println("InheritanceTechnique1bMain.InheritanceTechnique1bMain()"); 6 | } 7 | 8 | public static void main(String args[]) { 9 | BeActive beActive = new BeActive(); 10 | beActive.task1(); 11 | beActive.task2(); 12 | beActive.task3(); 13 | beActive.task4(); 14 | 15 | BeActive beActive2 = new BeActive(10, 20, 30); 16 | beActive2.task1(); 17 | beActive2.task2(); 18 | beActive2.task3(); 19 | beActive2.task4(); 20 | 21 | BeActive beActive3 = new BeActive('r', 20); 22 | beActive3.task1(); 23 | beActive3.task2(); 24 | beActive3.task3(); 25 | beActive3.task4(); 26 | 27 | BeActive beActive4 = new BeActive(79, 20); 28 | beActive4.task1(); 29 | beActive4.task2(); 30 | beActive4.task3(); 31 | beActive4.task4(); 32 | } 33 | } -------------------------------------------------------------------------------- /InheritanceTechnique2/ExistedLogic.java: -------------------------------------------------------------------------------- 1 | package InheritanceTechnique2; 2 | 3 | public class ExistedLogic { 4 | public ExistedLogic() { 5 | System.out.println("ExistedLogic.ExistedLogic()"); 6 | } 7 | 8 | public void task1() { 9 | System.out.println("ExistedLogic.task1()"); 10 | int a = 10; 11 | int b = 20; 12 | int result = a + b; 13 | System.out.println("Result :: " + result); 14 | } 15 | } -------------------------------------------------------------------------------- /InheritanceTechnique2/InheritanceTechnique2Main.java: -------------------------------------------------------------------------------- 1 | package InheritanceTechnique2; 2 | 3 | public class InheritanceTechnique2Main { 4 | 5 | public InheritanceTechnique2Main() { 6 | System.out.println("InheritanceTechnique2Main.InheritanceTechnique2Main()"); 7 | } 8 | 9 | public static void main(String args[]) { 10 | System.out.println("InheritanceTechnique2Main.main()"); 11 | NewLogic newLogic = new NewLogic(); 12 | newLogic.task1(); 13 | } 14 | 15 | } 16 | 17 | /** 18 | * OUT PUT = 143 19 | */ 20 | -------------------------------------------------------------------------------- /InheritanceTechnique2/NewLogic.java: -------------------------------------------------------------------------------- 1 | package InheritanceTechnique2; 2 | 3 | public class NewLogic extends ExistedLogic { 4 | 5 | public NewLogic() { 6 | System.out.println("NewLogic.NewLogic()"); 7 | } 8 | 9 | @Override 10 | public void task1() { 11 | System.out.println("NewLogic.task1()"); 12 | int a = 67; 13 | int b = 76; 14 | int result = a + b; 15 | System.out.println("Result :: " + result); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /InnerClasses/AnonymousInnerClasses/MainApp.java: -------------------------------------------------------------------------------- 1 | package InnerClasses.AnonymousInnerClasses; 2 | 3 | public class MainApp { 4 | 5 | public MainApp() { 6 | System.out.println("MainApp.MainApp()"); 7 | } 8 | 9 | public static void main(String args[]) { 10 | ProjectApp projectApp = new ProjectApp() { 11 | @Override 12 | public void task1() { 13 | System.out.println("MainApp.main(...).new ProjectApp() {...}.task1()"); 14 | System.out.println("Anonymous Inner class"); 15 | } 16 | }; 17 | 18 | projectApp.task1(); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /InnerClasses/AnonymousInnerClasses/ProjectApp.java: -------------------------------------------------------------------------------- 1 | package InnerClasses.AnonymousInnerClasses; 2 | 3 | public abstract class ProjectApp { 4 | 5 | public ProjectApp() { 6 | System.out.println("ProjectApp.ProjectApp()"); 7 | } 8 | 9 | public abstract void task1(); 10 | } 11 | -------------------------------------------------------------------------------- /InnerClasses/NormalInnerClasses/MainClass.java: -------------------------------------------------------------------------------- 1 | package InnerClasses.NormalInnerClasses; 2 | 3 | public class MainClass { 4 | public MainClass() { 5 | System.out.println("MainClass.MainClass()"); 6 | } 7 | 8 | public static void main(String args[]) { 9 | OuterClass outerClass = new OuterClass(); 10 | outerClass.task1(); 11 | 12 | OuterClass.Inner inner = new OuterClass.Inner(); 13 | inner.task2(); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /InnerClasses/NormalInnerClasses/OuterClass.java: -------------------------------------------------------------------------------- 1 | package InnerClasses.NormalInnerClasses; 2 | 3 | public class OuterClass { 4 | public OuterClass() { 5 | System.out.println("OuterClass.OuterClass()"); 6 | } 7 | 8 | public void task1() { 9 | System.out.println("OuterClass.task1()"); 10 | } 11 | 12 | /** Here static block is mandatory to create inner class */ 13 | static class Inner { 14 | public void task2() { 15 | System.out.println("OuterClass.Inner.task2()"); 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Interfaces/Example1/ClientApp.java: -------------------------------------------------------------------------------- 1 | package Interfaces.Example1; 2 | 3 | public class ClientApp { 4 | public ClientApp() { 5 | System.out.println("ClientApp.ClientApp()"); 6 | } 7 | 8 | public static void main(String args[]) { 9 | System.out.println("ClientApp.main()"); 10 | ProjectApp projectApp = new DevApp(); 11 | projectApp.task1(); 12 | projectApp.task2(); 13 | 14 | ProjectApp2 projectApp2 = new DevApp(); 15 | projectApp2.task3(); 16 | projectApp2.task4(); 17 | 18 | DevApp devApp = new DevApp(); 19 | devApp.task1(); 20 | devApp.task2(); 21 | devApp.task3(); 22 | devApp.task4(); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /Interfaces/Example1/DevApp.java: -------------------------------------------------------------------------------- 1 | package Interfaces.Example1; 2 | 3 | public class DevApp implements ProjectApp, ProjectApp2 { 4 | 5 | public DevApp() { 6 | System.out.println("DevApp.DevApp()"); 7 | } 8 | 9 | @Override 10 | public void task1() { 11 | System.out.println("DevApp.task1()"); 12 | System.out.println("task1() - value of a is " + a); 13 | 14 | } 15 | 16 | @Override 17 | public void task2() { 18 | System.out.println("DevApp.task2()"); 19 | System.out.println("task2() - value of a is " + a); 20 | } 21 | 22 | @Override 23 | public void task3() { 24 | System.out.println("DevApp.task3()"); 25 | System.out.println("task3() - value of b is " + b); 26 | } 27 | 28 | @Override 29 | public void task4() { 30 | System.out.println("DevApp.task4()"); 31 | System.out.println("task4() - value of b is " + b); 32 | 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /Interfaces/Example1/ProjectApp.java: -------------------------------------------------------------------------------- 1 | package Interfaces.Example1; 2 | 3 | /** DESIGN */ 4 | public interface ProjectApp { 5 | /** 6 | * In Interfaces we declared variables. Those variable will act like final and 7 | * static 8 | * Meaning we can't able to update the variable value.and even we can't able to 9 | * add construcors in 10 | * Interfaces due to interfaces no constructors. 11 | */ 12 | int a = 10; 13 | 14 | /** 15 | * In Interfaces we declared methods and those methods will act like abstract 16 | * methods 17 | * Meaning methods not containing body and implementaion and interface all 18 | * methods 19 | * Are abstract methods, Even we can't able to write normal methods and 20 | * staticmethods 21 | */ 22 | void task1(); 23 | 24 | void task2(); 25 | } 26 | -------------------------------------------------------------------------------- /Interfaces/Example1/ProjectApp2.java: -------------------------------------------------------------------------------- 1 | package Interfaces.Example1; 2 | 3 | public interface ProjectApp2 { 4 | int b = 30; 5 | 6 | public void task3(); 7 | 8 | public void task4(); 9 | } 10 | -------------------------------------------------------------------------------- /LogicalOpsExample.java: -------------------------------------------------------------------------------- 1 | public class LogicalOpsExample { 2 | public static void main(String args[]) { 3 | int a = 10; 4 | int b = 20; 5 | int c = 4; 6 | 7 | if (a < b && b > c) { 8 | System.out.println("Condition will be true - AND"); 9 | } 10 | 11 | if (a > b || b > c) { 12 | System.out.println("Condition will be true - OR"); 13 | } 14 | } 15 | } -------------------------------------------------------------------------------- /MethodOverloading/DevelopmentOveload.java: -------------------------------------------------------------------------------- 1 | package MethodOverloading; 2 | 3 | public class DevelopmentOveload { 4 | private int a; 5 | private int b; 6 | 7 | public DevelopmentOveload() { 8 | System.out.println("DevelopmentOveload.DevelopmentOveload()"); 9 | } 10 | 11 | public DevelopmentOveload(int a, int b) { 12 | System.out.println("DevelopmentOveload.DevelopmentOveload()"); 13 | this.a = a; 14 | this.b = b; 15 | } 16 | 17 | public void task1() { 18 | System.out.println("DevelopmentOveload.task1() - zero params"); 19 | int res = this.a + this.b; 20 | System.out.println("res is " + res); 21 | } 22 | 23 | public void task1(int a, int b) { 24 | System.out.println("DevelopmentOveload.task1() - two params"); 25 | this.a = a; 26 | this.b = b; 27 | int res = this.a + this.b; 28 | System.out.println("res is " + res); 29 | } 30 | 31 | public void task1(int a) { 32 | System.out.println("DevelopmentOveload.task1() - one param"); 33 | this.a = a; 34 | int res = this.a + this.b; 35 | System.out.println("res is " + res); 36 | } 37 | 38 | public void task1(int a, int b, int c) { 39 | System.out.println("DevelopmentOveload.task1() - three params"); 40 | this.a = a; 41 | this.b = b; 42 | int res = this.a + this.b + c; 43 | System.out.println("res value is " + res); 44 | } 45 | 46 | public void task1(int a, int b, int c, int d) { 47 | System.out.println("DevelopmentOveload.task1() - four params"); 48 | this.a = a; 49 | this.b = b; 50 | int res = this.a + this.b + c + d; 51 | System.out.println("res value is " + res); 52 | } 53 | 54 | } 55 | -------------------------------------------------------------------------------- /MethodOverloading/MethodOverloadingMain.java: -------------------------------------------------------------------------------- 1 | package MethodOverloading; 2 | 3 | public class MethodOverloadingMain { 4 | 5 | public MethodOverloadingMain() { 6 | System.out.println("MethodOverloadingMain.MethodOverloadingMain()"); 7 | } 8 | 9 | public static void main(String args[]) { 10 | System.out.println("MethodOverloadingMain.main()"); 11 | DevelopmentOveload dOveload = new DevelopmentOveload(15, 25); 12 | dOveload.task1(); 13 | dOveload.task1(25); 14 | dOveload.task1(47, 98); 15 | dOveload.task1(11, 22, 85); 16 | dOveload.task1(75, 99, 11, 73); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /NewInstance/NewInstanceExample.java: -------------------------------------------------------------------------------- 1 | package NewInstance; 2 | 3 | import java.util.Scanner; 4 | 5 | public class NewInstanceExample { 6 | public NewInstanceExample() { 7 | System.out.println("NewInstanceExample.NewInstanceExample()"); 8 | } 9 | 10 | public static void main(String args[]) throws Exception { 11 | System.out.println("NewInstanceExample.main()"); 12 | Scanner scanner = new Scanner(System.in); 13 | String req; 14 | System.out.println("Enter input"); 15 | req = scanner.nextLine(); 16 | Object object = Class.forName(req).newInstance(); 17 | System.out.println(object); 18 | scanner.close(); 19 | 20 | } 21 | } -------------------------------------------------------------------------------- /OddOrEvenNumber.java: -------------------------------------------------------------------------------- 1 | public class OddOrEvenNumber { 2 | public static void main(String args[]) { 3 | int number = 6; 4 | if (number % 2 == 0) { 5 | System.out.println(number + " is even number"); 6 | } else { 7 | System.out.println(number + " is odd number"); 8 | } 9 | } 10 | } -------------------------------------------------------------------------------- /OddOrEvenNumberScannerExample.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | public class OddOrEvenNumberScannerExample { 4 | public static void main(String args[]) { 5 | Scanner sc = new Scanner(System.in); 6 | System.out.println("Please Enter number "); 7 | int number = sc.nextInt(); 8 | if (number % 2 == 0) { 9 | System.out.println(number + " is even number"); 10 | } else { 11 | System.out.println(number + " is odd number"); 12 | } 13 | 14 | sc.close(); 15 | } 16 | } -------------------------------------------------------------------------------- /OopsProject1/App1.java: -------------------------------------------------------------------------------- 1 | package OopsProject1; 2 | 3 | public class App1 { 4 | 5 | public int a = 10; 6 | 7 | public App1() { 8 | System.out.println("App1.App1()"); 9 | } 10 | 11 | public void task1() { 12 | System.out.println("App1.task1()"); 13 | System.out.println(" a value is " + a); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /OopsProject1/App2.java: -------------------------------------------------------------------------------- 1 | package OopsProject1; 2 | 3 | public class App2 { 4 | public int b = 20; 5 | 6 | public App2() { 7 | System.out.println("App2.App2()"); 8 | } 9 | 10 | public void task2() { 11 | System.out.println("App2.task2()"); 12 | System.out.println("value of b is " + b); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /OopsProject1/App3.java: -------------------------------------------------------------------------------- 1 | package OopsProject1; 2 | 3 | public class App3 { 4 | public int c = 30; 5 | 6 | public App3() { 7 | System.out.println("App3.App3()"); 8 | } 9 | 10 | public void task3() { 11 | System.out.println("App3.task3()"); 12 | System.out.println("value of c is " + c); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /OopsProject1/ProjectMain.java: -------------------------------------------------------------------------------- 1 | package OopsProject1; 2 | 3 | public class ProjectMain { 4 | 5 | public static void main(String args[]) { 6 | System.out.println("------------------------------------------"); 7 | /** object creation for App1 */ 8 | App1 app1 = new App1(); 9 | app1.task1(); 10 | System.out.println("------------------------------------------"); 11 | 12 | /** object creation for App2 */ 13 | App2 app2 = new App2(); 14 | app2.task2(); 15 | System.out.println("------------------------------------------"); 16 | 17 | /** object creation for App3 */ 18 | App3 app3 = new App3(); 19 | app3.task3(); 20 | System.out.println("------------------------------------------"); 21 | } 22 | } -------------------------------------------------------------------------------- /OopsProject2/Employee.java: -------------------------------------------------------------------------------- 1 | package OopsProject2; 2 | 3 | import java.util.Scanner; 4 | 5 | public class Employee { 6 | private int eid; 7 | private String eName; 8 | private String eCompany; 9 | private double eSalary; 10 | 11 | public Employee() { 12 | System.out.println("Employee.Employee()"); 13 | } 14 | 15 | public void reading() { 16 | Scanner scanner = new Scanner(System.in); 17 | System.out.println("Please enter employee details below"); 18 | System.out.println("Employee Eid : "); 19 | this.eid = scanner.nextInt(); 20 | System.out.println("Employee Name : "); 21 | this.eName = scanner.next(); 22 | System.out.println("Employee Company : "); 23 | this.eCompany = scanner.next(); 24 | System.out.println("Employee Salary : "); 25 | this.eSalary = scanner.nextDouble(); 26 | scanner.close(); 27 | } 28 | 29 | public void details() { 30 | System.out.println("Entered Employee Details"); 31 | System.out.println("Employee Id: " + this.eid); 32 | System.out.println("Employee Name: " + this.eName); 33 | System.out.println("Employee Company: " + this.eCompany); 34 | System.out.println("Employee Salary: " + this.eSalary); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /OopsProject2/ProjectMain.java: -------------------------------------------------------------------------------- 1 | package OopsProject2; 2 | 3 | public class ProjectMain { 4 | 5 | public static void main(String args[]) { 6 | Employee employee = new Employee(); 7 | System.out.println("--------------------------------"); 8 | employee.reading(); 9 | System.out.println("--------------------------------"); 10 | employee.details(); 11 | System.out.println("--------------------------------"); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /OopsProject3/OOPSTech3.java: -------------------------------------------------------------------------------- 1 | package OopsProject3; 2 | 3 | public class OOPSTech3 { 4 | 5 | public OOPSTech3() { 6 | System.out.println("OOPSTech3.OOPSTech3()"); 7 | } 8 | 9 | public static void main(String args[]) { 10 | System.out.println("OOPSTech3.main()"); 11 | OOPSTech3 oopsTech3 = new OOPSTech3(); 12 | WorkingWithSameMethodNames wMethodNames = new WorkingWithSameMethodNames(); 13 | 14 | /** calling method with zero params with int type */ 15 | wMethodNames.task(); 16 | 17 | /** calling method with one param with int type */ 18 | wMethodNames.task(35); 19 | 20 | /** calling method with two params with int type */ 21 | wMethodNames.task(35, 45); 22 | 23 | /** calling method with one param with char tyoe */ 24 | wMethodNames.task('c'); 25 | 26 | /** calling method with three params with int type */ 27 | wMethodNames.task(10, 20, 30); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /OopsProject3/ParametersActualVsFormal.java: -------------------------------------------------------------------------------- 1 | package OopsProject3; 2 | 3 | public class ParametersActualVsFormal { 4 | 5 | int a; 6 | int b; 7 | 8 | public ParametersActualVsFormal() { 9 | System.out.println("ParametersActualVsFormal.ParametersActualVsFormal()"); 10 | } 11 | 12 | public void actualParams(int a, int b) { 13 | System.out.println("ParametersActualVsFormal.actualParams()"); 14 | /* 15 | * Actual parameters habituated with this keyword 16 | */ 17 | this.a = a; 18 | this.b = b; 19 | int sum = a + b; 20 | System.out.println(sum); 21 | } 22 | 23 | public void formalParms(int c, int d) { 24 | System.out.println("ParametersActualVsFormal.formalParms()"); 25 | a = c; 26 | b = d; 27 | int sum = a + b; 28 | System.out.println(sum); 29 | } 30 | 31 | public void printInstVariableValues() { 32 | System.out.println("value of a is " + a); 33 | System.out.println("value of b is " + b); 34 | } 35 | 36 | public static void main(String args[]) { 37 | System.out.println("ParametersActualVsFormal.main()"); 38 | /* Creating a object */ 39 | ParametersActualVsFormal actualVsFormal = new ParametersActualVsFormal(); 40 | actualVsFormal.printInstVariableValues(); 41 | actualVsFormal.actualParams(10, 20); 42 | actualVsFormal.printInstVariableValues(); 43 | 44 | actualVsFormal.formalParms(40, 60); 45 | actualVsFormal.printInstVariableValues(); 46 | 47 | } 48 | } -------------------------------------------------------------------------------- /OopsProject3/WorkingWithSameMethodNames.java: -------------------------------------------------------------------------------- 1 | package OopsProject3; 2 | 3 | public class WorkingWithSameMethodNames { 4 | 5 | private int a = 10; 6 | private int b = 20; 7 | 8 | public WorkingWithSameMethodNames() { 9 | System.out.println("WorkingWithSameMethodNames.WorkingWithSameMethodNames()"); 10 | } 11 | 12 | public void task(int a, int b) { 13 | System.out.println("WorkingWithSameMethodNames.task()"); 14 | System.out.println("value of a and b is " + a + " , " + b); 15 | } 16 | 17 | public void task() { 18 | System.out.println("WorkingWithSameMethodNames.task()"); 19 | System.out.println("value of a and b is " + a + " , " + b); 20 | } 21 | 22 | public void task(int a) { 23 | System.out.println("WorkingWithSameMethodNames.task()"); 24 | System.out.println("value of a and b is " + a + "," + b); 25 | } 26 | 27 | public void task(char c) { 28 | System.out.println("WorkingWithSameMethodNames.task()"); 29 | System.out.println("value of a and b is " + a + " , " + b); 30 | } 31 | 32 | public void task(int a, int b, int c) { 33 | System.out.println("WorkingWithSameMethodNames.task()"); 34 | System.out.println("value of a and b is " + a + " , " + b); 35 | } 36 | 37 | public static void main(int a, char b) { 38 | System.out.println("WorkingWithSameMethodNames.main()"); 39 | System.out.println("value of a and b is " + a + "," + b); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /OopsProject4/ConstructorsExample.java: -------------------------------------------------------------------------------- 1 | package OopsProject4; 2 | 3 | public class ConstructorsExample { 4 | 5 | int a = 10; 6 | int b = 20; 7 | char x = 'y'; 8 | 9 | public ConstructorsExample() { 10 | System.out.println("ConstructorsExample.ConstructorsExample()"); 11 | } 12 | 13 | public ConstructorsExample(int a) { 14 | System.out.println("ConstructorsExample.ConstructorsExample()"); 15 | this.a = a; 16 | } 17 | 18 | public ConstructorsExample(int a, int b) { 19 | System.out.println("ConstructorsExample.ConstructorsExample()"); 20 | this.a = a; 21 | this.b = b; 22 | } 23 | 24 | public ConstructorsExample(int a, char x) { 25 | System.out.println("ConstructorsExample.ConstructorsExample()"); 26 | this.a = a; 27 | this.x = x; 28 | } 29 | 30 | public ConstructorsExample(int a, int b, char x) { 31 | System.out.println("ConstructorsExample.ConstructorsExample()"); 32 | this.a = a; 33 | this.b = b; 34 | this.x = x; 35 | } 36 | 37 | public ConstructorsExample(char x) { 38 | System.out.println("ConstructorsExample.ConstructorsExample()"); 39 | this.x = x; 40 | } 41 | 42 | public void task1() { 43 | System.out.println("ConstructorsExample.task1()"); 44 | System.out.println("The value of a is " + a); 45 | } 46 | 47 | public void task2() { 48 | System.out.println("ConstructorsExample.task2()"); 49 | System.out.println("The value of a is " + a); 50 | System.out.println("The value of b is " + b); 51 | System.out.println("The valeu of x is " + x); 52 | } 53 | 54 | public void task3() { 55 | System.out.println("ConstructorsExample.task3()"); 56 | System.out.println("The value of a is " + a); 57 | System.out.println("The valeu of b is " + b); 58 | System.out.println("The value of x is " + x); 59 | } 60 | 61 | public void task4() { 62 | System.out.println("ConstructorsExample.task4()"); 63 | System.out.println("The value of a is " + a); 64 | System.out.println("The value of b is " + b); 65 | System.out.println("The value of x is " + x); 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /OopsProject4/OOPSTechnique4.java: -------------------------------------------------------------------------------- 1 | package OopsProject4; 2 | 3 | public class OOPSTechnique4 { 4 | 5 | public OOPSTechnique4() { 6 | System.out.println("OOPSTechnique4.OOPSTechnique4()"); 7 | } 8 | 9 | public static void main(String args[]) { 10 | System.out.println("OOPSTechnique4.main()"); 11 | OOPSTechnique4 oopsTechnique4 = new OOPSTechnique4(); 12 | ConstructorsExample cExample = new ConstructorsExample(); 13 | cExample.task1(); 14 | cExample.task2(); 15 | cExample.task3(); 16 | cExample.task4(); 17 | 18 | ConstructorsExample constructorsExample = new ConstructorsExample(70); 19 | constructorsExample.task1(); 20 | constructorsExample.task2(); 21 | constructorsExample.task3(); 22 | constructorsExample.task4(); 23 | 24 | ConstructorsExample cExample2 = new ConstructorsExample('R'); 25 | cExample2.task1(); 26 | cExample2.task2(); 27 | cExample2.task3(); 28 | cExample2.task4(); 29 | 30 | ConstructorsExample cExample3 = new ConstructorsExample(85, 'D'); 31 | cExample3.task1(); 32 | cExample3.task2(); 33 | cExample3.task3(); 34 | cExample3.task4(); 35 | 36 | ConstructorsExample cExample4 = new ConstructorsExample(65, 75); 37 | cExample4.task1(); 38 | cExample4.task2(); 39 | cExample4.task3(); 40 | cExample4.task4(); 41 | 42 | ConstructorsExample cExample5 = new ConstructorsExample(25, 56, 'L'); 43 | cExample5.task1(); 44 | cExample5.task2(); 45 | cExample5.task3(); 46 | cExample5.task4(); 47 | } 48 | } -------------------------------------------------------------------------------- /OopsProject5/Employee.java: -------------------------------------------------------------------------------- 1 | package OopsProject5; 2 | 3 | public class Employee { 4 | 5 | private int eid; 6 | private String eName; 7 | private double eSalary; 8 | public final static String COMPANY_NAME = "TCS"; 9 | 10 | public Employee() { 11 | System.out.println("Employee.Employee()"); 12 | } 13 | 14 | public Employee(int eid, String eName, double eSalary) { 15 | System.out.println("Employee.Employee()"); 16 | this.eid = eid; 17 | this.eName = eName; 18 | this.eSalary = eSalary; 19 | } 20 | 21 | public void printEmployeeDetails() { 22 | System.out.println("Employee Details"); 23 | System.out.println("Employee Id : " + eid); 24 | System.out.println("Employee Name : " + eName); 25 | System.out.println("Employee Salary : " + eSalary); 26 | System.out.println("Employee Company : " + COMPANY_NAME); 27 | } 28 | 29 | public static void change(String companyName) { 30 | /* 31 | * Throwing erro like The final field Employee.COMPANY_NAME cannot be assigned 32 | */ 33 | // COMPANY_NAME =companyName; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /OopsProject5/OOPSTechnique5.java: -------------------------------------------------------------------------------- 1 | package OopsProject5; 2 | 3 | import java.util.Scanner; 4 | 5 | public class OOPSTechnique5 { 6 | 7 | public OOPSTechnique5() { 8 | System.out.println("OOPSTechnique5.OOPSTechnique5()"); 9 | } 10 | 11 | public static void main(String args[]) { 12 | System.out.println("OOPSTechnique5.main()"); 13 | OOPSTechnique5 oTechnique5 = new OOPSTechnique5(); 14 | Scanner scanner = new Scanner(System.in); 15 | 16 | System.out.println("Enter Employee Details"); 17 | 18 | System.out.print("Enter Employee Id: "); 19 | int eid = scanner.nextInt(); 20 | 21 | System.out.print("Enter Employee Salary: "); 22 | double eSalary = scanner.nextDouble(); 23 | 24 | System.out.print("Enter Employee Name: "); 25 | String eName = scanner.next(); 26 | 27 | /* Creating object */ 28 | Employee employee = new Employee(eid, eName, eSalary); 29 | employee.printEmployeeDetails(); 30 | 31 | /** close scanner */ 32 | scanner.close(); 33 | 34 | } 35 | } -------------------------------------------------------------------------------- /OverrideCases/PracticalCase1/DevApp.java: -------------------------------------------------------------------------------- 1 | package OverrideCases.PracticalCase1; 2 | 3 | public class DevApp extends ProjectApp { 4 | 5 | public DevApp() { 6 | System.out.println("DevApp.DevApp()"); 7 | } 8 | 9 | @Override 10 | public void task(int x) { 11 | System.out.println("DevApp.task()"); 12 | System.out.println("Square root of x is " + Math.sqrt(x)); 13 | System.out.println("Square root of x is " + (x * 0.5)); 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /OverrideCases/PracticalCase1/MainApp.java: -------------------------------------------------------------------------------- 1 | package OverrideCases.PracticalCase1; 2 | 3 | public class MainApp { 4 | public MainApp() { 5 | System.out.println("MainApp.MainApp()"); 6 | } 7 | 8 | public static void main(String args[]) { 9 | System.out.println("MainApp.main()"); 10 | ProjectApp projectApp = new DevApp(); 11 | projectApp.task(3); 12 | } 13 | 14 | } -------------------------------------------------------------------------------- /OverrideCases/PracticalCase1/ProjectApp.java: -------------------------------------------------------------------------------- 1 | package OverrideCases.PracticalCase1; 2 | 3 | public class ProjectApp { 4 | 5 | public ProjectApp() { 6 | System.out.println("ProjectApp.ProjectApp()"); 7 | } 8 | 9 | public void task(int x) { 10 | System.out.println("ProjectApp.task()"); 11 | System.out.println("Nothing is there"); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /OverrideCases/PracticalCase2/DevApp1.java: -------------------------------------------------------------------------------- 1 | package OverrideCases.PracticalCase2; 2 | 3 | public class DevApp1 extends ProjectApp { 4 | 5 | public DevApp1() { 6 | System.out.println("DevApp.DevApp()"); 7 | } 8 | 9 | @Override 10 | public void task(int x) { 11 | System.out.println("DevApp.task()"); 12 | System.out.println("value of x is " + x); 13 | System.out.println("sqrt of x is " + Math.sqrt(x)); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /OverrideCases/PracticalCase2/DevApp2.java: -------------------------------------------------------------------------------- 1 | package OverrideCases.PracticalCase2; 2 | 3 | public class DevApp2 extends DevApp1 { 4 | 5 | public DevApp2() { 6 | System.out.println("DevApp2.DevApp2()"); 7 | } 8 | 9 | @Override 10 | public void task(int x) { 11 | System.out.println("DevApp2.task()"); 12 | System.out.println("The value of x in devapp2 is" + x); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /OverrideCases/PracticalCase2/MainApp.java: -------------------------------------------------------------------------------- 1 | package OverrideCases.PracticalCase2; 2 | 3 | public class MainApp { 4 | public MainApp() { 5 | System.out.println("MainApp.MainApp()"); 6 | } 7 | 8 | public static void main(String args[]) { 9 | System.out.println("MainApp.main()"); 10 | /** 11 | * We can update the method implementation by using overiding class 12 | * In that way we can able use different methods in deferent situations 13 | */ 14 | /** 15 | * Here am creating DevApp1 object with shared memory. 16 | */ 17 | ProjectApp projectApp1 = new DevApp1(); 18 | projectApp1.task(7); 19 | 20 | /** 21 | * Here am creating DevApp2 object with shared memory. 22 | */ 23 | ProjectApp projectApp2 = new DevApp2(); 24 | projectApp2.task(5); 25 | 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /OverrideCases/PracticalCase2/ProjectApp.java: -------------------------------------------------------------------------------- 1 | package OverrideCases.PracticalCase2; 2 | 3 | public class ProjectApp { 4 | public ProjectApp() { 5 | System.out.println("ProjectApp.ProjectApp()"); 6 | } 7 | 8 | public void task(int x) { 9 | System.out.println("ProjectApp.task()"); 10 | System.out.println("Nothing is there value of x is " + x); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /Packages/com/mypackage/Test.java: -------------------------------------------------------------------------------- 1 | package Packages.com.mypackage; 2 | 3 | public class Test { 4 | private int a; 5 | 6 | public Test() { 7 | System.out.println("Test.Test()"); 8 | a = 10; 9 | } 10 | 11 | public void task1() { 12 | System.out.println("Test.task1()"); 13 | System.out.println("The value of a is " + a); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Packages/com/mypackage2/Test2.java: -------------------------------------------------------------------------------- 1 | package Packages.com.mypackage2; 2 | 3 | import Packages.com.mypackage.Test; 4 | 5 | public class Test2 { 6 | public Test2() { 7 | System.out.println("Test2.Test2()"); 8 | } 9 | 10 | public static void main(String args[]) { 11 | System.out.println("Test2.main()"); 12 | Test test = new Test(); 13 | test.task1(); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # core-java 2 | This project provides you programs related to core java concepts 3 | -------------------------------------------------------------------------------- /ReadInputFromBufferReader.java: -------------------------------------------------------------------------------- 1 | import java.io.BufferedReader; 2 | import java.io.IOException; 3 | import java.io.InputStreamReader; 4 | 5 | public class ReadInputFromBufferReader { 6 | public ReadInputFromBufferReader() { 7 | System.out.println("ReadInputFromBufferReader.ReadInputFromBufferReader()"); 8 | } 9 | 10 | public static void main(String args[]) throws IOException { 11 | System.out.println("ReadInputFromBufferReader.main()"); 12 | /* Read Data from buffer reader */ 13 | BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in)); 14 | System.out.print("Enter name : "); 15 | String name = bufferedReader.readLine(); 16 | System.out.println("====================================="); 17 | System.out.println(" Entered Details"); 18 | System.out.println("====================================="); 19 | System.out.println("Name " + name); 20 | System.out.println("====================================="); 21 | 22 | } 23 | } -------------------------------------------------------------------------------- /ReadInputFromConsole.java: -------------------------------------------------------------------------------- 1 | import java.io.Console; 2 | 3 | public class ReadInputFromConsole { 4 | public ReadInputFromConsole() { 5 | System.out.println("ReadInputFromConsole.ReadInputFromConsole()"); 6 | } 7 | 8 | public static void main(String args[]) { 9 | ReadInputFromConsole readInputFromConsole = new ReadInputFromConsole(); 10 | Console console = System.console(); 11 | System.out.print("Enter name : "); 12 | String name = console.readLine(); 13 | System.out.println("Entered Name : " + name); 14 | } 15 | } -------------------------------------------------------------------------------- /RelationalOpsExample.java: -------------------------------------------------------------------------------- 1 | public class RelationalOpsExample { 2 | public static void main(String args[]) { 3 | int a = 10; 4 | int b = 30; 5 | System.out.println("======================="); 6 | if (a == b) { 7 | System.out.println("a and b are equal"); 8 | } else { 9 | System.out.println("a and b are not equal"); 10 | } 11 | 12 | if (a > b) { 13 | System.out.println("a is greater than b"); 14 | } else { 15 | System.out.println("a is less than b"); 16 | } 17 | System.out.println("======================="); 18 | } 19 | } -------------------------------------------------------------------------------- /ReturnAndNonReturnTypeMethods/ProjectMain.java: -------------------------------------------------------------------------------- 1 | package ReturnAndNonReturnTypeMethods; 2 | 3 | public class ProjectMain { 4 | 5 | public ProjectMain() { 6 | System.out.println("ProjectMain.ProjectMain()"); 7 | } 8 | 9 | public static void main(String args[]) { 10 | System.out.println("ProjectMain.main()"); 11 | ReturnTypeAndNonReturnType returnTypeAndNonReturnType = new ReturnTypeAndNonReturnType(); 12 | returnTypeAndNonReturnType.addTwoNumberNonReturnType(20, 17); 13 | System.out.println("value of result is " + returnTypeAndNonReturnType.addTwoNumberReturnType(11, 19)); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /ReturnAndNonReturnTypeMethods/ReturnTypeAndNonReturnType.java: -------------------------------------------------------------------------------- 1 | package ReturnAndNonReturnTypeMethods; 2 | 3 | public class ReturnTypeAndNonReturnType { 4 | 5 | public ReturnTypeAndNonReturnType() { 6 | System.out.println("ReturnTypeAndNonReturnType.ReturnTypeAndNonReturnType()"); 7 | } 8 | 9 | public void addTwoNumberNonReturnType(int a, int b) { 10 | System.out.println("ReturnTypeAndNonReturnType.addTwoNumberNonReturnType()"); 11 | int result = a + b; 12 | System.out.println("value of result is " + result); 13 | } 14 | 15 | public int addTwoNumberReturnType(int a, int b) { 16 | System.out.println("ReturnTypeAndNonReturnType.addTwoNumberReturnType()"); 17 | int result = a + b; 18 | return result; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /ScannerExample.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | public class ScannerExample { 4 | public static void main(String... args) { 5 | int id; 6 | String name; 7 | double salary; 8 | String companyName; 9 | 10 | // creating scanner object 11 | Scanner sc = new Scanner(System.in); 12 | System.out.println("Please Enter Employee-Id"); 13 | id = sc.nextInt(); 14 | System.out.println("Please Enter Employee name"); 15 | name = sc.next(); 16 | System.out.println("Please Enter Company Name"); 17 | companyName = sc.next(); 18 | System.out.println("Please Enter Employee Salary"); 19 | salary = sc.nextDouble(); 20 | System.out.println("============= Employee Details =============="); 21 | System.out.println("Employee-Id : " + id); 22 | System.out.println("Employee-name : " + name); 23 | System.out.println("Employee Company : " + companyName); 24 | System.out.println("Employee-salary : " + salary); 25 | sc.close();// close scanner 26 | } 27 | } -------------------------------------------------------------------------------- /ScannerExample2.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | public class ScannerExample2 { 4 | public static void main(String[] args) { 5 | // Adding two numbers 6 | int a = 10; 7 | int b = 20; 8 | int c; 9 | int d; 10 | int res1; 11 | int res2; 12 | 13 | res1 = a + b; 14 | Scanner sc = new Scanner(System.in); 15 | System.out.print("Enter value of c = "); 16 | c = sc.nextInt(); 17 | System.out.print("Enter value of d = "); 18 | d = sc.nextInt(); 19 | 20 | res2 = c + d; 21 | System.out.println("res1 is " + res1); 22 | System.out.println("res2 is " + res2); 23 | 24 | sc.close(); 25 | } 26 | } -------------------------------------------------------------------------------- /ScannerExample3.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | /* 4 | * Tables printing 5 | */ 6 | public class ScannerExample3 { 7 | public static void main(String args[]) { 8 | int value; 9 | Scanner sc = new Scanner(System.in); 10 | System.out.println("Enter the value of table e.g 1 to 10"); 11 | value = sc.nextInt(); 12 | System.out.println("============= " + value + " Table ============"); 13 | for (int i = 1; i <= 10; i++) { 14 | int mulValue = i * value; 15 | System.out.println(value + " x " + i + " = " + mulValue); 16 | } 17 | sc.close(); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /ScannerExample4.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | public class ScannerExample4 { 4 | public static void main(String args[]) { 5 | String username; 6 | String password; 7 | Scanner sc = new Scanner(System.in); 8 | System.out.print("Enter username :: "); 9 | username = sc.next(); 10 | System.out.print("Enter password :: "); 11 | password = sc.next(); 12 | System.out.println(username); 13 | System.out.println(password); 14 | if (username.equals("admin") && password.equals("admin")) { 15 | System.out.println("Login successfull"); 16 | } else { 17 | System.out.println("Login fail"); 18 | } 19 | sc.close(); 20 | } 21 | } -------------------------------------------------------------------------------- /ScannerExample5.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | public class ScannerExample5 { 4 | 5 | public static void main(String args[]) { 6 | int sum = 0; 7 | int n = 0; 8 | Scanner sc = new Scanner(System.in); 9 | System.out.println("Enter value for number of values to sum"); 10 | n = sc.nextInt(); 11 | for (int i = 1; i <= n; i++) { 12 | sum = sum + i; 13 | } 14 | System.out.println("Sum of numbers is " + sum); 15 | sc.close(); 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /SecondApp.java: -------------------------------------------------------------------------------- 1 | public class SecondApp { 2 | public static void main(String[] args) { 3 | System.out.println("Welcome to java"); 4 | System.out.println("====================================================="); 5 | int a = 10, b = 20, c = 5, res1, res2; 6 | res1 = (a + b) / c; 7 | System.out.println("value of res1 " + res1);// value of res1 is 6 8 | res2 = ++res1; 9 | System.out.println("value of a is " + a);// value of a is 10 10 | System.out.println("value of b is " + b);// value of b is 20 11 | System.out.println("value of c is " + c);// value of c is 5 12 | System.out.println("value of res1 " + res1);// value of res1 is 7 13 | System.out.println("value of res2 " + res2); // value of res2 is 7 14 | // System.out.println(a, b, c);// error 15 | System.out.println(a + "::::" + b + "::::" + c); 16 | System.out.println(a + "," + b + "," + c + "," + res1 + "," + res2); 17 | System.out.println("a = " + a + "\nb = " + b + "\nc = " + c + "\nres1 = " + res1 + "\nres2 = " + res2); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /SecondJavaApp.java: -------------------------------------------------------------------------------- 1 | public class SecondJavaApp { 2 | int empId; 3 | String empName; 4 | Double empSalary; 5 | 6 | public SecondJavaApp(int empId, String empName, double empSalary) { 7 | this.empId = empId; 8 | this.empName = empName; 9 | this.empSalary = empSalary; 10 | System.out.println("SecondJavaApp.SecondJavaApp()"); 11 | } 12 | 13 | public void printEmployeeDetails() { 14 | System.out.println("=================================="); 15 | System.out.println("Employee Id : " + this.empId); 16 | System.out.println("Employee Name : " + this.empName); 17 | System.out.println("Employee Salary : " + this.empSalary); 18 | System.out.println("=================================="); 19 | } 20 | 21 | public static void main(String args[]) { 22 | SecondJavaApp secondJavaApp = new SecondJavaApp(504, "Srikanth Y", 50000); 23 | secondJavaApp.printEmployeeDetails(); 24 | 25 | } 26 | } -------------------------------------------------------------------------------- /SetterVsGetter/Employee.java: -------------------------------------------------------------------------------- 1 | package SetterVsGetter; 2 | 3 | public class Employee { 4 | private int id; 5 | private String name; 6 | private double salary; 7 | private String companyName; 8 | 9 | public Employee() { 10 | System.out.println("Employee.Employee()"); 11 | } 12 | 13 | public Employee(int id, String name, double salary, String companyName) { 14 | this.id = id; 15 | this.name = name; 16 | this.salary = salary; 17 | this.companyName = companyName; 18 | } 19 | 20 | public int getId() { 21 | return id; 22 | } 23 | 24 | public void setId(int id) { 25 | this.id = id; 26 | } 27 | 28 | public String getName() { 29 | return name; 30 | } 31 | 32 | public void setName(String name) { 33 | this.name = name; 34 | } 35 | 36 | public double getSalary() { 37 | return salary; 38 | } 39 | 40 | public void setSalary(double salary) { 41 | this.salary = salary; 42 | } 43 | 44 | public String getCompanyName() { 45 | return companyName; 46 | } 47 | 48 | public void setCompanyName(String companyName) { 49 | this.companyName = companyName; 50 | } 51 | 52 | @Override 53 | public String toString() { 54 | return "Employee [companyName=" + companyName + ", id=" + id + ", name=" + name + ", salary=" + salary + "]"; 55 | } 56 | 57 | } 58 | -------------------------------------------------------------------------------- /SetterVsGetter/ProjectMain.java: -------------------------------------------------------------------------------- 1 | package SetterVsGetter; 2 | 3 | public class ProjectMain { 4 | 5 | public ProjectMain() { 6 | System.out.println("ProjectMain.ProjectMain()"); 7 | } 8 | 9 | public static void main(String[] args) { 10 | System.out.println("ProjectMain.main()"); 11 | 12 | Employee employeeOne = new Employee(); 13 | employeeOne.setId(1021); 14 | employeeOne.setName("Srikanth"); 15 | employeeOne.setCompanyName("TCS"); 16 | employeeOne.setSalary(20000.50); 17 | 18 | System.out.println("Employee #1 Details"); 19 | System.out.println(employeeOne); 20 | 21 | Employee employeeTwo = new Employee(); 22 | employeeTwo.setId(1122); 23 | employeeTwo.setName("Raju"); 24 | employeeTwo.setSalary(52520); 25 | employeeTwo.setCompanyName("TCS"); 26 | 27 | System.out.println("Employee #2 Details"); 28 | System.out.println(employeeTwo); 29 | 30 | Student studentOne = new Student(1021, "Srikanth", "Svn", 8000, 8); 31 | System.out.println("Student #1 Details"); 32 | System.out.println(studentOne); 33 | 34 | Student studentTwo = new Student(); 35 | studentTwo.setSid(8888); 36 | studentTwo.setSchoolName("svn"); 37 | studentTwo.setSname("Raju"); 38 | studentTwo.setFee(8000); 39 | studentTwo.setSid(8); 40 | 41 | System.out.println("Student #2 Details"); 42 | System.out.println(studentTwo); 43 | } 44 | 45 | } 46 | -------------------------------------------------------------------------------- /SetterVsGetter/Student.java: -------------------------------------------------------------------------------- 1 | package SetterVsGetter; 2 | 3 | public class Student { 4 | private int sid; 5 | private String sname; 6 | private String schoolName; 7 | private double fee; 8 | private int std; 9 | 10 | public Student() { 11 | System.out.println("Student.Student()"); 12 | } 13 | 14 | public Student(int sid, String sname, String schoolName, double fee, int std) { 15 | this.sid = sid; 16 | this.sname = sname; 17 | this.schoolName = schoolName; 18 | this.fee = fee; 19 | this.std = std; 20 | } 21 | 22 | public int getSid() { 23 | return sid; 24 | } 25 | 26 | public void setSid(int sid) { 27 | this.sid = sid; 28 | } 29 | 30 | public String getSname() { 31 | return sname; 32 | } 33 | 34 | public void setSname(String sname) { 35 | this.sname = sname; 36 | } 37 | 38 | public String getSchoolName() { 39 | return schoolName; 40 | } 41 | 42 | public void setSchoolName(String schoolName) { 43 | this.schoolName = schoolName; 44 | } 45 | 46 | public double getFee() { 47 | return fee; 48 | } 49 | 50 | public void setFee(double fee) { 51 | this.fee = fee; 52 | } 53 | 54 | public int getStd() { 55 | return std; 56 | } 57 | 58 | public void setStd(int std) { 59 | this.std = std; 60 | } 61 | 62 | @Override 63 | public String toString() { 64 | return "Student [fee=" + fee + ", schoolName=" + schoolName + ", sid=" + sid + ", sname=" + sname + ", std=" 65 | + std + "]"; 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /StringExample.java: -------------------------------------------------------------------------------- 1 | public class StringExample { 2 | public static void main(String args[]) { 3 | String string = "welcome to java"; 4 | System.out.println(string); 5 | char[] charArray = string.toCharArray(); 6 | String reverseString = new String(); 7 | for (int i = charArray.length - 1; i >= 0; --i) { 8 | reverseString = reverseString + String.valueOf(charArray[i]); 9 | } 10 | System.out.println(reverseString); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /StringScannerExample.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | public class StringScannerExample { 4 | public static void main(String args[]) { 5 | Scanner scanner = new Scanner(System.in); 6 | System.out.print("Please enter string "); 7 | String string = scanner.nextLine(); 8 | System.out.println(string); 9 | char[] charArray = string.toCharArray(); 10 | String reverseString = new String(); 11 | for (int i = charArray.length - 1; i >= 0; --i) { 12 | reverseString = reverseString + String.valueOf(charArray[i]); 13 | } 14 | System.out.println(reverseString); 15 | scanner.close(); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /TernaryOpsExample.java: -------------------------------------------------------------------------------- 1 | public class TernaryOpsExample { 2 | public static void main(String args[]) { 3 | int a = 30; 4 | int b = 20; 5 | 6 | String res = a > b ? "a is bigger than b" : "b is bigger than a"; 7 | System.out.println("==========================================="); 8 | System.out.println("res value is " + res); 9 | System.out.println("==========================================="); 10 | 11 | } 12 | } -------------------------------------------------------------------------------- /TernaryOpsExample2.java: -------------------------------------------------------------------------------- 1 | public class TernaryOpsExample2 { 2 | public static void main(String args[]) { 3 | int a = 34; 4 | int b = 35; 5 | int c = 76; 6 | int res1; 7 | int res2; 8 | 9 | System.out.println("================================================"); 10 | res1 = (--b < ++a) ? ((a++ + c--) + (b++ - (--a))) : ((b-- + c++) + (c-- + b++)); // 110 11 | 12 | res2 = (--b < ++a) ? ((a++ + c--) + (b++ - (--a))) : ((b-- + c++) + (c-- + b++)); // 109 13 | 14 | System.out.println("res1 value is " + res1); 15 | System.out.println("res2 value is " + res2); 16 | 17 | System.out.println("================================================"); 18 | } 19 | } -------------------------------------------------------------------------------- /Threads/Example1/MainApp.java: -------------------------------------------------------------------------------- 1 | package Threads.Example1; 2 | 3 | public class MainApp { 4 | public MainApp() { 5 | System.out.println("MainApp.MainApp()"); 6 | } 7 | 8 | public static void main(String args[]) { 9 | System.out.println("MainApp.main()"); 10 | Thread thread1 = new SBIAtm1(); 11 | Thread thread2 = new SBIAtm2(); 12 | Thread thread3 = new SBIAtm3(); 13 | 14 | /** Threads will be executed by ThreadSchedular by using run method */ 15 | thread1.start(); 16 | thread2.start(); 17 | thread3.start(); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /Threads/Example1/SBIAtm1.java: -------------------------------------------------------------------------------- 1 | package Threads.Example1; 2 | 3 | public class SBIAtm1 extends Thread { 4 | public SBIAtm1() { 5 | System.out.println("SBIAtm1.SBIAtm1()"); 6 | } 7 | 8 | @Override 9 | public void run() { 10 | System.out.println("SBIAtm1.run()"); 11 | task1(); 12 | } 13 | 14 | public void task1() { 15 | System.out.println("SBIAtm1.task1()"); 16 | System.out.println("Task1 is completed"); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Threads/Example1/SBIAtm2.java: -------------------------------------------------------------------------------- 1 | package Threads.Example1; 2 | 3 | public class SBIAtm2 extends Thread { 4 | public SBIAtm2() { 5 | System.out.println("SBIAtm2.SBIAtm2()"); 6 | } 7 | 8 | @Override 9 | public void run() { 10 | System.out.println("SBIAtm2.run()"); 11 | task2(); 12 | } 13 | 14 | public void task2() { 15 | System.out.println("SBIAtm2.task2()"); 16 | System.out.println("Task2 is completed"); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Threads/Example1/SBIAtm3.java: -------------------------------------------------------------------------------- 1 | package Threads.Example1; 2 | 3 | public class SBIAtm3 extends Thread { 4 | public SBIAtm3() { 5 | System.out.println("SBIAtm3.SBIAtm3()"); 6 | } 7 | 8 | @Override 9 | public void run() { 10 | System.out.println("SBIAtm3.run()"); 11 | task3(); 12 | } 13 | 14 | public void task3() { 15 | System.out.println("SBIAtm3.task3()"); 16 | System.out.println("Task3 is completed."); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Threads/Example2/Client1.java: -------------------------------------------------------------------------------- 1 | package Threads.Example2; 2 | 3 | public class Client1 extends Thread { 4 | public Client1() { 5 | System.out.println("Client1.Client1()"); 6 | } 7 | 8 | @Override 9 | public void run() { 10 | System.out.println("Client1.run()"); 11 | System.out.println("Client #1 is running....."); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /Threads/Example2/Client2.java: -------------------------------------------------------------------------------- 1 | package Threads.Example2; 2 | 3 | public class Client2 extends Thread { 4 | 5 | public Client2() { 6 | System.out.println("Client2.Client2()"); 7 | } 8 | 9 | @Override 10 | public void run() { 11 | System.out.println("Client2.run()"); 12 | System.out.println("Client #2 is running...."); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /Threads/Example2/Clinet3.java: -------------------------------------------------------------------------------- 1 | package Threads.Example2; 2 | 3 | public class Clinet3 extends Thread { 4 | 5 | public Clinet3() { 6 | System.out.println("Clinet3.Clinet3()"); 7 | } 8 | 9 | @Override 10 | public void run() { 11 | System.out.println("Clinet3.run()"); 12 | System.out.println("Client 3 is running ...."); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /Threads/Example2/ServerMain.java: -------------------------------------------------------------------------------- 1 | package Threads.Example2; 2 | 3 | public class ServerMain { 4 | 5 | public ServerMain() { 6 | System.out.println("ServerMain.ServerMain()"); 7 | } 8 | 9 | public static void main(String[] args) { 10 | System.out.println("ServerMain.main()"); 11 | Thread thread1 = new Client1(); 12 | Thread thread2 = new Client2(); 13 | Thread thread3 = new Clinet3(); 14 | 15 | synchronized (thread1) { 16 | try { 17 | Client1.sleep(8000); 18 | thread1.start(); 19 | } catch (Exception e) { 20 | System.out.println(e.getLocalizedMessage()); 21 | } 22 | } 23 | 24 | synchronized (thread2) { 25 | try { 26 | Client2.sleep(10000); 27 | thread2.start(); 28 | } catch (Exception e) { 29 | System.out.println(e.getLocalizedMessage()); 30 | } 31 | } 32 | 33 | synchronized (thread3) { 34 | try { 35 | Clinet3.sleep(12000); 36 | thread3.start(); 37 | } catch (Exception e) { 38 | System.out.println(e.getLocalizedMessage()); 39 | } 40 | } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /UnitaryOpsExample.java: -------------------------------------------------------------------------------- 1 | public class UnitaryOpsExample { 2 | public static void main(String args[]) { 3 | int a = 10; 4 | System.out.println("==============================================="); 5 | System.out.println("after post increment a value is " + a++);// 10 6 | System.out.println("a value is " + a);// 11 7 | System.out.println("after pre increment a value is " + ++a); // 12 8 | System.out.println("a value is " + a);// 12 9 | System.out.println("after post decrement a value is " + a--); // 12 10 | System.out.println("a value is " + a);// 11 11 | System.out.println("after pre decrement a values is " + --a); // 10 12 | System.out.println("a values is " + a);// 10 13 | 14 | int b = 78; 15 | int c = 22; 16 | int d = 23; 17 | int res; 18 | 19 | res = (b-- + c++) + (d++ - ++b) + (c-- + --d) + d++; 20 | // res = (78 + 22) + (23 - 78)+ (23 + 23) + 23 = 114 21 | System.out.println("res value is " + res);// 114 22 | System.out.println("==============================================="); 23 | } 24 | } -------------------------------------------------------------------------------- /VarArgs/VarArgsExample.java: -------------------------------------------------------------------------------- 1 | package VarArgs; 2 | 3 | import java.util.Arrays; 4 | 5 | public class VarArgsExample { 6 | 7 | public VarArgsExample() { 8 | System.out.println("VarArgsExample.VarArgsExample()"); 9 | } 10 | 11 | public void task1(int... array) { 12 | System.out.println("VarArgsExample.task1()"); 13 | String value = Arrays.toString(array); 14 | for (int arrayValue : array) { 15 | System.out.println(arrayValue); 16 | } 17 | System.out.println(value); 18 | } 19 | } -------------------------------------------------------------------------------- /VarArgs/VarArgsExampleMain.java: -------------------------------------------------------------------------------- 1 | package VarArgs; 2 | 3 | public class VarArgsExampleMain { 4 | 5 | public VarArgsExampleMain() { 6 | System.out.println("VarArgsExampleMain.VarArgsExampleMain()"); 7 | } 8 | 9 | public static void main(String args[]) { 10 | VarArgsExample vArgsExample = new VarArgsExample(); 11 | vArgsExample.task1(20, 30, 40); 12 | vArgsExample.task1(20, 30, 40, 99, 78); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /Welcome.java: -------------------------------------------------------------------------------- 1 | class Welcome { 2 | 3 | public static void main(String args[]) { 4 | System.out.println("Hello World!"); 5 | } 6 | 7 | } -------------------------------------------------------------------------------- /WrapperClasses/String/StringOperations.java: -------------------------------------------------------------------------------- 1 | package WrapperClasses.String; 2 | 3 | public class StringOperations { 4 | 5 | private StringOperations() { 6 | System.out.println("StringOperations.StringOperations()"); 7 | } 8 | 9 | public static void main(String args[]) { 10 | System.out.println("StringOperations.main()"); 11 | String name = "Srikanth Java Developer"; 12 | System.out.println(name.length()); 13 | System.out.println(name.charAt(3)); 14 | System.out.println(name.isEmpty()); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /WrapperClasses/StringTokenizer/StringTokenizerExample.java: -------------------------------------------------------------------------------- 1 | package WrapperClasses.StringTokenizer; 2 | 3 | import java.util.Iterator; 4 | import java.util.StringTokenizer; 5 | 6 | public class StringTokenizerExample { 7 | 8 | public StringTokenizerExample() { 9 | System.out.println("StringTokenizerExample.StringTokenizerExample()"); 10 | } 11 | 12 | public static void main(String args[]) { 13 | System.out.println("StringTokenizerExample.main()"); 14 | StringTokenizer stringTokenizer = new StringTokenizer("raju kumar dusa"); 15 | System.out.println(stringTokenizer.countTokens()); 16 | Iterator tokens = stringTokenizer.asIterator(); 17 | while (tokens.hasNext()) { 18 | System.out.println(tokens.next()); 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /WrapperClasses/StringVsStringBuffer/StringVsStringBuffer.java: -------------------------------------------------------------------------------- 1 | package WrapperClasses.StringVsStringBuffer; 2 | 3 | public class StringVsStringBuffer { 4 | 5 | public StringVsStringBuffer() { 6 | System.out.println("StringVsStringBuffer.StringVsStringBuffer()"); 7 | } 8 | 9 | public static void main(String args[]) { 10 | System.out.println("StringVsStringBuffer.main()"); 11 | String name = new String("Ravi Sai"); 12 | System.out.println("before ::::::"); 13 | System.out.println(name.getClass().getName()); 14 | System.out.println("name is " + name); 15 | System.out.println("hashcode of name is " + name.hashCode()); 16 | name = name.concat(" Dusa"); 17 | System.out.println("after ::::::"); 18 | System.out.println(name.getClass().getName()); 19 | System.out.println("name is " + name); 20 | System.out.println("hashcode of name is " + name.hashCode()); 21 | System.out.println(); 22 | StringBuffer stringBuffer = new StringBuffer("Raju Kumar"); 23 | System.out.println("before ::::::"); 24 | System.out.println(name.getClass().getName()); 25 | System.out.println("stringBuffer is " + stringBuffer); 26 | System.out.println("hash code of stringBuffer is " + stringBuffer.hashCode()); 27 | stringBuffer.append(" Dusa"); 28 | System.out.println("after ::::::"); 29 | System.out.println(name.getClass().getName()); 30 | System.out.println("stringBuffer is " + stringBuffer); 31 | System.out.println("hash code of stringBuffer is " + stringBuffer.hashCode()); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /listofemployees.ser: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mryenagandula/core-java/c1e1e52374da6a2aa82253d162de0e0b32bcf141/listofemployees.ser --------------------------------------------------------------------------------