├── Java DOc.pdf └── src ├── ArrayListClone.java ├── BasicOfJava ├── ClassObjectAndMethod.java ├── Employee.java ├── Notes.java ├── Person.java ├── StaticAndNonStaticInJava.java ├── StaticAndNonStaticInJava1.java ├── StaticAndNonStaticInJava2.java └── StaticAndNonStaticNotes.java ├── Calculator.java ├── CloningOfCollectionInJava ├── CollectionDeepCloningArrayListTest.java ├── CollectionDeepCloningHashSetTest.java ├── CollectionDeepCloningMapTest.java ├── CollectionShallowCloningArrayListTest.java ├── CollectionShallowCloningHashMapTest.java ├── CollectionShallowCloningHashSetTest.java ├── Employee.java └── Employee2.java ├── Employee.java ├── HasCodeExampl1.java ├── OnlyPrimitive.java ├── Person.java ├── PersonHashingTest.java ├── PersonHashingTest1.java ├── PersonHashingTest2.java ├── PersonHashingTest3.java ├── ReturnTypeInJava ├── Example1.java └── Notes.java ├── RuntimePolymorphism ├── Animal.java ├── Cat.java ├── Dog.java ├── Example1.java ├── Example2.java ├── Example3.java ├── Lion.java └── TestPolym.java ├── StringTest.java ├── Student.java ├── Student2.java ├── ThisExample ├── Example1.java ├── Example2.java ├── Example3.java ├── Example4.java ├── Example5.java ├── Example6.java ├── Example7.java └── Example8.java ├── VariableDataType └── Example1.java ├── abstractInJava ├── A.java ├── Employee.java ├── Example1.java ├── Example2.java ├── Example3.java └── Person.java ├── abstractionInJava ├── Contractor.java ├── Employee.java ├── FullTimeEmployee.java └── TestAbstraction.java ├── access └── modifier │ └── test │ ├── Example3.java │ └── Example4.java ├── accessModifierInJava ├── Example1.java └── Example2.java ├── accessmodifier ├── Example1.java └── Example2.java ├── anonymousInnerClass ├── AbstractState.java ├── State.java ├── TestAbstractState.java ├── TestAnonymousClass.java └── TestState.java ├── arrayList ├── Address.java ├── Department.java ├── Department1.java ├── DistrictSorter.java ├── Employee.java ├── Employee1.java ├── Example1.java ├── Example10.java ├── Example11.java ├── Example12.java ├── Example13.java ├── Example14.java ├── Example15.java ├── Example16.java ├── Example17.java ├── Example18.java ├── Example19.java ├── Example2.java ├── Example20.java ├── Example21.java ├── Example22.java ├── Example23.java ├── Example3.java ├── Example4.java ├── Example5.java ├── Example6.java ├── Example7.java ├── Example8.java ├── Example9.java ├── LanguageSorter.java ├── PopulationSorter.java ├── RemoveMethods.java ├── State.java ├── State2.java ├── Student.java ├── Test1.java ├── TestCloning.java ├── TestCloning1.java ├── TestCloning2.java ├── TestObjectSorting.java └── TestState2Sorting.java ├── classExample └── Example1.java ├── collectionFramewrokInJava ├── ArrayListInJava.java ├── ArrayListInJava2.java ├── ArrayListInJava3.java ├── CollectionInjava.java ├── EnumerationInjava.java ├── HashSetInJava.java ├── HashSetInJava2.java ├── IteratorsInJava.java ├── LinkedHashSetClassInJava.java ├── LinkedListInJava.java ├── LinkedListInJava2.java ├── LinkedListInJava3.java ├── TreeSetInJava.java ├── VectorInJava.java └── VectorInJava2.java ├── concurrentHashMap ├── ComputeMethods_1.java ├── ConcurrentHashMapExample.java ├── ConcurrentHashMapStructure.java ├── ConcurrentMapVsMap_1.java ├── ConcurrentMapVsMap_2.java ├── ConcurrentMapVsMap_3.java ├── ConcurrentMapVsMap_4.java ├── ConcurrentMapVsSynchronizedMap_2.java ├── ConcurrentMapVsSynchronizedMap_3.java ├── Country.java ├── CrunchifyConcurrentHashMapVsSynchronizedMap.java └── ForEachMethods_2.java ├── constructor ├── controlStatements ├── BreakExample1.java ├── BreakExample2.java ├── BreakExample3.java ├── ContinueExample1.java ├── ContinueExample2.java ├── DoWhileLoopExample.java ├── ForEachLoopExample.java ├── ForLoopExample.java ├── ForLoopExample1.java ├── IfEleseifIF.java ├── IfElseExample.java ├── IfElseExample1.java ├── LabeledForLoop.java ├── SwitchCaseExample1.java ├── SwitchExample.java ├── WhileExam.java ├── WhileLoopExample.java ├── WhileLoopExample1.java └── WhileLoopExample2.java ├── customException ├── DAOException.java ├── DataException.java ├── ErrorCode.java ├── TestDataException.java └── TestException.java ├── encapsulationInJava ├── Bank.java ├── BirthDay.java ├── BrewingUnit.java ├── Coffee.java ├── CoffeeApp.java ├── CoffeeBean.java ├── CoffeeMachine.java ├── CoffeeMachineIf.java ├── CoffeeSelection.java ├── CollectionGetterSetter.java ├── CollectionGetterSetter2.java ├── Configuration.java ├── EncapsulationTest1.java ├── Example1.java ├── Example2.java ├── Example3.java ├── Example4.java ├── Grinder.java ├── GroundCoffee.java ├── Student.java ├── TestExample2.java ├── TestExample3.java ├── TestExample4.java ├── TestExample5.java ├── TestExample6.java ├── TestTestExample5.java └── TestTestExample6.java ├── enumjava ├── Example1.java ├── Example2.java ├── Operation.java ├── State.java ├── TestOperation.java └── TestState.java ├── exception ├── Example1.java ├── Example10.java ├── Example11.java ├── Example12.java ├── Example13.java ├── Example14.java ├── Example15.java ├── Example16.java ├── Example17.java ├── Example18.java ├── Example19.java ├── Example2.java ├── Example20.java ├── Example21.java ├── Example22.java ├── Example23.java ├── Example24.java ├── Example25.java ├── Example26.java ├── Example3.java ├── Example4.java ├── Example5.java ├── Example6.java ├── Example7.java ├── Example8.java ├── Example9.java ├── TestExample19.java └── test190.java ├── finalInJava ├── Example1.java ├── Example10.java ├── Example2.java ├── Example3.java ├── Example4.java ├── Example5.java ├── Example6.java ├── Example7.java ├── Example8.java └── Example9.java ├── inheritance ├── Address.java ├── C.java ├── Car.java ├── Circle.java ├── ClassRoom.java ├── College.java ├── Conts1.java ├── Conts2.java ├── D.java ├── Employee.java ├── Example2.java ├── Example3.java ├── Example4.java ├── Example6.java ├── Exaple1.java ├── JavaTeacher.java ├── Jeep.java ├── Operation.java ├── Ram.java ├── Student.java ├── Students.java ├── Teacher.java └── Vehicle.java ├── inheritanceInJava ├── A.java ├── B.java ├── ChildClass.java ├── Notes.java └── ParentClass.java ├── instanceOfInJava ├── Animal.java ├── Dog.java ├── Example1.java ├── Example2.java └── Example3.java ├── interfaceInjava ├── A.java ├── B1.java ├── B1Test.java ├── Bike.java ├── Car.java ├── Eample100.java ├── Exampl3.java ├── Exampl3Test.java ├── Example1.java ├── Example101.java ├── Example102.java ├── Example2.java ├── Example3.java ├── Example4.java ├── Example5.java ├── Example6.java ├── Example7.java ├── Example8.java ├── ImplementExample2.java ├── TestExample7.java ├── TestVehicle.java └── Vehicle.java ├── linkedList ├── Example1.java ├── Example2.java ├── Example3.java ├── Example4.java ├── Example5.java ├── Example6.java ├── ParentClass.java └── Test1234.java ├── mapClass ├── ComputeMethod.java ├── Example1.java ├── Example10.java ├── Example11.java ├── Example12.java ├── Example13.java ├── Example14.java ├── Example15.java ├── Example16.java ├── Example2.java ├── Example3.java ├── Example4.java ├── Example5.java ├── Example6.java ├── Example7.java ├── Example8.java ├── Example9.java ├── HowToHandelThreadconcurrency.java ├── MapObjects.java ├── School.java ├── TreeMapExample.java ├── UnderstandingOfMap.java └── ceilingEntry1.java ├── methodOverLoadingInjava ├── Example1.java ├── Example2.java ├── Example3.java └── Notes.java ├── methodOverloading ├── A.java ├── Overloading1.java ├── Overloading10.java ├── Overloading11.java ├── Overloading2.java ├── Overloading3.java ├── Overloading4.java ├── Overloading5.java ├── Overloading6.java ├── Overloading7.java ├── Overloading8.java └── Overloading9.java ├── methodOverriding ├── Bank.java ├── Bike.java ├── Car.java ├── Example1.java ├── Example2.java ├── HDFCBank.java ├── ICICI.java ├── Jeep.java ├── Overriding1.java ├── Overriding2.java ├── SBI.java ├── TestOverride.java ├── TestRateOfInterest.java └── Vehicle.java ├── methodOverridingInJava ├── Example1.java ├── Example2.java ├── Example3.java ├── Notes.java ├── TestExample1.java ├── TestExample2.java └── TestExample3.java ├── programs ├── CalculateSumOfNumbersOfArray.java ├── ConvertStringToNumber.java ├── CountNumberInArray.java ├── GenerateRandomNumber.java ├── IsPerfectNumber.java ├── PatternProgram1.java ├── PatternProgram2.java ├── PatternProgram3.java ├── PatternProgram5.java ├── PatternProgram6.java ├── PatternProgram7.java ├── PatternProgram8.java ├── ReverseNumber.java ├── SumOfArray.java └── TwoMaxNumbersInArray.java ├── queueImpl ├── Example1.java └── Example2.java ├── setClass ├── AgeComparator.java ├── AllAddMethods.java ├── AllRemoveMethods.java ├── Book.java ├── CloneWith_InstanceVariable.java ├── CloneWith_InstanceVariable2.java ├── CloneWith_Reference2.java ├── CloneWith_Reference3.java ├── CloneWith_Reference4.java ├── CloneWith_Reference5.java ├── ContainsMethods.java ├── CustomeObject.java ├── Example1.java ├── Example2.java ├── Example3.java ├── Example4.java ├── Example5.java ├── Example6.java ├── Example7.java ├── HashSetDuplicatehandling.java ├── HashSetObjects.java ├── PersonTreeSet.java ├── PersonTreeSet2.java ├── RetainAllMethods.java ├── SetClassWithCustomeObject.java ├── TestCustomeObject.java └── TestDefault.java ├── stack └── Example1.java ├── staticAndDynamicBinding ├── Example1.java ├── Example2.java ├── Example3.java ├── Example4.java ├── Example5.java └── Human.java ├── staticBlock ├── Example1.java ├── Example10.java ├── Example11.java ├── Example12.java ├── Example13.java ├── Example2.java ├── Example3.java ├── Example4.java ├── Example5.java ├── Example6.java ├── Example7.java ├── Example8.java ├── Example9.java └── Student.java ├── stringBuffer ├── Example1.java ├── Example2.java └── Example3.java ├── stringInjava ├── Example1.java ├── Example10.java ├── Example11.java ├── Example12.java ├── Example13.java ├── Example14.java ├── Example15.java ├── Example16.java ├── Example17.java ├── Example18.java ├── Example19.java ├── Example2.java ├── Example20.java ├── Example21.java ├── Example22.java ├── Example23.java ├── Example24.java ├── Example25.java ├── Example26.java ├── Example27.java ├── Example28.java ├── Example29.java ├── Example3.java ├── Example30.java ├── Example31.java ├── Example4.java ├── Example5.java ├── Example6.java ├── Example7.java ├── Example8.java └── Example9.java ├── testAccessModifierInJava ├── TestProtectedAndDefault.java └── TestProtectedAndDefault2.java ├── testInheritance ├── A.java ├── B.java ├── C.java └── TestInheritanceFromDifferentPackage.java ├── typeCasting ├── A.java ├── B.java ├── TypeCastingExample1.java ├── TypeCastingExample2.java ├── TypeCastingExample3.java └── TypeCastingExample4.java └── wrapperClassInjava ├── Ecample2.java ├── Example1.java ├── Example2.java ├── Snippet.java ├── Test1.java └── Test3.java /Java DOc.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LearnByBhanuPratap/coreJava/8321fb007d9117f54e7cd8397090d87e75c4143c/Java DOc.pdf -------------------------------------------------------------------------------- /src/BasicOfJava/ClassObjectAndMethod.java: -------------------------------------------------------------------------------- 1 | package BasicOfJava; 2 | 3 | public class ClassObjectAndMethod { 4 | 5 | public int hight; 6 | public int weight; 7 | public String color; 8 | 9 | public void walk(){ 10 | System.out.println("walk()"); 11 | } 12 | 13 | public void eat(int i){ 14 | System.out.println(i); 15 | } 16 | 17 | public void run(){ 18 | System.out.println("run()"); 19 | } 20 | 21 | public static void main(String[] args) { 22 | ClassObjectAndMethod obj = new ClassObjectAndMethod(); 23 | obj.walk(); 24 | obj.run(); 25 | obj.eat(5); 26 | System.out.println(obj.hight); 27 | ClassObjectAndMethod obj1 = new ClassObjectAndMethod(); 28 | obj1.eat(4); 29 | ClassObjectAndMethod obj2 = new ClassObjectAndMethod(); 30 | obj2.walk(); 31 | } 32 | 33 | 34 | 35 | } 36 | -------------------------------------------------------------------------------- /src/BasicOfJava/Employee.java: -------------------------------------------------------------------------------- 1 | package BasicOfJava; 2 | 3 | public class Employee { 4 | 5 | int i; 6 | int j; 7 | Person person; 8 | 9 | } 10 | -------------------------------------------------------------------------------- /src/BasicOfJava/Person.java: -------------------------------------------------------------------------------- 1 | package BasicOfJava; 2 | 3 | public class Person { 4 | 5 | String name; 6 | String department; 7 | 8 | } 9 | -------------------------------------------------------------------------------- /src/BasicOfJava/StaticAndNonStaticInJava.java: -------------------------------------------------------------------------------- 1 | package BasicOfJava; 2 | 3 | public class StaticAndNonStaticInJava { 4 | 5 | int i; 6 | int j; 7 | 8 | static int p; 9 | static int k; 10 | 11 | public void test1(){ 12 | System.out.println("test 1 non static"); 13 | } 14 | 15 | public static void test2(){ 16 | System.out.println("test 2 static"); 17 | } 18 | 19 | public void test3(){ 20 | System.out.println("test 1 non static"); 21 | } 22 | 23 | public static void test4(){ 24 | System.out.println("test 4 static"); 25 | } 26 | 27 | public static void main(String[] args) { 28 | 29 | StaticAndNonStaticInJava obj = new StaticAndNonStaticInJava(); 30 | obj.test1(); 31 | obj.test3(); 32 | System.out.println(obj.i); 33 | System.out.println(obj.j); 34 | 35 | StaticAndNonStaticInJava.test2(); 36 | StaticAndNonStaticInJava.test4(); 37 | System.out.println(StaticAndNonStaticInJava.k); 38 | System.out.println(StaticAndNonStaticInJava.p); 39 | } 40 | 41 | } 42 | -------------------------------------------------------------------------------- /src/BasicOfJava/StaticAndNonStaticInJava1.java: -------------------------------------------------------------------------------- 1 | package BasicOfJava; 2 | 3 | public class StaticAndNonStaticInJava1 { 4 | 5 | public static void main(String[] args) { 6 | 7 | StaticAndNonStaticInJava obj = new StaticAndNonStaticInJava(); 8 | obj.test1(); 9 | obj.test3(); 10 | 11 | StaticAndNonStaticInJava.test2(); 12 | StaticAndNonStaticInJava.test4(); 13 | 14 | StaticAndNonStaticInJava obj1 = new StaticAndNonStaticInJava(); 15 | 16 | obj1.test1(); 17 | obj1.test3(); 18 | 19 | StaticAndNonStaticInJava obj3 = new StaticAndNonStaticInJava(); 20 | 21 | obj3.test1(); 22 | obj3.test3(); 23 | 24 | StaticAndNonStaticInJava.test2(); 25 | StaticAndNonStaticInJava.test4(); 26 | 27 | StaticAndNonStaticInJava.test2(); 28 | StaticAndNonStaticInJava.test4(); 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /src/BasicOfJava/StaticAndNonStaticInJava2.java: -------------------------------------------------------------------------------- 1 | package BasicOfJava; 2 | 3 | public class StaticAndNonStaticInJava2 { 4 | 5 | int i; 6 | 7 | static int j; 8 | 9 | public void test1() { 10 | System.out.println(j); 11 | System.out.println(i); 12 | } 13 | 14 | public static void test2() { 15 | System.out.println(j); 16 | // System.out.println(i); 17 | } 18 | 19 | } 20 | -------------------------------------------------------------------------------- /src/BasicOfJava/StaticAndNonStaticNotes.java: -------------------------------------------------------------------------------- 1 | package BasicOfJava; 2 | 3 | public class StaticAndNonStaticNotes { 4 | 5 | /** 6 | Static Members of class are accessed by class Name, Since static members are class 7 | Non Static members of class are accessed by object. Non Static members are object members 8 | */ 9 | } 10 | -------------------------------------------------------------------------------- /src/CloningOfCollectionInJava/Employee2.java: -------------------------------------------------------------------------------- 1 | package CloningOfCollectionInJava; 2 | 3 | class Employee2{ 4 | 5 | private String name; 6 | private String designation; 7 | 8 | public Employee2(String name, String designation) { 9 | this.name = name; 10 | this.designation = designation; 11 | } 12 | 13 | public String getDesignation() { 14 | return designation; 15 | } 16 | 17 | public void setDesignation(String designation) { 18 | this.designation = designation; 19 | } 20 | 21 | public String getName() { 22 | return name; 23 | } 24 | 25 | public void setName(String name) { 26 | this.name = name; 27 | } 28 | 29 | @Override 30 | public String toString() { 31 | return "Employee [name=" + name + ", designation=" + designation + "]"; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/Employee.java: -------------------------------------------------------------------------------- 1 | 2 | public class Employee implements Comparable { 3 | String name; 4 | 5 | @Override 6 | public int compareTo(Employee o) { 7 | 8 | return name.compareTo(o.name); 9 | } 10 | 11 | } 12 | -------------------------------------------------------------------------------- /src/HasCodeExampl1.java: -------------------------------------------------------------------------------- 1 | 2 | public class HasCodeExampl1 { 3 | 4 | @Override 5 | public int hashCode() { 6 | return super.hashCode(); 7 | } 8 | 9 | public static void main(String[] args) { 10 | 11 | HasCodeExampl1 codeExampl1 = new HasCodeExampl1(); 12 | 13 | String s1 = "test"; 14 | String s2 = "test"; 15 | String s3 = new String("test1"); 16 | 17 | System.out.println(s1 == s3); 18 | System.out.println(s1 == s2); 19 | 20 | HasCodeExampl1 codeExampl2 = codeExampl1; 21 | 22 | HasCodeExampl1 codeExampl3 = new HasCodeExampl1(); 23 | 24 | System.out.println("codeExampl1.hashCode()==" + codeExampl1.hashCode()); 25 | System.out.println("codeExampl2.hashCode()==" + codeExampl2.hashCode()); 26 | System.out.println("codeExampl3.hashCode()==" + codeExampl3.hashCode()); 27 | System.out.println("s1.hashCode()==" + s1.hashCode()); 28 | System.out.println("s2.hashCode()==" + s2.hashCode()); 29 | System.out.println("s3.hashCode()==" + s3.hashCode()); 30 | 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/Person.java: -------------------------------------------------------------------------------- 1 | 2 | public class Person implements Cloneable{ 3 | 4 | String name; 5 | 6 | public Person(String name) { 7 | this.name = name; 8 | } 9 | 10 | public String getName() { 11 | return name; 12 | } 13 | 14 | public void setName(String name) { 15 | this.name = name; 16 | } 17 | 18 | @Override 19 | protected Object clone() throws CloneNotSupportedException { 20 | return super.clone(); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/ReturnTypeInJava/Notes.java: -------------------------------------------------------------------------------- 1 | package ReturnTypeInJava; 2 | 3 | public class Notes { 4 | 5 | /** 6 | The data type of the return value must match the method's declared return type We can't return an integer 7 | value from a method whose declaration type is void. 8 | */ 9 | } 10 | -------------------------------------------------------------------------------- /src/RuntimePolymorphism/Animal.java: -------------------------------------------------------------------------------- 1 | package RuntimePolymorphism; 2 | 3 | public class Animal { 4 | 5 | void eat() { 6 | System.out.println("eating..."); 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /src/RuntimePolymorphism/Cat.java: -------------------------------------------------------------------------------- 1 | package RuntimePolymorphism; 2 | 3 | public class Cat extends Animal{ 4 | 5 | void eat() { 6 | System.out.println("eats rat..."); 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /src/RuntimePolymorphism/Dog.java: -------------------------------------------------------------------------------- 1 | package RuntimePolymorphism; 2 | 3 | public class Dog extends Animal{ 4 | 5 | void eat() { 6 | System.out.println("eats bread..."); 7 | } 8 | 9 | } 10 | -------------------------------------------------------------------------------- /src/RuntimePolymorphism/Example1.java: -------------------------------------------------------------------------------- 1 | package RuntimePolymorphism; 2 | 3 | public class Example1 { 4 | 5 | void run() { 6 | System.out.println("running"); 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /src/RuntimePolymorphism/Example2.java: -------------------------------------------------------------------------------- 1 | package RuntimePolymorphism; 2 | 3 | public class Example2 extends Example1{ 4 | 5 | void run() { 6 | System.out.println("running safely with 60km"); 7 | } 8 | 9 | public static void main(String args[]) { 10 | Example1 b = new Example2();// upcasting 11 | b.run(); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/RuntimePolymorphism/Example3.java: -------------------------------------------------------------------------------- 1 | package RuntimePolymorphism; 2 | 3 | public class Example3 { 4 | 5 | float getRateOfInterest() { 6 | return 0; 7 | } 8 | } 9 | 10 | class SBI extends Example3 { 11 | float getRateOfInterest() { 12 | return 7.4f; 13 | } 14 | } 15 | 16 | class ICICI extends Example3 { 17 | float getRateOfInterest() { 18 | return 7.3f; 19 | } 20 | } 21 | 22 | class HDFC extends Example3 { 23 | float getRateOfInterest() { 24 | return 8.7f; 25 | } 26 | } 27 | 28 | class TestPolymorphism { 29 | public static void main(String args[]) { 30 | Example3 b; 31 | b = new SBI(); 32 | System.out.println("SBI Rate of Interest: " + b.getRateOfInterest()); 33 | b = new ICICI(); 34 | System.out.println("ICICI Rate of Interest: " + b.getRateOfInterest()); 35 | b = new HDFC(); 36 | System.out.println("HDFC Rate of Interest: " + b.getRateOfInterest()); 37 | } 38 | } -------------------------------------------------------------------------------- /src/RuntimePolymorphism/Lion.java: -------------------------------------------------------------------------------- 1 | package RuntimePolymorphism; 2 | 3 | public class Lion extends Animal{ 4 | 5 | void eat() { 6 | System.out.println("eats meat..."); 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /src/RuntimePolymorphism/TestPolym.java: -------------------------------------------------------------------------------- 1 | package RuntimePolymorphism; 2 | 3 | public class TestPolym { 4 | 5 | public static void main(String[] args) { 6 | Animal a = new Dog(); 7 | a.eat(); 8 | 9 | a = new Cat(); 10 | a.eat(); 11 | 12 | a = new Lion(); 13 | a.eat(); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/StringTest.java: -------------------------------------------------------------------------------- 1 | 2 | public class StringTest { 3 | 4 | public static void main(String[] args) { 5 | String s1 = new String("Test"); 6 | String s2 = new String("Test"); 7 | String s3 = "Test"; 8 | String s4 = "Test"; 9 | 10 | System.out.println(s1 == s2); 11 | 12 | System.out.println(s3 == s4); 13 | 14 | System.out.println(s1 == s4); 15 | 16 | System.out.println(s1.equals(s2)); 17 | 18 | System.out.println(s3.equals(s4)); 19 | 20 | System.out.println(s1.equals(s4)); 21 | } 22 | 23 | } 24 | -------------------------------------------------------------------------------- /src/Student2.java: -------------------------------------------------------------------------------- 1 | import java.util.ArrayList; 2 | import java.util.Collections; 3 | 4 | public class Student2 implements Comparable { 5 | int rollno; 6 | String name; 7 | int age; 8 | 9 | Student2(int rollno, String name, int age) { 10 | this.rollno = rollno; 11 | this.name = name; 12 | this.age = age; 13 | } 14 | 15 | @Override 16 | public int compareTo(Student2 st) { 17 | return name.compareTo(st.name); 18 | } 19 | 20 | public static void main(String[] args) { 21 | 22 | ArrayList al = new ArrayList(); 23 | 24 | al.add(new Student2(101, "BB", 23)); 25 | al.add(new Student2(102, "CC", 20)); 26 | al.add(new Student2(109, "AA", 22)); 27 | 28 | Collections.sort(al); 29 | 30 | for (Student2 st : al) { 31 | System.out.println(st.rollno + " " + st.name + " " + st.age); 32 | } 33 | } 34 | } -------------------------------------------------------------------------------- /src/ThisExample/Example1.java: -------------------------------------------------------------------------------- 1 | package ThisExample; 2 | 3 | public class Example1 { 4 | int rollno; 5 | String name; 6 | float fee; 7 | 8 | Example1(int rollno, String name, float fee) { 9 | rollno = rollno; 10 | name = name; 11 | fee = fee; 12 | } 13 | 14 | void display() { 15 | System.out.println(rollno + " " + name + " " + fee); 16 | } 17 | 18 | public static void main(String args[]) { 19 | Example1 s1 = new Example1(111, "ankit", 5000f); 20 | Example1 s2 = new Example1(112, "sumit", 6000f); 21 | s1.display(); 22 | s2.display(); 23 | } 24 | } -------------------------------------------------------------------------------- /src/ThisExample/Example2.java: -------------------------------------------------------------------------------- 1 | package ThisExample; 2 | 3 | public class Example2 { 4 | int rollno; 5 | String name; 6 | float fee; 7 | 8 | Example2(int rollno, String name, float fee) { 9 | this.rollno = rollno; 10 | this.name = name; 11 | this.fee = fee; 12 | } 13 | 14 | void display() { 15 | System.out.println(rollno + " " + name + " " + fee); 16 | } 17 | 18 | public static void main(String args[]) { 19 | Example2 s1 = new Example2(111, "ankit", 5000f); 20 | Example2 s2 = new Example2(112, "sumit", 6000f); 21 | s1.display(); 22 | s2.display(); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/ThisExample/Example3.java: -------------------------------------------------------------------------------- 1 | package ThisExample; 2 | 3 | public class Example3 { 4 | 5 | void display() { 6 | this.show(); 7 | 8 | System.out.println("Inside display function"); 9 | } 10 | 11 | void show() { 12 | System.out.println("Inside show funcion"); 13 | } 14 | 15 | public static void main(String args[]) { 16 | Example3 t1 = new Example3(); 17 | t1.display(); 18 | } 19 | } -------------------------------------------------------------------------------- /src/ThisExample/Example4.java: -------------------------------------------------------------------------------- 1 | package ThisExample; 2 | 3 | public class Example4 { 4 | int a; 5 | int b; 6 | 7 | Example4() { 8 | this(10, 20); 9 | System.out.println("Inside default constructor \n"); 10 | } 11 | 12 | Example4(int a, int b) { 13 | this.a = a; 14 | this.b = b; 15 | System.out.println("Inside parameterized constructor"); 16 | } 17 | 18 | public static void main(String[] args) { 19 | Example4 object = new Example4(); 20 | } 21 | } -------------------------------------------------------------------------------- /src/ThisExample/Example5.java: -------------------------------------------------------------------------------- 1 | package ThisExample; 2 | 3 | public class Example5 { 4 | 5 | void m(Example5 obj) { 6 | System.out.println("method is invoked"); 7 | } 8 | 9 | void p() { 10 | m(this); 11 | } 12 | 13 | public static void main(String args[]) { 14 | Example5 s1 = new Example5(); 15 | s1.p(); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/ThisExample/Example6.java: -------------------------------------------------------------------------------- 1 | package ThisExample; 2 | 3 | public class Example6 { 4 | 5 | Example7 obj; 6 | 7 | Example6(Example7 obj) { 8 | 9 | Example7 obj1 = new Example7(); 10 | this.obj = obj; 11 | obj.display(); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/ThisExample/Example7.java: -------------------------------------------------------------------------------- 1 | package ThisExample; 2 | 3 | public class Example7 { 4 | 5 | int i = 90; 6 | 7 | Example7() { 8 | Example6 obj = new Example6(this); 9 | } 10 | 11 | void display() { 12 | System.out.println("Value of i in Class Example7 : " + i); 13 | } 14 | 15 | public static void main(String[] args) { 16 | Example7 obj = new Example7(); 17 | 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/ThisExample/Example8.java: -------------------------------------------------------------------------------- 1 | package ThisExample; 2 | 3 | public class Example8 { 4 | int a; 5 | int b; 6 | 7 | Example8() { 8 | a = 10; 9 | b = 20; 10 | } 11 | 12 | Example8 get() { 13 | return this; 14 | } 15 | 16 | void display() { 17 | System.out.println("a = " + a + " b = " + b); 18 | } 19 | 20 | public static void main(String[] args) { 21 | Example8 object = new Example8(); 22 | 23 | Example8 data = object.get(); 24 | 25 | data.display(); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/VariableDataType/Example1.java: -------------------------------------------------------------------------------- 1 | package VariableDataType; 2 | 3 | public class Example1 { 4 | 5 | public int a = 90; 6 | 7 | public String s1 = "Test"; 8 | 9 | public double d1 = 90.80; 10 | 11 | public float f1 = 90.80f; 12 | 13 | public long l1 = 90l; 14 | 15 | public static int b = 80; 16 | 17 | public static String s2 = "Test1"; 18 | 19 | public void test(){ 20 | int a = 80; 21 | System.out.println(a); 22 | } 23 | 24 | public void test1(int a){ 25 | System.out.println(a); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/abstractInJava/A.java: -------------------------------------------------------------------------------- 1 | package abstractInJava; 2 | 3 | public abstract class A { 4 | 5 | int i = 90; 6 | int j; 7 | 8 | public static final int k = 900; 9 | 10 | A() { 11 | 12 | } 13 | 14 | A(int a) { 15 | 16 | } 17 | 18 | abstract void test1(); 19 | 20 | void test(){ 21 | 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/abstractInJava/Employee.java: -------------------------------------------------------------------------------- 1 | package abstractInJava; 2 | 3 | public class Employee extends Person { 4 | 5 | private int empId; 6 | 7 | public Employee(String nm, String gen, int id) { 8 | super(nm, gen); 9 | this.empId = id; 10 | } 11 | 12 | @Override 13 | public void work() { 14 | if (empId == 0) { 15 | System.out.println("Not working"); 16 | } else { 17 | System.out.println("Working as employee"); 18 | } 19 | } 20 | 21 | public static void main(String args[]) { 22 | Person student = new Employee("Test1", "Female", 0); 23 | Person employee = new Employee("Test2", "Male", 12); 24 | student.work(); 25 | employee.work(); 26 | System.out.println(employee.toString()); 27 | employee.changeName("Test3"); 28 | System.out.println(employee.toString()); 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /src/abstractInJava/Example1.java: -------------------------------------------------------------------------------- 1 | package abstractInJava; 2 | 3 | public abstract class Example1 { 4 | 5 | void test1() { 6 | 7 | } 8 | 9 | abstract void test2(); 10 | 11 | } 12 | -------------------------------------------------------------------------------- /src/abstractInJava/Example2.java: -------------------------------------------------------------------------------- 1 | package abstractInJava; 2 | 3 | public abstract class Example2 { 4 | 5 | int i = 80; 6 | 7 | public static final int j = 40; 8 | 9 | abstract void test1(); 10 | 11 | public abstract void test2(); 12 | 13 | } 14 | -------------------------------------------------------------------------------- /src/abstractInJava/Example3.java: -------------------------------------------------------------------------------- 1 | package abstractInJava; 2 | 3 | public abstract class Example3 { 4 | 5 | int i; 6 | 7 | String name; 8 | 9 | public Example3(int i, String name) { 10 | this.i = i; 11 | this.name = name; 12 | } 13 | 14 | Example3() { 15 | 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/abstractInJava/Person.java: -------------------------------------------------------------------------------- 1 | package abstractInJava; 2 | 3 | public abstract class Person { 4 | 5 | private String name; 6 | private String gender; 7 | 8 | public Person(String nm, String gen) { 9 | this.name = nm; 10 | this.gender = gen; 11 | } 12 | 13 | public abstract void work(); 14 | 15 | @Override 16 | public String toString() { 17 | return "Person [name=" + name + ", gender=" + gender + "]"; 18 | } 19 | 20 | public void changeName(String newName) { 21 | this.name = newName; 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/abstractionInJava/Contractor.java: -------------------------------------------------------------------------------- 1 | package abstractionInJava; 2 | 3 | public class Contractor extends Employee { 4 | 5 | private int workingHours; 6 | 7 | public Contractor(String name, int paymentPerHour, int workingHours) { 8 | super(name, paymentPerHour); 9 | this.workingHours = workingHours; 10 | } 11 | 12 | @Override 13 | public int calculateSalary() { 14 | return getPaymentPerHour() * workingHours; 15 | } 16 | 17 | } 18 | -------------------------------------------------------------------------------- /src/abstractionInJava/Employee.java: -------------------------------------------------------------------------------- 1 | package abstractionInJava; 2 | 3 | public abstract class Employee { 4 | 5 | private String name; 6 | private int paymentPerHour; 7 | 8 | public Employee(String name, int paymentPerHour) { 9 | this.name = name; 10 | this.paymentPerHour = paymentPerHour; 11 | } 12 | 13 | public abstract int calculateSalary(); 14 | 15 | public String getName() { 16 | return name; 17 | } 18 | 19 | public void setName(String name) { 20 | this.name = name; 21 | } 22 | 23 | public int getPaymentPerHour() { 24 | return paymentPerHour; 25 | } 26 | 27 | public void setPaymentPerHour(int paymentPerHour) { 28 | this.paymentPerHour = paymentPerHour; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/abstractionInJava/FullTimeEmployee.java: -------------------------------------------------------------------------------- 1 | package abstractionInJava; 2 | 3 | public class FullTimeEmployee extends Employee { 4 | 5 | public FullTimeEmployee(String name, int paymentPerHour) { 6 | super(name, paymentPerHour); 7 | } 8 | 9 | @Override 10 | public int calculateSalary() { 11 | return getPaymentPerHour() * 8; 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/abstractionInJava/TestAbstraction.java: -------------------------------------------------------------------------------- 1 | package abstractionInJava; 2 | 3 | public class TestAbstraction { 4 | 5 | public static void main(String[] args) { 6 | 7 | Employee obj = new Contractor("Test1", 300, 4); 8 | 9 | System.out.println("Contractor Salary "+obj.calculateSalary()); 10 | 11 | Employee obj1 = new FullTimeEmployee("Test1", 500); 12 | 13 | System.out.println("FillTime Salary "+obj1.calculateSalary()); 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /src/access/modifier/test/Example3.java: -------------------------------------------------------------------------------- 1 | package access.modifier.test; 2 | 3 | import accessmodifier.Example1; 4 | 5 | public class Example3 { 6 | 7 | public static void main(String[] args) { 8 | 9 | Example1 example1 = new Example1(); 10 | 11 | example1.name2(); 12 | 13 | 14 | System.out.println(example1.s1); 15 | } 16 | 17 | } 18 | -------------------------------------------------------------------------------- /src/access/modifier/test/Example4.java: -------------------------------------------------------------------------------- 1 | package access.modifier.test; 2 | 3 | import accessmodifier.Example1; 4 | 5 | public class Example4 extends Example1{ 6 | 7 | public static void main(String[] args) { 8 | Example4 example4 = new Example4(); 9 | example4.name1(); 10 | example4.name2(); 11 | 12 | System.out.println(example4.s1); 13 | System.out.println(example4.s3); 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /src/accessModifierInJava/Example1.java: -------------------------------------------------------------------------------- 1 | package accessModifierInJava; 2 | 3 | public class Example1 { 4 | 5 | public int i; 6 | protected int k; 7 | private int p; 8 | int d; 9 | 10 | public void test1() { 11 | System.out.println("public void test1()"); 12 | } 13 | 14 | protected void test2() { 15 | System.out.println("protected void test2()"); 16 | } 17 | 18 | void test3() { 19 | System.out.println("void test3()"); 20 | } 21 | 22 | private void test4() { 23 | System.out.println("private void test4()"); 24 | } 25 | 26 | public static void main(String[] args) { 27 | Example1 obj = new Example1(); 28 | obj.test1(); 29 | obj.test2(); 30 | obj.test3(); 31 | obj.test4(); 32 | 33 | System.out.println(obj.i); 34 | System.out.println(obj.k); 35 | System.out.println(obj.p); 36 | System.out.println(obj.d); 37 | } 38 | 39 | } 40 | -------------------------------------------------------------------------------- /src/accessModifierInJava/Example2.java: -------------------------------------------------------------------------------- 1 | package accessModifierInJava; 2 | 3 | public class Example2 { 4 | 5 | public static void main(String[] args) { 6 | 7 | Example1 obj = new Example1(); 8 | obj.test1(); 9 | obj.test2(); 10 | obj.test3(); 11 | //obj.test4(); 12 | 13 | System.out.println(obj.i); 14 | System.out.println(obj.k); 15 | //System.out.println(obj.p); 16 | System.out.println(obj.d); 17 | } 18 | 19 | } 20 | -------------------------------------------------------------------------------- /src/accessmodifier/Example1.java: -------------------------------------------------------------------------------- 1 | package accessmodifier; 2 | 3 | public class Example1 { 4 | 5 | public String s1; 6 | 7 | private String s2; 8 | 9 | protected String s3; 10 | 11 | String s4; 12 | 13 | protected void name1() { 14 | System.out.println("protected method"); 15 | } 16 | 17 | public void name2() { 18 | System.out.println("public method"); 19 | } 20 | 21 | private void name3() { 22 | System.out.println("private method"); 23 | } 24 | 25 | void name4() { 26 | System.out.println("default method"); 27 | } 28 | 29 | public static void main(String[] args) { 30 | Example1 obj = new Example1(); 31 | obj.name1(); 32 | } 33 | 34 | } 35 | -------------------------------------------------------------------------------- /src/accessmodifier/Example2.java: -------------------------------------------------------------------------------- 1 | package accessmodifier; 2 | 3 | public class Example2 { 4 | 5 | public static void main(String[] args) { 6 | 7 | Example1 example1 = new Example1(); 8 | 9 | example1.name1(); 10 | example1.name2(); 11 | example1.name4(); 12 | 13 | System.out.println(example1.s1); 14 | System.out.println(example1.s3); 15 | System.out.println(example1.s4); 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /src/anonymousInnerClass/AbstractState.java: -------------------------------------------------------------------------------- 1 | package anonymousInnerClass; 2 | 3 | public abstract class AbstractState { 4 | 5 | String s1 = ""; 6 | 7 | abstract void population(); 8 | 9 | void numberOfDistrict(int number) { 10 | System.out.println("numberOfDistrict is " + number); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/anonymousInnerClass/State.java: -------------------------------------------------------------------------------- 1 | package anonymousInnerClass; 2 | 3 | public interface State { 4 | 5 | void population(); 6 | 7 | void numberOfDistrict(); 8 | 9 | } 10 | -------------------------------------------------------------------------------- /src/anonymousInnerClass/TestAbstractState.java: -------------------------------------------------------------------------------- 1 | package anonymousInnerClass; 2 | 3 | public class TestAbstractState { 4 | 5 | AbstractState biharAbstractState = new AbstractState() { 6 | 7 | @Override 8 | void population() { 9 | 10 | System.out.println("population is 15 crore"); 11 | 12 | } 13 | }; 14 | 15 | AbstractState upAbstractState = new AbstractState() { 16 | 17 | @Override 18 | void population() { 19 | 20 | System.out.println("population is 21 crore"); 21 | 22 | } 23 | }; 24 | 25 | public static void main(String[] args) { 26 | TestAbstractState abstractState = new TestAbstractState(); 27 | abstractState.biharAbstractState.population(); 28 | abstractState.biharAbstractState.numberOfDistrict(90); 29 | abstractState.upAbstractState.population(); 30 | abstractState.upAbstractState.numberOfDistrict(900); 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /src/anonymousInnerClass/TestAnonymousClass.java: -------------------------------------------------------------------------------- 1 | package anonymousInnerClass; 2 | 3 | public class TestAnonymousClass { 4 | 5 | public static void main(String[] args) { 6 | 7 | TestState testState = new TestState(); 8 | testState.biharState.population(); 9 | testState.upState.population(); 10 | 11 | testState.upState.numberOfDistrict(); 12 | 13 | testState.biharState.numberOfDistrict(); 14 | 15 | } 16 | 17 | } 18 | -------------------------------------------------------------------------------- /src/anonymousInnerClass/TestState.java: -------------------------------------------------------------------------------- 1 | package anonymousInnerClass; 2 | 3 | public class TestState { 4 | 5 | int i; 6 | 7 | State biharState = new State() { 8 | 9 | @Override 10 | public void population() { 11 | 12 | System.out.println("population is 21 crore"); 13 | 14 | } 15 | 16 | @Override 17 | public void numberOfDistrict() { 18 | System.out.println("numberOfDistrict is 80"); 19 | 20 | } 21 | }; 22 | 23 | State upState = new State() { 24 | 25 | @Override 26 | public void population() { 27 | 28 | System.out.println("population is 15 crore"); 29 | 30 | } 31 | 32 | @Override 33 | public void numberOfDistrict() { 34 | System.out.println("numberOfDistrict is 800"); 35 | 36 | } 37 | }; 38 | 39 | public static void main(String[] args) { 40 | TestState testState = new TestState(); 41 | State state = testState.biharState; 42 | state.population(); 43 | 44 | testState.upState.population(); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/arrayList/Address.java: -------------------------------------------------------------------------------- 1 | package arrayList; 2 | 3 | public class Address { 4 | 5 | private String address; 6 | 7 | public Address(String address) { 8 | super(); 9 | this.address = address; 10 | } 11 | 12 | public String getAddress() { 13 | return address; 14 | } 15 | 16 | public void setAddress(String address) { 17 | this.address = address; 18 | } 19 | 20 | @Override 21 | public String toString() { 22 | return "Address [address=" + address + "]"; 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /src/arrayList/Department.java: -------------------------------------------------------------------------------- 1 | package arrayList; 2 | 3 | public class Department { 4 | 5 | private int id; 6 | private String name; 7 | 8 | public Department(int id, String name) { 9 | this.id = id; 10 | this.name = name; 11 | } 12 | 13 | public int getId() { 14 | return id; 15 | } 16 | 17 | public void setId(int id) { 18 | this.id = id; 19 | } 20 | 21 | public String getName() { 22 | return name; 23 | } 24 | 25 | public void setName(String name) { 26 | this.name = name; 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /src/arrayList/Department1.java: -------------------------------------------------------------------------------- 1 | package arrayList; 2 | 3 | public class Department1 implements Cloneable { 4 | 5 | private int id; 6 | private String name; 7 | 8 | public Department1(int id, String name) { 9 | this.id = id; 10 | this.name = name; 11 | } 12 | 13 | public int getId() { 14 | return id; 15 | } 16 | 17 | public void setId(int id) { 18 | this.id = id; 19 | } 20 | 21 | public String getName() { 22 | return name; 23 | } 24 | 25 | public void setName(String name) { 26 | this.name = name; 27 | } 28 | 29 | @Override 30 | protected Object clone() throws CloneNotSupportedException { 31 | return (Department1)super.clone(); 32 | } 33 | 34 | } 35 | -------------------------------------------------------------------------------- /src/arrayList/DistrictSorter.java: -------------------------------------------------------------------------------- 1 | package arrayList; 2 | 3 | import java.util.Comparator; 4 | 5 | public class DistrictSorter implements Comparator{ 6 | 7 | @Override 8 | public int compare(State o1, State o2) { 9 | return o1.getDistrict().compareTo(o2.getDistrict()); 10 | } 11 | 12 | } 13 | -------------------------------------------------------------------------------- /src/arrayList/Example10.java: -------------------------------------------------------------------------------- 1 | package arrayList; 2 | 3 | import java.util.ArrayList; 4 | 5 | public class Example10 { 6 | 7 | public static void main(String[] args) { 8 | { 9 | ArrayList list = new ArrayList<>(2); 10 | list.add("A"); 11 | list.add("B"); 12 | list.add("C"); 13 | list.add("D"); 14 | System.out.println(list.indexOf("A") > 0); // true 15 | 16 | System.out.println(list.indexOf("Z") > 0); // false 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/arrayList/Example11.java: -------------------------------------------------------------------------------- 1 | package arrayList; 2 | 3 | import java.util.ArrayList; 4 | import java.util.Arrays; 5 | 6 | public class Example11 { 7 | 8 | public static void main(String[] args) { 9 | 10 | ArrayList list = new ArrayList<>( 11 | Arrays.asList("test1", "test2", "test3", "test4", "test5", "test6", "test7", "test8")); 12 | 13 | int firstIndex = list.indexOf("test3"); 14 | 15 | System.out.println(firstIndex); 16 | 17 | firstIndex = list.indexOf("hello"); 18 | 19 | System.out.println(firstIndex); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/arrayList/Example12.java: -------------------------------------------------------------------------------- 1 | package arrayList; 2 | 3 | import java.util.ArrayList; 4 | import java.util.Arrays; 5 | 6 | public class Example12 { 7 | 8 | public static void main(String[] args) { 9 | ArrayList list = new ArrayList<>( 10 | Arrays.asList("test7", "test2", "test3", "test4", "test5", "tset6", "trset7", "test8")); 11 | 12 | int lastIndex = list.lastIndexOf("test7"); 13 | 14 | System.out.println(lastIndex); 15 | 16 | lastIndex = list.lastIndexOf("hello"); 17 | 18 | System.out.println(lastIndex); 19 | } 20 | 21 | } 22 | -------------------------------------------------------------------------------- /src/arrayList/Example13.java: -------------------------------------------------------------------------------- 1 | package arrayList; 2 | 3 | import java.util.ArrayList; 4 | 5 | public class Example13 { 6 | 7 | public static void main(String[] args) { 8 | ArrayList list = new ArrayList<>(); 9 | list.add("Test1"); 10 | list.add("Test2"); 11 | list.add("Test3"); 12 | list.add("Test4"); 13 | list.add("Test5"); 14 | 15 | System.out.println(list); 16 | 17 | list.removeAll(list); 18 | 19 | System.out.println(list); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/arrayList/Example14.java: -------------------------------------------------------------------------------- 1 | package arrayList; 2 | 3 | import java.util.ArrayList; 4 | 5 | public class Example14 { 6 | 7 | public static void main(String[] args) { 8 | ArrayList list = new ArrayList<>(); 9 | list.add("Test1"); 10 | list.add("Test2"); 11 | list.add("Test3"); 12 | list.add("Test4"); 13 | list.add("Test5"); 14 | 15 | System.out.println(list); 16 | 17 | ArrayList list1 = new ArrayList<>(); 18 | list1.add("Test1"); 19 | list1.add("Test2"); 20 | list1.add("Test3"); 21 | 22 | list.removeAll(list1); 23 | 24 | System.out.println(list); 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /src/arrayList/Example15.java: -------------------------------------------------------------------------------- 1 | package arrayList; 2 | 3 | import java.util.ArrayList; 4 | 5 | public class Example15 { 6 | 7 | public static void main(String[] args) { 8 | ArrayList list = new ArrayList<>(); 9 | list.add("Test1"); 10 | list.add("Test2"); 11 | list.add("Test3"); 12 | list.add("Test4"); 13 | list.add("Test5"); 14 | 15 | System.out.println(list); 16 | 17 | ArrayList list1 = new ArrayList<>(); 18 | list1.add("Test1"); 19 | list1.add("Test2"); 20 | list1.add("Test3"); 21 | 22 | list.retainAll(list1); 23 | 24 | System.out.println(list); 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /src/arrayList/Example16.java: -------------------------------------------------------------------------------- 1 | package arrayList; 2 | 3 | import java.util.ArrayList; 4 | import java.util.Collections; 5 | 6 | public class Example16 { 7 | 8 | public static void main(String[] args) { 9 | ArrayList list = new ArrayList<>(); 10 | list.add("Test1"); 11 | list.add("Test2"); 12 | list.add("Test3"); 13 | list.add("Test4"); 14 | list.add("Test1"); 15 | 16 | System.out.println(list); 17 | 18 | Collections.replaceAll(list, "Test1","Test30"); 19 | 20 | System.out.println(list); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/arrayList/Example17.java: -------------------------------------------------------------------------------- 1 | package arrayList; 2 | 3 | import java.util.ArrayList; 4 | import java.util.Collections; 5 | 6 | public class Example17 { 7 | 8 | public static void main(String[] args) { 9 | ArrayList list = new ArrayList<>(); 10 | list.add(10); 11 | list.add(9); 12 | list.add(20); 13 | list.add(11); 14 | list.add(15); 15 | 16 | System.out.println("before sorting="+list); 17 | Collections.sort(list); 18 | 19 | System.out.println("After sorting="+list); 20 | 21 | ArrayList list1 = new ArrayList<>(); 22 | list1.add("CC"); 23 | list1.add("BB"); 24 | list1.add("AA"); 25 | System.out.println("before sorting="+list1); 26 | Collections.sort(list1); 27 | 28 | System.out.println("After sorting="+list1); 29 | 30 | } 31 | 32 | } 33 | -------------------------------------------------------------------------------- /src/arrayList/Example18.java: -------------------------------------------------------------------------------- 1 | package arrayList; 2 | 3 | import java.util.ArrayList; 4 | import java.util.Collections; 5 | 6 | public class Example18 { 7 | 8 | public static void main(String[] args) { 9 | ArrayList list = new ArrayList<>(); 10 | list.add("Shyam"); 11 | list.add("Bdanu"); 12 | list.add("Ram"); 13 | list.add("Amit"); 14 | list.add("Baoy"); 15 | 16 | System.out.println("before sorting=" + list); 17 | 18 | Collections.sort(list); 19 | 20 | System.out.println("After sorting=" + list); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/arrayList/Example19.java: -------------------------------------------------------------------------------- 1 | package arrayList; 2 | 3 | public class Example19 { 4 | 5 | public static void main(String args[]) { 6 | String Str = new String("Welcome to learnjava.com"); 7 | 8 | System.out.print("Return Value :"); 9 | System.out.println(Str.replaceAll("(.*)learnjava(.*)", "youtube")); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /src/arrayList/Example2.java: -------------------------------------------------------------------------------- 1 | package arrayList; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | 6 | public class Example2 { 7 | 8 | public static void main(String[] args) { 9 | List li = new ArrayList(); 10 | li.add(Integer.valueOf(90)); 11 | li.add(190); 12 | li.add(Integer.valueOf(100)); 13 | li.add(900); 14 | 15 | ArrayList list = new ArrayList<>(); 16 | list.add("Test1"); 17 | list.add("Test2"); 18 | list.add("Test3"); 19 | list.add("Test4"); 20 | list.add("Test5"); 21 | System.out.println(list); 22 | list.remove(1); 23 | System.out.println(list); 24 | list.remove(1); 25 | System.out.println(list); 26 | list.remove(1); 27 | System.out.println(list); 28 | list.remove(1); 29 | System.out.println("After data removal from list"); 30 | System.out.println(list); 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /src/arrayList/Example20.java: -------------------------------------------------------------------------------- 1 | package arrayList; 2 | 3 | public class Example20 { 4 | 5 | public static void main(String args[]) { 6 | String str = "String replaceAll() method example!!"; 7 | String strRegExTest = "Java 12 23 String 4 Replace Example"; 8 | String strObj = null; 9 | 10 | // Replace all occurrences of "t" to "T" 11 | strObj = str.replaceAll("t", "T"); 12 | System.out.println(strObj); 13 | 14 | // Remove all occurrences of "!" 15 | strObj = str.replaceAll("!", ""); 16 | System.out.println(strObj); 17 | 18 | // Replace "example" to "Example" 19 | strObj = str.replaceAll("example", "Example"); 20 | System.out.println(strObj); 21 | 22 | // Remove all the numbers 23 | strObj = strRegExTest.replaceAll("[0-9]+", ""); 24 | System.out.println(strObj); 25 | 26 | // Replace all the words to "Word" 27 | strObj = strRegExTest.replaceAll("[a-zA-Z]+", "Word"); 28 | System.out.println(strObj); 29 | 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/arrayList/Example21.java: -------------------------------------------------------------------------------- 1 | package arrayList; 2 | 3 | import java.util.ArrayList; 4 | import java.util.Arrays; 5 | 6 | public class Example21 { 7 | 8 | public static void main(String[] args) { 9 | ArrayList list = new ArrayList<>(Arrays.asList(0, 10, 20, 30, 40, 50, 60, 70, 80, 90)); 10 | 11 | ArrayList sublist = new ArrayList(list.subList(2, 6)); 12 | 13 | System.out.println(sublist); 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /src/arrayList/Example22.java: -------------------------------------------------------------------------------- 1 | package arrayList; 2 | 3 | import java.util.ArrayList; 4 | import java.util.Arrays; 5 | 6 | public class Example22 { 7 | 8 | public static void main(String[] args) { 9 | 10 | ArrayList list = new ArrayList<>(2); 11 | 12 | list.add("A"); 13 | list.add("B"); 14 | list.add("C"); 15 | list.add("D"); 16 | 17 | // Convert to object array 18 | Object[] array = list.toArray(); 19 | 20 | System.out.println(Arrays.toString(array)); 21 | 22 | // Iterate and convert to desired type 23 | for (Object o : array) { 24 | String s = (String) o; 25 | 26 | System.out.println(s); 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/arrayList/Example23.java: -------------------------------------------------------------------------------- 1 | package arrayList; 2 | 3 | import java.util.ArrayList; 4 | 5 | public class Example23 { 6 | 7 | public static void main(String[] args) { 8 | ArrayList list = new ArrayList<>(2); 9 | 10 | list.add("A"); 11 | list.add("B"); 12 | list.add("C"); 13 | list.add("D"); 14 | 15 | ArrayList list1 = new ArrayList<>(2); 16 | 17 | list1.add("E"); 18 | list1.add("F"); 19 | list1.add("G"); 20 | list1.add("H"); 21 | 22 | list.addAll(list1); 23 | 24 | System.out.println(list); 25 | 26 | list.clear(); 27 | System.out.println(list); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/arrayList/Example4.java: -------------------------------------------------------------------------------- 1 | package arrayList; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | 6 | public class Example4 { 7 | 8 | public static void main(String[] args) { 9 | List li = new ArrayList(); 10 | li.add(Integer.valueOf(2)); 11 | li.add(3); 12 | System.out.println(li); 13 | li.add(0, 90); 14 | int i = 10; 15 | if(li.size()<10) { 16 | i = li.size(); 17 | li.add(i, 900); 18 | System.out.println(li); 19 | } 20 | 21 | 22 | ArrayList li1 = new ArrayList(); 23 | 24 | ArrayList list = new ArrayList<>(); 25 | list.add("Test1"); 26 | list.add("Test2"); 27 | list.add("Test3"); 28 | list.add("Test4"); 29 | list.add("Test5"); 30 | 31 | System.out.println(list); 32 | ArrayList list1 = new ArrayList<>(); 33 | list1.add("Test11"); 34 | list1.add("Test21"); 35 | 36 | list.addAll(1,list1); 37 | 38 | //System.out.println(list); 39 | 40 | list.clear(); 41 | System.out.println(list); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/arrayList/Example5.java: -------------------------------------------------------------------------------- 1 | package arrayList; 2 | 3 | import java.util.ArrayList; 4 | 5 | public class Example5 { 6 | 7 | public static void main(String[] args) { 8 | ArrayList list = new ArrayList<>(); 9 | System.out.println(list.isEmpty()); 10 | list.add("Test1"); 11 | list.add("Test2"); 12 | list.add("Test3"); 13 | list.add("Test4"); 14 | list.add("Test5"); 15 | list.add("Test1"); 16 | list.add("Test1"); 17 | list.add("Test1"); 18 | System.out.println(list); 19 | 20 | System.out.println("list.lastIndexOf(\"Test1\")="+list.lastIndexOf("Test1")); 21 | System.out.println(list.lastIndexOf("Test1000")); 22 | System.out.println(list.isEmpty()); 23 | 24 | //list.clear(); 25 | 26 | System.out.println(list); 27 | 28 | ArrayList list1 = (ArrayList) list.clone(); 29 | list1.remove(3); 30 | System.out.println(list1); 31 | System.out.println(list); 32 | 33 | System.out.println(list.contains("123")); 34 | System.out.println(list.contains("Test5")); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/arrayList/Example6.java: -------------------------------------------------------------------------------- 1 | package arrayList; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | 6 | public class Example6 { 7 | 8 | public static ArrayList createData() { 9 | 10 | ArrayList arrayListObject = new ArrayList<>(); 11 | 12 | arrayListObject.add("A"); 13 | arrayListObject.add("B"); 14 | arrayListObject.add("C"); 15 | arrayListObject.add("D"); 16 | return arrayListObject; 17 | } 18 | 19 | public static void cloneData() { 20 | ArrayList actualData = createData(); 21 | ArrayList arrayListClone = (ArrayList) actualData.clone(); 22 | arrayListClone.add("9"); 23 | System.out.println(actualData); 24 | System.out.println(arrayListClone); 25 | } 26 | 27 | public static void main(String[] args) { 28 | Example6.cloneData(); 29 | 30 | ArrayList li = new ArrayList(); 31 | li.ensureCapacity(2000); 32 | li.add(10); 33 | li.add(10); 34 | li.add(10); 35 | 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/arrayList/Example9.java: -------------------------------------------------------------------------------- 1 | package arrayList; 2 | 3 | import java.util.ArrayList; 4 | 5 | public class Example9 { 6 | 7 | public static void main(String[] args) { 8 | ArrayList list = new ArrayList<>(); 9 | list.add("Test1"); 10 | list.add("Test2"); 11 | list.add("Test3"); 12 | list.add("Test4"); 13 | list.add("Test5"); 14 | 15 | list.contains("Test1"); 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /src/arrayList/LanguageSorter.java: -------------------------------------------------------------------------------- 1 | package arrayList; 2 | 3 | import java.util.Comparator; 4 | 5 | public class LanguageSorter implements Comparator { 6 | 7 | @Override 8 | public int compare(State o1, State o2) { 9 | return o1.getLanguage().compareToIgnoreCase(o2.getLanguage()); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /src/arrayList/PopulationSorter.java: -------------------------------------------------------------------------------- 1 | package arrayList; 2 | 3 | import java.util.Comparator; 4 | 5 | public class PopulationSorter implements Comparator { 6 | 7 | @Override 8 | public int compare(State o1, State o2) { 9 | if (o1.getPopulation() == o2.getPopulation()) 10 | return 0; 11 | else if (o1.getPopulation() > o2.getPopulation()) 12 | return 1; 13 | else 14 | return -1; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/arrayList/Student.java: -------------------------------------------------------------------------------- 1 | package arrayList; 2 | 3 | public class Student { 4 | 5 | private int age; 6 | private String name; 7 | private String school; 8 | 9 | private Address address; 10 | 11 | public Student(int age, String name, String school, Address address) { 12 | super(); 13 | this.age = age; 14 | this.name = name; 15 | this.school = school; 16 | this.address = address; 17 | } 18 | 19 | @Override 20 | public String toString() { 21 | return "Student [age=" + age + ", name=" + name + ", school=" + school + ", address=" + address + "]"; 22 | } 23 | 24 | public int getAge() { 25 | return age; 26 | } 27 | 28 | public String getName() { 29 | return name; 30 | } 31 | 32 | public String getSchool() { 33 | return school; 34 | } 35 | 36 | public Address getAddress() { 37 | return address; 38 | } 39 | 40 | } 41 | -------------------------------------------------------------------------------- /src/arrayList/TestState2Sorting.java: -------------------------------------------------------------------------------- 1 | package arrayList; 2 | 3 | import java.util.ArrayList; 4 | import java.util.Collections; 5 | import java.util.Comparator; 6 | import java.util.List; 7 | 8 | public class TestState2Sorting { 9 | 10 | public static void main(String[] args) { 11 | 12 | State2 state = new State2(); 13 | 14 | List list = new ArrayList(); 15 | 16 | list.add(new State2(100, "AB", "BB")); 17 | list.add(new State2(500, "DC", "CC")); 18 | list.add(new State2(300, "BC", "AA")); 19 | list.add(new State2(800, "FC", "FF")); 20 | list.add(new State2(600, "ED", "EE")); 21 | System.out.println(list); 22 | 23 | Comparator pSorter = state.populationSorter; 24 | Collections.sort(list, pSorter); 25 | 26 | System.out.println(list); 27 | 28 | Collections.sort(list, state.languageSorter); 29 | 30 | System.out.println(list); 31 | 32 | Collections.sort(list, state.districtSorter); 33 | System.out.println(list); 34 | 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /src/classExample/Example1.java: -------------------------------------------------------------------------------- 1 | package classExample; 2 | 3 | public class Example1 extends Object{ 4 | 5 | int age; 6 | static final int MAX_AGE = 18; 7 | 8 | public int getAge() { 9 | return age; 10 | } 11 | 12 | public void setAge(int age) { 13 | this.age = age; 14 | } 15 | 16 | public static void setAge1(int age) { 17 | 18 | } 19 | 20 | 21 | public static void main(String... xyx) { 22 | Example1 obj1 = new Example1(); 23 | 24 | obj1.setAge(4); 25 | obj1.getAge(); 26 | 27 | System.out.println(obj1.getAge()); 28 | Example1 obj2 = new Example1(); 29 | 30 | System.out.println(obj2.getAge()); 31 | 32 | obj2.setAge(6); 33 | obj2.getAge(); 34 | System.out.println(obj2.getAge()); 35 | 36 | Example1.setAge1(4); 37 | 38 | 39 | } 40 | 41 | } -------------------------------------------------------------------------------- /src/collectionFramewrokInJava/ArrayListInJava.java: -------------------------------------------------------------------------------- 1 | package collectionFramewrokInJava; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | 6 | public class ArrayListInJava { 7 | 8 | public static void main(String[] args) { 9 | 10 | List arrayList = new ArrayList<>(); 11 | 12 | arrayList.add(2); 13 | arrayList.add(9.8); 14 | arrayList.add(true); 15 | arrayList.add("Test"); 16 | arrayList.add(2); 17 | 18 | System.out.println(arrayList); 19 | 20 | List arrayList1 = new ArrayList(); 21 | arrayList1.add(4); 22 | arrayList1.add(4); 23 | arrayList1.add(5); 24 | arrayList1.add(9); 25 | 26 | System.out.println(arrayList1); 27 | 28 | } 29 | 30 | } 31 | -------------------------------------------------------------------------------- /src/collectionFramewrokInJava/ArrayListInJava2.java: -------------------------------------------------------------------------------- 1 | package collectionFramewrokInJava; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | 6 | public class ArrayListInJava2 { 7 | 8 | public static void main(String[] args) { 9 | 10 | List arrayList = new ArrayList(); 11 | arrayList.add(4); 12 | arrayList.add(4); 13 | arrayList.add(5); 14 | arrayList.add(9); 15 | System.out.println(arrayList); 16 | 17 | List arrayList1 = new ArrayList(); 18 | arrayList1.add(4); 19 | arrayList1.add(40); 20 | arrayList1.add(50); 21 | arrayList1.add(9); 22 | 23 | //System.out.println(arrayList1); 24 | //arrayList.addAll(arrayList1); 25 | //arrayList.add(2, 600); 26 | 27 | //arrayList.removeAll(arrayList1); 28 | arrayList.remove(3); 29 | 30 | 31 | System.out.println(arrayList); 32 | 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /src/collectionFramewrokInJava/ArrayListInJava3.java: -------------------------------------------------------------------------------- 1 | package collectionFramewrokInJava; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | 6 | public class ArrayListInJava3 { 7 | 8 | public static void main(String[] args) { 9 | 10 | List arrayList = new ArrayList(); 11 | arrayList.add(4); 12 | arrayList.add(4); 13 | arrayList.add(true); 14 | arrayList.add(8.9); 15 | System.out.println(arrayList); 16 | 17 | List arrayList1 = new ArrayList(); 18 | arrayList1.add(3); 19 | arrayList1.add(4); 20 | arrayList1.add(6); 21 | arrayList1.add(8); 22 | 23 | //arrayList.retainAll(arrayList1); 24 | 25 | //System.out.println(arrayList.size()); 26 | 27 | //System.out.println(arrayList.get(3)); 28 | 29 | //System.out.println(arrayList.contains(4)); 30 | 31 | //System.out.println(arrayList.contains(400)); 32 | 33 | System.out.println(arrayList.containsAll(arrayList1)); 34 | 35 | //System.out.println(arrayList); 36 | 37 | } 38 | 39 | } 40 | -------------------------------------------------------------------------------- /src/collectionFramewrokInJava/CollectionInjava.java: -------------------------------------------------------------------------------- 1 | package collectionFramewrokInJava; 2 | 3 | public class CollectionInjava { 4 | /** 5 | The Java collections framework (JCF) is a set of classes and interfaces that implement 6 | commonly reusable collection data structures. 7 | Collection framework allow us to manipulate and store group of object. 8 | Collection Interface and classes are present in Java.utill package. 9 | */ 10 | 11 | } 12 | -------------------------------------------------------------------------------- /src/collectionFramewrokInJava/HashSetInJava.java: -------------------------------------------------------------------------------- 1 | package collectionFramewrokInJava; 2 | 3 | import java.util.HashSet; 4 | import java.util.Set; 5 | 6 | public class HashSetInJava { 7 | 8 | public static void main(String[] args) { 9 | Set hashSet = new HashSet<>(); 10 | hashSet.add(2); 11 | hashSet.add(2); 12 | hashSet.add(3); 13 | hashSet.add(2); 14 | hashSet.add(9.08); 15 | 16 | System.out.println(hashSet); 17 | 18 | Set hashSet1 = new HashSet(); 19 | hashSet1.add(2); 20 | hashSet1.add(2); 21 | hashSet1.add(3); 22 | hashSet1.add(2); 23 | hashSet1.add(9.08); 24 | System.out.println(hashSet1); 25 | HashSet hashSet2 = new HashSet(); 26 | hashSet2.add(2); 27 | hashSet2.add(2); 28 | hashSet2.add(3); 29 | hashSet2.add(2); 30 | 31 | 32 | System.out.println(hashSet2); 33 | 34 | 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /src/collectionFramewrokInJava/HashSetInJava2.java: -------------------------------------------------------------------------------- 1 | package collectionFramewrokInJava; 2 | 3 | import java.util.HashSet; 4 | import java.util.Set; 5 | 6 | public class HashSetInJava2 { 7 | 8 | public static void main(String[] args) { 9 | 10 | HashSet hashSet2 = new HashSet(); 11 | hashSet2.add(21); 12 | hashSet2.add(20); 13 | hashSet2.add(3); 14 | hashSet2.add(2); 15 | 16 | HashSet hashSet1 = new HashSet(); 17 | hashSet1.add(211); 18 | hashSet1.add(200); 19 | hashSet1.add(30); 20 | hashSet1.add(20); 21 | 22 | 23 | System.out.println(hashSet2); 24 | 25 | //hashSet2.addAll(hashSet1); 26 | //hashSet2.removeAll(hashSet1); 27 | //hashSet2.retainAll(hashSet1); 28 | //System.out.println(hashSet2.contains(20)); 29 | 30 | //System.out.println(hashSet2.containsAll(hashSet1)); 31 | 32 | System.out.println(hashSet2.size()); 33 | //System.out.println(hashSet2); 34 | 35 | 36 | 37 | } 38 | 39 | } 40 | -------------------------------------------------------------------------------- /src/collectionFramewrokInJava/LinkedListInJava.java: -------------------------------------------------------------------------------- 1 | package collectionFramewrokInJava; 2 | 3 | import java.util.LinkedList; 4 | import java.util.List; 5 | 6 | public class LinkedListInJava { 7 | 8 | public static void main(String[] args) { 9 | List linkedList = new LinkedList<>(); 10 | linkedList.add(50); 11 | linkedList.add(50); 12 | linkedList.add(9.8); 13 | linkedList.add(100); 14 | linkedList.add(true); 15 | linkedList.add(50); 16 | 17 | System.out.println(linkedList); 18 | 19 | System.out.println(linkedList.get(4)); 20 | 21 | List linkedList1 = new LinkedList(); 22 | linkedList1.add(50); 23 | linkedList1.add(50); 24 | linkedList1.add(9.8); 25 | linkedList1.add(100); 26 | linkedList1.add(true); 27 | linkedList1.add(50); 28 | 29 | System.out.println(linkedList1); 30 | } 31 | 32 | } 33 | -------------------------------------------------------------------------------- /src/collectionFramewrokInJava/LinkedListInJava3.java: -------------------------------------------------------------------------------- 1 | package collectionFramewrokInJava; 2 | 3 | import java.util.LinkedList; 4 | import java.util.List; 5 | 6 | public class LinkedListInJava3 { 7 | 8 | public static void main(String[] args) { 9 | List linkedList = new LinkedList(); 10 | linkedList.add("50"); 11 | linkedList.add("50"); 12 | linkedList.add("Test"); 13 | linkedList.add("100"); 14 | linkedList.add("true"); 15 | linkedList.add("50"); 16 | System.out.println(linkedList); 17 | //linkedList.clear(); 18 | System.out.println(linkedList); 19 | 20 | System.out.println(linkedList.isEmpty()); 21 | 22 | LinkedList linkedList1 = new LinkedList(); 23 | linkedList1.add("50"); 24 | linkedList1.add("50"); 25 | linkedList1.add("Test"); 26 | linkedList1.add("100"); 27 | linkedList1.add("true"); 28 | linkedList1.add("50"); 29 | 30 | System.out.println(linkedList1); 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /src/concurrentHashMap/Country.java: -------------------------------------------------------------------------------- 1 | package concurrentHashMap; 2 | 3 | public class Country { 4 | 5 | String name; 6 | long population; 7 | 8 | public Country(String name, long population) { 9 | super(); 10 | this.name = name; 11 | this.population = population; 12 | } 13 | 14 | public String getName() { 15 | return name; 16 | } 17 | 18 | public void setName(String name) { 19 | this.name = name; 20 | } 21 | 22 | public long getPopulation() { 23 | return population; 24 | } 25 | 26 | public void setPopulation(long population) { 27 | this.population = population; 28 | } 29 | 30 | @Override 31 | public int hashCode() { 32 | final int prime = 31; 33 | int result = 1; 34 | result = prime * result + ((name == null) ? 0 : name.hashCode()); 35 | return result; 36 | } 37 | 38 | @Override 39 | public boolean equals(Object obj) { 40 | 41 | Country other = (Country) obj; 42 | if (name.equalsIgnoreCase((other.name))) 43 | return true; 44 | return false; 45 | } 46 | 47 | } -------------------------------------------------------------------------------- /src/constructor/Book.java: -------------------------------------------------------------------------------- 1 | package constructor; 2 | 3 | public class Book { 4 | 5 | int length; 6 | int breadth; 7 | int height=90; 8 | 9 | public Book(int length, int breadth, int height) { 10 | this.length = length; 11 | this.breadth = breadth; 12 | this.height = height; 13 | } 14 | 15 | Book(){ 16 | 17 | } 18 | 19 | public static void main(String[] args) { 20 | Book obj = new Book(10, 20, 30); 21 | System.out.println(obj.length); 22 | Book obj1 = new Book(20, 200, 300); 23 | Book obj2 = new Book(101, 201, 301); 24 | System.out.println(obj.length); 25 | 26 | Book ob = new Book(); 27 | System.out.println(ob.length); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/constructor/Example1.java: -------------------------------------------------------------------------------- 1 | package constructor; 2 | 3 | public class Example1 { 4 | 5 | public String name; 6 | public int i = 90; 7 | 8 | Example1() { 9 | System.out.println("======"); 10 | } 11 | 12 | public static void main(String[] args) { 13 | Example1 obj = new Example1(); 14 | Example1 obj2 = new Example1(); 15 | Example1 obj3 = new Example1(); 16 | Example1 obj4 = new Example1(); 17 | System.out.println(obj.name); 18 | System.out.println(obj.i); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/constructor/Example10.java: -------------------------------------------------------------------------------- 1 | package constructor; 2 | 3 | public class Example10 extends Object{ 4 | 5 | private String name; 6 | private int age; 7 | private String state; 8 | 9 | public Example10(String name, int age, String state) { 10 | System.out.println("Example10(String name, int age, String state)"); 11 | this.name = name; 12 | this.age = age; 13 | this.state = state; 14 | } 15 | 16 | @Override 17 | public String toString() { 18 | return "Example10 [name=" + name + ", age=" + age + ", state=" + state + "]"; 19 | } 20 | 21 | public Example10(int age, String name, String state) { 22 | this.name = name; 23 | this.age = age; 24 | this.state = state; 25 | } 26 | 27 | public static void main(String[] args) { 28 | Example10 obj = new Example10(10, "Test1", "Bihar"); 29 | System.out.println(obj); 30 | Example10 obj1 = new Example10("Test2", 20, "Bihar1"); 31 | System.out.println(obj1); 32 | } 33 | 34 | } 35 | -------------------------------------------------------------------------------- /src/constructor/Example3.java: -------------------------------------------------------------------------------- 1 | package constructor; 2 | 3 | public class Example3 { 4 | int i; 5 | 6 | public Example3(int i) { 7 | this.i = i; 8 | System.out.println("Parameterized"); 9 | } 10 | 11 | Example3() { 12 | System.out.println("default"); 13 | } 14 | 15 | public static void main(String[] args) { 16 | Example3 obj = new Example3(); 17 | Example3 obj1 = new Example3(5); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/constructor/Example4.java: -------------------------------------------------------------------------------- 1 | package constructor; 2 | 3 | public class Example4 { 4 | 5 | private Example4(){ 6 | System.out.println("default"); 7 | } 8 | 9 | public static void main(String[] args) { 10 | Example4 obj = new Example4(); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/constructor/Example5.java: -------------------------------------------------------------------------------- 1 | package constructor; 2 | 3 | public class Example5 { 4 | 5 | void test(){ 6 | System.out.println("default"); 7 | } 8 | 9 | Example5(){ 10 | System.out.println("======"); 11 | } 12 | 13 | public static void main(String[] args) { 14 | Example5 obj = new Example5(); 15 | obj.test(); 16 | obj.test(); 17 | obj.test(); 18 | obj.test(); 19 | obj.test(); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/constructor/Example6.java: -------------------------------------------------------------------------------- 1 | package constructor; 2 | 3 | public class Example6 extends Object{ 4 | 5 | Example6() { 6 | super(); 7 | } 8 | 9 | public static void main(String[] args) { 10 | 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /src/constructor/Example7.java: -------------------------------------------------------------------------------- 1 | package constructor; 2 | 3 | public class Example7 { 4 | 5 | Example7() { 6 | this(90,10); 7 | System.out.println("I am Example7()"); 8 | } 9 | 10 | Example7(int i) { 11 | this(); 12 | System.out.println("I am Example7(int i)"); 13 | } 14 | 15 | Example7(int i, int b){ 16 | System.out.println("(int i, int b)"); 17 | } 18 | 19 | public static void main(String[] args) { 20 | 21 | Example7 obj = new Example7(3); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/constructor/Example8.java: -------------------------------------------------------------------------------- 1 | package constructor; 2 | 3 | public class Example8 { 4 | 5 | Example8() { 6 | System.out.println("I am Example7()"); 7 | } 8 | 9 | Example8(int i) { 10 | this(); 11 | System.out.println("I am Example7(int i)"); 12 | } 13 | 14 | Example8(int i, int j) { 15 | this(5); 16 | System.out.println("I am Example8(int i,int j) "); 17 | } 18 | 19 | public static void main(String[] args) { 20 | Example8 obj = new Example8(3,6); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/constructor/Example9.java: -------------------------------------------------------------------------------- 1 | package constructor; 2 | 3 | public class Example9 { 4 | 5 | private String name; 6 | private int age; 7 | private String state; 8 | 9 | public Example9(){ 10 | } 11 | public Example9(String name, int age, String state) { 12 | this.name = name; 13 | this.age = age; 14 | this.state = state; 15 | } 16 | 17 | public void display(){ 18 | System.out.println("Example9 [name=" + name + ", age=" + age + ", state=" + state + "]"); 19 | } 20 | 21 | 22 | public static void main(String[] args) { 23 | 24 | Example9 obj2 = new Example9(); 25 | obj2.display(); 26 | 27 | Example9 obj = new Example9("test", 23, "B"); 28 | obj.display(); 29 | 30 | Example9 obj1 = new Example9("test1", 24, "A"); 31 | obj1.display(); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/constructor/Exemple2.java: -------------------------------------------------------------------------------- 1 | package constructor; 2 | 3 | public class Exemple2 { 4 | int i ; 5 | 6 | public Exemple2(int i) { 7 | this.i = i; 8 | } 9 | 10 | public static void main(String[] args) { 11 | //Exemple2 obj = new Exemple2(); 12 | 13 | Exemple2 obj1 = new Exemple2(7); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/constructor/Test1.java: -------------------------------------------------------------------------------- 1 | package constructor; 2 | 3 | public class Test1 { 4 | int a; 5 | int b; 6 | 7 | Test1(int a, int b) { 8 | this.a = a; 9 | this.b = b; 10 | } 11 | 12 | 13 | } 14 | -------------------------------------------------------------------------------- /src/constructor/Test2.java: -------------------------------------------------------------------------------- 1 | package constructor; 2 | 3 | public class Test2 extends Test1 { 4 | 5 | Test2() { 6 | super(8,9); 7 | } 8 | 9 | Test2(int i, int j) { 10 | super(i,j); 11 | } 12 | 13 | public static void main(String[] args) { 14 | Test2 obj = new Test2(); 15 | System.out.println(obj.a); 16 | System.out.println(obj.b); 17 | 18 | Test2 obj1 = new Test2(80,90); 19 | System.out.println(obj1.a); 20 | System.out.println(obj1.b); 21 | } 22 | 23 | } 24 | -------------------------------------------------------------------------------- /src/controlStatements/BreakExample1.java: -------------------------------------------------------------------------------- 1 | package controlStatements; 2 | 3 | public class BreakExample1 { 4 | 5 | public static void main(String[] args) { 6 | int i = 0; 7 | while (i >= 0) { 8 | if (i == 10) { 9 | break; 10 | } 11 | //System.out.println("i counter="+i); 12 | i++; 13 | System.out.println("i counter="+i); 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/controlStatements/BreakExample2.java: -------------------------------------------------------------------------------- 1 | package controlStatements; 2 | 3 | public class BreakExample2 { 4 | 5 | public static void main(String[] args) { 6 | int array[] = { 120, 230, 404, 560, 708 }; 7 | 8 | for (int i = 0; i < array.length; i++) { 9 | for (int j = 0; j < array.length; j++) { 10 | System.out.println(array[j]); 11 | if (array[j] == 560) { 12 | break; 13 | } 14 | } 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/controlStatements/BreakExample3.java: -------------------------------------------------------------------------------- 1 | package controlStatements; 2 | 3 | public class BreakExample3 { 4 | 5 | public static void main(String[] args) { 6 | int array[] = { 120, 230, 404, 560, 708 }; 7 | 8 | for (int i = 0; i < array.length; i++) { 9 | 10 | for (int j = 0; j < array.length; j++) { 11 | 12 | System.out.println(array[j]); 13 | if (array[j] == 560) { 14 | break; 15 | } 16 | } 17 | System.out.println("break outer for loop"); 18 | break; 19 | } 20 | } 21 | 22 | } 23 | -------------------------------------------------------------------------------- /src/controlStatements/ContinueExample1.java: -------------------------------------------------------------------------------- 1 | package controlStatements; 2 | 3 | public class ContinueExample1 { 4 | 5 | public static void main(String[] args) { 6 | 7 | int array[] = { 120, 230, 404, 560, 708, 90, 10, 20 }; 8 | 9 | for (int i = 0; i < array.length; i++) { 10 | 11 | System.out.println("number is=" + array[i]); 12 | System.out.println("number is=" + array[i]); 13 | System.out.println("number is=" + array[i]); 14 | System.out.println("number is=" + array[i]); 15 | 16 | if (array[i] < 560) { 17 | continue; 18 | } 19 | 20 | System.out.println("number is=" + array[i]); 21 | System.out.println("number is=" + array[i]); 22 | System.out.println("number is=" + array[i]); 23 | System.out.println("number is=" + array[i]); 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/controlStatements/ContinueExample2.java: -------------------------------------------------------------------------------- 1 | package controlStatements; 2 | 3 | public class ContinueExample2 { 4 | 5 | public static void main(String[] args) { 6 | for (int i = 0; i < 100; i++) { 7 | if (i > 10) { 8 | System.out.println("Skipped by continue value is=" + i); 9 | continue; 10 | } 11 | System.out.println("value of i is=" + i); 12 | } 13 | } 14 | 15 | 16 | 17 | 18 | } 19 | -------------------------------------------------------------------------------- /src/controlStatements/DoWhileLoopExample.java: -------------------------------------------------------------------------------- 1 | package controlStatements; 2 | 3 | public class DoWhileLoopExample { 4 | 5 | public static void main(String[] args) { 6 | int i = 0; 7 | do { 8 | i++; 9 | System.out.println(i); 10 | } while (i < 5); 11 | 12 | 13 | while(i<=5){ 14 | System.out.println(i); 15 | i++; 16 | } 17 | } 18 | 19 | } 20 | -------------------------------------------------------------------------------- /src/controlStatements/ForEachLoopExample.java: -------------------------------------------------------------------------------- 1 | package controlStatements; 2 | 3 | public class ForEachLoopExample { 4 | 5 | public static void main(String[] args) { 6 | int array[] = { 120, 230, 404, 560, 708 }; 7 | 8 | 9 | System.out.println(array.length); 10 | 11 | for (int i = 0; i < array.length; i++) { 12 | System.out.println(array[i]); 13 | } 14 | 15 | System.out.println("============"); 16 | 17 | for (int i : array) { 18 | System.out.println(i); 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/controlStatements/ForLoopExample.java: -------------------------------------------------------------------------------- 1 | package controlStatements; 2 | 3 | public class ForLoopExample { 4 | 5 | public static void main(String[] args) { 6 | 7 | for (int i = 0; i <= 8; i++) { 8 | String string = "Running For Loop and count is=" + i; 9 | System.out.println(string); 10 | } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/controlStatements/ForLoopExample1.java: -------------------------------------------------------------------------------- 1 | package controlStatements; 2 | 3 | public class ForLoopExample1 { 4 | 5 | public static void main(String[] args) { 6 | 7 | int array[] = { 120, 230, 404, 560, 708 }; 8 | 9 | int a[] = new int[4]; 10 | a[0] = 10; 11 | a[1] = 10; 12 | a[2] = 10; 13 | a[3] = 10; 14 | 15 | for (int i = 0; i < array.length; i++) { 16 | System.out.println(array[i]); 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/controlStatements/IfEleseifIF.java: -------------------------------------------------------------------------------- 1 | package controlStatements; 2 | 3 | public class IfEleseifIF { 4 | 5 | public void testAge(int age) { 6 | if (age > 18) { 7 | System.out.println("Person is Major"); 8 | } else if(age < 5) { 9 | System.out.println("Person is Minor"); 10 | } 11 | 12 | else if(age < 10) { 13 | System.out.println("Person is Minor"); 14 | } 15 | 16 | 17 | else if(age < 11) { 18 | System.out.println("Person is Minor"); 19 | } 20 | 21 | else{ 22 | System.out.println("Invalid data"); 23 | } 24 | } 25 | 26 | public static void main(String[] args) { 27 | IfEleseifIF obj = new IfEleseifIF(); 28 | 29 | obj.testAge(20); 30 | 31 | obj.testAge(2); 32 | 33 | obj.testAge(6); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/controlStatements/IfElseExample.java: -------------------------------------------------------------------------------- 1 | package controlStatements; 2 | 3 | public class IfElseExample { 4 | 5 | static boolean condition; 6 | 7 | public static void main(String[] args) { 8 | System.out.println(condition); 9 | if (condition) { 10 | System.out.println("IN IF PART"); 11 | } else { 12 | System.out.println("In ELSE PART"); 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/controlStatements/IfElseExample1.java: -------------------------------------------------------------------------------- 1 | package controlStatements; 2 | 3 | public class IfElseExample1 { 4 | 5 | public void testAge(int age) { 6 | if (age > 18) { 7 | System.out.println("Person is Major"); 8 | } else { 9 | System.out.println("Person is Minor"); 10 | } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/controlStatements/LabeledForLoop.java: -------------------------------------------------------------------------------- 1 | package controlStatements; 2 | 3 | public class LabeledForLoop { 4 | 5 | public static void main(String[] args) { 6 | 7 | aa: for (int i = 1; i <= 5; i++) { 8 | 9 | bb: for (int j = 1; j <= 5; j++) { 10 | 11 | if (i == 2 && j == 2) { 12 | break aa; 13 | } 14 | 15 | System.out.println(i + " " + j); 16 | } 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/controlStatements/SwitchCaseExample1.java: -------------------------------------------------------------------------------- 1 | package controlStatements; 2 | 3 | public class SwitchCaseExample1 { 4 | 5 | public static void main(String args[]) { 6 | int i = 9; 7 | switch (i) { 8 | case 0: 9 | System.out.println("i is zero."); 10 | break; 11 | case 1: 12 | System.out.println("i is one."); 13 | break; 14 | case 2: 15 | System.out.println("i is two."); 16 | break; 17 | default: 18 | System.out.println("i is greater than 2."); 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/controlStatements/SwitchExample.java: -------------------------------------------------------------------------------- 1 | package controlStatements; 2 | 3 | public class SwitchExample { 4 | 5 | public void checkBookTypeAndPrice(String bookName) { 6 | String s1; 7 | switch (bookName) { 8 | case "MATH": 9 | s1 = "Author Aryabhata Price=200"; 10 | System.out.println(s1); 11 | break; 12 | case "PHYSICS": 13 | s1 = "Author Bhanu Prata Price=100"; 14 | System.out.println(s1); 15 | break; 16 | case "CHEMISTRY": 17 | s1 = "Author Pratap Price=300"; 18 | System.out.println(s1); 19 | break; 20 | default: 21 | System.out.println("No Book Found Supply Proper Input"); 22 | } 23 | } 24 | 25 | public static void main(String[] args) { 26 | SwitchExample switchExample = new SwitchExample(); 27 | switchExample.checkBookTypeAndPrice("MATH1"); 28 | } 29 | 30 | } 31 | -------------------------------------------------------------------------------- /src/controlStatements/WhileExam.java: -------------------------------------------------------------------------------- 1 | package controlStatements; 2 | 3 | public class WhileExam { 4 | 5 | public static void main(String[] args) { 6 | int myNumber = 1; 7 | 8 | while (myNumber != 1000) { 9 | 10 | if ((myNumber % 2) == 0) { 11 | System.out.println(myNumber + " is even"); 12 | } 13 | 14 | myNumber++; 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/controlStatements/WhileLoopExample.java: -------------------------------------------------------------------------------- 1 | package controlStatements; 2 | 3 | public class WhileLoopExample { 4 | 5 | public static void main(String[] args) { 6 | 7 | int i = 5; 8 | while (i <= 10) { 9 | System.out.println(i); 10 | i++; 11 | } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/controlStatements/WhileLoopExample1.java: -------------------------------------------------------------------------------- 1 | package controlStatements; 2 | 3 | public class WhileLoopExample1 { 4 | 5 | public static void main(String[] args) { 6 | 7 | while(true){ 8 | System.out.println("while loop is running in infinitive"); 9 | } 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /src/controlStatements/WhileLoopExample2.java: -------------------------------------------------------------------------------- 1 | package controlStatements; 2 | 3 | public class WhileLoopExample2 { 4 | 5 | public static void main(String[] args) { 6 | 7 | final double danger_rate = 2; 8 | 9 | int a = 2; 10 | 11 | int minute; 12 | minute = 0; 13 | double total_danger = 0; 14 | while (total_danger <= 1) { 15 | total_danger = danger_rate * minute; 16 | minute++; 17 | } 18 | 19 | System.out.println("danger hits 100% after " + minute + " minutes"); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/customException/DAOException.java: -------------------------------------------------------------------------------- 1 | package customException; 2 | 3 | public class DAOException extends Exception { 4 | 5 | private ErrorCode erroCode; 6 | 7 | public ErrorCode getErroCode() { 8 | return erroCode; 9 | } 10 | 11 | /** 12 | * 13 | */ 14 | private static final long serialVersionUID = 1L; 15 | 16 | DAOException(String msg, Throwable t) { 17 | super(msg, t); 18 | } 19 | 20 | DAOException(String msg) { 21 | super(msg); 22 | } 23 | 24 | DAOException(ErrorCode erroCode,String msg, Throwable t) { 25 | super(msg, t); 26 | this.erroCode = erroCode; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/customException/DataException.java: -------------------------------------------------------------------------------- 1 | package customException; 2 | 3 | import java.io.Serializable; 4 | 5 | public class DataException extends Exception { 6 | 7 | 8 | DataException(String msg, Throwable t) { 9 | super(msg, t); 10 | } 11 | 12 | DataException(String msg) { 13 | super(msg); 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /src/customException/ErrorCode.java: -------------------------------------------------------------------------------- 1 | package customException; 2 | 3 | public enum ErrorCode { 4 | 5 | INVALID_DATA, 6 | INVALID_STATAE, 7 | INVALID_CITY; 8 | 9 | } 10 | -------------------------------------------------------------------------------- /src/customException/TestDataException.java: -------------------------------------------------------------------------------- 1 | package customException; 2 | 3 | public class TestDataException { 4 | 5 | public static void test1(int a) throws DataException { 6 | if (a < 10) { 7 | throw new DataException("data is not valid"); 8 | } 9 | } 10 | 11 | public static void test2() throws DataException { 12 | try { 13 | int i = 9 / 0; 14 | } catch (ArithmeticException e) { 15 | throw new DataException("data is not valid", e); 16 | } 17 | } 18 | 19 | public static void main(String[] args) { 20 | try { 21 | TestDataException.test2(); 22 | } catch (DataException e) { 23 | System.out.println(e.getCause()); 24 | System.out.println(e.getMessage()); 25 | } 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /src/encapsulationInJava/Bank.java: -------------------------------------------------------------------------------- 1 | package encapsulationInJava; 2 | 3 | public abstract class Bank { 4 | private int accno; 5 | private String name; 6 | private int loan; 7 | private int balance; 8 | 9 | void display_to_clerk() { 10 | System.out.println("Accno = " + accno); 11 | System.out.println("Name = " + name); 12 | } 13 | 14 | void display_to_manager() { 15 | System.out.println("Accno = " + accno); 16 | System.out.println("Name = " + name); 17 | System.out.println("Loan = " + loan); 18 | System.out.println("Balance = " + balance); 19 | } 20 | } -------------------------------------------------------------------------------- /src/encapsulationInJava/BrewingUnit.java: -------------------------------------------------------------------------------- 1 | package encapsulationInJava; 2 | 3 | public class BrewingUnit { 4 | 5 | public Coffee brew(CoffeeSelection selection, GroundCoffee groundCoffee, double quantity) { 6 | return new Coffee(selection, quantity); 7 | } 8 | 9 | } -------------------------------------------------------------------------------- /src/encapsulationInJava/Coffee.java: -------------------------------------------------------------------------------- 1 | 2 | package encapsulationInJava; 3 | 4 | public class Coffee { 5 | 6 | private CoffeeSelection selection; 7 | private double quantity; 8 | 9 | public Coffee(CoffeeSelection selection, double quantity) { 10 | this.selection = selection; 11 | this.quantity = quantity; 12 | } 13 | 14 | public CoffeeSelection getSelection() { 15 | return selection; 16 | } 17 | 18 | public double getQuantity() { 19 | return quantity; 20 | } 21 | 22 | public void setQuantity(double quantity) throws Exception { 23 | if (quantity >= 0.0) { 24 | this.quantity = quantity; 25 | } else { 26 | throw new Exception("Quantity has to be >= 0.0."); 27 | } 28 | } 29 | } -------------------------------------------------------------------------------- /src/encapsulationInJava/CoffeeApp.java: -------------------------------------------------------------------------------- 1 | package encapsulationInJava; 2 | 3 | import java.util.HashMap; 4 | import java.util.Map; 5 | 6 | public class CoffeeApp { 7 | 8 | public static void main(String[] args) { 9 | 10 | Map beans = new HashMap(); 11 | 12 | beans.put(CoffeeSelection.ESPRESSO, new CoffeeBean("My favorite espresso bean", 10)); 13 | beans.put(CoffeeSelection.FILTER_COFFEE, new CoffeeBean("My favorite filter coffee bean", 4)); 14 | CoffeeMachineIf machine = new CoffeeMachine(beans); 15 | try { 16 | Coffee espresso = machine.brewCoffee(CoffeeSelection.ESPRESSO); 17 | System.out.println("Your " + espresso.getSelection() + " is ready"); 18 | } catch (Exception e) { 19 | e.printStackTrace(); 20 | } 21 | } 22 | } -------------------------------------------------------------------------------- /src/encapsulationInJava/CoffeeBean.java: -------------------------------------------------------------------------------- 1 | package encapsulationInJava; 2 | 3 | public class CoffeeBean { 4 | 5 | private String name; 6 | 7 | private double quantity; 8 | 9 | public CoffeeBean(String name, double quantity) { 10 | this.name = name; 11 | this.quantity = quantity; 12 | } 13 | 14 | public String getName() { 15 | return name; 16 | } 17 | 18 | public void setName(String name) { 19 | this.name = name; 20 | } 21 | 22 | public double getQuantity() { 23 | return quantity; 24 | } 25 | 26 | public void setQuantity(double quantity) { 27 | this.quantity = quantity; 28 | } 29 | 30 | } -------------------------------------------------------------------------------- /src/encapsulationInJava/CoffeeMachineIf.java: -------------------------------------------------------------------------------- 1 | package encapsulationInJava; 2 | 3 | public interface CoffeeMachineIf { 4 | 5 | Coffee brewCoffee(CoffeeSelection selection) throws Exception; 6 | } 7 | -------------------------------------------------------------------------------- /src/encapsulationInJava/CoffeeSelection.java: -------------------------------------------------------------------------------- 1 | package encapsulationInJava; 2 | 3 | //CoffeeSelection is a simple enum providing a set of predefined values 4 | // for the different kinds of coffees. 5 | 6 | public enum CoffeeSelection { 7 | ESPRESSO, CAPPUCCINO,FILTER_COFFEE, ; 8 | } -------------------------------------------------------------------------------- /src/encapsulationInJava/CollectionGetterSetter.java: -------------------------------------------------------------------------------- 1 | package encapsulationInJava; 2 | 3 | import java.util.*; 4 | 5 | public class CollectionGetterSetter { 6 | private List listTitles; 7 | 8 | public void setListTitles(List titles) { 9 | this.listTitles = titles; 10 | } 11 | 12 | public List getListTitles() { 13 | return this.listTitles; 14 | } 15 | 16 | public static void main(String[] args) { 17 | CollectionGetterSetter app = new CollectionGetterSetter(); 18 | List titles1 = new ArrayList(); 19 | titles1.add("Name"); 20 | titles1.add("Address"); 21 | titles1.add("Email"); 22 | titles1.add("Job"); 23 | app.setListTitles(titles1); 24 | System.out.println("Titles 1: " + titles1); 25 | titles1.set(2, "Habilitation"); 26 | List titles2 = app.getListTitles(); 27 | System.out.println("Titles 2: " + titles2); 28 | titles2.set(0, "Full name"); 29 | List titles3 = app.getListTitles(); 30 | System.out.println("Titles 3: " + titles3); 31 | } 32 | } -------------------------------------------------------------------------------- /src/encapsulationInJava/Configuration.java: -------------------------------------------------------------------------------- 1 | package encapsulationInJava; 2 | 3 | public class Configuration { 4 | 5 | private double quantityCoffee; 6 | private double quantityWater; 7 | 8 | public Configuration(double quantityCoffee, double quantityWater) { 9 | this.quantityCoffee = quantityCoffee; 10 | this.quantityWater = quantityWater; 11 | } 12 | 13 | public double getQuantityCoffee() { 14 | return quantityCoffee; 15 | } 16 | 17 | public double getQuantityWater() { 18 | return quantityWater; 19 | } 20 | 21 | } -------------------------------------------------------------------------------- /src/encapsulationInJava/EncapsulationTest1.java: -------------------------------------------------------------------------------- 1 | package encapsulationInJava; 2 | 3 | public class EncapsulationTest1 { 4 | 5 | public static void main(String[]args) { 6 | 7 | Student st = new Student(); 8 | //st.id = "5"; // As the field is not private. So, it can be accessed by 9 | // anyone from outside the class. 10 | 11 | st.setId("5"); 12 | String data = st.getId(); 13 | 14 | System.out.println(data); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/encapsulationInJava/Example1.java: -------------------------------------------------------------------------------- 1 | package encapsulationInJava; 2 | 3 | public class Example1 { 4 | 5 | private String name; 6 | 7 | public String age; 8 | 9 | public String getName() { 10 | return name; 11 | } 12 | 13 | public void setName(String name) { 14 | this.name = name; 15 | } 16 | 17 | public static void main(String[] args) { 18 | Example1 obj = new Example1(); 19 | 20 | obj.age="20"; 21 | 22 | Example1 obj1 = new Example1(); 23 | 24 | System.out.println(obj1.age); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/encapsulationInJava/Example2.java: -------------------------------------------------------------------------------- 1 | package encapsulationInJava; 2 | 3 | public class Example2 { 4 | 5 | private String name; 6 | 7 | private String age; 8 | 9 | public String getName() { 10 | 11 | return name; 12 | } 13 | 14 | public void setName(String name) { 15 | this.name = name; 16 | } 17 | 18 | public String getAge() { 19 | return age; 20 | } 21 | 22 | public void setAge(String age) { 23 | this.age = age; 24 | } 25 | 26 | 27 | } 28 | -------------------------------------------------------------------------------- /src/encapsulationInJava/Example3.java: -------------------------------------------------------------------------------- 1 | package encapsulationInJava; 2 | 3 | public class Example3 { 4 | 5 | private int age; 6 | private String name; 7 | 8 | public int getAge() { 9 | return age; 10 | } 11 | 12 | public void setAge(int age) throws Exception { 13 | 14 | if (age < 10) { 15 | throw new Exception("age should not be less than 10"); 16 | } 17 | this.age = age; 18 | } 19 | 20 | public String getName() { 21 | return name; 22 | } 23 | 24 | public void setName(String name) throws Exception { 25 | if (name == null || name == "") { 26 | throw new Exception("name should not be empty or null"); 27 | 28 | } 29 | this.name = name; 30 | } 31 | 32 | } 33 | -------------------------------------------------------------------------------- /src/encapsulationInJava/Example4.java: -------------------------------------------------------------------------------- 1 | package encapsulationInJava; 2 | 3 | public class Example4 { 4 | 5 | private String schoolName = "ABC"; 6 | 7 | private String studentName; 8 | 9 | 10 | public String getSchoolName() { 11 | return schoolName; 12 | } 13 | 14 | public String getStudentName() { 15 | return studentName; 16 | } 17 | 18 | public void setStudentName(String studentName) { 19 | this.studentName = studentName; 20 | } 21 | 22 | @Override 23 | public String toString() { 24 | return "Example4 [schoolName=" + schoolName + ", studentName=" + studentName + "]"; 25 | } 26 | 27 | 28 | } 29 | -------------------------------------------------------------------------------- /src/encapsulationInJava/Grinder.java: -------------------------------------------------------------------------------- 1 | package encapsulationInJava; 2 | public class Grinder { 3 | 4 | public GroundCoffee grind(CoffeeBean coffeeBean, double quantityCoffee) { 5 | return new GroundCoffee(); 6 | } 7 | } -------------------------------------------------------------------------------- /src/encapsulationInJava/GroundCoffee.java: -------------------------------------------------------------------------------- 1 | package encapsulationInJava; 2 | 3 | public class GroundCoffee { 4 | 5 | } -------------------------------------------------------------------------------- /src/encapsulationInJava/Student.java: -------------------------------------------------------------------------------- 1 | package encapsulationInJava; 2 | 3 | public class Student { 4 | 5 | private long id; // Here, No encapsulation is used. Since the field is not 6 | // private. 7 | 8 | public String getId() { 9 | return String.valueOf(id); 10 | } 11 | 12 | public void setId(String id) { 13 | this.id = Long.parseLong(id); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/encapsulationInJava/TestExample2.java: -------------------------------------------------------------------------------- 1 | package encapsulationInJava; 2 | 3 | public class TestExample2 { 4 | 5 | public static void main(String[] args) { 6 | Example2 obj = new Example2(); 7 | obj.setAge("100"); 8 | obj.setName("Test"); 9 | 10 | 11 | System.out.println("name="+obj.getName()+" age="+obj.getAge()); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/encapsulationInJava/TestExample3.java: -------------------------------------------------------------------------------- 1 | package encapsulationInJava; 2 | 3 | public class TestExample3 { 4 | 5 | public static void main(String[] args) throws Exception { 6 | Example3 obj = new Example3(); 7 | obj.setAge(11); 8 | System.out.println(obj.getAge()); 9 | 10 | obj.setAge(9); 11 | System.out.println(obj.getAge()); 12 | } 13 | 14 | } 15 | -------------------------------------------------------------------------------- /src/encapsulationInJava/TestExample4.java: -------------------------------------------------------------------------------- 1 | package encapsulationInJava; 2 | 3 | public class TestExample4 { 4 | 5 | public static void main(String[] args) { 6 | 7 | Example4 obj = new Example4(); 8 | obj.setStudentName("Ram"); 9 | 10 | System.out.println(obj); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/encapsulationInJava/TestExample5.java: -------------------------------------------------------------------------------- 1 | package encapsulationInJava; 2 | 3 | public class TestExample5 { 4 | 5 | private int[] a = { 1, 2, 3, 4 }; 6 | 7 | public int[] getA() { 8 | return a.clone(); 9 | } 10 | 11 | public void setA(int[] a) { 12 | this.a = a; 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /src/encapsulationInJava/TestExample6.java: -------------------------------------------------------------------------------- 1 | package encapsulationInJava; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | 6 | public class TestExample6 { 7 | 8 | private List books; 9 | 10 | public TestExample6() { 11 | this.books = new ArrayList(); 12 | books.add("Test1"); 13 | books.add("Test2"); 14 | books.add("Test3"); 15 | } 16 | 17 | public List getBooks() { 18 | return new ArrayList(books); 19 | //return books; 20 | } 21 | 22 | public void setBooks(List books) { 23 | this.books = books; 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /src/encapsulationInJava/TestTestExample5.java: -------------------------------------------------------------------------------- 1 | package encapsulationInJava; 2 | 3 | import java.util.Arrays; 4 | 5 | public class TestTestExample5 { 6 | 7 | public static void main(String[] args) { 8 | 9 | TestExample5 example5 = new TestExample5(); 10 | int[] data = example5.getA(); 11 | 12 | System.out.println(Arrays.toString(example5.getA())); 13 | data[2] = 0; 14 | //System.out.println(example5.getA()); 15 | System.out.println(Arrays.toString(example5.getA())); 16 | 17 | //TestExample5 example6 = new TestExample5(); 18 | //int[] data1 = example5.getA().clone(); 19 | //data1[2] = 0; 20 | //System.out.println(Arrays.toString(example6.getA())); 21 | } 22 | 23 | } 24 | -------------------------------------------------------------------------------- /src/encapsulationInJava/TestTestExample6.java: -------------------------------------------------------------------------------- 1 | package encapsulationInJava; 2 | 3 | import java.util.List; 4 | 5 | public class TestTestExample6 { 6 | 7 | public static void main(String[] args) { 8 | 9 | TestExample6 example6 = new TestExample6(); 10 | 11 | System.out.println(example6.getBooks()); 12 | 13 | List data = example6.getBooks(); 14 | 15 | data.remove(1); 16 | 17 | System.out.println(example6.getBooks()); 18 | 19 | List data1 = example6.getBooks(); 20 | data1.remove(0); 21 | data1 = null; 22 | System.out.println(example6.getBooks()); 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /src/enumjava/Example1.java: -------------------------------------------------------------------------------- 1 | package enumjava; 2 | 3 | public class Example1 { 4 | 5 | public enum Season { 6 | WINTER, SPRING, SUMMER, FALL 7 | } 8 | 9 | public static void main(String[] args) { 10 | for (Season s : Season.values()) 11 | System.out.println(s); 12 | 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /src/enumjava/Example2.java: -------------------------------------------------------------------------------- 1 | package enumjava; 2 | 3 | public class Example2 { 4 | 5 | enum Season { 6 | WINTER(5), SPRING(10), SUMMER(15), FALL(20); 7 | 8 | private int value; 9 | 10 | private Season(int value) { 11 | this.value = value; 12 | } 13 | 14 | public int getValue(){ 15 | return value; 16 | } 17 | } 18 | 19 | public static void main(String args[]) { 20 | System.out.println(Season.WINTER.value); 21 | 22 | for (Season s : Season.values()) 23 | System.out.println(s + " " + s.value); 24 | 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/enumjava/Operation.java: -------------------------------------------------------------------------------- 1 | package enumjava; 2 | 3 | public enum Operation { 4 | 5 | PLUS, MINUS, TIMES, DIVIDE; 6 | 7 | double calculate(double x, double y) { 8 | switch (this) { 9 | case PLUS: 10 | return x + y; 11 | case MINUS: 12 | return x - y; 13 | case TIMES: 14 | return x * y; 15 | case DIVIDE: 16 | return x / y; 17 | default: 18 | throw new AssertionError("Unknown operations " + this); 19 | } 20 | } 21 | } -------------------------------------------------------------------------------- /src/enumjava/State.java: -------------------------------------------------------------------------------- 1 | package enumjava; 2 | 3 | public enum State { 4 | 5 | BIHAR(100, "Hindi", "Bjp"), UP(1000, "Hindi", "Bjp"), MP(100, "Hindi", "Congress"), GOA(100, "Hindi", "Test"); 6 | 7 | private State(int population, String language, String party) { 8 | this.population = population; 9 | this.language = language; 10 | this.party = party; 11 | } 12 | 13 | private int population; 14 | private String language; 15 | private String party; 16 | 17 | public int getPopulation() { 18 | return population; 19 | } 20 | 21 | public String getLanguage() { 22 | return language; 23 | } 24 | 25 | public String getParty() { 26 | return party; 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /src/enumjava/TestOperation.java: -------------------------------------------------------------------------------- 1 | package enumjava; 2 | 3 | public class TestOperation { 4 | 5 | public static void main(String[] args) { 6 | 7 | double result = Operation.PLUS.calculate(1, 3); 8 | 9 | System.out.println(result); 10 | 11 | result = Operation.MINUS.calculate(1, 3); 12 | System.out.println(result); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /src/enumjava/TestState.java: -------------------------------------------------------------------------------- 1 | package enumjava; 2 | public class TestState { 3 | public static void main(String[] args) { 4 | String data = State.BIHAR.getLanguage(); 5 | String party = State.MP.getParty(); 6 | 7 | System.out.println(data); 8 | System.out.println(party); 9 | 10 | if(State.BIHAR.name().equals("BIHAR")){ 11 | System.out.println("---"); 12 | } 13 | 14 | State datai = State.valueOf("BIHAR"); 15 | System.out.println(datai.getParty()); 16 | 17 | System.out.println(); 18 | 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/exception/Example1.java: -------------------------------------------------------------------------------- 1 | package exception; 2 | 3 | public class Example1 { 4 | 5 | public void test1() { 6 | try { 7 | int i = 90 / 0; 8 | System.out.println("execution completed"); 9 | } 10 | catch (ArithmeticException e) { 11 | e.printStackTrace(); 12 | } catch (Exception e) { 13 | e.printStackTrace(); 14 | } 15 | } 16 | 17 | public void test2() { 18 | try { 19 | int i = 90 / 0; 20 | } catch (Exception e) { 21 | System.out.println("exception occured"); 22 | } 23 | System.out.println("execution completed"); 24 | } 25 | 26 | public static void main(String[] args) { 27 | Example1 obj = new Example1(); 28 | // obj.test1(); 29 | obj.test2(); 30 | } 31 | 32 | } 33 | -------------------------------------------------------------------------------- /src/exception/Example11.java: -------------------------------------------------------------------------------- 1 | package exception; 2 | 3 | public class Example11 { 4 | 5 | public void test1() { 6 | int i = 90 / 1; 7 | } 8 | 9 | public void test2() { 10 | int a[] = { 20 }; 11 | int k = a[1]; 12 | } 13 | 14 | public void test3() { 15 | try { 16 | test1(); 17 | System.out.println("No exception is test1() method"); 18 | try { 19 | test2(); 20 | System.out.println("No exception is test2() method"); 21 | } catch (ArrayIndexOutOfBoundsException e) { 22 | System.out.println("ArrayIndexOutOfBoundsException handeled"); 23 | } 24 | } catch (ArrayIndexOutOfBoundsException e) { 25 | System.out.println("ArithmeticException handeled"); 26 | } 27 | } 28 | 29 | public static void main(String[] args) { 30 | Example11 obj = new Example11(); 31 | obj.test3(); 32 | } 33 | 34 | } 35 | -------------------------------------------------------------------------------- /src/exception/Example14.java: -------------------------------------------------------------------------------- 1 | package exception; 2 | 3 | public class Example14 { 4 | 5 | public static void main(String[] args) { 6 | try { 7 | int num = 9 / 0; 8 | System.out.println(num); 9 | } catch (ArrayIndexOutOfBoundsException e) { 10 | System.out.println("Number should not be divided by zero"); 11 | } 12 | /* 13 | * Finally block will always execute even if there is no exception in 14 | * try block 15 | */ 16 | finally { 17 | System.out.println("This is finally block"); 18 | } 19 | System.out.println("Out of try-catch-finally"); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/exception/Example15.java: -------------------------------------------------------------------------------- 1 | package exception; 2 | 3 | public class Example15 { 4 | 5 | public static void main(String[] args) { 6 | try { 7 | int num = 9 / 0; 8 | System.out.println(num); 9 | } catch (NumberFormatException e) { 10 | System.out.println("Number should not be divided by zero"); 11 | } 12 | finally { 13 | System.out.println("This is finally block"); 14 | } 15 | System.out.println("Out of try-catch-finally"); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/exception/Example16.java: -------------------------------------------------------------------------------- 1 | package exception; 2 | 3 | public class Example16 { 4 | 5 | public static void main(String[] args) { 6 | try { 7 | int num = 9 / 0; 8 | System.out.println(num); 9 | } catch (ArithmeticException e) { 10 | System.out.println("Number should not be divided by zero"); 11 | } finally { 12 | int num = 9 / 0; 13 | System.out.println(num); 14 | System.out.println("This is finally block"); 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/exception/Example17.java: -------------------------------------------------------------------------------- 1 | package exception; 2 | 3 | public class Example17 { 4 | 5 | public static void main(String[] args) { 6 | try { 7 | int num = 9 / 1; 8 | System.out.println(num); 9 | //return; 10 | } 11 | catch (ArithmeticException e) { 12 | System.out.println("Number should not be divided by zero"); 13 | } 14 | 15 | finally { 16 | System.out.println("This is finally block"); 17 | } 18 | System.out.println("Hello Java"); 19 | 20 | System.out.println("Hello Java"); 21 | System.out.println("Hello Java"); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/exception/Example18.java: -------------------------------------------------------------------------------- 1 | package exception; 2 | 3 | public class Example18 { 4 | 5 | static void checkEligibiltyProcess(int age, int weight) { 6 | if (age < 10 && weight < 30) { 7 | throw new ArithmeticException("Student is not eligible for registration"); 8 | } else { 9 | System.out.println("Student is eligible for registration"); 10 | } 11 | } 12 | 13 | public static void main(String args[]) { 14 | System.out.println("Welcome to the Admission process"); 15 | checkEligibiltyProcess(9, 25); 16 | System.out.println("Have a good day"); 17 | 18 | checkEligibiltyProcess(10, 39); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/exception/Example19.java: -------------------------------------------------------------------------------- 1 | package exception; 2 | 3 | import java.io.IOException; 4 | 5 | public class Example19 { 6 | 7 | static void checkEligibiltyProcess(int age) { 8 | if (age < 18) { 9 | throw new ArithmeticException("Not Eligible for voting"); 10 | } else { 11 | System.out.println("Eligible for voting"); 12 | } 13 | } 14 | 15 | static void checkData(int data) throws IOException, Exception { 16 | 17 | if (data < 100) { 18 | throw new IOException("issue with data"); 19 | } 20 | 21 | if (data < 100) { 22 | throw new Exception("issue with data"); 23 | } 24 | 25 | } 26 | 27 | public static void main(String[] args) { 28 | Example19.checkEligibiltyProcess(15); 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /src/exception/Example2.java: -------------------------------------------------------------------------------- 1 | package exception; 2 | 3 | public class Example2 { 4 | 5 | public static void main(String[] args) { 6 | int i = 90 / 0; 7 | } 8 | 9 | } 10 | -------------------------------------------------------------------------------- /src/exception/Example20.java: -------------------------------------------------------------------------------- 1 | package exception; 2 | 3 | public class Example20 { 4 | 5 | static void check() throws ArithmeticException { 6 | System.out.println("Inside check function"); 7 | throw new ArithmeticException("demo"); 8 | } 9 | 10 | public static void main(String args[]) { 11 | try { 12 | check(); 13 | } catch (ArithmeticException e) { 14 | System.out.println("caught======" + e); 15 | } 16 | 17 | Example21 obj = new Example21(); 18 | try { 19 | obj.tset2(); 20 | } catch (Exception e) { 21 | // TODO Auto-generated catch block 22 | e.printStackTrace(); 23 | } 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /src/exception/Example21.java: -------------------------------------------------------------------------------- 1 | package exception; 2 | 3 | import java.io.IOException; 4 | 5 | public class Example21 { 6 | 7 | void test() throws Exception { 8 | throw new IOException("device error");// checked exception 9 | } 10 | 11 | void tset2() throws Exception { 12 | test(); 13 | } 14 | 15 | void tset1() { 16 | try { 17 | tset2(); 18 | } catch (Exception e) { 19 | System.out.println("exception handled"); 20 | } 21 | } 22 | 23 | public static void main(String args[]) { 24 | Example21 obj = new Example21(); 25 | obj.tset1(); 26 | System.out.println("normal flow..."); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/exception/Example22.java: -------------------------------------------------------------------------------- 1 | package exception; 2 | 3 | public class Example22 { 4 | 5 | void test1() throws ArithmeticException { 6 | throw new ArithmeticException("Calculation error"); 7 | } 8 | 9 | void test2() { 10 | test1(); 11 | } 12 | 13 | void test3() { 14 | try { 15 | test2(); 16 | } catch (ArithmeticException e) { 17 | System.out.println("ArithmeticException handled"); 18 | } 19 | } 20 | 21 | public static void main(String args[]) { 22 | Example22 obj = new Example22(); 23 | obj.test3(); 24 | System.out.println("End Of Program"); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/exception/Example23.java: -------------------------------------------------------------------------------- 1 | package exception; 2 | 3 | import java.io.FileNotFoundException; 4 | 5 | public class Example23 { 6 | 7 | void method() throws ArithmeticException { 8 | throw new ArithmeticException("ArithmeticException Occurred"); 9 | } 10 | 11 | public static void main(String[] args) { 12 | Example26 obj = new Example26(); 13 | try { 14 | obj.test1(); 15 | } catch ( NullPointerException e ) { 16 | 17 | e.printStackTrace(); 18 | } 19 | catch (FileNotFoundException e) { 20 | 21 | e.printStackTrace(); 22 | } 23 | catch (InterruptedException e) { 24 | 25 | e.printStackTrace(); 26 | } 27 | 28 | catch (Exception e) { 29 | 30 | e.printStackTrace(); 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/exception/Example24.java: -------------------------------------------------------------------------------- 1 | package exception; 2 | 3 | public class Example24 { 4 | public static void main(String args[]) throws ArithmeticException { 5 | Example23 obj = new Example23(); 6 | obj.method(); 7 | 8 | System.out.println("End Of Program"); 9 | 10 | 11 | Example26 obj1 = new Example26(); 12 | try { 13 | obj1.test1(); 14 | } catch (Exception e) { 15 | // TODO Auto-generated catch block 16 | e.printStackTrace(); 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/exception/Example25.java: -------------------------------------------------------------------------------- 1 | package exception; 2 | 3 | public class Example25 { 4 | 5 | static void fun() { 6 | try { 7 | throw new NullPointerException("demo"); 8 | } catch (NullPointerException e) { 9 | System.out.println("Caught inside fun()."); 10 | throw e; 11 | } 12 | } 13 | 14 | public static void main(String args[]) { 15 | try { 16 | fun(); 17 | } catch (NullPointerException e) { 18 | System.out.println("Caught in main."); 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/exception/Example26.java: -------------------------------------------------------------------------------- 1 | package exception; 2 | 3 | import java.io.FileNotFoundException; 4 | 5 | public class Example26 { 6 | 7 | void test1() throws FileNotFoundException, NullPointerException,InterruptedException, Exception { 8 | try { 9 | System.out.println(); 10 | System.out.println(); 11 | System.out.println(); 12 | System.out.println(); 13 | System.out.println(); 14 | System.out.println(); 15 | System.out.println(); 16 | System.out.println(); 17 | System.out.println(); 18 | System.out.println(); 19 | System.out.println(); 20 | throw new Exception(); 21 | } catch (Exception e) { 22 | throw e; 23 | } 24 | } 25 | 26 | 27 | 28 | } 29 | -------------------------------------------------------------------------------- /src/exception/Example3.java: -------------------------------------------------------------------------------- 1 | package exception; 2 | 3 | public class Example3 { 4 | 5 | public static void main(String[] args) { 6 | int a[] = { 10, 20, 30 }; 7 | System.out.println(a[8]); 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /src/exception/Example4.java: -------------------------------------------------------------------------------- 1 | package exception; 2 | 3 | public class Example4 { 4 | 5 | public static void main(String[] args) { 6 | String s1 = null; 7 | System.out.println(s1.toString()); 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /src/exception/Example5.java: -------------------------------------------------------------------------------- 1 | package exception; 2 | 3 | public class Example5 { 4 | 5 | public static void main(String[] args) { 6 | try { 7 | Class.forName("Test1278778787"); 8 | } catch (ClassNotFoundException e) { 9 | // TODO Auto-generated catch block 10 | e.printStackTrace(); 11 | } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/exception/Example6.java: -------------------------------------------------------------------------------- 1 | package exception; 2 | 3 | import java.io.BufferedReader; 4 | import java.io.File; 5 | import java.io.FileNotFoundException; 6 | import java.io.FileReader; 7 | import java.io.IOException; 8 | 9 | public class Example6 { 10 | 11 | public static void main(String[] args) { 12 | 13 | BufferedReader rd = null; 14 | try { 15 | // rd = new BufferedReader(new FileReader(new File(""))); 16 | // rd.readLine(); 17 | int i = 9 / 0; 18 | } catch (Exception e) { 19 | System.out.println("---"); 20 | } 21 | 22 | finally { 23 | System.out.println("000"); 24 | } 25 | } 26 | 27 | // try { 28 | // rd.readLine(); 29 | //} catch (IOException e) { 30 | // e.printStackTrace(); 31 | //} 32 | } 33 | -------------------------------------------------------------------------------- /src/exception/Example7.java: -------------------------------------------------------------------------------- 1 | package exception; 2 | 3 | public class Example7 { 4 | 5 | public void handelException() { 6 | try { 7 | int i = 90 / 0; 8 | } catch (Exception e) { 9 | System.out.println("exception handeled"); 10 | } 11 | System.out.println("code execution completed"); 12 | } 13 | 14 | public void donotHandelException() { 15 | int i = 90 / 0; 16 | System.out.println("code execution completed"); 17 | } 18 | 19 | public static void main(String[] args) { 20 | Example7 obj = new Example7(); 21 | obj.handelException(); 22 | obj.donotHandelException(); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/exception/Example8.java: -------------------------------------------------------------------------------- 1 | package exception; 2 | 3 | public class Example8 { 4 | 5 | public void handelException() { 6 | try { 7 | int i = 90 / 1; 8 | int a[] = { 20 }; 9 | int k = a[2]; 10 | } catch (ArithmeticException e) { 11 | System.out.println("exception handeled"); 12 | } 13 | System.out.println("code execution completed"); 14 | } 15 | 16 | public static void main(String[] args) { 17 | Example8 obj = new Example8(); 18 | obj.handelException(); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/exception/Example9.java: -------------------------------------------------------------------------------- 1 | package exception; 2 | 3 | public class Example9 { 4 | 5 | public void handelException() { 6 | try { 7 | int i = 90 / 1; 8 | int a[] = { 20 }; 9 | int k = a[2]; 10 | } 11 | 12 | catch (ArithmeticException e) { 13 | System.out.println("ArithmeticException handeled"); 14 | } 15 | 16 | catch (ArrayIndexOutOfBoundsException e) { 17 | System.out.println("ArrayIndexOutOfBoundsException handeled"); 18 | } 19 | 20 | finally { 21 | 22 | } 23 | System.out.println("code execution completed"); 24 | } 25 | 26 | public static void main(String[] args) { 27 | Example9 obj = new Example9(); 28 | obj.handelException(); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/exception/TestExample19.java: -------------------------------------------------------------------------------- 1 | package exception; 2 | 3 | import java.io.IOException; 4 | 5 | public class TestExample19 { 6 | 7 | static void test1() throws IOException, Exception { 8 | Example19.checkData(900); 9 | } 10 | 11 | public static void main(String[] args) { 12 | Example19.checkEligibiltyProcess(90); 13 | } 14 | 15 | 16 | 17 | } 18 | -------------------------------------------------------------------------------- /src/exception/test190.java: -------------------------------------------------------------------------------- 1 | package exception; 2 | 3 | import java.io.IOException; 4 | 5 | public class test190 { 6 | 7 | public static void main(String[] args) { 8 | try { 9 | TestExample19.test1(); 10 | } catch (IOException e) { 11 | // TODO Auto-generated catch block 12 | e.printStackTrace(); 13 | } catch (Exception e) { 14 | // TODO Auto-generated catch block 15 | e.printStackTrace(); 16 | } 17 | } 18 | 19 | } 20 | -------------------------------------------------------------------------------- /src/finalInJava/Example1.java: -------------------------------------------------------------------------------- 1 | package finalInJava; 2 | 3 | public class Example1 { 4 | 5 | final int speedlimit = 100; 6 | 7 | void run() { 8 | //speedlimit = 400; 9 | } 10 | 11 | public static void main(String args[]) { 12 | Example1 obj = new Example1(); 13 | obj.run(); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/finalInJava/Example10.java: -------------------------------------------------------------------------------- 1 | package finalInJava; 2 | 3 | public class Example10 { 4 | 5 | 6 | //final Example10(){ 7 | 8 | //} 9 | 10 | } 11 | -------------------------------------------------------------------------------- /src/finalInJava/Example2.java: -------------------------------------------------------------------------------- 1 | package finalInJava; 2 | 3 | public class Example2 { 4 | 5 | final void test1(){ 6 | 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /src/finalInJava/Example3.java: -------------------------------------------------------------------------------- 1 | package finalInJava; 2 | 3 | public class Example3 extends Example2{ 4 | 5 | // final void test1() { 6 | // 7 | // } 8 | 9 | } 10 | -------------------------------------------------------------------------------- /src/finalInJava/Example4.java: -------------------------------------------------------------------------------- 1 | package finalInJava; 2 | 3 | public final class Example4 { 4 | 5 | } 6 | -------------------------------------------------------------------------------- /src/finalInJava/Example5.java: -------------------------------------------------------------------------------- 1 | package finalInJava; 2 | 3 | public class Example5 extends Example4{ 4 | 5 | } 6 | -------------------------------------------------------------------------------- /src/finalInJava/Example6.java: -------------------------------------------------------------------------------- 1 | package finalInJava; 2 | 3 | public class Example6 { 4 | 5 | int id; 6 | String name; 7 | final String PAN_CARD_NUMBER="123"; 8 | 9 | Example6(String panNumber) { 10 | this.PAN_CARD_NUMBER = panNumber; 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/finalInJava/Example7.java: -------------------------------------------------------------------------------- 1 | package finalInJava; 2 | 3 | public class Example7 { 4 | 5 | final int speedlimit; 6 | 7 | Example7() { 8 | speedlimit = 70; 9 | System.out.println(speedlimit); 10 | } 11 | 12 | public static void main(String args[]) { 13 | new Example7(); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/finalInJava/Example8.java: -------------------------------------------------------------------------------- 1 | package finalInJava; 2 | 3 | public class Example8 { 4 | 5 | static final int data; 6 | static { 7 | data = 50; 8 | } 9 | 10 | public static void main(String args[]) { 11 | System.out.println(Example8.data); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/finalInJava/Example9.java: -------------------------------------------------------------------------------- 1 | package finalInJava; 2 | 3 | public class Example9 { 4 | 5 | int cube(final int n) { 6 | n = n + 2; 7 | return n * n * n; 8 | } 9 | 10 | public static void main(String args[]) { 11 | Example9 b = new Example9(); 12 | b.cube(5); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /src/inheritance/Address.java: -------------------------------------------------------------------------------- 1 | package inheritance; 2 | 3 | public class Address { 4 | 5 | String city, state, country; 6 | 7 | public Address(String city, String state, String country) { 8 | this.city = city; 9 | this.state = state; 10 | this.country = country; 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/inheritance/C.java: -------------------------------------------------------------------------------- 1 | package inheritance; 2 | 3 | public class C { 4 | 5 | private int a; 6 | 7 | public int b; 8 | 9 | } 10 | -------------------------------------------------------------------------------- /src/inheritance/Car.java: -------------------------------------------------------------------------------- 1 | package inheritance; 2 | 3 | public class Car extends Vehicle{ 4 | 5 | int price; 6 | 7 | String name; 8 | 9 | public Car(int price, String name) { 10 | this.price = price; 11 | this.name = name; 12 | } 13 | 14 | public static void main(String[] args) { 15 | Car car = new Car(2000,"Maruti"); 16 | car.speed(10); 17 | System.out.println(car); 18 | } 19 | 20 | @Override 21 | public String toString() { 22 | return "Car [price=" + price + ", name=" + name + ", speed=" + speed + "]"; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/inheritance/Circle.java: -------------------------------------------------------------------------------- 1 | package inheritance; 2 | 3 | public class Circle { 4 | 5 | Operation operation; 6 | 7 | public void calculateArea(int area){ 8 | operation = new Operation(); 9 | int a = operation.square(area); 10 | System.out.println("Circle area="+a); 11 | } 12 | 13 | public static void main(String[] args) { 14 | 15 | Circle circle = new Circle(); 16 | circle.calculateArea(5); 17 | } 18 | 19 | } 20 | -------------------------------------------------------------------------------- /src/inheritance/ClassRoom.java: -------------------------------------------------------------------------------- 1 | package inheritance; 2 | 3 | public class ClassRoom extends College{ 4 | 5 | public String classRoom = "10Th"; 6 | } 7 | -------------------------------------------------------------------------------- /src/inheritance/College.java: -------------------------------------------------------------------------------- 1 | package inheritance; 2 | 3 | public class College { 4 | 5 | public String collegeName = "LS COLLEGE"; 6 | 7 | } 8 | -------------------------------------------------------------------------------- /src/inheritance/Conts1.java: -------------------------------------------------------------------------------- 1 | package inheritance; 2 | 3 | public class Conts1 { 4 | 5 | int a; 6 | 7 | public Conts1(int a) { 8 | this.a = a; 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /src/inheritance/Conts2.java: -------------------------------------------------------------------------------- 1 | package inheritance; 2 | 3 | public class Conts2 extends Conts1{ 4 | 5 | public static void main(String[] args) { 6 | Conts2 conts2 = new Conts2(4); 7 | 8 | Conts2 conts3 = new Conts2(); 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /src/inheritance/D.java: -------------------------------------------------------------------------------- 1 | package inheritance; 2 | 3 | public class D extends C { 4 | 5 | void test1() { 6 | 7 | } 8 | 9 | public static void main(String[] args) { 10 | D obj = new D(); 11 | 12 | obj.test1(); 13 | 14 | int c = obj.b; 15 | 16 | //System.out.println(obj.a); 17 | 18 | System.out.println(obj.b); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/inheritance/Employee.java: -------------------------------------------------------------------------------- 1 | package inheritance; 2 | 3 | public class Employee { 4 | 5 | int id; 6 | String name; 7 | Address address; 8 | 9 | public Employee(int id, String name, Address address) { 10 | this.id = id; 11 | this.name = name; 12 | this.address = address; 13 | } 14 | 15 | void display() { 16 | System.out.println(id + " " + name); 17 | System.out.println(address.city + " " + address.state + " " + address.country); 18 | } 19 | 20 | public static void main(String[] args) { 21 | Address address1 = new Address("test1", "BIHAR", "india"); 22 | Address address2 = new Address("test2", "BIHAR", "india"); 23 | 24 | Employee e = new Employee(11, "Ram", address1); 25 | Employee e2 = new Employee(12, "Mohan", address2); 26 | 27 | e.display(); 28 | e2.display(); 29 | 30 | } 31 | } -------------------------------------------------------------------------------- /src/inheritance/Example2.java: -------------------------------------------------------------------------------- 1 | package inheritance; 2 | 3 | public class Example2 extends Exaple1{ 4 | 5 | } 6 | -------------------------------------------------------------------------------- /src/inheritance/Example3.java: -------------------------------------------------------------------------------- 1 | package inheritance; 2 | 3 | public class Example3 { 4 | 5 | void msg(){ 6 | 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /src/inheritance/Example4.java: -------------------------------------------------------------------------------- 1 | package inheritance; 2 | 3 | public class Example4 { 4 | 5 | void msg() { 6 | 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /src/inheritance/Example6.java: -------------------------------------------------------------------------------- 1 | //package inheritance; 2 | // 3 | //public class Example6 extends Example3,Example4{ 4 | // 5 | //} 6 | -------------------------------------------------------------------------------- /src/inheritance/Exaple1.java: -------------------------------------------------------------------------------- 1 | package inheritance; 2 | 3 | public class Exaple1 { 4 | 5 | } 6 | -------------------------------------------------------------------------------- /src/inheritance/JavaTeacher.java: -------------------------------------------------------------------------------- 1 | package inheritance; 2 | 3 | public class JavaTeacher extends Teacher { 4 | 5 | String mainSubject = "Spark"; 6 | 7 | public static void main(String args[]) { 8 | 9 | JavaTeacher obj = new JavaTeacher(); 10 | 11 | System.out.println(obj.collegeName); 12 | System.out.println(obj.designation); 13 | System.out.println(obj.mainSubject); 14 | 15 | obj.does(); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/inheritance/Jeep.java: -------------------------------------------------------------------------------- 1 | package inheritance; 2 | 3 | public class Jeep extends Vehicle{ 4 | 5 | int price; 6 | 7 | String name; 8 | 9 | public Jeep(int price, String name) { 10 | this.price = price; 11 | this.name = name; 12 | } 13 | 14 | public static void main(String[] args) { 15 | Jeep jeep = new Jeep(1000,"Jeep"); 16 | jeep.speed(100); 17 | System.out.println(jeep); 18 | } 19 | 20 | @Override 21 | public String toString() { 22 | return "Jeep [price=" + price + ", name=" + name + ", speed=" + speed + "]"; 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /src/inheritance/Operation.java: -------------------------------------------------------------------------------- 1 | package inheritance; 2 | 3 | public class Operation { 4 | 5 | int square(int n) { 6 | return n * n; 7 | } 8 | 9 | int circle(int radious) { 10 | return (22 / 7) * radious; 11 | } 12 | 13 | int rectangle(int length,int width) { 14 | return width*length; 15 | } 16 | 17 | } 18 | -------------------------------------------------------------------------------- /src/inheritance/Ram.java: -------------------------------------------------------------------------------- 1 | package inheritance; 2 | 3 | public class Ram extends Student { 4 | 5 | int roolnumber; 6 | 7 | public Ram(int roolnumber) { 8 | this.roolnumber = roolnumber; 9 | } 10 | 11 | public String display() { 12 | return "Ram [roolnumber=" + roolnumber + ", getSchooladdress()=" + getSchooladdress() + ", getSchoolName()=" 13 | + getSchoolName() + "]"; 14 | } 15 | 16 | 17 | 18 | public static void main(String[] args) { 19 | Ram ram = new Ram(8); 20 | ram.getSchooladdress(); 21 | ram.getSchoolName(); 22 | 23 | System.out.println(ram.Schooladdress); 24 | 25 | System.out.println(ram.display()); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/inheritance/Student.java: -------------------------------------------------------------------------------- 1 | package inheritance; 2 | 3 | public class Student { 4 | 5 | public String Schooladdress; 6 | 7 | private String SchoolName; 8 | 9 | 10 | public String getSchooladdress() { 11 | return "Muzaffarpur Bihar 560100"; 12 | } 13 | 14 | public String getSchoolName() { 15 | return "DAV"; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/inheritance/Students.java: -------------------------------------------------------------------------------- 1 | package inheritance; 2 | 3 | public class Students extends ClassRoom { 4 | 5 | int age; 6 | String name; 7 | 8 | public Students(int age, String name) { 9 | this.age = age; 10 | this.name = name; 11 | } 12 | 13 | public static void main(String[] args) { 14 | Students students = new Students(10, "Mohan"); 15 | System.out.println(students); 16 | Students students1 = new Students(10, "RAM"); 17 | System.out.println(students1); 18 | Students students2 = new Students(10, "SOHAN"); 19 | System.out.println(students2); 20 | } 21 | 22 | @Override 23 | public String toString() { 24 | return "Students [age=" + age + ", name=" + name + ", classRoom=" + classRoom + ", collegeName=" + collegeName 25 | + "]"; 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /src/inheritance/Teacher.java: -------------------------------------------------------------------------------- 1 | package inheritance; 2 | 3 | public class Teacher { 4 | 5 | String designation = "Teacher"; 6 | String collegeName = "L.S College Muzaffarpur"; 7 | 8 | void does() { 9 | System.out.println("Teaching"); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /src/inheritance/Vehicle.java: -------------------------------------------------------------------------------- 1 | package inheritance; 2 | 3 | public class Vehicle { 4 | 5 | int speed; 6 | 7 | public void speed(int speed){ 8 | this.speed = speed; 9 | System.out.println("Vehicle runts at:="+speed+"KM/H"); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /src/inheritanceInJava/A.java: -------------------------------------------------------------------------------- 1 | package inheritanceInJava; 2 | 3 | public class A { 4 | 5 | public int i; 6 | private int j; 7 | protected int k; 8 | int p; 9 | 10 | public void test1() { 11 | System.out.println("A test1()"); 12 | } 13 | 14 | private void test2() { 15 | System.out.println("A test2()"); 16 | } 17 | 18 | protected void test3() { 19 | System.out.println("A test3()"); 20 | } 21 | 22 | void test4() { 23 | System.out.println("A test4()"); 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /src/inheritanceInJava/B.java: -------------------------------------------------------------------------------- 1 | package inheritanceInJava; 2 | 3 | public class B extends A{ 4 | 5 | public static void main(String[] args) { 6 | B obj = new B(); 7 | obj.test1(); 8 | obj.test3(); 9 | obj.test4(); 10 | 11 | System.out.println(obj.i); 12 | System.out.println(obj.k); 13 | System.out.println(obj.p); 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /src/inheritanceInJava/ChildClass.java: -------------------------------------------------------------------------------- 1 | package inheritanceInJava; 2 | 3 | public class ChildClass extends ParentClass{ 4 | 5 | public static void main(String[] args) { 6 | ChildClass obj = new ChildClass(); 7 | obj.test1(); 8 | obj.test2(); 9 | obj.test3(); 10 | } 11 | 12 | } 13 | -------------------------------------------------------------------------------- /src/inheritanceInJava/Notes.java: -------------------------------------------------------------------------------- 1 | package inheritanceInJava; 2 | 3 | public class Notes { 4 | /** 5 | Points to Note: 6 | Through inheritance child class will acquire all non static members of class. 7 | We can't inherit private member of class. 8 | We can't inherit static members of class. since static members are class members. 9 | Final Members can not be inherit. 10 | */ 11 | } 12 | -------------------------------------------------------------------------------- /src/inheritanceInJava/ParentClass.java: -------------------------------------------------------------------------------- 1 | package inheritanceInJava; 2 | 3 | public class ParentClass { 4 | 5 | public void test1() { 6 | System.out.println("ParentClass test1()"); 7 | } 8 | 9 | public void test2() { 10 | System.out.println("ParentClass test2()"); 11 | } 12 | 13 | public void test3() { 14 | System.out.println("ParentClass test3()"); 15 | } 16 | 17 | } 18 | -------------------------------------------------------------------------------- /src/instanceOfInJava/Animal.java: -------------------------------------------------------------------------------- 1 | package instanceOfInJava; 2 | 3 | public class Animal { 4 | 5 | } 6 | -------------------------------------------------------------------------------- /src/instanceOfInJava/Dog.java: -------------------------------------------------------------------------------- 1 | package instanceOfInJava; 2 | 3 | public class Dog extends Animal { 4 | 5 | public static void main(String args[]) { 6 | Dog d = new Dog(); 7 | System.out.println(d instanceof Animal); 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /src/instanceOfInJava/Example1.java: -------------------------------------------------------------------------------- 1 | package instanceOfInJava; 2 | 3 | public class Example1 { 4 | 5 | public static void main(String args[]) { 6 | Example1 s = new Example1(); 7 | System.out.println(s instanceof Example1); 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /src/instanceOfInJava/Example3.java: -------------------------------------------------------------------------------- 1 | package instanceOfInJava; 2 | 3 | public class Example3 { 4 | static int i = 0; 5 | static boolean b = false; 6 | static double d = 9.0; 7 | static char c = 'v'; 8 | static float f = 9.0f; 9 | 10 | public static void main(String[] args) { 11 | 12 | // As the name suggests, instanceof means an instance (object) of a class. 13 | // Primitive data types are not instances. 14 | //if (i instanceof Integer) { 15 | 16 | //} 17 | 18 | if(Integer.class.isInstance(b)) { 19 | System.out.println("True"); 20 | } 21 | else { 22 | System.out.println("False"); 23 | } 24 | if(Boolean.class.isInstance(b)) { 25 | System.out.println("True"); 26 | } 27 | if(Double.class.isInstance(d)) { 28 | System.out.println("True"); 29 | } 30 | if(Character.class.isInstance(c)) { 31 | System.out.println("True"); 32 | } 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /src/interfaceInjava/A.java: -------------------------------------------------------------------------------- 1 | package interfaceInjava; 2 | 3 | public interface A { 4 | 5 | } 6 | 7 | class B implements A { 8 | 9 | } 10 | -------------------------------------------------------------------------------- /src/interfaceInjava/B1.java: -------------------------------------------------------------------------------- 1 | package interfaceInjava; 2 | 3 | public interface B1 { 4 | 5 | void test1(); 6 | void test2(); 7 | } 8 | -------------------------------------------------------------------------------- /src/interfaceInjava/B1Test.java: -------------------------------------------------------------------------------- 1 | package interfaceInjava; 2 | 3 | public class B1Test implements B1, Example7{ 4 | 5 | @Override 6 | public void test1() { 7 | // TODO Auto-generated method stub 8 | 9 | } 10 | 11 | @Override 12 | public void test2() { 13 | B1Test obj = new B1Test(); 14 | obj.test1(); 15 | 16 | } 17 | 18 | @Override 19 | public void method5() { 20 | 21 | Example7.test2(); 22 | 23 | } 24 | 25 | @Override 26 | public void method6() { 27 | // TODO Auto-generated method stub 28 | 29 | } 30 | 31 | @Override 32 | public void tset56() { 33 | // TODO Auto-generated method stub 34 | 35 | } 36 | 37 | public static void main(String[] args) { 38 | Example7.test2(); 39 | } 40 | 41 | } 42 | -------------------------------------------------------------------------------- /src/interfaceInjava/Bike.java: -------------------------------------------------------------------------------- 1 | package interfaceInjava; 2 | 3 | public class Bike implements Vehicle { 4 | 5 | int speed; 6 | int gear; 7 | 8 | @Override 9 | public void changeGear(int a) { 10 | gear = a; 11 | } 12 | 13 | @Override 14 | public void speedUp(int a) { 15 | 16 | speed = a; 17 | } 18 | 19 | @Override 20 | public void applyBrakes(int a) { 21 | 22 | speed = speed - a; 23 | } 24 | 25 | public void display() { 26 | System.out.println("speed: " + speed + " gear: " + gear); 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /src/interfaceInjava/Car.java: -------------------------------------------------------------------------------- 1 | package interfaceInjava; 2 | 3 | public class Car implements Vehicle { 4 | 5 | int speed; 6 | int gear; 7 | 8 | @Override 9 | public void changeGear(int a) { 10 | gear = a; 11 | } 12 | 13 | @Override 14 | public void speedUp(int a) { 15 | 16 | speed = a; 17 | } 18 | 19 | @Override 20 | public void applyBrakes(int a) { 21 | 22 | speed = speed - a; 23 | } 24 | 25 | public void display() { 26 | System.out.println("speed: " + speed + " gear: " + gear); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/interfaceInjava/Eample100.java: -------------------------------------------------------------------------------- 1 | package interfaceInjava; 2 | 3 | public class Eample100 implements Example101 { 4 | 5 | @Override 6 | public void test1() { 7 | 8 | } 9 | 10 | public void test5() { 11 | 12 | } 13 | 14 | public static void main(String[] args) { 15 | Example101 obj = new Eample100(); 16 | 17 | obj.test1(); 18 | obj.test2(); 19 | obj.test3(); 20 | 21 | Example102 obj1 = new Eample100(); 22 | obj1.test3(); 23 | 24 | Eample100 obj2 = new Eample100(); 25 | obj2.test5(); 26 | 27 | } 28 | 29 | @Override 30 | public void test3() { 31 | // TODO Auto-generated method stub 32 | 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /src/interfaceInjava/Exampl3.java: -------------------------------------------------------------------------------- 1 | package interfaceInjava; 2 | 3 | public interface Exampl3 { 4 | 5 | default void test1(){ 6 | System.out.println("I am default"); 7 | } 8 | 9 | static void test2(){ 10 | System.out.println("I am static"); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /src/interfaceInjava/Exampl3Test.java: -------------------------------------------------------------------------------- 1 | package interfaceInjava; 2 | 3 | public class Exampl3Test implements Exampl3 { 4 | 5 | public static void main(String[] args) { 6 | Exampl3.test2(); 7 | 8 | Exampl3Test obj = new Exampl3Test(); 9 | obj.test1(); 10 | 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/interfaceInjava/Example1.java: -------------------------------------------------------------------------------- 1 | package interfaceInjava; 2 | 3 | public interface Example1 { 4 | 5 | int i = 90; 6 | 7 | void test1(); 8 | 9 | } 10 | -------------------------------------------------------------------------------- /src/interfaceInjava/Example101.java: -------------------------------------------------------------------------------- 1 | package interfaceInjava; 2 | 3 | public interface Example101 extends Example102{ 4 | 5 | void test1(); 6 | 7 | default void test2(){ 8 | System.out.println("default method"); 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /src/interfaceInjava/Example102.java: -------------------------------------------------------------------------------- 1 | package interfaceInjava; 2 | 3 | public interface Example102 { 4 | 5 | void test3(); 6 | } 7 | -------------------------------------------------------------------------------- /src/interfaceInjava/Example2.java: -------------------------------------------------------------------------------- 1 | package interfaceInjava; 2 | 3 | public interface Example2 { 4 | 5 | int i = 90; 6 | 7 | void test1(); 8 | 9 | void test2(); 10 | } 11 | -------------------------------------------------------------------------------- /src/interfaceInjava/Example3.java: -------------------------------------------------------------------------------- 1 | package interfaceInjava; 2 | 3 | public interface Example3 { 4 | 5 | 6 | // Example3(){ 7 | // 8 | // } 9 | } 10 | -------------------------------------------------------------------------------- /src/interfaceInjava/Example4.java: -------------------------------------------------------------------------------- 1 | package interfaceInjava; 2 | 3 | public interface Example4 { 4 | 5 | //Example4 example4; 6 | 7 | int i = 90; 8 | 9 | } 10 | -------------------------------------------------------------------------------- /src/interfaceInjava/Example5.java: -------------------------------------------------------------------------------- 1 | package interfaceInjava; 2 | 3 | public interface Example5 { 4 | 5 | void method5(); 6 | } 7 | -------------------------------------------------------------------------------- /src/interfaceInjava/Example6.java: -------------------------------------------------------------------------------- 1 | package interfaceInjava; 2 | 3 | public interface Example6 { 4 | 5 | void method6(); 6 | } 7 | -------------------------------------------------------------------------------- /src/interfaceInjava/Example7.java: -------------------------------------------------------------------------------- 1 | package interfaceInjava; 2 | 3 | public interface Example7 extends Example5, Example6{ 4 | 5 | 6 | void tset56(); 7 | 8 | default void test1(){ 9 | System.out.println("I am default"); 10 | } 11 | 12 | static void test2(){ 13 | System.out.println("I am static"); 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /src/interfaceInjava/Example8.java: -------------------------------------------------------------------------------- 1 | package interfaceInjava; 2 | 3 | public interface Example8 { 4 | 5 | void method6(); 6 | 7 | default void test1() { 8 | System.out.println("I am test1"); 9 | } 10 | 11 | static void test2() { 12 | System.out.println("I am test2"); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /src/interfaceInjava/ImplementExample2.java: -------------------------------------------------------------------------------- 1 | package interfaceInjava; 2 | 3 | public class ImplementExample2 implements Example2{ 4 | 5 | @Override 6 | public void test1() { 7 | // TODO Auto-generated method stub 8 | 9 | } 10 | 11 | @Override 12 | public void test2() { 13 | // TODO Auto-generated method stub 14 | 15 | } 16 | 17 | } 18 | -------------------------------------------------------------------------------- /src/interfaceInjava/TestExample7.java: -------------------------------------------------------------------------------- 1 | package interfaceInjava; 2 | 3 | public class TestExample7 implements Example7{ 4 | 5 | @Override 6 | public void method5() { 7 | // TODO Auto-generated method stub 8 | 9 | } 10 | 11 | @Override 12 | public void method6() { 13 | // TODO Auto-generated method stub 14 | 15 | } 16 | 17 | @Override 18 | public void tset56() { 19 | // TODO Auto-generated method stub 20 | 21 | } 22 | 23 | 24 | } 25 | -------------------------------------------------------------------------------- /src/interfaceInjava/TestVehicle.java: -------------------------------------------------------------------------------- 1 | package interfaceInjava; 2 | 3 | public class TestVehicle { 4 | 5 | public static void main(String[] args) { 6 | 7 | Car car = new Car(); 8 | car.changeGear(3); 9 | car.speedUp(4); 10 | car.applyBrakes(1); 11 | 12 | System.out.println("Car present state :"); 13 | car.display(); 14 | 15 | Bike bike = new Bike(); 16 | bike.changeGear(2); 17 | bike.speedUp(4); 18 | bike.applyBrakes(1); 19 | 20 | System.out.println("Bike present state :"); 21 | bike.display(); 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /src/interfaceInjava/Vehicle.java: -------------------------------------------------------------------------------- 1 | package interfaceInjava; 2 | 3 | public interface Vehicle { 4 | 5 | void changeGear(int a); 6 | 7 | void speedUp(int a); 8 | 9 | void applyBrakes(int a); 10 | } 11 | -------------------------------------------------------------------------------- /src/linkedList/Example3.java: -------------------------------------------------------------------------------- 1 | package linkedList; 2 | 3 | import java.util.LinkedList; 4 | 5 | public class Example3 { 6 | 7 | public static void main(String[] args) { 8 | 9 | LinkedList linkedList = new LinkedList<>(); 10 | 11 | linkedList.add("A"); 12 | linkedList.add("B"); 13 | linkedList.add("C"); 14 | linkedList.add("D"); 15 | 16 | LinkedList linkedList1 = new LinkedList<>(); 17 | 18 | linkedList1.add("AA"); 19 | 20 | linkedList1.add("BB"); 21 | linkedList1.add("CC"); 22 | linkedList1.add(2,"AAA"); 23 | linkedList1.add("DD"); 24 | 25 | System.out.println(linkedList1); 26 | 27 | linkedList.addAll(linkedList1); 28 | 29 | System.out.println(linkedList); 30 | 31 | linkedList.addAll(1, linkedList1); 32 | 33 | //System.out.println(linkedList); 34 | 35 | //linkedList.add 36 | 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/linkedList/ParentClass.java: -------------------------------------------------------------------------------- 1 | package linkedList; 2 | 3 | public interface ParentClass { 4 | 5 | void add(); 6 | 7 | void test(); 8 | 9 | } 10 | -------------------------------------------------------------------------------- /src/linkedList/Test1234.java: -------------------------------------------------------------------------------- 1 | package linkedList; 2 | 3 | import java.util.ArrayList; 4 | import java.util.LinkedList; 5 | import java.util.List; 6 | 7 | public class Test1234 { 8 | 9 | public static void main(String[] args) { 10 | 11 | List list = new ArrayList(); 12 | list.add(4); 13 | list.add(4); 14 | list.add(4); 15 | list.add(3); 16 | list.add(4); 17 | 18 | List list1 = new LinkedList(list); 19 | 20 | System.out.println(list1); 21 | 22 | LinkedList list2 = new LinkedList(); 23 | list2.add(4); 24 | list2.add(4); 25 | list2.add(4); 26 | list2.add(3); 27 | list2.add(4); 28 | 29 | list2.addFirst(7); 30 | list2.addFirst(8); 31 | list2.addFirst(9); 32 | list2.add(40); 33 | list2.addLast(90); 34 | list2.addLast(70); 35 | list2.addLast(9000); 36 | 37 | System.out.println(list2); 38 | 39 | List list3 = new ArrayList(list2); 40 | System.out.println(list3); 41 | } 42 | 43 | } 44 | -------------------------------------------------------------------------------- /src/mapClass/Example10.java: -------------------------------------------------------------------------------- 1 | package mapClass; 2 | 3 | import java.util.LinkedHashMap; 4 | import java.util.TreeMap; 5 | 6 | public class Example10 { 7 | 8 | public static void main(String[] args) { 9 | 10 | LinkedHashMap linkedHashMap = new LinkedHashMap<>(); 11 | linkedHashMap.put(10, "Test1"); 12 | linkedHashMap.put(11, "Test2"); 13 | linkedHashMap.put(1000, "Test1"); 14 | linkedHashMap.put(40, "Test4"); 15 | linkedHashMap.put(20, "Test5"); 16 | 17 | System.out.println(linkedHashMap); 18 | 19 | TreeMap treeMap = new TreeMap<>(); 20 | 21 | treeMap.put(10, "Test1"); 22 | treeMap.put(11, "Test2"); 23 | treeMap.put(1000, "Test1"); 24 | treeMap.put(40, "Test4"); 25 | treeMap.put(20, "Test5"); 26 | 27 | System.out.println(treeMap); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/mapClass/Example16.java: -------------------------------------------------------------------------------- 1 | package mapClass; 2 | 3 | import java.util.HashMap; 4 | import java.util.TreeMap; 5 | 6 | public class Example16 { 7 | 8 | public static void main(String[] args) { 9 | 10 | HashMap hasMap = new HashMap(); 11 | 12 | hasMap.put(null, null); 13 | hasMap.put(null, null); 14 | hasMap.put(null, null); 15 | hasMap.put(20, null); 16 | hasMap.put(30, null); 17 | 18 | System.out.println(hasMap); 19 | 20 | System.out.println("---------"); 21 | TreeMap treeMap = new TreeMap(); 22 | 23 | treeMap.put(null, null); 24 | treeMap.put(null, null); 25 | treeMap.put(null, null); 26 | treeMap.put(20, null); 27 | treeMap.put(30, null); 28 | 29 | System.out.println(treeMap); 30 | 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/mapClass/Example2.java: -------------------------------------------------------------------------------- 1 | package mapClass; 2 | 3 | import java.util.HashMap; 4 | 5 | public class Example2 { 6 | 7 | public static void main(String[] args) { 8 | 9 | HashMap map = new HashMap<>(); 10 | map.put("Test1", "A"); 11 | map.put("Test2", "B"); 12 | map.put("Test3", "C"); 13 | map.put("Test4", "D"); 14 | System.out.println(map); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/mapClass/Example3.java: -------------------------------------------------------------------------------- 1 | package mapClass; 2 | 3 | import java.util.HashMap; 4 | 5 | public class Example3 { 6 | 7 | public static void main(String[] args) { 8 | 9 | HashMap map = new HashMap<>(); 10 | map.put("Test1", "A"); 11 | map.put("Test2", "B"); 12 | map.put("Test3", "C"); 13 | map.put("Test4", "D"); 14 | System.out.println(map); 15 | 16 | System.out.println(map.get("Test1")); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/mapClass/Example8.java: -------------------------------------------------------------------------------- 1 | package mapClass; 2 | 3 | import java.util.HashMap; 4 | import java.util.Map; 5 | 6 | public class Example8 { 7 | 8 | public static void main(String[] args) { 9 | 10 | Map map = new HashMap<>(); 11 | 12 | School s1 = new School("Test1", "20", "A"); 13 | School s2 = new School("Test2", "30", "B"); 14 | School s3 = new School("Test3", "40", "C"); 15 | School s4 = new School("Test4", "50", "D"); 16 | 17 | map.put(1, s1); 18 | map.put(2, s2); 19 | map.put(3, s3); 20 | 21 | // What happens when you store duplicate key 22 | map.put(3, s4); 23 | 24 | System.out.println(map); 25 | 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/mapClass/Example9.java: -------------------------------------------------------------------------------- 1 | package mapClass; 2 | 3 | import java.util.HashMap; 4 | import java.util.Map; 5 | 6 | public class Example9 { 7 | 8 | public static void main(String[] args) { 9 | 10 | Map map = new HashMap<>(); 11 | 12 | map.put(null, "Test1"); 13 | map.put(null, "Test1"); 14 | map.put(null, "Test1"); 15 | map.put(null, "Test1"); 16 | map.put(1, null); 17 | map.put(2, null); 18 | map.put(3, null); 19 | map.put(4, null); 20 | 21 | System.out.println(map); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/mapClass/HowToHandelThreadconcurrency.java: -------------------------------------------------------------------------------- 1 | package mapClass; 2 | 3 | import java.util.Collections; 4 | import java.util.HashSet; 5 | 6 | public class HowToHandelThreadconcurrency { 7 | 8 | public static void main(String[] args) { 9 | Collections.synchronizedSet(new HashSet()); 10 | } 11 | 12 | } 13 | -------------------------------------------------------------------------------- /src/mapClass/School.java: -------------------------------------------------------------------------------- 1 | package mapClass; 2 | 3 | public class School { 4 | 5 | private String name; 6 | private String age; 7 | private String schoolName; 8 | 9 | 10 | public School(String name, String age, String schoolName) { 11 | this.name = name; 12 | this.age = age; 13 | this.schoolName = schoolName; 14 | } 15 | 16 | 17 | @Override 18 | public String toString() { 19 | return "School [name=" + name + ", age=" + age + ", schoolName=" + schoolName + "]"; 20 | } 21 | 22 | 23 | } 24 | -------------------------------------------------------------------------------- /src/mapClass/UnderstandingOfMap.java: -------------------------------------------------------------------------------- 1 | package mapClass; 2 | 3 | import java.util.HashMap; 4 | import java.util.Map; 5 | import java.util.Map.Entry; 6 | import java.util.Set; 7 | 8 | public class UnderstandingOfMap { 9 | 10 | public static void main(String[] args) { 11 | HashMap map = new HashMap(); 12 | map.put("Test1", 10); 13 | map.put("Test2", 10); 14 | map.put("Test3", 10); 15 | map.put("Test5", 10); 16 | 17 | map.get("Test1"); 18 | 19 | Set< Entry > entrySet = map.entrySet(); 20 | 21 | for (Entry entry : entrySet) { 22 | System.out.println(entry.getKey()); 23 | System.out.println(entry.getKey().hashCode()); 24 | System.out.println(entry.getKey().hashCode()%15); 25 | System.out.println("-----"); 26 | } 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /src/methodOverLoadingInjava/Example1.java: -------------------------------------------------------------------------------- 1 | package methodOverLoadingInjava; 2 | 3 | public class Example1 { 4 | 5 | public void test1() { 6 | System.out.println("test1()"); 7 | } 8 | 9 | public void test1(int i) { 10 | System.out.println("test1(int i)"); 11 | } 12 | 13 | public void test1(int i, int j) { 14 | System.out.println("test1(int i, int j)"); 15 | } 16 | 17 | public void test1(int i, int j, int k) { 18 | System.out.println("test1(int i, int j, int k)"); 19 | } 20 | 21 | public static void main(String[] args) { 22 | Example1 obj = new Example1(); 23 | obj.test1(); 24 | obj.test1(7); 25 | obj.test1(7,8); 26 | 27 | obj.test1(7,8,10); 28 | } 29 | 30 | } 31 | -------------------------------------------------------------------------------- /src/methodOverLoadingInjava/Example2.java: -------------------------------------------------------------------------------- 1 | package methodOverLoadingInjava; 2 | 3 | public class Example2 { 4 | 5 | public void test1() { 6 | System.out.println("test1()"); 7 | } 8 | 9 | public void test1(int i) { 10 | System.out.println("test1(int i)"); 11 | } 12 | 13 | public void test1(int i, int j) { 14 | System.out.println("test1(int i, int j)"); 15 | } 16 | 17 | public void test1(int i, int j, int k) { 18 | System.out.println("test1(int i, int j, int k)"); 19 | } 20 | 21 | public void test1(double i) { 22 | System.out.println("test1(int i)"); 23 | } 24 | 25 | public void test1(double i, double j) { 26 | System.out.println("test1(double i, double j)"); 27 | } 28 | 29 | public static void main(String[] args) { 30 | Example2 obj = new Example2(); 31 | obj.test1(9.8, 9.0); 32 | obj.test1(9, 9); 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /src/methodOverLoadingInjava/Example3.java: -------------------------------------------------------------------------------- 1 | package methodOverLoadingInjava; 2 | 3 | public class Example3 { 4 | /* 5 | public void test1() { 6 | System.out.println("test1()"); 7 | } 8 | 9 | public int test1() { 10 | System.out.println("test1()"); 11 | return 2; 12 | } 13 | */ 14 | public final void test2() { 15 | 16 | } 17 | 18 | public final void test2(int i) { 19 | 20 | } 21 | 22 | public static void test3() { 23 | System.out.println("test1()"); 24 | } 25 | 26 | public static void test3(int p) { 27 | System.out.println("test1()"); 28 | } 29 | 30 | } 31 | -------------------------------------------------------------------------------- /src/methodOverLoadingInjava/Notes.java: -------------------------------------------------------------------------------- 1 | package methodOverLoadingInjava; 2 | 3 | public class Notes { 4 | 5 | /** 6 | Method Overloading will allow us to create more than one methods with same name by changing the method arguments. 7 | Method Overloading is called as compile time polymorphisms. 8 | Arguments list can be different in following ways 9 | 1) Numbers of parameters to method 10 | 2) Data Type of parameters 11 | 3) Sequence Type of parameters 12 | */ 13 | } 14 | -------------------------------------------------------------------------------- /src/methodOverloading/A.java: -------------------------------------------------------------------------------- 1 | package methodOverloading; 2 | 3 | public class A { 4 | 5 | public static void main(String[] args) { 6 | Overloading2.display(3); 7 | } 8 | 9 | } 10 | -------------------------------------------------------------------------------- /src/methodOverloading/Overloading1.java: -------------------------------------------------------------------------------- 1 | package methodOverloading; 2 | 3 | public class Overloading1 { 4 | 5 | private static void display(int a) { 6 | System.out.println("Arguments: " + a); 7 | } 8 | 9 | private static void display(int a, int b) { 10 | System.out.println("Arguments: " + a + " and " + b); 11 | } 12 | 13 | public static void main(String[] args) { 14 | display(1); 15 | display(1, 4); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/methodOverloading/Overloading10.java: -------------------------------------------------------------------------------- 1 | package methodOverloading; 2 | 3 | public class Overloading10 { 4 | 5 | Overloading10(int i) { 6 | 7 | } 8 | 9 | Overloading10() { 10 | 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/methodOverloading/Overloading11.java: -------------------------------------------------------------------------------- 1 | package methodOverloading; 2 | 3 | public class Overloading11 extends Overloading10{ 4 | 5 | Overloading11(){ 6 | 7 | } 8 | 9 | } 10 | -------------------------------------------------------------------------------- /src/methodOverloading/Overloading2.java: -------------------------------------------------------------------------------- 1 | package methodOverloading; 2 | 3 | public class Overloading2 { 4 | 5 | public static void display(int a) { 6 | System.out.println("Got Integer data."); 7 | } 8 | 9 | public static void display(String a) { 10 | System.out.println("Got String object."); 11 | } 12 | 13 | public static void main(String[] args) { 14 | display(1); 15 | display("Hello"); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/methodOverloading/Overloading3.java: -------------------------------------------------------------------------------- 1 | package methodOverloading; 2 | 3 | public class Overloading3 { 4 | 5 | private String formatNumber(int value) { 6 | return String.format("%d", value); 7 | } 8 | 9 | private String formatNumber(double value) { 10 | return String.format("%.3f", value); 11 | } 12 | 13 | private String formatNumber(String value) { 14 | return String.format("%.2f", Double.parseDouble(value)); 15 | } 16 | 17 | public static void main(String[] args) { 18 | Overloading3 hs = new Overloading3(); 19 | System.out.println(hs.formatNumber(500)); 20 | System.out.println(hs.formatNumber(89.9934)); 21 | System.out.println(hs.formatNumber("550")); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/methodOverloading/Overloading4.java: -------------------------------------------------------------------------------- 1 | package methodOverloading; 2 | 3 | public class Overloading4 { 4 | 5 | static int add(int a, int b) { 6 | return a + b; 7 | } 8 | 9 | // static double add(int a, int b) { 10 | // return a + b; 11 | // } 12 | } 13 | 14 | class TestOverloading3 { 15 | public static void main(String[] args) { 16 | //System.out.println(Adder.add(11, 11)); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/methodOverloading/Overloading5.java: -------------------------------------------------------------------------------- 1 | package methodOverloading; 2 | 3 | public class Overloading5 { 4 | 5 | public static void main(String[] args) { 6 | System.out.println("main with String[]"); 7 | } 8 | 9 | public static void main(String args) { 10 | System.out.println("main with String"); 11 | } 12 | 13 | public static void main() { 14 | System.out.println("main without args"); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/methodOverloading/Overloading6.java: -------------------------------------------------------------------------------- 1 | package methodOverloading; 2 | 3 | public class Overloading6 { 4 | 5 | void sum(int a, long b) { 6 | System.out.println(a + b); 7 | } 8 | 9 | void sum(int a, int b, int c) { 10 | System.out.println(a + b + c); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /src/methodOverloading/Overloading7.java: -------------------------------------------------------------------------------- 1 | package methodOverloading; 2 | 3 | public class Overloading7 { 4 | 5 | void sum(int a, long b) { 6 | System.out.println("a method invoked"); 7 | } 8 | 9 | void sum(long a, int b) { 10 | System.out.println("b method invoked"); 11 | } 12 | 13 | public static void main(String args[]) { 14 | Overloading7 obj = new Overloading7(); 15 | //obj.sum(20, 20); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/methodOverloading/Overloading8.java: -------------------------------------------------------------------------------- 1 | package methodOverloading; 2 | 3 | public class Overloading8 { 4 | 5 | Overloading8(int i) { 6 | 7 | } 8 | 9 | } 10 | -------------------------------------------------------------------------------- /src/methodOverloading/Overloading9.java: -------------------------------------------------------------------------------- 1 | package methodOverloading; 2 | 3 | public class Overloading9 extends Overloading8 { 4 | 5 | Overloading9(int i) { 6 | super(i); 7 | } 8 | 9 | public static void main(String[] args) { 10 | 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/methodOverriding/Bank.java: -------------------------------------------------------------------------------- 1 | package methodOverriding; 2 | 3 | public class Bank { 4 | 5 | public int rateOfInterest(){ 6 | System.out.println("rateOfInterest= 0%"); 7 | return 0; 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /src/methodOverriding/Bike.java: -------------------------------------------------------------------------------- 1 | package methodOverriding; 2 | 3 | public class Bike extends Vehicle{ 4 | 5 | } 6 | -------------------------------------------------------------------------------- /src/methodOverriding/Car.java: -------------------------------------------------------------------------------- 1 | package methodOverriding; 2 | 3 | public class Car extends Vehicle{ 4 | 5 | public void run(){ 6 | System.out.println("runs at 180KM/H"); 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /src/methodOverriding/Example1.java: -------------------------------------------------------------------------------- 1 | package methodOverriding; 2 | 3 | public class Example1 { 4 | 5 | static void test1() { 6 | System.out.println("Example1"); 7 | } 8 | 9 | static void test2() { 10 | System.out.println("Example1 test2"); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/methodOverriding/Example2.java: -------------------------------------------------------------------------------- 1 | package methodOverriding; 2 | 3 | public class Example2 extends Example1 { 4 | 5 | static void test1() { 6 | System.out.println("Example2"); 7 | } 8 | 9 | public static void main(String[] args) { 10 | 11 | Example2.test1(); 12 | 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /src/methodOverriding/HDFCBank.java: -------------------------------------------------------------------------------- 1 | package methodOverriding; 2 | 3 | public class HDFCBank extends Bank { 4 | 5 | public int rateOfInterest() { 6 | System.out.println("rateOfInterest= 8.5%"); 7 | return 0; 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /src/methodOverriding/ICICI.java: -------------------------------------------------------------------------------- 1 | package methodOverriding; 2 | 3 | public class ICICI extends Bank{ 4 | 5 | } 6 | -------------------------------------------------------------------------------- /src/methodOverriding/Jeep.java: -------------------------------------------------------------------------------- 1 | package methodOverriding; 2 | 3 | public class Jeep extends Vehicle{ 4 | 5 | } 6 | -------------------------------------------------------------------------------- /src/methodOverriding/Overriding1.java: -------------------------------------------------------------------------------- 1 | package methodOverriding; 2 | 3 | public class Overriding1 { 4 | 5 | public void test(){ 6 | System.out.println("This is test implementation"); 7 | } 8 | 9 | public void test1(){ 10 | System.out.println("This is test implementation test1"); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /src/methodOverriding/Overriding2.java: -------------------------------------------------------------------------------- 1 | package methodOverriding; 2 | 3 | public class Overriding2 extends Overriding1{ 4 | 5 | public void test(){ 6 | System.out.println("This is test implementation-1"); 7 | } 8 | 9 | public static void main(String[] args) { 10 | Overriding2 Overriding2 = new Overriding2(); 11 | Overriding2.test(); 12 | 13 | Overriding2.test1(); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/methodOverriding/SBI.java: -------------------------------------------------------------------------------- 1 | package methodOverriding; 2 | 3 | public class SBI extends Bank { 4 | 5 | public int rateOfInterest() { 6 | System.out.println("rateOfInterest= 7.5%"); 7 | return 0; 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /src/methodOverriding/TestOverride.java: -------------------------------------------------------------------------------- 1 | package methodOverriding; 2 | 3 | public class TestOverride { 4 | 5 | public static void main(String[] args) { 6 | Car car = new Car(); 7 | car.run(); 8 | 9 | Jeep jeep = new Jeep(); 10 | jeep.run(); 11 | 12 | Bike bike = new Bike(); 13 | bike.run(); 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /src/methodOverriding/TestRateOfInterest.java: -------------------------------------------------------------------------------- 1 | package methodOverriding; 2 | 3 | public class TestRateOfInterest { 4 | 5 | public static void main(String[] args) { 6 | 7 | HDFCBank hDFCBank = new HDFCBank(); 8 | 9 | hDFCBank.rateOfInterest(); 10 | 11 | ICICI iCICI = new ICICI(); 12 | 13 | iCICI.rateOfInterest(); 14 | 15 | SBI sBI = new SBI(); 16 | 17 | sBI.rateOfInterest(); 18 | } 19 | 20 | } 21 | -------------------------------------------------------------------------------- /src/methodOverriding/Vehicle.java: -------------------------------------------------------------------------------- 1 | package methodOverriding; 2 | 3 | public class Vehicle { 4 | 5 | public void run() { 6 | System.out.println("runs at 80KM/H"); 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /src/methodOverridingInJava/Example1.java: -------------------------------------------------------------------------------- 1 | package methodOverridingInJava; 2 | 3 | public class Example1 { 4 | 5 | public void test1(){ 6 | System.out.println("Example1 test1()"); 7 | } 8 | 9 | public void test2(){ 10 | System.out.println("Example1 test2()"); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /src/methodOverridingInJava/Example2.java: -------------------------------------------------------------------------------- 1 | package methodOverridingInJava; 2 | 3 | public class Example2 { 4 | 5 | public void test1(){ 6 | System.out.println("Example1 test1()"); 7 | } 8 | 9 | private void test2(){ 10 | System.out.println("Example1 test2()"); 11 | } 12 | 13 | public static void test3(){ 14 | System.out.println("Example1 test3()"); 15 | } 16 | 17 | public final void test4(){ 18 | System.out.println("Example1 test4()"); 19 | } 20 | 21 | } 22 | -------------------------------------------------------------------------------- /src/methodOverridingInJava/Example3.java: -------------------------------------------------------------------------------- 1 | package methodOverridingInJava; 2 | 3 | public class Example3 { 4 | 5 | public void test1(){ 6 | System.out.println("Example3 test1()"); 7 | } 8 | 9 | private void test2(){ 10 | System.out.println("Example3 test2()"); 11 | } 12 | 13 | public static void test3(){ 14 | System.out.println("Example3 test3()"); 15 | } 16 | 17 | public void test4(){ 18 | System.out.println("Example3 test4()"); 19 | } 20 | 21 | } 22 | -------------------------------------------------------------------------------- /src/methodOverridingInJava/Notes.java: -------------------------------------------------------------------------------- 1 | package methodOverridingInJava; 2 | 3 | public class Notes { 4 | 5 | /** 6 | Method overriding In Java 7 | 8 | Points to Note:- 9 | 1. Method Overriding is the the feature of java which allow us to create same method in parent 10 | and child class with same name and with same arguments. 11 | 2. Method Overriding is the the ability of java which will make sure method call will happen from a 12 | class for which we have created the object. Not from referenced class. 13 | 3. At compile time method call happens from reference class. 14 | 4. At Run time method call happens from object class. 15 | 5. Method Overriding is possible only by inheritance. 16 | 6. Method Overriding we also call it as run time polymorphism. 17 | 7. Method Overriding is the the feature of java which allow us to create same method 18 | in parent and child class with same name and with same arguments. 19 | */ 20 | } 21 | -------------------------------------------------------------------------------- /src/methodOverridingInJava/TestExample1.java: -------------------------------------------------------------------------------- 1 | package methodOverridingInJava; 2 | 3 | public class TestExample1 extends Example1{ 4 | 5 | public void test1(){ 6 | System.out.println("TestExample1 test1()"); 7 | } 8 | 9 | public static void main(String[] args) { 10 | TestExample1 obj = new TestExample1(); 11 | obj.test1(); 12 | obj.test2(); 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /src/methodOverridingInJava/TestExample2.java: -------------------------------------------------------------------------------- 1 | package methodOverridingInJava; 2 | 3 | public class TestExample2 extends Example2{ 4 | 5 | public void test1(){ 6 | System.out.println("TestExample2 test1()"); 7 | } 8 | 9 | private void test2(){ 10 | System.out.println("TestExample2 test2()"); 11 | } 12 | 13 | public static void test3(){ 14 | System.out.println("TestExample2 test3()"); 15 | } 16 | /* 17 | public final void test4(){ 18 | System.out.println("TestExample2 test4()"); 19 | } 20 | */ 21 | public static void main(String[] args) { 22 | TestExample2 obj = new TestExample2(); 23 | obj.test1(); 24 | obj.test2(); 25 | obj.test4(); 26 | 27 | TestExample2.test3(); 28 | 29 | System.out.println("-------"); 30 | Example2 obj1 = new TestExample2(); 31 | obj1.test1(); 32 | obj1.test4(); 33 | Example2.test3(); 34 | 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /src/methodOverridingInJava/TestExample3.java: -------------------------------------------------------------------------------- 1 | package methodOverridingInJava; 2 | 3 | public class TestExample3 extends Example3{ 4 | 5 | public void test1(){ 6 | System.out.println("TestExample3 test1()"); 7 | } 8 | 9 | private void test2(){ 10 | System.out.println("TestExample3 test2()"); 11 | } 12 | 13 | public static void test3(){ 14 | System.out.println("TestExample3 test3()"); 15 | } 16 | 17 | public void test4(){ 18 | System.out.println("TestExample3 test4()"); 19 | } 20 | 21 | public static void main(String[] args) { 22 | Example3 obj = new TestExample3(); 23 | obj.test1(); 24 | Example3.test3(); 25 | obj.test4(); 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /src/programs/CalculateSumOfNumbersOfArray.java: -------------------------------------------------------------------------------- 1 | package programs; 2 | 3 | public class CalculateSumOfNumbersOfArray { 4 | 5 | public int calculateSumOfNumbers(){ 6 | int[] a = {10,20,30,40}; 7 | int sum = 0; 8 | for(int arr:a){ 9 | sum = sum + arr; 10 | } 11 | return sum; 12 | } 13 | 14 | public static void main(String[] args) { 15 | CalculateSumOfNumbersOfArray obj = new CalculateSumOfNumbersOfArray(); 16 | System.out.println(obj.calculateSumOfNumbers()); 17 | } 18 | 19 | } 20 | -------------------------------------------------------------------------------- /src/programs/ConvertStringToNumber.java: -------------------------------------------------------------------------------- 1 | package programs; 2 | 3 | public class ConvertStringToNumber { 4 | 5 | } 6 | -------------------------------------------------------------------------------- /src/programs/CountNumberInArray.java: -------------------------------------------------------------------------------- 1 | package programs; 2 | 3 | import java.util.HashMap; 4 | 5 | public class CountNumberInArray { 6 | 7 | public static void main(String[] args) { 8 | int[] a = {355,655,677}; 9 | 10 | HashMap map = new HashMap<>(); 11 | 12 | for(int i =0; i=1;i--){ 29 | for(int j =1; j<=i;j++){ 30 | System.out.print(j+" "); 31 | } 32 | System.out.println(); 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/programs/PatternProgram5.java: -------------------------------------------------------------------------------- 1 | package programs; 2 | 3 | import java.util.Scanner; 4 | 5 | public class PatternProgram5 { 6 | 7 | /** 8 | 1 2 3 4 5 6 7 9 | 1 2 3 4 5 6 10 | 1 2 3 4 5 11 | 1 2 3 4 12 | 1 2 3 13 | 1 2 14 | 1 15 | */ 16 | public static void main(String[] args) { 17 | 18 | Scanner scanner = new Scanner(System.in); 19 | System.out.println("enter input data"); 20 | int number = scanner.nextInt(); 21 | for(int i=number;i>=1; i--){ 22 | for(int j = 1; j<=i;j++){ 23 | System.out.print("*"+" "); 24 | } 25 | System.out.println(); 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/programs/PatternProgram6.java: -------------------------------------------------------------------------------- 1 | package programs; 2 | 3 | import java.util.Scanner; 4 | 5 | public class PatternProgram6{ 6 | 7 | /** 8 | 7 6 5 4 3 2 1 9 | 7 6 5 4 3 2 10 | 7 6 5 4 3 11 | 7 6 5 4 12 | 7 6 5 13 | 7 6 14 | 7 15 | */ 16 | public static void main(String[] args) { 17 | Scanner scanner = new Scanner(System.in); 18 | System.out.println("enter input data"); 19 | int number = scanner.nextInt(); 20 | for(int i =1; i<=number;i++){ 21 | for(int j = number; j>=i;j--){ 22 | System.out.print(j+" "); 23 | } 24 | System.out.println(); 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/programs/PatternProgram7.java: -------------------------------------------------------------------------------- 1 | package programs; 2 | 3 | public class PatternProgram7 { 4 | 5 | /** 6 | 1 2 3 4 5 6 7 7 | 1 2 3 4 5 6 8 | 1 2 3 4 5 9 | 1 2 3 4 10 | 1 2 3 11 | 1 2 12 | 1 13 | 1 2 14 | 1 2 3 15 | 1 2 3 4 16 | 1 2 3 4 5 17 | 1 2 3 4 5 6 18 | 1 2 3 4 5 6 7 19 | 20 | */ 21 | 22 | public static void main(String[] args) { 23 | for(int i =7; i>=1; i--){ 24 | for(int j =1 ; j<=i; j++){ 25 | System.out.print(j+" "); 26 | } 27 | System.out.println(); 28 | } 29 | 30 | for(int k = 2; k<=7; k++){ 31 | for(int j =1 ; j<=k; j++){ 32 | System.out.print(j+" "); 33 | } 34 | System.out.println(); 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/programs/PatternProgram8.java: -------------------------------------------------------------------------------- 1 | package programs; 2 | 3 | public class PatternProgram8 { 4 | 5 | /** 6 | 1 7 | 1 2 1 8 | 1 2 3 2 1 9 | 1 2 3 4 3 2 1 10 | 1 2 3 4 5 4 3 2 1 11 | 1 2 3 4 5 6 5 4 3 2 1 12 | 1 2 3 4 5 6 7 6 5 4 3 2 1 13 | 14 | */ 15 | public static void main(String[] args) { 16 | for(int i = 1; i<=7; i++){ 17 | 18 | for(int j = 1; j<=i; j++){ 19 | System.out.print(j+" "); 20 | } 21 | 22 | for(int j = i-1; j>=1; j--){ 23 | System.out.print(j+" "); 24 | } 25 | System.out.println(); 26 | } 27 | 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/programs/ReverseNumber.java: -------------------------------------------------------------------------------- 1 | package programs; 2 | 3 | import java.util.Scanner; 4 | 5 | public class ReverseNumber { 6 | 7 | public void reverseNumber(){ 8 | Scanner scn = new Scanner(System.in); 9 | System.out.println("Enter number"); 10 | int number = scn.nextInt(); 11 | int reverse = 0; 12 | while(number!=0){ 13 | reverse = reverse*10; 14 | reverse = reverse + number%10; 15 | number = number/10; 16 | } 17 | System.out.println("Reversed number is:-"+reverse); 18 | } 19 | 20 | public static void main(String[] args) { 21 | ReverseNumber obj = new ReverseNumber(); 22 | obj.reverseNumber(); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/programs/SumOfArray.java: -------------------------------------------------------------------------------- 1 | package programs; 2 | 3 | public class SumOfArray { 4 | 5 | } 6 | -------------------------------------------------------------------------------- /src/setClass/AgeComparator.java: -------------------------------------------------------------------------------- 1 | package setClass; 2 | 3 | import java.util.Comparator; 4 | import java.util.TreeSet; 5 | 6 | public class AgeComparator implements Comparator{ 7 | 8 | 9 | @Override 10 | public int compare(PersonTreeSet o1, PersonTreeSet o2) { 11 | return o1.getAge().compareTo(o2.getAge()); 12 | } 13 | 14 | public static void main(String[] args) { 15 | PersonTreeSet personTreeSet = new PersonTreeSet(); 16 | 17 | TreeSet personTreeSets = 18 | new TreeSet(personTreeSet.ageComparator); 19 | 20 | personTreeSets.add(new PersonTreeSet("CC", 40)); 21 | personTreeSets.add(new PersonTreeSet("DD", 20)); 22 | personTreeSets.add(new PersonTreeSet("AA", 30)); 23 | 24 | System.out.println(personTreeSets); 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /src/setClass/Book.java: -------------------------------------------------------------------------------- 1 | package setClass; 2 | 3 | public class Book { 4 | 5 | int id; 6 | String name, author, publisher; 7 | int quantity; 8 | 9 | public Book(int id, String name, String author, String publisher, int quantity) { 10 | this.id = id; 11 | this.name = name; 12 | this.author = author; 13 | this.publisher = publisher; 14 | this.quantity = quantity; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/setClass/CloneWith_InstanceVariable2.java: -------------------------------------------------------------------------------- 1 | package setClass; 2 | 3 | import java.util.HashSet; 4 | 5 | public class CloneWith_InstanceVariable2 { 6 | 7 | public static void main(String[] args) { 8 | 9 | HashSet original = new HashSet(); 10 | original.add("3000"); 11 | original.add("2000"); 12 | original.add("2000"); 13 | 14 | // Cloning will give one copy of object 15 | HashSet cloned = (HashSet)original.clone(); 16 | System.out.println("Original Object=="+original); 17 | System.out.println("Cloned Object=="+cloned); 18 | 19 | // Modifying clone object 20 | cloned.add("80"); 21 | 22 | System.out.println("Original Object=="+original); 23 | System.out.println("Cloned Object=="+cloned); 24 | 25 | // Modifying original object 26 | original.add("800"); 27 | 28 | System.out.println("Original Object=="+original); 29 | System.out.println("Cloned Object=="+cloned); 30 | } 31 | 32 | } 33 | -------------------------------------------------------------------------------- /src/setClass/ContainsMethods.java: -------------------------------------------------------------------------------- 1 | package setClass; 2 | 3 | import java.util.HashSet; 4 | import java.util.LinkedHashSet; 5 | import java.util.TreeSet; 6 | 7 | public class ContainsMethods { 8 | 9 | public static void main(String[] args) { 10 | 11 | HashSet original = new HashSet(); 12 | original.add(70); 13 | original.add(20); 14 | 15 | LinkedHashSet linkedHashSet = new LinkedHashSet(); 16 | linkedHashSet.add(70); 17 | linkedHashSet.add(20); 18 | 19 | TreeSet treeSet = new TreeSet(); 20 | treeSet.add(70); 21 | treeSet.add(20); 22 | 23 | System.out.println(original.contains(200)); 24 | 25 | original.containsAll(linkedHashSet); 26 | 27 | System.out.println(original.size()); 28 | System.out.println(treeSet.size()); 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /src/setClass/Example2.java: -------------------------------------------------------------------------------- 1 | package setClass; 2 | 3 | import java.util.HashSet; 4 | import java.util.Iterator; 5 | 6 | public class Example2 { 7 | 8 | public static void main(String args[]) { 9 | HashSet set = new HashSet(); 10 | set.add("Test1"); 11 | Iterator itr = set.iterator(); 12 | while (itr.hasNext()) { 13 | System.out.println(itr.next().hashCode()); 14 | } 15 | set.add("Test2"); 16 | itr = set.iterator(); 17 | while (itr.hasNext()) { 18 | System.out.println(itr.next().hashCode()); 19 | } 20 | set.add("Test3"); 21 | set.add("Test2"); 22 | 23 | itr = set.iterator(); 24 | while (itr.hasNext()) { 25 | System.out.println(itr.next()); 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/setClass/Example3.java: -------------------------------------------------------------------------------- 1 | package setClass; 2 | 3 | import java.util.HashSet; 4 | 5 | public class Example3 { 6 | 7 | public static void main(String[] args) { 8 | HashSet set = new HashSet(); 9 | set.add("Test1"); 10 | set.add("Test2"); 11 | set.add("Test3"); 12 | set.add("Test4"); 13 | System.out.println("An initial list of elements: " + set); 14 | set.remove("Test1"); 15 | System.out.println("After invoking remove(object) method: " + set); 16 | HashSet set1 = new HashSet(); 17 | set1.add("Test2"); 18 | set1.add("Test3"); 19 | set.addAll(set1); 20 | System.out.println("Updated List: " + set); 21 | set.removeAll(set1); 22 | System.out.println("After invoking removeAll() method: " + set); 23 | set.clear(); 24 | System.out.println("After invoking clear() method: " + set); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/setClass/Example4.java: -------------------------------------------------------------------------------- 1 | package setClass; 2 | 3 | import java.util.HashSet; 4 | 5 | public class Example4 { 6 | 7 | public static void main(String[] args) { 8 | 9 | HashSet set = new HashSet(); 10 | Book b1 = new Book(11, "Test1", "author1", "publisher1", 8); 11 | Book b2 = new Book(12, "Test2", "author2", "publisher2", 4); 12 | Book b3 = new Book(13, "Test3", "author3", "publisher3", 6); 13 | set.add(b1); 14 | set.add(b2); 15 | set.add(b3); 16 | for (Book book : set) { 17 | System.out.println( 18 | book.id + " " + book.name + " " + book.author + " " + book.publisher + " " + book.quantity); 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/setClass/Example5.java: -------------------------------------------------------------------------------- 1 | package setClass; 2 | 3 | import java.util.HashSet; 4 | import java.util.Iterator; 5 | import java.util.LinkedHashSet; 6 | 7 | public class Example5 { 8 | 9 | public static void main(String args[]) { 10 | 11 | HashSet set = new HashSet(); 12 | set.add("Test1"); 13 | set.add("Test40"); 14 | set.add("Test3"); 15 | set.add("Test2"); 16 | set.add("Test20"); 17 | set.add("Test2"); 18 | Iterator itr = set.iterator(); 19 | while (itr.hasNext()) { 20 | System.out.println(itr.next()); 21 | } 22 | System.out.println("========="); 23 | LinkedHashSet linkedset = new LinkedHashSet(); 24 | linkedset.add("Test1"); 25 | linkedset.add("Test40"); 26 | linkedset.add("Test3"); 27 | linkedset.add("Test2"); 28 | linkedset.add("Test20"); 29 | linkedset.add("Test2"); 30 | Iterator itr1 = linkedset.iterator(); 31 | while (itr1.hasNext()) { 32 | System.out.println(itr1.next()); 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/setClass/TestCustomeObject.java: -------------------------------------------------------------------------------- 1 | package setClass; 2 | 3 | public class TestCustomeObject { 4 | 5 | 6 | public static void main(String[] args) throws CloneNotSupportedException { 7 | Emplyee emp = new Emplyee("Test1", 30); 8 | CustomeObject originalObject = new CustomeObject(1,emp); 9 | 10 | CustomeObject clonedObject = (CustomeObject)originalObject.clone(); 11 | 12 | System.out.println(originalObject); 13 | System.out.println(clonedObject); 14 | 15 | clonedObject.getEmplyee().setName("Changed"); 16 | 17 | System.out.println(originalObject); 18 | System.out.println(clonedObject); 19 | 20 | } 21 | 22 | } 23 | -------------------------------------------------------------------------------- /src/setClass/TestDefault.java: -------------------------------------------------------------------------------- 1 | package setClass; 2 | 3 | public class TestDefault { 4 | 5 | public static void main(String[] args) { 6 | Person1234 obj = new Person1234(20, "test"); 7 | 8 | System.out.println(obj.getAge()); 9 | } 10 | 11 | } 12 | -------------------------------------------------------------------------------- /src/staticAndDynamicBinding/Example1.java: -------------------------------------------------------------------------------- 1 | package staticAndDynamicBinding; 2 | 3 | public class Example1 { 4 | private void eat() { 5 | System.out.println("dog is eating..."); 6 | } 7 | 8 | public static void main(String args[]) { 9 | Example1 d1 = new Example1(); 10 | d1.eat(); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/staticAndDynamicBinding/Example2.java: -------------------------------------------------------------------------------- 1 | package staticAndDynamicBinding; 2 | 3 | public class Example2 { 4 | 5 | void eat() { 6 | System.out.println("animal is eating..."); 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /src/staticAndDynamicBinding/Example3.java: -------------------------------------------------------------------------------- 1 | package staticAndDynamicBinding; 2 | 3 | public class Example3 extends Example2 { 4 | 5 | void eat() { 6 | System.out.println("dog is eating..."); 7 | } 8 | 9 | public static void main(String args[]) { 10 | Example2 a = new Example3(); 11 | a.eat(); 12 | } 13 | } -------------------------------------------------------------------------------- /src/staticAndDynamicBinding/Example4.java: -------------------------------------------------------------------------------- 1 | package staticAndDynamicBinding; 2 | 3 | public class Example4 { 4 | public static void test() { 5 | System.out.println("Example4"); 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /src/staticAndDynamicBinding/Example5.java: -------------------------------------------------------------------------------- 1 | package staticAndDynamicBinding; 2 | 3 | public class Example5 extends Example4 { 4 | public static void test() { 5 | System.out.println("Example5"); 6 | } 7 | 8 | public static void main(String args[]) { 9 | Example4 obj = new Example5(); 10 | 11 | Example4 obj2 = new Example5(); 12 | obj.test(); 13 | obj2.test(); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/staticAndDynamicBinding/Human.java: -------------------------------------------------------------------------------- 1 | package staticAndDynamicBinding; 2 | 3 | class Human { 4 | public static void walk() { 5 | System.out.println("Human walks"); 6 | } 7 | } 8 | 9 | class Boy extends Human { 10 | public static void walk() { 11 | System.out.println("Boy walks"); 12 | } 13 | 14 | public static void main(String args[]) { 15 | Human obj = new Boy(); 16 | Human obj2 = new Human(); 17 | obj.walk(); 18 | obj2.walk(); 19 | } 20 | } -------------------------------------------------------------------------------- /src/staticBlock/Example1.java: -------------------------------------------------------------------------------- 1 | package staticBlock; 2 | 3 | public class Example1 { 4 | 5 | private static int a; 6 | 7 | public static void test1() { 8 | 9 | } 10 | 11 | static { 12 | System.out.println("this is sttaic block"); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /src/staticBlock/Example10.java: -------------------------------------------------------------------------------- 1 | package staticBlock; 2 | 3 | public class Example10 { 4 | 5 | public static void main(String[] args) { 6 | Example9.test1(); 7 | 8 | //Example9.test2(); 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /src/staticBlock/Example11.java: -------------------------------------------------------------------------------- 1 | package staticBlock; 2 | 3 | public class Example11 { 4 | 5 | private static String str = "test"; 6 | 7 | public static void test1(){ 8 | 9 | } 10 | static class MyNestedClass { 11 | public void disp() { 12 | System.out.println(str); 13 | } 14 | } 15 | 16 | public static void main(String[] args) { 17 | Example11.test1(); 18 | 19 | Example11.MyNestedClass obj = new Example11.MyNestedClass(); 20 | obj.disp(); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/staticBlock/Example12.java: -------------------------------------------------------------------------------- 1 | package staticBlock; 2 | 3 | public class Example12 { 4 | 5 | private static String str = "test"; 6 | 7 | class MyNestedClass { 8 | public void disp() { 9 | System.out.println(str); 10 | } 11 | } 12 | 13 | public static void main(String[] args) { 14 | Example12.MyNestedClass obj = new Example12().new MyNestedClass(); 15 | obj.disp(); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/staticBlock/Example13.java: -------------------------------------------------------------------------------- 1 | package staticBlock; 2 | 3 | public class Example13 { 4 | 5 | private static String str = "test"; 6 | 7 | public static class MyNestedClass { 8 | public void disp() { 9 | System.out.println(str); 10 | } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/staticBlock/Example2.java: -------------------------------------------------------------------------------- 1 | package staticBlock; 2 | 3 | public class Example2 { 4 | 5 | static int i = 10; 6 | static int j; 7 | 8 | int k; 9 | 10 | static { 11 | System.out.println("Static block initialized."); 12 | j = i * 2; 13 | } 14 | 15 | Example2(){ 16 | k = 30; 17 | } 18 | 19 | public static void main(String[] args) { 20 | Example2 onj = new Example2(); 21 | System.out.println("Value of i : " + Example2.i); 22 | System.out.println("Value of j : " + Example2.j); 23 | System.out.println("Value of k : " + onj.k); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/staticBlock/Example3.java: -------------------------------------------------------------------------------- 1 | package staticBlock; 2 | 3 | public class Example3 { 4 | static int j = 80; 5 | 6 | public static void test() { 7 | System.out.println(j); 8 | int i = 90; 9 | System.out.println(i); 10 | } 11 | 12 | public static void test1() { 13 | System.out.println(j); 14 | //static int i = 90; 15 | System.out.println(j); 16 | } 17 | 18 | public static void test2() { 19 | System.out.println(j); 20 | } 21 | 22 | public static void main(String[] args) { 23 | Example3.test(); 24 | Example3.test1(); 25 | Example3.test2(); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/staticBlock/Example4.java: -------------------------------------------------------------------------------- 1 | package staticBlock; 2 | 3 | public class Example4 { 4 | 5 | static { 6 | System.out.println("static block"); 7 | } 8 | 9 | static int i = 0; 10 | static { 11 | System.out.println("value of i=" + i); 12 | i = 90; 13 | } 14 | 15 | static { 16 | System.out.println("value of i=" + i); 17 | } 18 | 19 | Example4(){ 20 | System.out.println("----"); 21 | } 22 | public static void main(String[] args) { 23 | 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/staticBlock/Example5.java: -------------------------------------------------------------------------------- 1 | package staticBlock; 2 | 3 | public class Example5 { 4 | 5 | static int k = 90; 6 | 7 | void display() { 8 | System.out.println("value of k is:=" + k); 9 | } 10 | 11 | public static void main(String[] args) { 12 | Example5 obj = new Example5(); 13 | 14 | obj.display(); 15 | 16 | Example5 obj1 = new Example5(); 17 | obj1.display(); 18 | 19 | Example5 obj2 = new Example5(); 20 | obj2.display(); 21 | } 22 | 23 | } 24 | -------------------------------------------------------------------------------- /src/staticBlock/Example6.java: -------------------------------------------------------------------------------- 1 | package staticBlock; 2 | 3 | public class Example6 { 4 | 5 | int i = 90; 6 | static int k = 80; 7 | static{ 8 | k = 100; 9 | //i = 60; 10 | } 11 | 12 | } 13 | -------------------------------------------------------------------------------- /src/staticBlock/Example7.java: -------------------------------------------------------------------------------- 1 | package staticBlock; 2 | 3 | public class Example7 { 4 | 5 | static int i = 10; 6 | int b = 20; 7 | 8 | static void test1() { 9 | i = 20; 10 | System.out.println("from m1"); 11 | //b = 10; 12 | //test2(); 13 | } 14 | 15 | void test2() { 16 | i = 20; 17 | b = 10; 18 | test1(); 19 | System.out.println("from m2"); 20 | } 21 | 22 | public static void main(String[] args) { 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/staticBlock/Example8.java: -------------------------------------------------------------------------------- 1 | package staticBlock; 2 | 3 | public class Example8 { 4 | 5 | static void test1(){ 6 | System.out.println("test1()"); 7 | } 8 | 9 | public static void main(String[] args) { 10 | test1(); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/staticBlock/Example9.java: -------------------------------------------------------------------------------- 1 | package staticBlock; 2 | 3 | public class Example9 { 4 | 5 | static void test1(){ 6 | System.out.println("test1()"); 7 | } 8 | 9 | void test2(){ 10 | System.out.println("test1()"); 11 | } 12 | 13 | public static void main(String[] args) { 14 | Example9.test1(); 15 | //test2(); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/stringBuffer/Example2.java: -------------------------------------------------------------------------------- 1 | package stringBuffer; 2 | 3 | public class Example2 { 4 | 5 | public static void main(String args[]) { 6 | StringBuffer sb = new StringBuffer(); 7 | System.out.println(sb.capacity());// default 16 8 | sb.append("Hello"); 9 | System.out.println(sb.capacity());// now 16 10 | sb.append("java is programming language"); 11 | System.out.println(sb.capacity());// now (16*2)+2=34 i.e 12 | // (oldcapacity*2)+2 13 | sb.ensureCapacity(10);// now no change 14 | System.out.println(sb.capacity());// now 34 15 | sb.ensureCapacity(50);// now (34*2)+2 16 | System.out.println(sb.capacity());// now 70 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/stringBuffer/Example3.java: -------------------------------------------------------------------------------- 1 | package stringBuffer; 2 | 3 | public class Example3 { 4 | 5 | public static String concatString() { 6 | String t = "Hello"; 7 | for (int i = 0; i < 10000; i++) { 8 | t = t + "Java"; 9 | } 10 | return t; 11 | } 12 | 13 | public static String concatStringBuffer() { 14 | StringBuffer sb = new StringBuffer("Hello"); 15 | for (int i = 0; i < 10000; i++) { 16 | sb.append("Java"); 17 | } 18 | return sb.toString(); 19 | } 20 | 21 | public static void main(String[] args) { 22 | long startTime = System.currentTimeMillis(); 23 | Example3.concatString(); 24 | long endTime = System.currentTimeMillis(); 25 | System.out.println("Time Take my string=" + (endTime - startTime)); 26 | 27 | long startTime1 = System.currentTimeMillis(); 28 | Example3.concatStringBuffer(); 29 | long endTime1 = System.currentTimeMillis(); 30 | 31 | System.out.println("Time Take my string=" + (endTime1 - startTime1)); 32 | } 33 | 34 | } 35 | -------------------------------------------------------------------------------- /src/stringInjava/Example1.java: -------------------------------------------------------------------------------- 1 | package stringInjava; 2 | 3 | public class Example1 { 4 | 5 | public static void main(String args[]) { 6 | String s = "Bhanu"; 7 | s.concat(" Java"); 8 | System.out.println(s); 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /src/stringInjava/Example10.java: -------------------------------------------------------------------------------- 1 | package stringInjava; 2 | 3 | public class Example10 { 4 | 5 | public static void main(String[] args) { 6 | String s1 = "java"; 7 | String s2 = "c"; 8 | String s3 = "java"; 9 | String s4 = "python"; 10 | System.out.println(s1.equals(s2)); 11 | System.out.println(s1.equals(s3)); 12 | System.out.println(s1.equals(s4)); 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /src/stringInjava/Example11.java: -------------------------------------------------------------------------------- 1 | package stringInjava; 2 | 3 | public class Example11 { 4 | 5 | public static void main(String[] args) { 6 | String s1 = "bhanu"; 7 | String s2 = "bhanu"; 8 | String s3 = "BHANU"; 9 | String s4 = "TEST"; 10 | System.out.println(s1.equalsIgnoreCase(s2)); 11 | System.out.println(s1.equalsIgnoreCase(s3)); 12 | System.out.println(s1.equalsIgnoreCase(s4)); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /src/stringInjava/Example13.java: -------------------------------------------------------------------------------- 1 | package stringInjava; 2 | 3 | public class Example13 { 4 | 5 | public static void main(String[] args) { 6 | String s1 = "ABCDEFG"; 7 | byte[] barr = s1.getBytes(); 8 | for (int i = 0; i < barr.length; i++) { 9 | System.out.println(barr[i]); 10 | } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/stringInjava/Example14.java: -------------------------------------------------------------------------------- 1 | package stringInjava; 2 | 3 | public class Example14 { 4 | 5 | public static void main(String[] args) { 6 | String str = new String("java is programming language"); 7 | char[] ch = new char[10]; 8 | try { 9 | str.getChars(5, 15, ch, 0); 10 | System.out.println(ch); 11 | } catch (Exception ex) { 12 | System.out.println(ex); 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/stringInjava/Example15.java: -------------------------------------------------------------------------------- 1 | package stringInjava; 2 | 3 | public class Example15 { 4 | 5 | public static void main(String[] args) { 6 | String str = new String("java is programming language"); 7 | char[] ch = new char[10]; 8 | try { 9 | str.getChars(5, 20, ch, 0); 10 | System.out.println(ch); 11 | } catch (Exception ex) { 12 | System.out.println(ex); 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/stringInjava/Example16.java: -------------------------------------------------------------------------------- 1 | package stringInjava; 2 | 3 | public class Example16 { 4 | 5 | public static void main(String[] args) { 6 | String s1 = "hello java program"; 7 | int index1 = s1.indexOf("ja"); 8 | int index2 = s1.indexOf("java"); 9 | System.out.println(index1); 10 | System.out.println(index2); 11 | 12 | int index3 = s1.indexOf("ro", 4); 13 | System.out.println(index3); 14 | 15 | int index4 = s1.indexOf('a'); 16 | System.out.println(index4); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/stringInjava/Example17.java: -------------------------------------------------------------------------------- 1 | package stringInjava; 2 | 3 | public class Example17 { 4 | 5 | public static void main(String[] args) { 6 | String s1 = new String("java"); 7 | String s2 = "java"; 8 | String s3 = s1.intern(); 9 | System.out.println(s1 == s2); 10 | System.out.println(s2 == s3); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/stringInjava/Example18.java: -------------------------------------------------------------------------------- 1 | package stringInjava; 2 | 3 | public class Example18 { 4 | 5 | public static void main(String[] args) { 6 | String s1 = "Java"; 7 | String s2 = s1.intern(); 8 | String s3 = new String("Java"); 9 | String s4 = s3.intern(); 10 | System.out.println(s1 == s2); 11 | System.out.println(s1 == s3); 12 | System.out.println(s1 == s4); 13 | System.out.println(s2 == s3); 14 | System.out.println(s2 == s4); 15 | System.out.println(s3 == s4); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/stringInjava/Example19.java: -------------------------------------------------------------------------------- 1 | package stringInjava; 2 | 3 | public class Example19 { 4 | 5 | public static void main(String[] args) { 6 | String s1 = ""; 7 | String s2 = "javatest"; 8 | 9 | System.out.println(s1.isEmpty()); 10 | System.out.println(s2.isEmpty()); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/stringInjava/Example20.java: -------------------------------------------------------------------------------- 1 | package stringInjava; 2 | 3 | public class Example20 { 4 | 5 | public static void main(String[] args) { 6 | String s1 = String.join("-", "hello", "java", "program"); 7 | System.out.println(s1); 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /src/stringInjava/Example21.java: -------------------------------------------------------------------------------- 1 | package stringInjava; 2 | 3 | public class Example21 { 4 | 5 | public static void main(String[] args) { 6 | String d = String.join("/", "20", "04", "2016"); 7 | System.out.print(d); 8 | String t = String.join(":", "11", "13", "10"); 9 | System.out.println(t); 10 | } 11 | 12 | } 13 | -------------------------------------------------------------------------------- /src/stringInjava/Example22.java: -------------------------------------------------------------------------------- 1 | package stringInjava; 2 | 3 | public class Example22 { 4 | 5 | public static void main(String[] args) { 6 | String s1 = "this is java index"; 7 | int index = s1.lastIndexOf('s'); 8 | System.out.println(index); 9 | 10 | s1.lastIndexOf('s', 5); 11 | System.out.println(index); 12 | 13 | s1.lastIndexOf("of"); 14 | System.out.println(index); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/stringInjava/Example23.java: -------------------------------------------------------------------------------- 1 | package stringInjava; 2 | 3 | public class Example23 { 4 | 5 | public static void main(String args[]) { 6 | String s1 = "bhanujava"; 7 | String s2 = "test"; 8 | System.out.println("string length is: " + s1.length()); 9 | System.out.println("string length is: " + s2.length()); 10 | } 11 | 12 | } 13 | -------------------------------------------------------------------------------- /src/stringInjava/Example24.java: -------------------------------------------------------------------------------- 1 | package stringInjava; 2 | 3 | public class Example24 { 4 | 5 | public static void main(String args[]) { 6 | String s1 = "hello java test"; 7 | String replaceString = s1.replace('a', 'e'); 8 | System.out.println(replaceString); 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /src/stringInjava/Example25.java: -------------------------------------------------------------------------------- 1 | package stringInjava; 2 | 3 | public class Example25 { 4 | 5 | public static void main(String args[]) { 6 | String s1 = "hello java test"; 7 | String[] words = s1.split("\\s"); 8 | for (String w : words) { 9 | System.out.println(w); 10 | } 11 | 12 | s1 = "hello:java:test"; 13 | words = s1.split(":"); 14 | for (String w : words) { 15 | System.out.println(w); 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/stringInjava/Example26.java: -------------------------------------------------------------------------------- 1 | package stringInjava; 2 | 3 | public class Example26 { 4 | 5 | public static void main(String[] args) { 6 | String s1 = "hello java test program"; 7 | System.out.println(s1.startsWith("hel")); 8 | System.out.println(s1.startsWith("hello java")); 9 | 10 | System.out.println(s1.startsWith("a",7)); 11 | 12 | System.out.println(s1.startsWith("a",40)); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /src/stringInjava/Example27.java: -------------------------------------------------------------------------------- 1 | package stringInjava; 2 | 3 | public class Example27 { 4 | 5 | public static void main(String[] args) { 6 | String s1 = "hellojavatest"; 7 | String substr = s1.substring(0); 8 | System.out.println(substr); 9 | String substr2 = s1.substring(5, 10); 10 | System.out.println(substr2); 11 | 12 | // java.lang.StringIndexOutOfBoundsException: 13 | String substr3 = s1.substring(5, 15); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/stringInjava/Example28.java: -------------------------------------------------------------------------------- 1 | package stringInjava; 2 | 3 | public class Example28 { 4 | 5 | public static void main(String[] args) { 6 | String s1 = "hello java test"; 7 | char[] ch = s1.toCharArray(); 8 | int len = ch.length; 9 | System.out.println("Char Array length: " + len); 10 | System.out.println("Char Array elements: "); 11 | for (int i = 0; i < len; i++) { 12 | System.out.println(ch[i]); 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/stringInjava/Example29.java: -------------------------------------------------------------------------------- 1 | package stringInjava; 2 | 3 | public class Example29 { 4 | 5 | public static void main(String[] args) { 6 | String s = "hello java"; 7 | 8 | System.out.println(s.toUpperCase()); 9 | 10 | String s1 = "HELLO"; 11 | 12 | System.out.println(s1.toLowerCase()); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /src/stringInjava/Example3.java: -------------------------------------------------------------------------------- 1 | package stringInjava; 2 | 3 | public class Example3 { 4 | 5 | public static void main(String[] args) { 6 | String s = 90 + 30 + "Bhanu" + 50 + 50; 7 | System.out.println(s); 8 | 9 | String s1 = "Bhanu "; 10 | String s2 = "Pratap"; 11 | String s3 = s1.concat(s2); 12 | System.out.println(s3); 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /src/stringInjava/Example30.java: -------------------------------------------------------------------------------- 1 | package stringInjava; 2 | 3 | public class Example30 { 4 | 5 | public static void main(String[] args) { 6 | String s1 = " Hello Java "; 7 | 8 | System.out.println("123"+s1.trim()+"12"); 9 | 10 | 11 | System.out.println("123"+s1+"12"); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/stringInjava/Example31.java: -------------------------------------------------------------------------------- 1 | package stringInjava; 2 | 3 | public class Example31 { 4 | 5 | public static void main(String[] args) { 6 | float f = 10.05f; 7 | double d = 10.02; 8 | String s1 = String.valueOf(f); 9 | String s2 = String.valueOf(d); 10 | System.out.println(s1); 11 | System.out.println(s2); 12 | 13 | char ch1 = 'A'; 14 | char ch2 = 'B'; 15 | s1 = String.valueOf(ch1); 16 | s2 = String.valueOf(ch2); 17 | System.out.println(s1); 18 | System.out.println(s2); 19 | 20 | int value = 30; 21 | s1 = String.valueOf(value); 22 | System.out.println(s1); 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /src/stringInjava/Example4.java: -------------------------------------------------------------------------------- 1 | package stringInjava; 2 | 3 | public class Example4 { 4 | 5 | public static void main(String[] args) { 6 | String s = "Bhanupratap"; 7 | System.out.println(s.substring(6)); 8 | System.out.println(s.substring(0, 6)); 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /src/stringInjava/Example5.java: -------------------------------------------------------------------------------- 1 | package stringInjava; 2 | 3 | public class Example5 { 4 | 5 | public static void main(String[] args) { 6 | String name = "bhanupratap"; 7 | char ch = name.charAt(4); 8 | System.out.println(ch); 9 | 10 | name.charAt(20); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/stringInjava/Example6.java: -------------------------------------------------------------------------------- 1 | package stringInjava; 2 | 3 | public class Example6 { 4 | 5 | public static void main(String[] args) { 6 | 7 | } 8 | 9 | } 10 | -------------------------------------------------------------------------------- /src/stringInjava/Example7.java: -------------------------------------------------------------------------------- 1 | package stringInjava; 2 | 3 | public class Example7 { 4 | 5 | public static void main(String[] args) { 6 | String name = "Hello java program"; 7 | System.out.println(name.contains("java program")); 8 | System.out.println(name.contains("am")); 9 | System.out.println(name.contains("hello")); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /src/stringInjava/Example8.java: -------------------------------------------------------------------------------- 1 | package stringInjava; 2 | 3 | public class Example8 { 4 | 5 | public static void main(String[] args) { 6 | String str = "if you want to move in automation learn java"; 7 | if (str.contains("learn java")) { 8 | System.out.println("I am in"); 9 | } else 10 | System.out.println("Result not found"); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/stringInjava/Example9.java: -------------------------------------------------------------------------------- 1 | package stringInjava; 2 | 3 | public class Example9 { 4 | 5 | public static void main(String[] args) { 6 | String s1 = "bhanu test"; 7 | System.out.println(s1.endsWith("t")); 8 | System.out.println(s1.endsWith("test1")); 9 | 10 | String str = "Welcome to youtube channel"; 11 | if (str.endsWith("channel")) { 12 | System.out.println("Welcome to youtube channel"); 13 | } else 14 | System.out.println("It does not end with channel"); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/testAccessModifierInJava/TestProtectedAndDefault.java: -------------------------------------------------------------------------------- 1 | package testAccessModifierInJava; 2 | 3 | import accessModifierInJava.Example1; 4 | 5 | public class TestProtectedAndDefault extends Example1{ 6 | 7 | public static void main(String[] args) { 8 | 9 | TestProtectedAndDefault obj = new TestProtectedAndDefault(); 10 | obj.test1(); 11 | obj.test2(); 12 | 13 | Example1 obj1 = new Example1(); 14 | obj1.test1(); 15 | System.out.println(obj1.i); 16 | 17 | } 18 | 19 | } 20 | -------------------------------------------------------------------------------- /src/testAccessModifierInJava/TestProtectedAndDefault2.java: -------------------------------------------------------------------------------- 1 | package testAccessModifierInJava; 2 | 3 | import accessModifierInJava.Example1; 4 | 5 | public class TestProtectedAndDefault2{ 6 | 7 | public static void main(String[] args) { 8 | 9 | TestProtectedAndDefault2 obj = new TestProtectedAndDefault2(); 10 | 11 | 12 | Example1 obj1 = new Example1(); 13 | obj1.test1(); 14 | 15 | System.out.println(obj1.i); 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /src/testInheritance/A.java: -------------------------------------------------------------------------------- 1 | package testInheritance; 2 | 3 | public class A { 4 | 5 | public void test1(){ 6 | System.out.println("A test1"); 7 | } 8 | 9 | } 10 | -------------------------------------------------------------------------------- /src/testInheritance/B.java: -------------------------------------------------------------------------------- 1 | package testInheritance; 2 | 3 | public class B extends A{ 4 | 5 | public void test2(){ 6 | System.out.println("B test1"); 7 | } 8 | 9 | } 10 | -------------------------------------------------------------------------------- /src/testInheritance/C.java: -------------------------------------------------------------------------------- 1 | package testInheritance; 2 | 3 | public class C extends B{ 4 | 5 | public void test3(){ 6 | System.out.println("C test1"); 7 | } 8 | 9 | public static void main(String[] args) { 10 | C obj = new C(); 11 | obj.test1(); 12 | obj.test2(); 13 | obj.test3(); 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /src/testInheritance/TestInheritanceFromDifferentPackage.java: -------------------------------------------------------------------------------- 1 | package testInheritance; 2 | 3 | import inheritanceInJava.A; 4 | 5 | public class TestInheritanceFromDifferentPackage extends A{ 6 | 7 | public static void main(String[] args) { 8 | TestInheritanceFromDifferentPackage obj = new TestInheritanceFromDifferentPackage(); 9 | obj.test1(); 10 | obj.test3(); 11 | 12 | System.out.println(obj.i); 13 | System.out.println(obj.k); 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /src/typeCasting/A.java: -------------------------------------------------------------------------------- 1 | package typeCasting; 2 | 3 | public class A { 4 | 5 | public void test2(){ 6 | System.out.println("test1"); 7 | } 8 | 9 | } 10 | -------------------------------------------------------------------------------- /src/typeCasting/B.java: -------------------------------------------------------------------------------- 1 | package typeCasting; 2 | 3 | public class B extends A { 4 | 5 | public void test1() { 6 | System.out.println("test1"); 7 | } 8 | 9 | public static void main(String[] args) { 10 | A obj = new B(); 11 | 12 | obj.test2(); 13 | 14 | A obj1 = new B(); 15 | 16 | ((B) obj1).test1(); 17 | } 18 | 19 | } 20 | -------------------------------------------------------------------------------- /src/typeCasting/TypeCastingExample1.java: -------------------------------------------------------------------------------- 1 | package typeCasting; 2 | 3 | public class TypeCastingExample1 { 4 | 5 | public static void main(String[] args) { 6 | int i = 200; 7 | 8 | long l = i; 9 | 10 | float f = l; 11 | 12 | double d = i; 13 | 14 | System.out.println("Int value " + i); 15 | System.out.println("Long value " + l); 16 | System.out.println("Float value " + f); 17 | System.out.println("Double value " + d); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/typeCasting/TypeCastingExample2.java: -------------------------------------------------------------------------------- 1 | package typeCasting; 2 | 3 | public class TypeCastingExample2 { 4 | 5 | public static void main(String[] args) { 6 | double d = 300.09; 7 | 8 | long l = (long) d; 9 | 10 | int i = (int) l; 11 | 12 | short b = (short)d; 13 | 14 | System.out.println("Double value " + d); 15 | 16 | System.out.println("Long value " + l); 17 | 18 | System.out.println("Int value " + i); 19 | 20 | System.out.println("Short value " + b); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/typeCasting/TypeCastingExample3.java: -------------------------------------------------------------------------------- 1 | package typeCasting; 2 | 3 | public class TypeCastingExample3 { 4 | 5 | public static void main(String args[]) { 6 | byte b; 7 | int i = 259; 8 | double d = 412.142; 9 | 10 | System.out.println("Convert int to byte."); 11 | 12 | b = (byte) i; 13 | System.out.println("i = " + i + " b = " + b); 14 | 15 | System.out.println("Convert double to byte."); 16 | b = (byte) d; 17 | System.out.println("d = " + d + " b= " + b); 18 | } 19 | } -------------------------------------------------------------------------------- /src/typeCasting/TypeCastingExample4.java: -------------------------------------------------------------------------------- 1 | package typeCasting; 2 | 3 | public class TypeCastingExample4 { 4 | 5 | public static void main(String args[]) { 6 | byte b = 47; 7 | char c = 'b'; 8 | short s = 1026; 9 | int i = 80000; 10 | float f = 8.67f; 11 | double d = .923; 12 | 13 | double result = (f * b) + (i / c) - (d * s); 14 | 15 | System.out.println("result = " + result); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/wrapperClassInjava/Ecample2.java: -------------------------------------------------------------------------------- 1 | package wrapperClassInjava; 2 | 3 | public class Ecample2 { 4 | public static void main(String[] args) { 5 | 6 | String s1; 7 | 8 | Double double1 = new Double(0.0/0.0); 9 | System.out.println(double1.isNaN()); 10 | double1.intValue(); 11 | double1.byteValue(); 12 | double1.shortValue(); 13 | 14 | Double double2 = new Double(1.0/0.0); 15 | System.out.println(double2.isNaN()); 16 | 17 | Boolean boolean1 = new Boolean(true); 18 | Boolean boolean2 = new Boolean("test"); 19 | 20 | System.out.println(boolean1.compareTo(boolean2)); 21 | System.out.println(boolean1.booleanValue()); 22 | 23 | System.out.println(Boolean.parseBoolean("true")); 24 | 25 | System.out.println(Boolean.parseBoolean("CDA")); 26 | 27 | 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/wrapperClassInjava/Example2.java: -------------------------------------------------------------------------------- 1 | package wrapperClassInjava; 2 | 3 | public class Example2 { 4 | 5 | public static void main(String args[]) { 6 | char val = 'A'; 7 | int str1 = Integer.valueOf(val); 8 | System.out.print(str1); 9 | //int str = Integer.parseInt(val); 10 | //System.out.print(str); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/wrapperClassInjava/Snippet.java: -------------------------------------------------------------------------------- 1 | package wrapperClassInjava; 2 | 3 | public class Snippet { 4 | public static void main(String args[]) { 5 | // Binary to decimal conversion 6 | System.out.println(Long.parseLong("101010", 2)); 7 | 8 | // Octal to decimal conversion 9 | int data = Integer.parseInt("463", 8); 10 | System.out.println(Byte.parseByte("463", 8)); 11 | 12 | // Hexadecimal to decimal conversion 13 | System.out.println(Long.parseLong("4AC", 16)); 14 | 15 | // String to decimal conversion - throughs NumberFormat Exception, Because it 16 | // contains D 17 | System.out.println(Integer.parseInt("6BDC", 13)); 18 | 19 | 20 | System.out.println(Byte.valueOf("101010", 2)); 21 | 22 | // Octal to decimal conversion 23 | int data1 = Integer.valueOf("463", 8); 24 | System.out.println(Long.valueOf("463", 8)); 25 | 26 | // Hexadecimal to decimal conversion 27 | System.out.println(Integer.valueOf("4AC", 16)); 28 | 29 | 30 | 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /src/wrapperClassInjava/Test1.java: -------------------------------------------------------------------------------- 1 | package wrapperClassInjava; 2 | 3 | public class Test1 { 4 | public static void main(String args[]) { 5 | String s = "77"; 6 | int str = Integer.parseInt(s); 7 | System.out.print(str); 8 | Integer str1 = Integer.valueOf(s); 9 | System.out.print(str1); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /src/wrapperClassInjava/Test3.java: -------------------------------------------------------------------------------- 1 | package wrapperClassInjava; 2 | 3 | class Test3 { 4 | public static void main(String args[]) { 5 | int val = 99; 6 | int str1 = Integer.valueOf(val); 7 | System.out.print(str1); 8 | // int str = Integer.parseInt(val); 9 | //System.out.print(str); 10 | } 11 | } --------------------------------------------------------------------------------