├── .gitignore ├── README.md ├── section3 └── HelloWorld │ ├── .gitignore │ ├── README.md │ └── src │ ├── Demo.java │ └── HelloWorld.java ├── section4 ├── .gitignore ├── README.md └── src │ ├── ArithmeticMain.java │ ├── ArithmeticOperations.java │ ├── Car.java │ ├── CarMain.java │ ├── Employee.java │ ├── EmployeeMain.java │ ├── HelloWorld.java │ ├── MethodInvocationDemo.java │ └── NullDemo.java ├── section5 ├── .gitignore ├── README.md └── src │ ├── Customer.java │ ├── JavaDocCommentsDemo.java │ ├── MultiLineCommentsDemo.java │ └── SingleLineCommentDemo.java ├── section6 ├── .gitignore ├── README.md └── src │ ├── ChangeCaseDemo.java │ ├── CharAtMethodDemo.java │ ├── ConcatMethodDemo.java │ ├── ConvertStringDemo.java │ ├── EmptyCheckDemo.java │ ├── EscapeSeqDemo.java │ ├── InternMethodDemo.java │ ├── LengthMethodDemo.java │ ├── PalindromeDemo.java │ ├── ParsingDemo.java │ ├── PrintfDemo.java │ ├── StringComparisonDemo.java │ ├── StringFormatDemo.java │ ├── StringImmutableDemo.java │ ├── StringJoinDemo.java │ ├── StringMutableDemo.java │ ├── StringPoolDemo.java │ ├── StringReplaceDemo.java │ ├── StringSearchDemo.java │ ├── StringSplitDemo.java │ ├── StringTrimDemo.java │ ├── SubStringDemo.java │ └── TextBlockDemo.java ├── section7 ├── .gitignore ├── README.md └── src │ ├── ArithmeticOperatorsDemo.java │ ├── AssignmentOperatorDemo.java │ ├── BitwiseOperatorsDemo.java │ ├── LogicalOperatorsDemo.java │ ├── Person.java │ ├── PrecedenceAssociativityDemo.java │ ├── RelationalOperatorsDemo.java │ ├── StringConcatenationDemo.java │ └── TernaryOperatorDemo.java ├── section8 ├── .gitignore ├── README.md └── src │ ├── BreakStatementDemo.java │ ├── CanVote.java │ ├── ContinueStatementDemo.java │ ├── DoWhileStatementDemo.java │ ├── EvenOddNumber.java │ ├── FindTheDay.java │ ├── ForLoopDemo.java │ ├── LocalVariablesDemo.java │ ├── MessageForDay.java │ ├── NestedForLoopDemo.java │ ├── NotOperatorExample.java │ ├── ReturnStatementDemo.java │ ├── SwitchCaseDemo.java │ ├── SwitchExpressionDemo.java │ ├── TernaryOperator.java │ └── WhileStatementDemo.java ├── section9 ├── .gitignore ├── README.md └── src │ └── com │ └── eazybytes │ ├── app │ ├── AccessModifiersDemo.java │ ├── MainClass.java │ └── MyOuterClass.java │ ├── model │ ├── Class1.java │ ├── Employee.java │ ├── Person.java │ └── Vehicle.java │ ├── service │ ├── Class1.java │ └── VehicleService.java │ └── utility │ └── MyConstants.java ├── section_10 ├── .gitignore ├── README.md └── src │ └── com │ └── eazybytes │ └── marvel │ ├── animals │ ├── Cat.java │ └── Dog.java │ ├── app │ ├── AnimalUtility.java │ ├── ConstructorDemo.java │ ├── DownCastingDemo.java │ ├── DynamicPoly.java │ ├── MarvelsMain.java │ ├── StaticPoly.java │ ├── TestFieldHiding.java │ ├── TestMethodHiding.java │ └── UpcastingDemo.java │ ├── base │ ├── Animal.java │ ├── Engine.java │ ├── Person.java │ ├── Subject.java │ └── Vehicle.java │ ├── heros │ ├── CaptainAmerica.java │ ├── IronMan.java │ └── SpiderMan.java │ ├── sealed │ ├── Employee.java │ ├── Person.java │ └── Student.java │ ├── subjects │ └── Mathematics.java │ └── vehicle │ └── Car.java ├── section_11 ├── .gitignore ├── README.md └── src │ └── com │ └── eazybytes │ └── marvel │ └── hero │ ├── Hero.java │ ├── MyFunctionalInterface.java │ ├── Person.java │ ├── SuperHero.java │ ├── app │ └── MarvelHeroDemo.java │ └── impl │ ├── CaptainAmerica.java │ ├── Developer.java │ ├── Employee.java │ ├── IronMan.java │ └── SpiderMan.java ├── section_12 ├── .gitignore ├── README.md └── src │ └── com │ └── eazybytes │ ├── main │ ├── AddMatricesDemo.java │ ├── ArrayCopyDemo.java │ ├── ArrayForEachLoopDemo.java │ ├── ArrayForLoopDemo.java │ ├── ArrayLengthDemo.java │ ├── ArraysBasics.java │ ├── FillDemo.java │ ├── JaggedArrayDemo.java │ ├── SearchDemo.java │ ├── SortDemo.java │ ├── ThreeDArrayDemo.java │ ├── ToStringDemo.java │ └── TwoDArrayDemo.java │ └── model │ └── Person.java ├── section_13 ├── .gitignore ├── README.md └── src │ └── com │ └── eazybytes │ ├── input │ ├── BufferedReaderDemo.java │ ├── BufferedReaderEvenOddDemo.java │ ├── BufferedReaderSumDemo.java │ ├── FileReaderWithBFR.java │ ├── FileReaderWithScanner.java │ ├── JavaBasicInputDemo.java │ ├── PrimeNumberChecker.java │ ├── PrimeNumberCheckerScanner.java │ └── ScannerDemo.java │ └── log │ └── LoggingDemo.java ├── section_14 ├── .gitignore ├── README.md └── src │ └── com │ └── eazybytes │ └── exception │ ├── AcceptAgeDetails.java │ ├── ArrayIndexOutofBoundsExceptionDemo.java │ ├── CheckedExceptionDemo.java │ ├── DivideByZero.java │ ├── Division.java │ ├── ExceptionDemo.java │ ├── ExceptionPropogationDemo.java │ ├── MultipleCatchDemo.java │ ├── NestedTryDemo.java │ ├── ThrowDemo.java │ ├── ThrowsDemo.java │ ├── TryWithResourcesDemo.java │ ├── UnCheckedExceptionsDemo.java │ └── custom │ ├── DivideByZeroException.java │ └── InvalidAgeException.java ├── section_15 ├── .gitignore ├── README.md └── src │ └── com │ └── eazybytes │ └── object │ └── demo │ ├── CloneDemo.java │ ├── CloneExample.java │ ├── Course.java │ ├── FinalizeDemo.java │ ├── GetClassDemo.java │ ├── HashCodeEqualsDemo.java │ ├── ImmutableDemo.java │ ├── ImmutablePerson.java │ ├── MutableDemo.java │ ├── MutablePerson.java │ ├── Person.java │ ├── PersonRecord.java │ ├── RecordDemo.java │ ├── StringDemo.java │ ├── Student.java │ └── VarDemo.java ├── section_16 ├── .gitignore ├── README.md └── src │ └── com │ └── eazybytes │ └── wrapper │ ├── AutoboxingUnboxingDemo.java │ ├── BoxingDemo.java │ ├── UnboxingDemo.java │ └── WrapperObjectsCaching.java ├── section_17 ├── .gitignore ├── README.md └── src │ └── com │ └── eazybytes │ └── list │ ├── ArrayListDemo.java │ ├── ArrayListForEachExample.java │ ├── ArrayListIteratorExample.java │ ├── ArrayListListIteratorExample.java │ ├── ArrayVsArrayList.java │ ├── DiamondOperator.java │ ├── ImmutableListDemo.java │ ├── LastCharComparator.java │ ├── SortingDemo.java │ ├── Student.java │ ├── StudentComparator.java │ ├── StudentMarkComparator.java │ └── StudentSortingDemo.java ├── section_18 ├── .gitignore ├── README.md └── src │ └── com │ └── eazybytes │ └── list │ ├── LastCharComparator.java │ ├── LinkedListDemo.java │ ├── LinkedListIteration.java │ └── SortingDemo.java ├── section_19 ├── .gitignore ├── README.md └── src │ └── com │ └── eazybytes │ └── generics │ ├── CovarianceDemo.java │ ├── GenericCodeDemo.java │ ├── GenericMethodDemo.java │ ├── GenericPair.java │ ├── LowerBoundWildCardDemo.java │ ├── NonGenericCodeDemo.java │ ├── Pair.java │ ├── UnBoundedWildCardDemo.java │ ├── UpperBoundWildCardDemo.java │ ├── WithOutGenericsDemo.java │ └── model │ ├── Developer.java │ ├── Employee.java │ └── Manager.java ├── section_20 ├── .gitignore ├── README.md └── src │ └── com │ └── eazybytes │ └── map │ ├── HashMapDemo.java │ ├── HashMapIterationDemo.java │ ├── ImmutableMapDemo.java │ ├── LinkedHashMapDemo.java │ └── TreeMapDemo.java ├── section_21 ├── .gitignore ├── README.md └── src │ └── com │ └── eazybytes │ └── set │ ├── HashSetDemo.java │ ├── HashSetIterationDemo.java │ ├── ImmutableSetDemo.java │ ├── LinkedHashSetDemo.java │ ├── SetOperationsDemo.java │ └── TreeSetDemo.java ├── section_22 ├── .gitignore ├── README.md └── src │ └── com │ └── eazybytes │ └── enumeration │ ├── AdvancedPriorityEnum.java │ ├── AdvancedPriorityEnumTest.java │ ├── Car.java │ ├── Day.java │ ├── EnumSetDemo.java │ ├── Grades.java │ ├── InternalEnumMethodsDemo.java │ ├── Priority.java │ ├── PriorityEnum.java │ ├── Size.java │ ├── TaskPriorityConstantDemo.java │ └── TaskUtil.java ├── section_23 ├── .gitignore ├── README.md └── src │ └── com │ └── eazybytes │ ├── legacy │ ├── CalendarDemo.java │ ├── DateFormattingDemo.java │ ├── JavaSQLDate.java │ ├── JavaUtilDate.java │ ├── LegacyDateAPIDemo.java │ ├── TimeZoneDatesDemo.java │ └── TimeZoneIDsList.java │ └── newapi │ ├── DateTimeFormatterDemo.java │ ├── FromAndWithMethodsDemo.java │ ├── GetPlusMinusMethodsDemo.java │ ├── InstantDemo.java │ ├── JapaneseCalendarDemo.java │ ├── MultiDivNegateDemo.java │ ├── NewDateTimeAPIDemo.java │ ├── OfMethodsDemo.java │ ├── OffsetDateTimeDemo.java │ ├── OffsetTimeDemo.java │ ├── ParsingDemo.java │ ├── PeriodDemo.java │ ├── ToAndAtMethodsDemo.java │ ├── TruncatedToMethodDemo.java │ ├── ZoneIDListDemo.java │ ├── ZonedDateTimeDSTDemo.java │ └── ZonedDateTimeDemo.java ├── section_24 ├── .gitignore ├── README.md └── src │ └── com │ └── eazybytes │ └── lambda │ ├── AnonymousClassDemo.java │ ├── ArithmeticOperation.java │ ├── BiFunctionsDemo.java │ ├── ConsumerDemo.java │ ├── FunctionDemo.java │ ├── Hello.java │ ├── LamdaExpressionDemo.java │ ├── LexicalScopeTest.java │ ├── PredicateDemo.java │ ├── PrimitiveFunctionsDemo.java │ ├── Printer.java │ ├── SupplierDemo.java │ ├── ThisDemo.java │ └── UnaryOperatorDemo.java ├── section_25 ├── .gitignore ├── README.md └── src │ └── com │ └── eazybytes │ └── method │ └── reference │ ├── ArithmeticOperation.java │ ├── ClassMethodReference.java │ ├── ConstructorReferenceDemo.java │ ├── InstanceMethodReference.java │ ├── Product.java │ ├── ProductInterface.java │ └── StaticMethodReference.java ├── section_26 ├── .gitignore ├── README.md └── src │ └── com │ └── eazybytes │ └── streams │ ├── Item.java │ ├── ParallelStreamDemo.java │ ├── Person.java │ ├── Product.java │ ├── StreamCollectOperationDemo.java │ ├── StreamCollectingAndThenDemo.java │ ├── StreamCreationDemo.java │ ├── StreamFilterOperationDemo.java │ ├── StreamFindMatchOperationDemo.java │ ├── StreamFlatMapOperationDemo.java │ ├── StreamGroupingByDemo.java │ ├── StreamLimitOperationDemo.java │ ├── StreamMapOperationDemo.java │ ├── StreamPartitioningByDemo.java │ ├── StreamReduceOperationDemo.java │ ├── StreamSkipOperationDemo.java │ └── StreamTraverseDemo.java ├── section_27 ├── .gitignore ├── README.md └── src │ └── com │ └── eazybytes │ └── optional │ ├── OptionalDemo.java │ └── StreamsAPINullCheckTip.java ├── section_28 ├── .gitignore ├── README.md └── src │ └── com │ └── eazybytes │ └── multithreading │ ├── Counter.java │ ├── CurrentThreadDemo.java │ ├── DeadLockDemo.java │ ├── Hello.java │ ├── HelloThread.java │ ├── HelloThread1.java │ ├── JoinExample.java │ ├── NonThreadDemo.java │ ├── PriorityExample.java │ ├── ProducerConsumerExample.java │ ├── SharedBooleanResource.java │ ├── SharedResource.java │ ├── SleepDemo.java │ ├── SumOfIntsDemo.java │ ├── SumOfIntsThreadDemo.java │ ├── SumThread.java │ ├── SynchronizationExample.java │ ├── ThreadDemo.java │ ├── ThreadIDNameDemo.java │ ├── ThreadPriorityDemo.java │ ├── UnSynchronizationExample.java │ ├── VirtualThreadDemo.java │ └── VolatileExample.java └── section_29 ├── .gitignore ├── README.md └── src └── com └── eazybytes ├── java22 ├── UnnamedPatterns.java ├── UnnamedVariables.java └── Vehicle.java └── java23 └── MarkDownComments.java /.gitignore: -------------------------------------------------------------------------------- 1 | HELP.md 2 | target/ 3 | !.mvn/wrapper/maven-wrapper.jar 4 | !**/src/main/**/target/ 5 | !**/src/test/**/target/ 6 | 7 | ### STS ### 8 | .apt_generated 9 | .classpath 10 | .factorypath 11 | .project 12 | .settings 13 | .springBeans 14 | .sts4-cache 15 | 16 | ### IntelliJ IDEA ### 17 | .idea 18 | *.iws 19 | *.iml 20 | *.ipr 21 | .DS_Store 22 | 23 | ### NetBeans ### 24 | /nbproject/private/ 25 | /nbbuild/ 26 | /dist/ 27 | /nbdist/ 28 | /.nb-gradle/ 29 | build/ 30 | !**/src/main/**/build/ 31 | !**/src/test/**/build/ 32 | -------------------------------------------------------------------------------- /section3/HelloWorld/.gitignore: -------------------------------------------------------------------------------- 1 | ### IntelliJ IDEA ### 2 | out/ 3 | !**/src/main/**/out/ 4 | !**/src/test/**/out/ 5 | 6 | ### Eclipse ### 7 | .apt_generated 8 | .classpath 9 | .factorypath 10 | .project 11 | .settings 12 | .springBeans 13 | .sts4-cache 14 | bin/ 15 | !**/src/main/**/bin/ 16 | !**/src/test/**/bin/ 17 | 18 | ### NetBeans ### 19 | /nbproject/private/ 20 | /nbbuild/ 21 | /dist/ 22 | /nbdist/ 23 | /.nb-gradle/ 24 | 25 | ### VS Code ### 26 | .vscode/ 27 | 28 | ### Mac OS ### 29 | .DS_Store -------------------------------------------------------------------------------- /section3/HelloWorld/src/HelloWorld.java: -------------------------------------------------------------------------------- 1 | public class HelloWorld { 2 | 3 | public static void main(String[] args) { 4 | System.out.println("Hello Madan"); 5 | } 6 | 7 | } 8 | -------------------------------------------------------------------------------- /section4/.gitignore: -------------------------------------------------------------------------------- 1 | ### IntelliJ IDEA ### 2 | out/ 3 | !**/src/main/**/out/ 4 | !**/src/test/**/out/ 5 | 6 | ### Eclipse ### 7 | .apt_generated 8 | .classpath 9 | .factorypath 10 | .project 11 | .settings 12 | .springBeans 13 | .sts4-cache 14 | bin/ 15 | !**/src/main/**/bin/ 16 | !**/src/test/**/bin/ 17 | 18 | ### NetBeans ### 19 | /nbproject/private/ 20 | /nbbuild/ 21 | /dist/ 22 | /nbdist/ 23 | /.nb-gradle/ 24 | 25 | ### VS Code ### 26 | .vscode/ 27 | 28 | ### Mac OS ### 29 | .DS_Store -------------------------------------------------------------------------------- /section4/src/ArithmeticMain.java: -------------------------------------------------------------------------------- 1 | public class ArithmeticMain { 2 | 3 | public static void main(String[] args) { 4 | int result = ArithmeticOperations.addition(20,4); 5 | System.out.println(result); 6 | System.out.println(ArithmeticOperations.PI_VALUE); 7 | ArithmeticOperations arithmeticOperations = new ArithmeticOperations(); 8 | int resultFromInstanceMethod = arithmeticOperations.sum(20,5); 9 | System.out.println(resultFromInstanceMethod); 10 | System.out.println(arithmeticOperations.piValue); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /section4/src/ArithmeticOperations.java: -------------------------------------------------------------------------------- 1 | public class ArithmeticOperations { 2 | 3 | double piValue = 3.14; 4 | static final double PI_VALUE = 3.14; 5 | 6 | public static void main(String[] args) { 7 | ArithmeticOperations arithmeticOperations = new ArithmeticOperations(); 8 | int result = arithmeticOperations.sum(20, 5); 9 | System.out.println(result); 10 | } 11 | 12 | public int sum(int num1, int num2) { 13 | subtract(num1, num2); 14 | addition(num1, num2); 15 | int result = num1 + num2; 16 | return result; 17 | } 18 | 19 | public int subtract(int num1, int num2) { 20 | int result = num1 - num2; 21 | return result; 22 | } 23 | 24 | public static int addition(int num1, int num2) { 25 | int result = num1 + num2; 26 | return result; 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /section4/src/Car.java: -------------------------------------------------------------------------------- 1 | public class Car { 2 | 3 | String model; 4 | String color; 5 | int horsePower; 6 | static final byte NO_OF_WHEELS = 4; 7 | static byte noOfEngines; 8 | 9 | static { 10 | noOfEngines = 1; 11 | System.out.println("static blocking is being executed"); 12 | } 13 | 14 | { 15 | System.out.println("Car object is being created...."); 16 | } 17 | 18 | public Car () { 19 | 20 | } 21 | 22 | public Car (String model, String color, int horsePower) { 23 | this.model = model; 24 | this.horsePower = horsePower; 25 | this.color =color; 26 | } 27 | 28 | public void startCar( ) { 29 | System.out.println("Vehicle started..."); 30 | } 31 | 32 | public String stopCar( ) { 33 | String output = "Vehicle stopped..."; 34 | return output; 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /section4/src/CarMain.java: -------------------------------------------------------------------------------- 1 | public class CarMain { 2 | 3 | static { 4 | System.out.println("static block from the same class"); 5 | } 6 | 7 | public static void main(String[] args) { 8 | System.out.println("Main method invocation started"); 9 | Car car1 = new Car(); 10 | Car car2 = new Car("Camry", "Black", 200); 11 | System.out.println(Car.noOfEngines); 12 | } 13 | 14 | } 15 | -------------------------------------------------------------------------------- /section4/src/Employee.java: -------------------------------------------------------------------------------- 1 | public class Employee { 2 | 3 | String firstName; 4 | String lastName; 5 | byte age; 6 | char gender; 7 | static final String EMPLOYER_NAME = "Google"; 8 | 9 | public Employee() { 10 | this("Will", "Smith", (byte) 55, 'M'); 11 | System.out.println("Object is getting created in Default Constructor....."); 12 | } 13 | 14 | public Employee(String firstName, String lastName, byte age, char gender) { 15 | this.firstName = firstName; 16 | this.lastName = lastName; 17 | this.age = age; 18 | this.gender = gender; 19 | System.out.println("Object is getting created in overloaded Constructor....."); 20 | } 21 | 22 | public byte getAge( ) { 23 | return age; 24 | } 25 | 26 | public char getGender( ) { 27 | return gender; 28 | } 29 | 30 | } 31 | -------------------------------------------------------------------------------- /section4/src/EmployeeMain.java: -------------------------------------------------------------------------------- 1 | public class EmployeeMain { 2 | 3 | public static void main(String[] args) { 4 | 5 | /*Employee employee1 = new Employee(); 6 | Employee employee2 = new Employee();*/ 7 | 8 | Employee employee1 = new Employee("John", "Doe", (byte) 30, 'M'); 9 | Employee employee2 = new Employee("Max", "Steve", (byte) 25, 'F'); 10 | Employee employee3 = new Employee(); 11 | 12 | /*employee.firstName = "John"; 13 | employee.lastName = "Doe"; 14 | employee.age = 30; 15 | employee.gender = 'M';*/ 16 | 17 | System.out.println(employee1.getAge()); 18 | System.out.println(employee1.getGender()); 19 | 20 | System.out.println(employee2.getAge()); 21 | System.out.println(employee2.getGender()); 22 | 23 | System.out.println(Employee.EMPLOYER_NAME); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /section4/src/HelloWorld.java: -------------------------------------------------------------------------------- 1 | public class HelloWorld { 2 | 3 | public static void main(String[] myArgs) { 4 | System.out.println("Hello World !!!"); 5 | } 6 | 7 | public static void main(String[] myArgs, float num) { 8 | System.out.println("Hello World !!!"); 9 | } 10 | 11 | public double main(){ 12 | return 3.14; 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /section4/src/MethodInvocationDemo.java: -------------------------------------------------------------------------------- 1 | public class MethodInvocationDemo { 2 | 3 | public static void main(String[] args) { 4 | MethodInvocationDemo demoObj = new MethodInvocationDemo(); 5 | demoObj.method1(); 6 | } 7 | 8 | public void method1() { 9 | int number = 10; 10 | System.out.println("Method 1"); 11 | String output = method2(); 12 | System.out.println(output); 13 | } 14 | 15 | public String method2() { 16 | String output = "Hello World"; 17 | System.out.println("Method 2"); 18 | method3("Hi"); 19 | return output; 20 | } 21 | 22 | public void method3(String input) { 23 | System.out.println(input); 24 | System.out.println("Method 3"); 25 | method4(10); 26 | } 27 | 28 | public void method4(int num) { 29 | MethodInvocationDemo demoObj = new MethodInvocationDemo(); 30 | System.out.println(num); 31 | System.out.println("Method 4"); 32 | } 33 | 34 | } 35 | -------------------------------------------------------------------------------- /section4/src/NullDemo.java: -------------------------------------------------------------------------------- 1 | public class NullDemo { 2 | 3 | public static void main(String[] args) { 4 | String myString = null; 5 | Employee employeeObject = null; 6 | int age = employeeObject.getAge(); 7 | System.gc(); 8 | } 9 | 10 | } 11 | -------------------------------------------------------------------------------- /section5/.gitignore: -------------------------------------------------------------------------------- 1 | ### IntelliJ IDEA ### 2 | out/ 3 | !**/src/main/**/out/ 4 | !**/src/test/**/out/ 5 | 6 | ### Eclipse ### 7 | .apt_generated 8 | .classpath 9 | .factorypath 10 | .project 11 | .settings 12 | .springBeans 13 | .sts4-cache 14 | bin/ 15 | !**/src/main/**/bin/ 16 | !**/src/test/**/bin/ 17 | 18 | ### NetBeans ### 19 | /nbproject/private/ 20 | /nbbuild/ 21 | /dist/ 22 | /nbdist/ 23 | /.nb-gradle/ 24 | 25 | ### VS Code ### 26 | .vscode/ 27 | 28 | ### Mac OS ### 29 | .DS_Store -------------------------------------------------------------------------------- /section5/src/Customer.java: -------------------------------------------------------------------------------- 1 | /* 2 | This class represents a customer in Bank app. 3 | It contains information such as firstName, 4 | lastName, DOB, address and account details. 5 | */ 6 | public class Customer { 7 | } 8 | -------------------------------------------------------------------------------- /section5/src/JavaDocCommentsDemo.java: -------------------------------------------------------------------------------- 1 | /** 2 | * This is a sample class to show demo about 3 | * javadoc 4 | * 5 | *

6 | * This is a sample demo of 7 | * paragraph 8 | *

9 | * 10 | * @see MultiLineCommentsDemo 11 | * @author Madan Reddy 12 | * @since 1.0 13 | */ 14 | public class JavaDocCommentsDemo { 15 | 16 | public static void main(String[] args) { 17 | 18 | } 19 | 20 | 21 | /** 22 | * Take two {@code int} numbers as input 23 | * and add them 24 | *

25 | * For example, 2+3 =5 26 | *

27 | * @param num1 Represent first number 28 | * @param num2 Represent second number 29 | * @return sum value of first and second number 30 | */ 31 | public int sum (int num1, int num2) { 32 | return num1+num2; 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /section5/src/MultiLineCommentsDemo.java: -------------------------------------------------------------------------------- 1 | public class MultiLineCommentsDemo { 2 | 3 | /* 4 | Based on business requirements, the end user is 5 | allowed to retry a maximum of 3 login attempts. 6 | Using the below constant, the same is going to be 7 | controlled. If the requirement changes, then change 8 | the below value 9 | */ 10 | static final int MAX_RETRY_ATTEMPTS = 3; 11 | 12 | public static void main(String[] args) { 13 | MultiLineCommentsDemo obj = new MultiLineCommentsDemo(); 14 | double totalArea = obj.calculateRectangleArea(24.5, 34.6); 15 | System.out.println(totalArea); 16 | } 17 | 18 | /* 19 | This method calculates the area of the rectangle based 20 | on given length and width. The logic it is going to have 21 | is multiply two given input method arguments and return 22 | the same to the caller 23 | */ 24 | public double calculateRectangleArea (double length, double width) { 25 | return length*width; 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /section5/src/SingleLineCommentDemo.java: -------------------------------------------------------------------------------- 1 | public class SingleLineCommentDemo { 2 | 3 | int age; // Represent the age of the Customer 4 | 5 | // Maximum number of login retry attempts allowed 6 | static final int MAX_RETRY_ATTEMPTS = 3; 7 | 8 | // main method is used to start the Java program 9 | public static void main(String[] args) { 10 | 11 | // Y indicates YES 12 | char y = 'Y'; 13 | // N indicates NO 14 | char n = 'N'; 15 | 16 | sum(12, 8); 17 | 18 | } 19 | 20 | public static void sum (int num1, int num2){ 21 | int num3 = num1 + num2; 22 | // System.out.println(num3); 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /section6/.gitignore: -------------------------------------------------------------------------------- 1 | ### IntelliJ IDEA ### 2 | out/ 3 | !**/src/main/**/out/ 4 | !**/src/test/**/out/ 5 | 6 | ### Eclipse ### 7 | .apt_generated 8 | .classpath 9 | .factorypath 10 | .project 11 | .settings 12 | .springBeans 13 | .sts4-cache 14 | bin/ 15 | !**/src/main/**/bin/ 16 | !**/src/test/**/bin/ 17 | 18 | ### NetBeans ### 19 | /nbproject/private/ 20 | /nbbuild/ 21 | /dist/ 22 | /nbdist/ 23 | /.nb-gradle/ 24 | 25 | ### VS Code ### 26 | .vscode/ 27 | 28 | ### Mac OS ### 29 | .DS_Store -------------------------------------------------------------------------------- /section6/src/ChangeCaseDemo.java: -------------------------------------------------------------------------------- 1 | public class ChangeCaseDemo { 2 | 3 | public static void main(String[] args) { 4 | String originalString = "Java"; 5 | String upperCaseString = originalString.toUpperCase(); 6 | String lowerCaseString = originalString.toLowerCase(); 7 | String specialString = "Java1@Best"; 8 | String specialUpperCaseString = specialString.toUpperCase(); 9 | String specialLowerCaseString = specialString.toLowerCase(); 10 | } 11 | 12 | } 13 | -------------------------------------------------------------------------------- /section6/src/CharAtMethodDemo.java: -------------------------------------------------------------------------------- 1 | public class CharAtMethodDemo { 2 | 3 | public static void main(String[] args) { 4 | String java = "JAVA"; 5 | char j = java.charAt(0); 6 | char exception = java.charAt(4); 7 | } 8 | 9 | } 10 | -------------------------------------------------------------------------------- /section6/src/ConcatMethodDemo.java: -------------------------------------------------------------------------------- 1 | public class ConcatMethodDemo { 2 | 3 | public static void main(String[] args) { 4 | String hello = "Hello"; 5 | hello = hello + " " + "World"; 6 | System.out.println(hello); 7 | 8 | String hello1 = "Hello"; 9 | hello1 = hello1.concat(" ").concat("World"); 10 | System.out.println(hello1); 11 | 12 | String emptyString = ""; 13 | String nullString = null; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /section6/src/ConvertStringDemo.java: -------------------------------------------------------------------------------- 1 | public class ConvertStringDemo { 2 | 3 | public static void main(String[] args) { 4 | int intValue = 42; 5 | double doubleValue = 3.14; 6 | boolean boolValue = true; 7 | 8 | String str1 = String.valueOf(intValue); 9 | String str2 = String.valueOf(doubleValue); 10 | String str3 = String.valueOf(boolValue); 11 | String str4 = String.valueOf('M'); 12 | 13 | int age = 30; 14 | String message = "My age is : "+ age; 15 | String piValue = ""+ 3.14; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /section6/src/EmptyCheckDemo.java: -------------------------------------------------------------------------------- 1 | public class EmptyCheckDemo { 2 | 3 | public static void main(String[] args) { 4 | String myString = ""; 5 | boolean isEmpty = myString.isEmpty(); 6 | boolean isLengthZero = myString.length()==0; 7 | boolean isEqualEmpty = "".equals(myString); 8 | 9 | String nullString = null; 10 | boolean isnullEmpty = "".equals(nullString); 11 | // boolean isEmptyNull = nullString.length()==0; 12 | String blankString = " "; 13 | boolean isBlankEmpty = blankString.isEmpty(); 14 | boolean isBlank = blankString.isBlank(); 15 | } 16 | 17 | } 18 | -------------------------------------------------------------------------------- /section6/src/EscapeSeqDemo.java: -------------------------------------------------------------------------------- 1 | public class EscapeSeqDemo { 2 | 3 | public static void main(String[] args) { 4 | String name = "\"Madan\""; 5 | System.out.println(name); 6 | 7 | String m = "\u004D"; 8 | System.out.println(m); 9 | String unicodeName = "\u004Dadan\u0021"; 10 | System.out.println(unicodeName); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /section6/src/InternMethodDemo.java: -------------------------------------------------------------------------------- 1 | public class InternMethodDemo { 2 | 3 | public static void main(String[] args) { 4 | String hello = "Hello"; 5 | String obj = new String("Hello").intern(); 6 | System.out.println(hello==obj); 7 | 8 | String s1 = "hello"; 9 | String s2 = new String("hello"); 10 | System.out.println(s1==s2); 11 | String s3 = s2.intern(); 12 | System.out.println(s1==s3); 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /section6/src/LengthMethodDemo.java: -------------------------------------------------------------------------------- 1 | public class LengthMethodDemo { 2 | 3 | public static void main(String[] args) { 4 | String str1 = "Hello"; 5 | String str2 = "World"; 6 | String combined = str1+ " "+str2; 7 | 8 | int length1 = str1.length(); 9 | int length2 = str2.length(); 10 | int length3 = combined.length(); 11 | 12 | int emptyLength = "".length(); 13 | int length4 = "Hello".length(); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /section6/src/PalindromeDemo.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Class helps to identify a given String is 3 | * a palindrome or not. 4 | * 5 | *

6 | * Examples of palindromes are, 7 | *

14 | *

15 | * 16 | */ 17 | public class PalindromeDemo { 18 | public static void main(String[] args) { 19 | String input = "mom"; 20 | StringBuffer stringBuffer = new StringBuffer(input); 21 | boolean isPalindrome = input.equals(stringBuffer.reverse().toString()); 22 | System.out.printf("Is the given String %s is a palindrome or not ? : %b%n", input, isPalindrome); 23 | String textBlock = """ 24 | """; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /section6/src/ParsingDemo.java: -------------------------------------------------------------------------------- 1 | public class ParsingDemo { 2 | 3 | public static void main(String[] args) { 4 | String strInt = "456"; 5 | int num = Integer.parseInt(strInt); 6 | String strDouble = "3.14"; 7 | double num1 = Double.parseDouble(strDouble); 8 | String strFloat = "2.718"; 9 | float num2 = Float.parseFloat(strFloat); 10 | String strLong = "3476543210"; 11 | long num3 = Long.parseLong(strLong); 12 | String strBoolean = "true"; 13 | boolean isTrue = Boolean.parseBoolean(strBoolean); 14 | String strName = "madan"; 15 | boolean isName = Boolean.parseBoolean(strName); 16 | String hello = "Hello"; 17 | char firstChar = hello.charAt(0); 18 | char[] charArray = hello.toCharArray(); 19 | char secondChar = charArray[1]; 20 | } 21 | 22 | } 23 | -------------------------------------------------------------------------------- /section6/src/PrintfDemo.java: -------------------------------------------------------------------------------- 1 | public class PrintfDemo { 2 | 3 | public static void main(String[] args) { 4 | /*String result = String.format("Name: %s, Age: %d", "John", 25); 5 | System.out.println(result);*/ 6 | 7 | System.out.printf("Name: %s, Age: %d%n", "John", 25); 8 | System.out.printf("Price: %.2f%n", 19.99); 9 | System.out.printf("Grade: %c%n", 'A'); 10 | System.out.printf("Is Java fun ?: %b%n", true); 11 | 12 | System.out.print("Sample String value"); 13 | System.out.print("Another String value"); 14 | 15 | System.out.println("Sample String value"); 16 | System.out.println("Another String value"); 17 | } 18 | 19 | } 20 | -------------------------------------------------------------------------------- /section6/src/StringComparisonDemo.java: -------------------------------------------------------------------------------- 1 | public class StringComparisonDemo { 2 | 3 | public static void main(String[] args) { 4 | 5 | String str1 = new String("Hey"); 6 | String str2 = new String("Hello"); 7 | String str3 = new String("Hey"); 8 | 9 | boolean b1 = str1.equals(str2); 10 | boolean b2 = str1.equals(str3); 11 | 12 | boolean b3 = str1.equals("Hey"); 13 | boolean b4 = "Hey".equals(str1); 14 | boolean b5 = "Hey".equals("Hello"); 15 | 16 | String str4 ="java"; 17 | String str5 ="JAVA"; 18 | boolean b6 = str4.equalsIgnoreCase(str5); 19 | 20 | int comparison1 = "java".compareTo("java"); 21 | int comparison2 = "java".compareTo("python"); 22 | int comparison3 = "python".compareTo("java"); 23 | 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /section6/src/StringFormatDemo.java: -------------------------------------------------------------------------------- 1 | public class StringFormatDemo { 2 | 3 | public static void main(String[] args) { 4 | String message = "Hello, %s ! You have %d messages."; 5 | String msgForMadan = String.format(message, "Madan", 3); 6 | String msgForSaanvi = String.format(message, "Saanvi", 6); 7 | 8 | String message1 = "The price is $%.2f"; 9 | String price1 = String.format(message1, 19.99); 10 | String price2 = String.format(message1, 9.99); 11 | 12 | String message2 = "The number is %5d"; 13 | String number1 = String.format(message2, 5); 14 | String number2 = String.format(message2, 15); 15 | 16 | String message3 = "My name is %3$s, I am %2$d years old, and I live in %1$s."; 17 | String result = String.format(message3, "NewYork", 25, "Nitin"); 18 | 19 | } 20 | 21 | } 22 | -------------------------------------------------------------------------------- /section6/src/StringImmutableDemo.java: -------------------------------------------------------------------------------- 1 | public class StringImmutableDemo { 2 | 3 | public static void main(String[] args) { 4 | String s1 = "Hello"; 5 | s1 = "Hello World"; 6 | System.out.println(s1); 7 | 8 | final String s2 = "Hi"; 9 | } 10 | 11 | } 12 | -------------------------------------------------------------------------------- /section6/src/StringJoinDemo.java: -------------------------------------------------------------------------------- 1 | public class StringJoinDemo { 2 | 3 | public static void main(String[] args) { 4 | String result = String.join(",", "Hello", "World", "Java"); 5 | String result1 = String.join("", "Java is", "fun and", "powerful"); 6 | } 7 | 8 | } 9 | -------------------------------------------------------------------------------- /section6/src/StringPoolDemo.java: -------------------------------------------------------------------------------- 1 | public class StringPoolDemo { 2 | 3 | public static void main(String[] args) { 4 | String hello = "hello"; 5 | String hi = "hello"; 6 | String hey = "hey"; 7 | System.out.println(hello == hi); 8 | System.out.println(hello.hashCode()); 9 | System.out.println(hi.hashCode()); 10 | System.out.println(hey.hashCode()); 11 | 12 | String obj = new String("hello"); 13 | String obj1 = new String("hello"); 14 | String obj2 = new String("hey"); 15 | System.out.println(obj.hashCode()); 16 | System.out.println(obj1.hashCode()); 17 | System.out.println(obj2.hashCode()); 18 | System.out.println(obj == obj1); 19 | 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /section6/src/StringReplaceDemo.java: -------------------------------------------------------------------------------- 1 | public class StringReplaceDemo { 2 | 3 | public static void main(String[] args) { 4 | String originalString = "Hello, World!"; 5 | String replacedString = originalString.replace('o', '*'); 6 | String replacedString1 = originalString.replace("World","Universe"); 7 | String replacedString2 = originalString.replace("world","Universe"); 8 | 9 | String originalString1 = "abababab"; 10 | String replacedString3 = originalString1.replace("ab","X"); 11 | 12 | String originalString2 = "Java is fun!"; 13 | String replacedString4 = originalString2.replaceAll("a|e|i|o|u", "*"); 14 | 15 | String originalString3 = "apple orange apple banana apple"; 16 | String replacedString5 = originalString3.replaceFirst("apple", "grape"); 17 | 18 | } 19 | 20 | } 21 | -------------------------------------------------------------------------------- /section6/src/StringSearchDemo.java: -------------------------------------------------------------------------------- 1 | public class StringSearchDemo { 2 | 3 | public static void main(String[] args) { 4 | 5 | String originalString = "Hello, World!"; 6 | int index = originalString.indexOf('!'); 7 | int index1 = originalString.indexOf("World"); 8 | int index2 = originalString.indexOf("@"); 9 | 10 | boolean isContains = originalString.contains("World"); 11 | boolean isPresent = originalString.contains("@"); 12 | 13 | boolean startsWith = originalString.startsWith("Hello"); 14 | boolean endsWith = originalString.endsWith("ld!"); 15 | 16 | boolean isMatched = originalString.matches(".*World.*"); 17 | } 18 | 19 | } 20 | -------------------------------------------------------------------------------- /section6/src/StringSplitDemo.java: -------------------------------------------------------------------------------- 1 | public class StringSplitDemo { 2 | 3 | public static void main(String[] args) { 4 | String fruits = "apple,orange,banana,grape"; 5 | String[] fruitArray = fruits.split(","); 6 | } 7 | 8 | } 9 | -------------------------------------------------------------------------------- /section6/src/StringTrimDemo.java: -------------------------------------------------------------------------------- 1 | public class StringTrimDemo { 2 | 3 | public static void main(String[] args) { 4 | String java1 = " java ".trim(); 5 | String java2 = "java ".trim(); 6 | String java3 = "\n \t java \n \r ".trim(); 7 | String java4 = "\n \t java \n \r "; 8 | String java5 = " ja va ".trim(); 9 | String java6 = " ja \n va ".trim(); 10 | 11 | boolean isSame = "java".equals("java ".trim()); 12 | 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /section6/src/SubStringDemo.java: -------------------------------------------------------------------------------- 1 | public class SubStringDemo { 2 | 3 | public static void main(String[] args) { 4 | String originalString = "Hello, World!"; 5 | String subString1 = originalString.substring(7); 6 | String subString2 = originalString.substring(0,5); 7 | } 8 | 9 | } 10 | -------------------------------------------------------------------------------- /section6/src/TextBlockDemo.java: -------------------------------------------------------------------------------- 1 | public class TextBlockDemo { 2 | 3 | public static void main(String[] args) { 4 | String input = "Hello, my name is John \n" + 5 | "and I am 25 years old."; 6 | System.out.println(input); 7 | 8 | String htmlCode = "\n" + 9 | "\n" + 10 | "

Hello World.

\n" + 11 | "\n" + 12 | "\n"; 13 | System.out.println(htmlCode); 14 | 15 | String textBlock = """ 16 | 17 | 18 |

Hello World.

19 | 20 | 21 | """; 22 | System.out.println(textBlock); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /section7/.gitignore: -------------------------------------------------------------------------------- 1 | ### IntelliJ IDEA ### 2 | out/ 3 | !**/src/main/**/out/ 4 | !**/src/test/**/out/ 5 | 6 | ### Eclipse ### 7 | .apt_generated 8 | .classpath 9 | .factorypath 10 | .project 11 | .settings 12 | .springBeans 13 | .sts4-cache 14 | bin/ 15 | !**/src/main/**/bin/ 16 | !**/src/test/**/bin/ 17 | 18 | ### NetBeans ### 19 | /nbproject/private/ 20 | /nbbuild/ 21 | /dist/ 22 | /nbdist/ 23 | /.nb-gradle/ 24 | 25 | ### VS Code ### 26 | .vscode/ 27 | 28 | ### Mac OS ### 29 | .DS_Store -------------------------------------------------------------------------------- /section7/src/AssignmentOperatorDemo.java: -------------------------------------------------------------------------------- 1 | public class AssignmentOperatorDemo { 2 | 3 | public static void main(String[] args) { 4 | int num1, num2, num3, num4, num5; 5 | num1 = num2 = num3 = num4 = num5 = 98; 6 | 7 | double dNum1 = 3.14; 8 | double dNum2 = 4.48; 9 | dNum1 = dNum2; 10 | System.out.println(dNum1); 11 | dNum2 = 6.58; 12 | System.out.println(dNum1); 13 | 14 | Person person1 = new Person("Madan"); 15 | Person person2 = new Person("Saanvi"); 16 | person1 = person2; 17 | System.out.println(person1.name); 18 | person2.name = "SAANVI"; 19 | System.out.println(person1.name); 20 | person1.name = "John"; 21 | System.out.println(person2.name); 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /section7/src/BitwiseOperatorsDemo.java: -------------------------------------------------------------------------------- 1 | public class BitwiseOperatorsDemo { 2 | 3 | public static void main(String[] args) { 4 | 5 | int x = 9; 6 | int y = ~x; // -10 7 | System.out.println(y); 8 | 9 | int x1 = 10; 10 | int y1 = 6; 11 | int z1 = x1 & y1; // 2 12 | System.out.println(z1); 13 | 14 | int z2 = x1 | y1; // 14 15 | System.out.println(z2); 16 | 17 | int z3 = x1 ^ y1; // 12 18 | System.out.println(z3); 19 | 20 | int z4 = x1 << 2; // 40 = 10*4 21 | System.out.println(z4); 22 | 23 | int x2 = 50; 24 | int x3 = -50; 25 | int z5 = x2 >> 3; //6 26 | System.out.println(z5); 27 | int z6 = x3 >> 3; //-7 28 | System.out.println(z6); 29 | 30 | int z7 = x1 >>> 2; // 2 31 | System.out.println(z7); 32 | 33 | int x4 = 10; 34 | int y4 = 6; 35 | x4 &= y4; 36 | System.out.println(x4); // 2 37 | 38 | } 39 | 40 | } 41 | -------------------------------------------------------------------------------- /section7/src/LogicalOperatorsDemo.java: -------------------------------------------------------------------------------- 1 | public class LogicalOperatorsDemo { 2 | 3 | public static void main(String[] args) { 4 | 5 | boolean isValid; 6 | isValid = !true; 7 | isValid = !false; 8 | int num1 = 9; 9 | int num2 = 6; 10 | isValid = ! (num1>num2); 11 | 12 | boolean a = (num1>10) && ((num2=16)>15); 13 | System.out.println(a); 14 | System.out.println(num2); 15 | 16 | boolean b = (num1 < 10) || ((num2=18)>15); 17 | System.out.println(b); 18 | System.out.println(num2); 19 | 20 | boolean c = (num1>5) ^ (num2>10); 21 | System.out.println(c); 22 | 23 | boolean b1 = true; 24 | b1 &= true; 25 | System.out.println(b1); 26 | 27 | boolean b2 = true; 28 | b2 |= false; 29 | System.out.println(b2); 30 | 31 | boolean b3 = true; 32 | b3 ^= false; 33 | System.out.println(b3); 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /section7/src/Person.java: -------------------------------------------------------------------------------- 1 | public class Person { 2 | 3 | String name; 4 | 5 | public Person(String name) { 6 | this.name = name; 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /section7/src/PrecedenceAssociativityDemo.java: -------------------------------------------------------------------------------- 1 | public class PrecedenceAssociativityDemo { 2 | 3 | public static void main(String[] args) { 4 | int calNum = (16 - 8) * 2; // 16 5 | System.out.println(calNum); 6 | 7 | calNum = 16 * (5 / 2); 8 | System.out.println(calNum); 9 | 10 | } 11 | 12 | } 13 | -------------------------------------------------------------------------------- /section7/src/RelationalOperatorsDemo.java: -------------------------------------------------------------------------------- 1 | public class RelationalOperatorsDemo { 2 | 3 | public static void main(String[] args) { 4 | 5 | int num1 = 9; 6 | int num2 = 9; 7 | int num3 = 9; 8 | boolean isSame = num1 == num2; 9 | 10 | boolean a = true; 11 | boolean b = false; 12 | boolean isEqual = a == b; 13 | 14 | boolean isSimilar = (num1 == num2) && (num2 == num3); 15 | 16 | int num4 = 5; 17 | int num5 = 10; 18 | boolean isNotEqual = num4 != num5; 19 | 20 | boolean bool1 = true; 21 | boolean bool2 = false; 22 | isNotEqual = bool1 != bool2; 23 | 24 | double num6 = 3.14; 25 | double num7 = 3.14; 26 | isNotEqual = num6 != num7; 27 | 28 | boolean isSimilar1 = (num1 != num2) && (num2 != num3); 29 | 30 | int num8 = 9; 31 | int num9 = 6; 32 | double num10 = Double.NaN; 33 | boolean isGreaterThanOrEqual; 34 | isGreaterThanOrEqual = num8 >= num9; // true 35 | isGreaterThanOrEqual = num10 >= Double.NaN; // false 36 | 37 | } 38 | 39 | } 40 | -------------------------------------------------------------------------------- /section7/src/StringConcatenationDemo.java: -------------------------------------------------------------------------------- 1 | public class StringConcatenationDemo { 2 | 3 | public static void main(String[] args) { 4 | int num1 = 4; 5 | int num2 = 2; 6 | String str1 = " goals"; 7 | String output = num1 + num2 + str1; 8 | 9 | output = num1 + (num2 + str1); 10 | output = num1 + "" + num2 + str1; 11 | 12 | boolean b = false; 13 | output = b + (num1 + num2 + str1); 14 | output = "" + b + num1 + num2 + str1; 15 | 16 | String str2 = null; 17 | String str3 = 6 + str2; 18 | String str4 = "goals" + str2; 19 | String str5 = "6" + null; 20 | 21 | 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /section7/src/TernaryOperatorDemo.java: -------------------------------------------------------------------------------- 1 | public class TernaryOperatorDemo { 2 | 3 | public static void main(String[] args) { 4 | int x = 10; 5 | int y = 20; 6 | int max = (x > y ) ? x : y; // 20 7 | System.out.println(max); 8 | 9 | boolean isEven = ((11%2)==0) ? true : false; 10 | System.out.println(isEven); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /section8/.gitignore: -------------------------------------------------------------------------------- 1 | ### IntelliJ IDEA ### 2 | out/ 3 | !**/src/main/**/out/ 4 | !**/src/test/**/out/ 5 | 6 | ### Eclipse ### 7 | .apt_generated 8 | .classpath 9 | .factorypath 10 | .project 11 | .settings 12 | .springBeans 13 | .sts4-cache 14 | bin/ 15 | !**/src/main/**/bin/ 16 | !**/src/test/**/bin/ 17 | 18 | ### NetBeans ### 19 | /nbproject/private/ 20 | /nbbuild/ 21 | /dist/ 22 | /nbdist/ 23 | /.nb-gradle/ 24 | 25 | ### VS Code ### 26 | .vscode/ 27 | 28 | ### Mac OS ### 29 | .DS_Store -------------------------------------------------------------------------------- /section8/src/CanVote.java: -------------------------------------------------------------------------------- 1 | public class CanVote { 2 | 3 | public static void main(String[] args) { 4 | boolean isCitizen = false; 5 | int age = 19; 6 | 7 | if (isCitizen && age > 18) { 8 | System.out.println("The person can vote"); 9 | } else { 10 | System.out.println("The person can't vote"); 11 | } 12 | } 13 | 14 | } 15 | -------------------------------------------------------------------------------- /section8/src/ContinueStatementDemo.java: -------------------------------------------------------------------------------- 1 | public class ContinueStatementDemo { 2 | 3 | public static void main(String[] args) { 4 | 5 | for(int i = 0; i < 10; i++) { 6 | if ( i % 2 == 0) { 7 | continue; 8 | } 9 | System.out.println(i); 10 | } 11 | 12 | outer: 13 | for (int i =1; i<5; i++ ) { 14 | 15 | inner: 16 | for (int j =1; j < 5; j++) { 17 | if(j == 2){ 18 | continue outer; 19 | } 20 | System.out.println(" i = " + i + " and j = " + j); 21 | } 22 | 23 | } 24 | 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /section8/src/DoWhileStatementDemo.java: -------------------------------------------------------------------------------- 1 | public class DoWhileStatementDemo { 2 | 3 | public static void main(String[] args) { 4 | 5 | int n = 6; 6 | 7 | do { 8 | System.out.println(n); 9 | n++; 10 | } while ( n < 10); 11 | 12 | } 13 | 14 | } 15 | -------------------------------------------------------------------------------- /section8/src/EvenOddNumber.java: -------------------------------------------------------------------------------- 1 | public class EvenOddNumber { 2 | 3 | public static void main(String[] args) { 4 | int inputNumber = 9; 5 | 6 | if (inputNumber%2 == 0) { 7 | System.out.println("The given number is even"); 8 | } else { 9 | System.out.println("The given number is odd"); 10 | } 11 | 12 | } 13 | 14 | } 15 | -------------------------------------------------------------------------------- /section8/src/ForLoopDemo.java: -------------------------------------------------------------------------------- 1 | public class ForLoopDemo { 2 | 3 | public static void main(String[] args) { 4 | int result ; 5 | for (int i = 1; i <= 10; i++) { 6 | result = i * 9; 7 | System.out.println("9 * " + i + " = "+ result); 8 | } 9 | 10 | /*for(; ;) { 11 | System.out.println("Hi"); 12 | }*/ 13 | 14 | for(; ;) ; 15 | 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /section8/src/MessageForDay.java: -------------------------------------------------------------------------------- 1 | public class MessageForDay { 2 | 3 | public static void main(String[] args) { 4 | 5 | String dayOfWeek = "Wednesday"; 6 | 7 | if (dayOfWeek.equals("Saturday") || dayOfWeek.equals("Sunday")) { 8 | System.out.println("Hooray, it's the weekend!"); 9 | if (dayOfWeek.equals("Saturday")) { 10 | System.out.println("Time for a relaxing day or maybe some outdoor activities!"); 11 | } else { 12 | System.out.println("Lazy Sunday vibes perfect for a cozy day indoors."); 13 | } 14 | } else { 15 | System.out.println("It's a weekday. Time to work or attend classes."); 16 | if (dayOfWeek.equals("Wednesday") || dayOfWeek.equals("Thursday") 17 | || dayOfWeek.equals("Friday")) { 18 | System.out.println("Midweek hustle! Keep going, the weekend is approaching."); 19 | } else { 20 | System.out.println("Monday blues? Grab some coffee and power through the day!"); 21 | } 22 | } 23 | 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /section8/src/NestedForLoopDemo.java: -------------------------------------------------------------------------------- 1 | public class NestedForLoopDemo { 2 | 3 | public static void main(String[] args) { 4 | 5 | int number = 10; 6 | 7 | for(int i = 1; i <= number; i++) { 8 | for(int j =1; j<=number;j++) { 9 | System.out.println(i + " x " + j + " = " + i*j); 10 | } 11 | } 12 | 13 | int rows = 10; 14 | for (int i =1; i <=rows; i ++ ) { 15 | for (int j =1; j <=i; j++) { 16 | System.out.print("*"); 17 | } 18 | System.out.println(); 19 | } 20 | 21 | } 22 | 23 | } 24 | -------------------------------------------------------------------------------- /section8/src/NotOperatorExample.java: -------------------------------------------------------------------------------- 1 | public class NotOperatorExample { 2 | 3 | public static void main(String[] args) { 4 | int number = 0; 5 | 6 | if(! (number == 0)) { 7 | System.out.println("The number is not zero."); 8 | } else { 9 | System.out.println("The number is zero."); 10 | } 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /section8/src/ReturnStatementDemo.java: -------------------------------------------------------------------------------- 1 | public class ReturnStatementDemo { 2 | 3 | public static void main(String[] args) { 4 | String result = getStudentGrade(90); 5 | System.out.println(result); 6 | int [] arrayOfInt = { 43, 455, 4376, 343, 6 }; 7 | int lookingFor = 455; 8 | int index = findAndReturnNumber(arrayOfInt,lookingFor); 9 | System.out.println(index); 10 | } 11 | 12 | public static String getStudentGrade ( int marks) { 13 | String result; 14 | if(marks>= 40) { 15 | result = "Passed"; 16 | } else { 17 | result = "Failed"; 18 | } 19 | return result; 20 | } 21 | 22 | public static int findAndReturnNumber (int [] arrayOfNums , int target) { 23 | for(int i =0;i5){ 6 | y = 20; 7 | }else { 8 | y = 30; 9 | }*/ 10 | y = x > 5 ? 20 : 30; 11 | System.out.println(y); 12 | sum(x, x > 5 ? 20 : 30 ); 13 | } 14 | 15 | public static void sum (int x, int y) { 16 | System.out.println(x+y); 17 | } 18 | 19 | } 20 | -------------------------------------------------------------------------------- /section8/src/WhileStatementDemo.java: -------------------------------------------------------------------------------- 1 | public class WhileStatementDemo { 2 | 3 | public static void main(String[] args) { 4 | 5 | int i = 1; 6 | 7 | while (i<=10 ) { 8 | System.out.println(i); 9 | i++; 10 | } 11 | 12 | while (true) { 13 | System.out.println("I can print infinitely"); 14 | } 15 | 16 | 17 | } 18 | 19 | } 20 | -------------------------------------------------------------------------------- /section9/.gitignore: -------------------------------------------------------------------------------- 1 | ### IntelliJ IDEA ### 2 | out/ 3 | !**/src/main/**/out/ 4 | !**/src/test/**/out/ 5 | 6 | ### Eclipse ### 7 | .apt_generated 8 | .classpath 9 | .factorypath 10 | .project 11 | .settings 12 | .springBeans 13 | .sts4-cache 14 | bin/ 15 | !**/src/main/**/bin/ 16 | !**/src/test/**/bin/ 17 | 18 | ### NetBeans ### 19 | /nbproject/private/ 20 | /nbbuild/ 21 | /dist/ 22 | /nbdist/ 23 | /.nb-gradle/ 24 | 25 | ### VS Code ### 26 | .vscode/ 27 | 28 | ### Mac OS ### 29 | .DS_Store -------------------------------------------------------------------------------- /section9/src/com/eazybytes/app/AccessModifiersDemo.java: -------------------------------------------------------------------------------- 1 | package com.eazybytes.app; 2 | 3 | public class AccessModifiersDemo { 4 | 5 | private int privateVariable; 6 | protected int protectedVariable; 7 | public int publicVariable; 8 | int defaultVariable; 9 | 10 | public void publicMethod ( ) { 11 | int num = 9; 12 | System.out.println("Hello from public method"); 13 | } 14 | 15 | private void privateMethod ( ) { 16 | System.out.println("Hello from private method"); 17 | } 18 | 19 | protected void protectedMethod ( ) { 20 | System.out.println("Hello from protected method"); 21 | } 22 | 23 | void defaultMethod ( ) { 24 | System.out.println("Hello from default method"); 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /section9/src/com/eazybytes/app/MyOuterClass.java: -------------------------------------------------------------------------------- 1 | package com.eazybytes.app; 2 | 3 | public class MyOuterClass { 4 | 5 | static class MyInnerClass { 6 | public void display() { 7 | System.out.println("Hello from Inner class"); 8 | } 9 | } 10 | 11 | } 12 | -------------------------------------------------------------------------------- /section9/src/com/eazybytes/model/Class1.java: -------------------------------------------------------------------------------- 1 | package com.eazybytes.model; 2 | 3 | public class Class1 { 4 | } 5 | -------------------------------------------------------------------------------- /section9/src/com/eazybytes/model/Employee.java: -------------------------------------------------------------------------------- 1 | package com.eazybytes.model; 2 | 3 | public class Employee { 4 | } 5 | -------------------------------------------------------------------------------- /section9/src/com/eazybytes/model/Person.java: -------------------------------------------------------------------------------- 1 | package com.eazybytes.model; 2 | 3 | public class Person { 4 | 5 | private String firstName; 6 | private String lastName; 7 | private int age; 8 | private double salary; 9 | 10 | public String getFirstName() { 11 | return firstName; 12 | } 13 | 14 | public void setFirstName(String firstName) { 15 | this.firstName = firstName; 16 | } 17 | 18 | public String getLastName() { 19 | if(null == lastName){ 20 | return "Unknown"; 21 | }else { 22 | return lastName; 23 | } 24 | } 25 | 26 | public void setLastName(String lastName) { 27 | this.lastName = lastName; 28 | } 29 | 30 | public int getAge() { 31 | return age; 32 | } 33 | 34 | public void setAge(int age) { 35 | if(age>100) { 36 | throw new RuntimeException("Invalid age details sent"); 37 | }else{ 38 | this.age = age; 39 | } 40 | } 41 | 42 | public double getSalary() { 43 | return salary; 44 | } 45 | 46 | public void setSalary(double salary) { 47 | this.salary = salary; 48 | } 49 | 50 | } 51 | -------------------------------------------------------------------------------- /section9/src/com/eazybytes/model/Vehicle.java: -------------------------------------------------------------------------------- 1 | package com.eazybytes.model; 2 | 3 | public class Vehicle { 4 | } 5 | -------------------------------------------------------------------------------- /section9/src/com/eazybytes/service/Class1.java: -------------------------------------------------------------------------------- 1 | package com.eazybytes.service; 2 | 3 | public class Class1 { 4 | 5 | } 6 | -------------------------------------------------------------------------------- /section9/src/com/eazybytes/service/VehicleService.java: -------------------------------------------------------------------------------- 1 | package com.eazybytes.service; 2 | 3 | public class VehicleService { 4 | } 5 | -------------------------------------------------------------------------------- /section9/src/com/eazybytes/utility/MyConstants.java: -------------------------------------------------------------------------------- 1 | package com.eazybytes.utility; 2 | 3 | public class MyConstants { 4 | 5 | public static final double TAX_RATE = 0.07; 6 | public static final double SHIPPING_COST = 5.95; 7 | 8 | public static double calculateTotalCost(double price) { 9 | return price + (price * TAX_RATE) + SHIPPING_COST; 10 | } 11 | 12 | } 13 | -------------------------------------------------------------------------------- /section_10/.gitignore: -------------------------------------------------------------------------------- 1 | ### IntelliJ IDEA ### 2 | out/ 3 | !**/src/main/**/out/ 4 | !**/src/test/**/out/ 5 | 6 | ### Eclipse ### 7 | .apt_generated 8 | .classpath 9 | .factorypath 10 | .project 11 | .settings 12 | .springBeans 13 | .sts4-cache 14 | bin/ 15 | !**/src/main/**/bin/ 16 | !**/src/test/**/bin/ 17 | 18 | ### NetBeans ### 19 | /nbproject/private/ 20 | /nbbuild/ 21 | /dist/ 22 | /nbdist/ 23 | /.nb-gradle/ 24 | 25 | ### VS Code ### 26 | .vscode/ 27 | 28 | ### Mac OS ### 29 | .DS_Store -------------------------------------------------------------------------------- /section_10/src/com/eazybytes/marvel/animals/Cat.java: -------------------------------------------------------------------------------- 1 | package com.eazybytes.marvel.animals; 2 | 3 | import com.eazybytes.marvel.base.Animal; 4 | 5 | public class Cat extends Animal { 6 | 7 | public void eat() { 8 | System.out.println("Cat is eating"); 9 | } 10 | 11 | public void meow() { 12 | System.out.println("Cat is meowing"); 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /section_10/src/com/eazybytes/marvel/animals/Dog.java: -------------------------------------------------------------------------------- 1 | package com.eazybytes.marvel.animals; 2 | 3 | import com.eazybytes.marvel.base.Animal; 4 | 5 | public class Dog extends Animal { 6 | 7 | public void eat() { 8 | System.out.println("Dog is eating"); 9 | } 10 | 11 | public void bark() { 12 | System.out.println("Dog is barking"); 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /section_10/src/com/eazybytes/marvel/app/AnimalUtility.java: -------------------------------------------------------------------------------- 1 | package com.eazybytes.marvel.app; 2 | 3 | import com.eazybytes.marvel.animals.Cat; 4 | import com.eazybytes.marvel.animals.Dog; 5 | import com.eazybytes.marvel.base.Animal; 6 | 7 | public class AnimalUtility { 8 | 9 | public static void printName(Animal animal) { 10 | System.out.println(animal.getName()); 11 | animal.eat(); 12 | } 13 | 14 | public static void performAction(Animal animal) { 15 | animal.eat(); 16 | if(animal instanceof Dog) { 17 | Dog dog = (Dog) animal; 18 | dog.bark(); 19 | } else if (animal instanceof Cat cat) { // Java 16 20 | cat.meow(); 21 | } 22 | 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /section_10/src/com/eazybytes/marvel/app/ConstructorDemo.java: -------------------------------------------------------------------------------- 1 | package com.eazybytes.marvel.app; 2 | 3 | import com.eazybytes.marvel.base.Subject; 4 | import com.eazybytes.marvel.vehicle.Car; 5 | 6 | public class ConstructorDemo { 7 | 8 | public static void main(String[] args) { 9 | Car car = new Car(); 10 | System.out.println(car.madeFor); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /section_10/src/com/eazybytes/marvel/app/DownCastingDemo.java: -------------------------------------------------------------------------------- 1 | package com.eazybytes.marvel.app; 2 | 3 | import com.eazybytes.marvel.animals.Cat; 4 | import com.eazybytes.marvel.animals.Dog; 5 | import com.eazybytes.marvel.base.Animal; 6 | 7 | public class DownCastingDemo { 8 | 9 | public static void main(String[] args) { 10 | Animal anm; 11 | Dog dog = new Dog(); 12 | anm = dog; // upcasting 13 | 14 | dog = (Dog) anm; // downcasting 15 | AnimalUtility.performAction(dog); 16 | 17 | if (anm instanceof Cat ) { 18 | Cat cat = (Cat) anm; 19 | } 20 | 21 | } 22 | 23 | } 24 | -------------------------------------------------------------------------------- /section_10/src/com/eazybytes/marvel/app/DynamicPoly.java: -------------------------------------------------------------------------------- 1 | package com.eazybytes.marvel.app; 2 | 3 | import com.eazybytes.marvel.base.Person; 4 | import com.eazybytes.marvel.heros.IronMan; 5 | 6 | public class DynamicPoly { 7 | 8 | public static void main(String[] args) { 9 | Person person = new IronMan(); // upcasting 10 | person.walk(); // IronMan walk method is going to be invoked 11 | person.eat("Ice Cream"); 12 | 13 | IronMan ironMan = new IronMan(); 14 | ironMan.callOverriddenEatMethod(); 15 | 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /section_10/src/com/eazybytes/marvel/app/MarvelsMain.java: -------------------------------------------------------------------------------- 1 | package com.eazybytes.marvel.app; 2 | 3 | import com.eazybytes.marvel.base.Person; 4 | import com.eazybytes.marvel.heros.IronMan; 5 | 6 | public class MarvelsMain { 7 | 8 | public static void main(String[] args) { 9 | IronMan ironMan = new IronMan(); 10 | ironMan.walk(); 11 | ironMan.eat("Pasta"); 12 | ironMan.sleep(); 13 | ironMan.usePower(); 14 | 15 | Person person = new Person(); 16 | int hc = person.hashCode(); 17 | String str = person.toString(); 18 | } 19 | 20 | } 21 | -------------------------------------------------------------------------------- /section_10/src/com/eazybytes/marvel/app/StaticPoly.java: -------------------------------------------------------------------------------- 1 | package com.eazybytes.marvel.app; 2 | 3 | import com.eazybytes.marvel.heros.IronMan; 4 | 5 | public class StaticPoly { 6 | 7 | public static void main(String[] args) { 8 | 9 | IronMan ironMan = new IronMan(); 10 | ironMan.eat("Pasta"); 11 | ironMan.eat("Pasta", 1); 12 | 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /section_10/src/com/eazybytes/marvel/app/TestFieldHiding.java: -------------------------------------------------------------------------------- 1 | package com.eazybytes.marvel.app; 2 | 3 | import com.eazybytes.marvel.base.Vehicle; 4 | import com.eazybytes.marvel.vehicle.Car; 5 | 6 | public class TestFieldHiding { 7 | 8 | public static void main(String[] args) { 9 | Car car = new Car(); 10 | System.out.println(car.color); 11 | System.out.println(car.horsePower); 12 | System.out.println(car.turningRadius); 13 | System.out.println(car.isAutomatic); 14 | car.printCarDetails(); 15 | 16 | Vehicle vehicle = car; 17 | System.out.println(vehicle.color); 18 | System.out.println(vehicle.horsePower); 19 | System.out.println(vehicle.turningRadius); 20 | 21 | } 22 | 23 | } 24 | -------------------------------------------------------------------------------- /section_10/src/com/eazybytes/marvel/app/TestMethodHiding.java: -------------------------------------------------------------------------------- 1 | package com.eazybytes.marvel.app; 2 | 3 | import com.eazybytes.marvel.base.Vehicle; 4 | import com.eazybytes.marvel.vehicle.Car; 5 | 6 | public class TestMethodHiding { 7 | 8 | public static void main(String[] args) { 9 | 10 | Vehicle vehicle = new Car(); // upcasting 11 | Car car = new Car(); 12 | 13 | Vehicle.start(); // 1 = Vehicle starting... 14 | vehicle.start(); // 2 = Vehicle starting... 15 | 16 | Car.start(); // 3 = Car starting... 17 | car.start(); // 4 = Car starting... 18 | ((Vehicle) car).start(); // 5 = Vehicle starting... 19 | 20 | vehicle = car; // 6 21 | vehicle.start(); // 7 = Vehicle starting... 22 | ((Car) vehicle).start(); // 8 = Car starting... 23 | 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /section_10/src/com/eazybytes/marvel/app/UpcastingDemo.java: -------------------------------------------------------------------------------- 1 | package com.eazybytes.marvel.app; 2 | 3 | import com.eazybytes.marvel.animals.Cat; 4 | import com.eazybytes.marvel.animals.Dog; 5 | import com.eazybytes.marvel.base.Animal; 6 | 7 | public class UpcastingDemo { 8 | 9 | public static void main(String[] args) { 10 | Animal anm = new Animal(); 11 | anm.setName("Scooby"); 12 | AnimalUtility.printName(anm); 13 | 14 | anm = new Dog(); 15 | anm.setName("Charlie"); 16 | AnimalUtility.printName(anm); 17 | 18 | Cat cat = new Cat(); 19 | cat.setName("Snoopy"); 20 | AnimalUtility.printName(cat); 21 | 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /section_10/src/com/eazybytes/marvel/base/Animal.java: -------------------------------------------------------------------------------- 1 | package com.eazybytes.marvel.base; 2 | 3 | public class Animal { 4 | 5 | private String name; 6 | 7 | public String getName() { 8 | return name; 9 | } 10 | 11 | public void setName(String name) { 12 | this.name = name; 13 | } 14 | 15 | public void eat() { 16 | System.out.println("Animal is eating"); 17 | } 18 | 19 | } 20 | -------------------------------------------------------------------------------- /section_10/src/com/eazybytes/marvel/base/Engine.java: -------------------------------------------------------------------------------- 1 | package com.eazybytes.marvel.base; 2 | 3 | public class Engine { 4 | } 5 | -------------------------------------------------------------------------------- /section_10/src/com/eazybytes/marvel/base/Person.java: -------------------------------------------------------------------------------- 1 | package com.eazybytes.marvel.base; 2 | 3 | public class Person { 4 | 5 | protected String name; 6 | protected int age; 7 | public static int noOfHands = 2; 8 | 9 | protected void calculateAge(int year) { 10 | System.out.println("Age method"); 11 | } 12 | 13 | public void eat(String food) { 14 | System.out.println("Person is eating the food : " + food); 15 | } 16 | 17 | public void walk () { 18 | System.out.println("Person is walking"); 19 | } 20 | 21 | public void sleep () { 22 | System.out.println("Person is sleeping"); 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /section_10/src/com/eazybytes/marvel/base/Subject.java: -------------------------------------------------------------------------------- 1 | package com.eazybytes.marvel.base; 2 | 3 | public abstract class Subject { 4 | 5 | public Subject(){ 6 | 7 | } 8 | 9 | public int marks; 10 | public static final int MIN_MARKS = 0; 11 | 12 | 13 | // concrete methods 14 | public int totalMarks () { 15 | return 100; 16 | } 17 | 18 | public abstract void teach (); 19 | 20 | } 21 | -------------------------------------------------------------------------------- /section_10/src/com/eazybytes/marvel/base/Vehicle.java: -------------------------------------------------------------------------------- 1 | package com.eazybytes.marvel.base; 2 | 3 | public class Vehicle { 4 | 5 | Engine engine; 6 | public int horsePower; 7 | public String color; 8 | public double turningRadius; 9 | public String madeFor; 10 | 11 | public Vehicle(String madeFor) { 12 | System.out.println("Inside Vehicle default constructor"); 13 | horsePower = 120; 14 | color = "White"; 15 | turningRadius = 5.23; 16 | this.madeFor = madeFor; 17 | } 18 | 19 | public static void start() { 20 | System.out.println("Vehicle starting..."); 21 | } 22 | 23 | } 24 | -------------------------------------------------------------------------------- /section_10/src/com/eazybytes/marvel/heros/CaptainAmerica.java: -------------------------------------------------------------------------------- 1 | package com.eazybytes.marvel.heros; 2 | 3 | import com.eazybytes.marvel.base.Person; 4 | 5 | public class CaptainAmerica extends Person { 6 | 7 | public void usePower() { 8 | System.out.println("Captain America is using his power"); 9 | } 10 | 11 | } 12 | -------------------------------------------------------------------------------- /section_10/src/com/eazybytes/marvel/heros/IronMan.java: -------------------------------------------------------------------------------- 1 | package com.eazybytes.marvel.heros; 2 | 3 | import com.eazybytes.marvel.base.Person; 4 | 5 | public class IronMan extends Person { 6 | 7 | public void usePower() { 8 | System.out.println("IronMan is using his power"); 9 | } 10 | 11 | @Override 12 | public void walk() { 13 | System.out.println("Ironman walking with his suite"); 14 | } 15 | 16 | @Override 17 | public void eat(String food) { 18 | super.eat("Pasta"); 19 | System.out.println("IronMan is eating the food : " + food); 20 | } 21 | // eat, String 22 | // eat, 23 | // eat, String, int 24 | // eat, int, String 25 | private void eat () { 26 | System.out.println("Method overloading 1"); 27 | } 28 | 29 | public void eat (String food, int quantity) { 30 | System.out.println("Method overloading 2"); 31 | } 32 | 33 | public void eat (int quantity, String food) { 34 | System.out.println("Method overloading 2"); 35 | } 36 | 37 | public void callOverriddenEatMethod() { 38 | super.eat("Pasta"); 39 | } 40 | 41 | } 42 | -------------------------------------------------------------------------------- /section_10/src/com/eazybytes/marvel/heros/SpiderMan.java: -------------------------------------------------------------------------------- 1 | package com.eazybytes.marvel.heros; 2 | 3 | import com.eazybytes.marvel.base.Person; 4 | 5 | public class SpiderMan extends Person { 6 | 7 | public void usePower() { 8 | System.out.println("SpiderMan is using his power"); 9 | } 10 | 11 | } 12 | -------------------------------------------------------------------------------- /section_10/src/com/eazybytes/marvel/sealed/Employee.java: -------------------------------------------------------------------------------- 1 | package com.eazybytes.marvel.sealed; 2 | 3 | public non-sealed class Employee extends Person { 4 | } 5 | -------------------------------------------------------------------------------- /section_10/src/com/eazybytes/marvel/sealed/Person.java: -------------------------------------------------------------------------------- 1 | package com.eazybytes.marvel.sealed; 2 | 3 | public sealed class Person permits Student, Employee { 4 | } 5 | -------------------------------------------------------------------------------- /section_10/src/com/eazybytes/marvel/sealed/Student.java: -------------------------------------------------------------------------------- 1 | package com.eazybytes.marvel.sealed; 2 | 3 | public final class Student extends Person { 4 | } 5 | -------------------------------------------------------------------------------- /section_10/src/com/eazybytes/marvel/subjects/Mathematics.java: -------------------------------------------------------------------------------- 1 | package com.eazybytes.marvel.subjects; 2 | 3 | import com.eazybytes.marvel.base.Subject; 4 | 5 | public class Mathematics extends Subject { 6 | 7 | @Override 8 | public void teach() { 9 | System.out.println("I am trying to teach mathematics"); 10 | } 11 | 12 | } 13 | -------------------------------------------------------------------------------- /section_10/src/com/eazybytes/marvel/vehicle/Car.java: -------------------------------------------------------------------------------- 1 | package com.eazybytes.marvel.vehicle; 2 | 3 | import com.eazybytes.marvel.base.Vehicle; 4 | 5 | public class Car extends Vehicle { 6 | 7 | public int horsePower ; 8 | public String color ; 9 | public String turningRadius; 10 | public boolean isAutomatic; 11 | 12 | public Car() { 13 | super("Water"); 14 | System.out.println("Inside Car default constructor"); 15 | horsePower = 150; 16 | color = "Black"; 17 | turningRadius = "6.23"; 18 | isAutomatic = true; 19 | } 20 | 21 | public static void start() { 22 | System.out.println("Car starting..."); 23 | } 24 | 25 | public void printCarDetails() { 26 | System.out.println(color); 27 | System.out.println(super.color); 28 | } 29 | 30 | } 31 | -------------------------------------------------------------------------------- /section_11/.gitignore: -------------------------------------------------------------------------------- 1 | ### IntelliJ IDEA ### 2 | out/ 3 | !**/src/main/**/out/ 4 | !**/src/test/**/out/ 5 | 6 | ### Eclipse ### 7 | .apt_generated 8 | .classpath 9 | .factorypath 10 | .project 11 | .settings 12 | .springBeans 13 | .sts4-cache 14 | bin/ 15 | !**/src/main/**/bin/ 16 | !**/src/test/**/bin/ 17 | 18 | ### NetBeans ### 19 | /nbproject/private/ 20 | /nbbuild/ 21 | /dist/ 22 | /nbdist/ 23 | /.nb-gradle/ 24 | 25 | ### VS Code ### 26 | .vscode/ 27 | 28 | ### Mac OS ### 29 | .DS_Store -------------------------------------------------------------------------------- /section_11/src/com/eazybytes/marvel/hero/Hero.java: -------------------------------------------------------------------------------- 1 | package com.eazybytes.marvel.hero; 2 | 3 | public interface Hero { 4 | 5 | default void walk() { 6 | System.out.println("Walking"); 7 | } 8 | 9 | } 10 | -------------------------------------------------------------------------------- /section_11/src/com/eazybytes/marvel/hero/MyFunctionalInterface.java: -------------------------------------------------------------------------------- 1 | package com.eazybytes.marvel.hero; 2 | 3 | @FunctionalInterface 4 | public interface MyFunctionalInterface { 5 | 6 | void myMethod(); 7 | 8 | } 9 | -------------------------------------------------------------------------------- /section_11/src/com/eazybytes/marvel/hero/Person.java: -------------------------------------------------------------------------------- 1 | package com.eazybytes.marvel.hero; 2 | 3 | public interface Person { 4 | 5 | static void main(String[] args) { 6 | System.out.println("Hello World from Interfaces"); 7 | } 8 | 9 | default void walk() { 10 | System.out.println("Walking"); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /section_11/src/com/eazybytes/marvel/hero/SuperHero.java: -------------------------------------------------------------------------------- 1 | package com.eazybytes.marvel.hero; 2 | 3 | public interface SuperHero extends Hero, Person { 4 | 5 | String UNIVERSE_NAME = "Marvel"; 6 | 7 | String usePower(); 8 | 9 | /** 10 | * If Y received kill the villain 11 | * If N received stop the villain 12 | * @param c indicates Y or N 13 | * @return - Returns status 14 | */ 15 | String stopVillain(char c); 16 | 17 | 18 | default String trackLiveLocation() { 19 | String liveLocation = "USA"; 20 | System.out.println("I am in "+ liveLocation); 21 | return liveLocation; 22 | } 23 | 24 | static String commonCharacteristics () { 25 | return "Superhuman abilities, Willingness to sacrifice"; 26 | } 27 | 28 | @Override 29 | default void walk() { 30 | Person.super.walk(); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /section_11/src/com/eazybytes/marvel/hero/app/MarvelHeroDemo.java: -------------------------------------------------------------------------------- 1 | package com.eazybytes.marvel.hero.app; 2 | 3 | import com.eazybytes.marvel.hero.SuperHero; 4 | import com.eazybytes.marvel.hero.impl.CaptainAmerica; 5 | import com.eazybytes.marvel.hero.impl.Developer; 6 | import com.eazybytes.marvel.hero.impl.IronMan; 7 | import com.eazybytes.marvel.hero.impl.SpiderMan; 8 | 9 | public class MarvelHeroDemo { 10 | 11 | public static void main(String[] args) { 12 | 13 | System.out.println(SuperHero.UNIVERSE_NAME); 14 | 15 | SuperHero ironMan = new IronMan(); 16 | invokeSuperHero(ironMan); 17 | 18 | SuperHero spiderMan = new SpiderMan(); 19 | invokeSuperHero(spiderMan); 20 | 21 | SuperHero captainAmerica = new CaptainAmerica(); 22 | invokeSuperHero(captainAmerica); 23 | 24 | Developer developer = new Developer(); 25 | developer.walk(); 26 | } 27 | 28 | private static void invokeSuperHero(SuperHero superHero) { 29 | System.out.println(superHero.usePower()); 30 | System.out.println(superHero.stopVillain('N')); 31 | } 32 | 33 | 34 | } 35 | -------------------------------------------------------------------------------- /section_11/src/com/eazybytes/marvel/hero/impl/CaptainAmerica.java: -------------------------------------------------------------------------------- 1 | package com.eazybytes.marvel.hero.impl; 2 | 3 | import com.eazybytes.marvel.hero.SuperHero; 4 | 5 | public class CaptainAmerica implements SuperHero { 6 | 7 | 8 | @Override 9 | public String usePower() { 10 | return "CaptainAmerica using his power"; 11 | } 12 | 13 | /** 14 | * If Y received kill the villain 15 | * If N received stop the villain 16 | * 17 | * @param c indicates Y or N 18 | * @return - Returns status 19 | */ 20 | @Override 21 | public String stopVillain(char c) { 22 | if(c=='Y') { 23 | return "CaptainAmerica killed the Villain"; 24 | } else { 25 | return "CaptainAmerica stopped the Villain"; 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /section_11/src/com/eazybytes/marvel/hero/impl/Developer.java: -------------------------------------------------------------------------------- 1 | package com.eazybytes.marvel.hero.impl; 2 | 3 | import com.eazybytes.marvel.hero.Person; 4 | 5 | public class Developer extends Employee implements Person { 6 | 7 | } 8 | -------------------------------------------------------------------------------- /section_11/src/com/eazybytes/marvel/hero/impl/Employee.java: -------------------------------------------------------------------------------- 1 | package com.eazybytes.marvel.hero.impl; 2 | 3 | import java.io.Serializable; 4 | 5 | public class Employee implements Cloneable, Serializable { 6 | 7 | public void walk() { 8 | System.out.println("Employee Walking"); 9 | } 10 | 11 | } 12 | -------------------------------------------------------------------------------- /section_11/src/com/eazybytes/marvel/hero/impl/IronMan.java: -------------------------------------------------------------------------------- 1 | package com.eazybytes.marvel.hero.impl; 2 | 3 | import com.eazybytes.marvel.hero.SuperHero; 4 | 5 | public class IronMan implements SuperHero { 6 | 7 | 8 | @Override 9 | public String usePower() { 10 | System.out.println(UNIVERSE_NAME); 11 | return "IronMan using his power"; 12 | } 13 | 14 | /** 15 | * If Y received kill the villain 16 | * If N received stop the villain 17 | * 18 | * @param c indicates Y or N 19 | * @return - Returns status 20 | */ 21 | @Override 22 | public String stopVillain(char c) { 23 | if(c=='Y') { 24 | return "IronMan killed the Villain"; 25 | } else { 26 | return "IronMan stopped the Villain"; 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /section_11/src/com/eazybytes/marvel/hero/impl/SpiderMan.java: -------------------------------------------------------------------------------- 1 | package com.eazybytes.marvel.hero.impl; 2 | 3 | import com.eazybytes.marvel.hero.SuperHero; 4 | 5 | public class SpiderMan implements SuperHero { 6 | 7 | 8 | @Override 9 | public String usePower() { 10 | return "SpiderMan using his power"; 11 | } 12 | 13 | /** 14 | * If Y received kill the villain 15 | * If N received stop the villain 16 | * 17 | * @param c indicates Y or N 18 | * @return - Returns status 19 | */ 20 | @Override 21 | public String stopVillain(char c) { 22 | if(c=='Y') { 23 | return "SpiderMan killed the Villain"; 24 | } else { 25 | return "SpiderMan stopped the Villain"; 26 | } 27 | } 28 | 29 | @Override 30 | public String trackLiveLocation() { 31 | String liveLocation = "London"; 32 | System.out.println("I am in "+ liveLocation); 33 | return liveLocation; 34 | } 35 | 36 | public static String commonCharacteristics () { 37 | return "Superhuman abilities, Willingness to sacrifice"; 38 | } 39 | 40 | } 41 | -------------------------------------------------------------------------------- /section_12/.gitignore: -------------------------------------------------------------------------------- 1 | ### IntelliJ IDEA ### 2 | out/ 3 | !**/src/main/**/out/ 4 | !**/src/test/**/out/ 5 | 6 | ### Eclipse ### 7 | .apt_generated 8 | .classpath 9 | .factorypath 10 | .project 11 | .settings 12 | .springBeans 13 | .sts4-cache 14 | bin/ 15 | !**/src/main/**/bin/ 16 | !**/src/test/**/bin/ 17 | 18 | ### NetBeans ### 19 | /nbproject/private/ 20 | /nbbuild/ 21 | /dist/ 22 | /nbdist/ 23 | /.nb-gradle/ 24 | 25 | ### VS Code ### 26 | .vscode/ 27 | 28 | ### Mac OS ### 29 | .DS_Store -------------------------------------------------------------------------------- /section_12/src/com/eazybytes/main/AddMatricesDemo.java: -------------------------------------------------------------------------------- 1 | package com.eazybytes.main; 2 | 3 | public class AddMatricesDemo { 4 | 5 | public static void main(String[] args) { 6 | 7 | int[][] array1 = { 8 | {4,7,9}, {5,7,0} 9 | }; 10 | int[][] array2 = { 11 | {3,8,2}, {2,6,1} 12 | }; 13 | 14 | int[][] sumArray = new int[2][3]; 15 | 16 | for (int i = 0;i i*2); 15 | System.out.println(Arrays.toString(indices)); 16 | 17 | } 18 | 19 | } 20 | -------------------------------------------------------------------------------- /section_12/src/com/eazybytes/main/JaggedArrayDemo.java: -------------------------------------------------------------------------------- 1 | package com.eazybytes.main; 2 | 3 | import java.util.Arrays; 4 | 5 | public class JaggedArrayDemo { 6 | 7 | public static void main(String[] args) { 8 | int[][] jaggedArray = new int[4][]; 9 | 10 | int[] array1 = {5,7,3,2,1,0}; 11 | int[] array2 = {}; 12 | int[] array3 = {65,74}; 13 | int[] array4 = {83,2,49,2}; 14 | 15 | jaggedArray[0] = array1; 16 | jaggedArray[1] = array2; 17 | jaggedArray[2] = array3; 18 | jaggedArray[3] = array4; 19 | 20 | System.out.println(Arrays.deepToString(jaggedArray)); 21 | } 22 | 23 | } 24 | -------------------------------------------------------------------------------- /section_12/src/com/eazybytes/main/SearchDemo.java: -------------------------------------------------------------------------------- 1 | package com.eazybytes.main; 2 | 3 | import java.util.Arrays; 4 | 5 | public class SearchDemo { 6 | 7 | public static void main(String[] args) { 8 | int[] num = {36, 9, 42, 18, 73}; 9 | Arrays.sort(num); 10 | int index = Arrays.binarySearch(num, 73); 11 | System.out.println(index); 12 | index = Arrays.binarySearch(num, 999); // -(insertion point) - 1 13 | System.out.println(index); // -6 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /section_12/src/com/eazybytes/main/SortDemo.java: -------------------------------------------------------------------------------- 1 | package com.eazybytes.main; 2 | 3 | import java.util.Arrays; 4 | import java.util.Random; 5 | 6 | public class SortDemo { 7 | 8 | public static void main(String[] args) { 9 | int[] smallArray = {5, 2,8,1,6}; 10 | Arrays.sort(smallArray); 11 | System.out.println(Arrays.toString(smallArray)); 12 | 13 | int[] largerArray = new int[10000]; 14 | Random random = new Random(); 15 | 16 | for(int i=0;i100) { 14 | throw new InvalidAgeException("Invalid age details entered. Please enter a age between 0-100"); 15 | } 16 | System.out.println("Your age is : "+age); 17 | } 18 | 19 | } 20 | -------------------------------------------------------------------------------- /section_14/src/com/eazybytes/exception/ArrayIndexOutofBoundsExceptionDemo.java: -------------------------------------------------------------------------------- 1 | package com.eazybytes.exception; 2 | 3 | import java.util.logging.Logger; 4 | 5 | public class ArrayIndexOutofBoundsExceptionDemo { 6 | 7 | private static Logger logger = Logger.getLogger( 8 | ArrayIndexOutofBoundsExceptionDemo.class.getName()); 9 | 10 | public static void main(String[] args) { 11 | try { 12 | int[] numbers = {1,2,3,4,5}; 13 | System.out.println(numbers[5]); 14 | } catch (Exception ex) { 15 | logger.severe("Invalid Array index. Please try again with a valid index number"); 16 | } 17 | 18 | } 19 | 20 | } 21 | -------------------------------------------------------------------------------- /section_14/src/com/eazybytes/exception/CheckedExceptionDemo.java: -------------------------------------------------------------------------------- 1 | package com.eazybytes.exception; 2 | 3 | import java.io.*; 4 | 5 | public class CheckedExceptionDemo { 6 | 7 | public static void main(String[] args) { 8 | try (InputStreamReader isr = new InputStreamReader(System.in); 9 | BufferedReader bf = new BufferedReader(isr)) { 10 | System.out.println("Please enter a value..."); 11 | String input = bf.readLine(); 12 | System.out.println("The user entered a value: "+ input); 13 | } catch (IOException ex) { 14 | ex.printStackTrace(); 15 | } 16 | } 17 | 18 | public void readFile() { 19 | try { 20 | FileReader fileReader = new FileReader("/Users/eazybytes/Desktop/story.txt"); 21 | } catch (FileNotFoundException ex){ 22 | ex.printStackTrace(); 23 | } 24 | 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /section_14/src/com/eazybytes/exception/DivideByZero.java: -------------------------------------------------------------------------------- 1 | package com.eazybytes.exception; 2 | 3 | import com.eazybytes.exception.custom.DivideByZeroException; 4 | 5 | import java.util.Scanner; 6 | 7 | public class DivideByZero { 8 | 9 | public static void main(String[] args) { 10 | Scanner scanner = new Scanner(System.in); 11 | System.out.println("Please enter a numerator number value to perform the division:"); 12 | int numerator = scanner.nextInt(); 13 | System.out.println("Please enter a denominator number value to perform the division:"); 14 | int denominator = scanner.nextInt(); 15 | if(denominator==0){ 16 | throw new DivideByZeroException("Denominator can't be zero"); 17 | } 18 | int result = numerator/denominator; 19 | System.out.println(result); 20 | } 21 | 22 | } 23 | -------------------------------------------------------------------------------- /section_14/src/com/eazybytes/exception/Division.java: -------------------------------------------------------------------------------- 1 | package com.eazybytes.exception; 2 | 3 | public class Division { 4 | 5 | public double divide (String num1, String num2) throws 6 | NumberFormatException, ArithmeticException { 7 | int n1 = Integer.parseInt(num1); 8 | int n2 = Integer.parseInt(num2); 9 | return n1/n2; 10 | } 11 | 12 | } 13 | -------------------------------------------------------------------------------- /section_14/src/com/eazybytes/exception/ExceptionDemo.java: -------------------------------------------------------------------------------- 1 | package com.eazybytes.exception; 2 | 3 | import java.util.InputMismatchException; 4 | import java.util.Scanner; 5 | 6 | public class ExceptionDemo { 7 | 8 | public static void main(String[] args) { 9 | Scanner scanner = null; 10 | try { 11 | scanner = new Scanner(System.in); 12 | System.out.println("Enter a number...."); 13 | int number = scanner.nextInt(); 14 | System.out.println(number); 15 | } 16 | catch(Exception ex) { 17 | System.out.println("Please provide input in numerical format only and try again..."); 18 | } 19 | finally { 20 | System.out.println("finally block is being executed"); 21 | if(scanner != null) { 22 | scanner.close(); 23 | } 24 | } 25 | 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /section_14/src/com/eazybytes/exception/ExceptionPropogationDemo.java: -------------------------------------------------------------------------------- 1 | package com.eazybytes.exception; 2 | 3 | import java.io.FileNotFoundException; 4 | 5 | public class ExceptionPropogationDemo { 6 | 7 | public static void main(String[] args) { 8 | method1(); 9 | System.out.println("Main method"); 10 | } 11 | 12 | static void method1() { 13 | try{ 14 | method2(); 15 | }catch (FileNotFoundException ex) { 16 | System.out.println(ex.getMessage()); 17 | } 18 | 19 | } 20 | 21 | static void method2() throws FileNotFoundException { 22 | method3(); 23 | } 24 | 25 | static void method3() throws FileNotFoundException{ 26 | throw new FileNotFoundException("File not found. Please check..."); 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /section_14/src/com/eazybytes/exception/MultipleCatchDemo.java: -------------------------------------------------------------------------------- 1 | package com.eazybytes.exception; 2 | 3 | import java.io.IOException; 4 | import java.util.InputMismatchException; 5 | import java.util.logging.Logger; 6 | 7 | public class MultipleCatchDemo { 8 | 9 | private static Logger logger = Logger.getLogger( 10 | MultipleCatchDemo.class.getName()); 11 | 12 | public static void main(String[] args) { 13 | String input = null; 14 | try { 15 | input = "Madan"; 16 | input = input.toUpperCase(); 17 | logger.info(input); 18 | input = input.substring(1,10); 19 | logger.info(input); 20 | } catch (NullPointerException ex) { 21 | logger.severe("An null pointer exception occurred. Please check your data"); 22 | } catch (StringIndexOutOfBoundsException | ArrayIndexOutOfBoundsException ex) { 23 | logger.severe("IndexOutOfBoundsException exception occurred. Please check your input data"); 24 | } catch (Exception ex) { 25 | logger.severe("An exception occurred. Please check your program"); 26 | } 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /section_14/src/com/eazybytes/exception/ThrowDemo.java: -------------------------------------------------------------------------------- 1 | package com.eazybytes.exception; 2 | 3 | import java.util.Scanner; 4 | 5 | public class ThrowDemo { 6 | 7 | public static void main(String[] args) { 8 | Scanner scanner = new Scanner(System.in); 9 | System.out.println("Please enter the numerator value"); 10 | String num1 = scanner.next(); 11 | System.out.println("Please enter the denominator value"); 12 | String num2 = scanner.next(); 13 | Division division = new Division(); 14 | if(num2.equals("0")) { 15 | throw new ArithmeticException("Division by zero"); 16 | } 17 | double output = division.divide(num1, num2); 18 | System.out.println(output); 19 | } 20 | 21 | } 22 | -------------------------------------------------------------------------------- /section_14/src/com/eazybytes/exception/ThrowsDemo.java: -------------------------------------------------------------------------------- 1 | package com.eazybytes.exception; 2 | 3 | public class ThrowsDemo { 4 | 5 | public static void main(String[] args) { 6 | Division division = new Division(); 7 | try{ 8 | double ouput = division.divide("4", "2"); 9 | System.out.println(ouput); 10 | } catch (NumberFormatException | ArithmeticException ex) { 11 | System.out.println("Invalid data provided. Please provide valid numbers and try again.."); 12 | } 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /section_14/src/com/eazybytes/exception/TryWithResourcesDemo.java: -------------------------------------------------------------------------------- 1 | package com.eazybytes.exception; 2 | 3 | import java.util.Scanner; 4 | 5 | public class TryWithResourcesDemo { 6 | 7 | public static void main(String[] args) { 8 | try (Scanner scanner = new Scanner(System.in)) { 9 | System.out.println("Enter a number...."); 10 | int number = scanner.nextInt(); 11 | System.out.println(number); 12 | } catch(Exception ex) { 13 | System.out.println("Please provide input in numerical format only and try again..."); 14 | } 15 | } 16 | 17 | } 18 | -------------------------------------------------------------------------------- /section_14/src/com/eazybytes/exception/UnCheckedExceptionsDemo.java: -------------------------------------------------------------------------------- 1 | package com.eazybytes.exception; 2 | 3 | public class UnCheckedExceptionsDemo { 4 | 5 | public static void main(String[] args) { 6 | String input = null; 7 | input = "Madan"; 8 | input = input.toUpperCase(); 9 | input = input.substring(1,10); 10 | } 11 | 12 | } 13 | -------------------------------------------------------------------------------- /section_14/src/com/eazybytes/exception/custom/DivideByZeroException.java: -------------------------------------------------------------------------------- 1 | package com.eazybytes.exception.custom; 2 | 3 | public class DivideByZeroException extends RuntimeException { 4 | 5 | public DivideByZeroException() { 6 | super(); 7 | } 8 | 9 | public DivideByZeroException(String message) { 10 | super(message); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /section_14/src/com/eazybytes/exception/custom/InvalidAgeException.java: -------------------------------------------------------------------------------- 1 | package com.eazybytes.exception.custom; 2 | 3 | public class InvalidAgeException extends Exception { 4 | 5 | public InvalidAgeException() { 6 | super(); 7 | } 8 | 9 | public InvalidAgeException(String message) { 10 | super(message); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /section_15/.gitignore: -------------------------------------------------------------------------------- 1 | ### IntelliJ IDEA ### 2 | out/ 3 | !**/src/main/**/out/ 4 | !**/src/test/**/out/ 5 | 6 | ### Eclipse ### 7 | .apt_generated 8 | .classpath 9 | .factorypath 10 | .project 11 | .settings 12 | .springBeans 13 | .sts4-cache 14 | bin/ 15 | !**/src/main/**/bin/ 16 | !**/src/test/**/bin/ 17 | 18 | ### NetBeans ### 19 | /nbproject/private/ 20 | /nbbuild/ 21 | /dist/ 22 | /nbdist/ 23 | /.nb-gradle/ 24 | 25 | ### VS Code ### 26 | .vscode/ 27 | 28 | ### Mac OS ### 29 | .DS_Store -------------------------------------------------------------------------------- /section_15/src/com/eazybytes/object/demo/CloneDemo.java: -------------------------------------------------------------------------------- 1 | package com.eazybytes.object.demo; 2 | 3 | public class CloneDemo { 4 | 5 | public static void main(String[] args) throws CloneNotSupportedException { 6 | Person p1 = new Person("John", 25 , 'M', 234323235); 7 | Person p2 = p1; 8 | p2.setName("John Doe"); 9 | System.out.println(p1.getName()); 10 | Person p3 = (Person) p1.clone(); 11 | System.out.println(p3.getName()); 12 | p3.setName("Will Smith"); 13 | System.out.println(p1.getName()); 14 | System.out.println(p3.getName()); 15 | 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /section_15/src/com/eazybytes/object/demo/CloneExample.java: -------------------------------------------------------------------------------- 1 | package com.eazybytes.object.demo; 2 | 3 | public class CloneExample { 4 | 5 | public static void main(String[] args) throws CloneNotSupportedException { 6 | Course course = new Course(); 7 | course.setCourseName("Math"); 8 | 9 | Student originalStudent = new Student("Alice", course); 10 | Student clonedStudent = (Student) originalStudent.clone(); 11 | System.out.println(originalStudent == clonedStudent); // false 12 | System.out.println(originalStudent.getCourse() == clonedStudent.getCourse()); // true 13 | 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /section_15/src/com/eazybytes/object/demo/Course.java: -------------------------------------------------------------------------------- 1 | package com.eazybytes.object.demo; 2 | 3 | public class Course implements Cloneable { 4 | 5 | private String courseName; 6 | 7 | public String getCourseName() { 8 | return courseName; 9 | } 10 | 11 | public void setCourseName(String courseName) { 12 | this.courseName = courseName; 13 | } 14 | 15 | @Override 16 | public Object clone() throws CloneNotSupportedException { 17 | return super.clone(); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /section_15/src/com/eazybytes/object/demo/FinalizeDemo.java: -------------------------------------------------------------------------------- 1 | package com.eazybytes.object.demo; 2 | 3 | public class FinalizeDemo { 4 | 5 | public static void main(String[] args) { 6 | for(int i=0;i<1000000;i++) { 7 | System.out.println(i); 8 | new Person(); 9 | } 10 | } 11 | 12 | } 13 | -------------------------------------------------------------------------------- /section_15/src/com/eazybytes/object/demo/GetClassDemo.java: -------------------------------------------------------------------------------- 1 | package com.eazybytes.object.demo; 2 | 3 | public class GetClassDemo { 4 | 5 | public static void main(String[] args) { 6 | Person person = new Person(); 7 | Class prsnClass = person.getClass(); 8 | System.out.println(prsnClass.getName()); 9 | System.out.println(prsnClass.getSimpleName()); 10 | System.out.println(prsnClass.getPackageName()); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /section_15/src/com/eazybytes/object/demo/HashCodeEqualsDemo.java: -------------------------------------------------------------------------------- 1 | package com.eazybytes.object.demo; 2 | 3 | public class HashCodeEqualsDemo { 4 | 5 | public static void main(String[] args) { 6 | Person p1 = new Person("John", 25, 'M', 564323456); 7 | Person p2 = new Person("John", 25, 'M', 564323456); 8 | System.out.println(p1.hashCode()); 9 | System.out.println(p2.hashCode()); 10 | System.out.println(p1.equals(p2)); // false 11 | System.out.println(p1); 12 | System.out.println(p2); 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /section_15/src/com/eazybytes/object/demo/ImmutableDemo.java: -------------------------------------------------------------------------------- 1 | package com.eazybytes.object.demo; 2 | 3 | public class ImmutableDemo { 4 | 5 | public static void main(String[] args) { 6 | ImmutablePerson immutablePerson = new ImmutablePerson("John", "Software Engineer"); 7 | } 8 | 9 | } 10 | -------------------------------------------------------------------------------- /section_15/src/com/eazybytes/object/demo/ImmutablePerson.java: -------------------------------------------------------------------------------- 1 | package com.eazybytes.object.demo; 2 | 3 | public final class ImmutablePerson { 4 | 5 | private final String name; 6 | private final String occupation; 7 | 8 | public ImmutablePerson(String name, String occupation) { 9 | this.name = name; 10 | this.occupation = occupation; 11 | } 12 | 13 | public String getName() { 14 | return name; 15 | } 16 | 17 | public String getOccupation() { 18 | return occupation; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /section_15/src/com/eazybytes/object/demo/MutableDemo.java: -------------------------------------------------------------------------------- 1 | package com.eazybytes.object.demo; 2 | 3 | public class MutableDemo { 4 | 5 | public static void main(String[] args) { 6 | MutablePerson mutablePerson = new MutablePerson("John", "Software Engineer"); 7 | System.out.println(mutablePerson.getOccupation()); 8 | mutablePerson.setOccupation("Doctor"); 9 | System.out.println(mutablePerson.getOccupation()); 10 | } 11 | 12 | } 13 | -------------------------------------------------------------------------------- /section_15/src/com/eazybytes/object/demo/MutablePerson.java: -------------------------------------------------------------------------------- 1 | package com.eazybytes.object.demo; 2 | 3 | public class MutablePerson { 4 | 5 | private String name; 6 | private String occupation; 7 | 8 | public MutablePerson(String name, String occupation) { 9 | this.name = name; 10 | this.occupation = occupation; 11 | } 12 | 13 | public String getName() { 14 | return name; 15 | } 16 | 17 | public void setName(String name) { 18 | this.name = name; 19 | } 20 | 21 | public String getOccupation() { 22 | return occupation; 23 | } 24 | 25 | public void setOccupation(String occupation) { 26 | this.occupation = occupation; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /section_15/src/com/eazybytes/object/demo/PersonRecord.java: -------------------------------------------------------------------------------- 1 | package com.eazybytes.object.demo; 2 | 3 | /** 4 | * 1) making the class as final 5 | * 2) make the fields as final and private 6 | * 3) generate the getter methods without any get prefix 7 | * 4) Generate a constructor with the fields mentioned inside the record header 8 | * 5) toString, equals and hashcode 9 | * @param name 10 | * @param occupation 11 | */ 12 | public record PersonRecord(String name, String occupation) { 13 | 14 | public static String country = "USA"; 15 | 16 | public PersonRecord { 17 | if(name == null || occupation == null) { 18 | throw new IllegalArgumentException(); 19 | } 20 | } 21 | 22 | } 23 | -------------------------------------------------------------------------------- /section_15/src/com/eazybytes/object/demo/RecordDemo.java: -------------------------------------------------------------------------------- 1 | package com.eazybytes.object.demo; 2 | 3 | import java.lang.reflect.RecordComponent; 4 | 5 | public class RecordDemo { 6 | 7 | public static void main(String[] args) { 8 | PersonRecord personRecord = new PersonRecord("John", "Doctor"); 9 | System.out.println(personRecord.name()); 10 | System.out.println(personRecord.occupation()); 11 | System.out.println(personRecord); 12 | Class personClass = personRecord.getClass(); 13 | System.out.println(personClass.isRecord()); 14 | RecordComponent[] recordComponents = personClass.getRecordComponents(); 15 | for (RecordComponent r: recordComponents) { 16 | System.out.println(r.toString()); 17 | } 18 | } 19 | 20 | } 21 | -------------------------------------------------------------------------------- /section_15/src/com/eazybytes/object/demo/StringDemo.java: -------------------------------------------------------------------------------- 1 | package com.eazybytes.object.demo; 2 | 3 | public class StringDemo { 4 | 5 | public static void main(String[] args) { 6 | String str1 = new String("John"); 7 | String str2 = new String("John"); 8 | System.out.println(str1.hashCode()); 9 | System.out.println(str2.hashCode()); 10 | System.out.println(str1.equals(str2)); 11 | System.out.println(str1); 12 | } 13 | 14 | } 15 | -------------------------------------------------------------------------------- /section_15/src/com/eazybytes/object/demo/Student.java: -------------------------------------------------------------------------------- 1 | package com.eazybytes.object.demo; 2 | 3 | public class Student implements Cloneable { 4 | 5 | private String name; 6 | private Course course; 7 | 8 | public Student(String name, Course course) { 9 | this.name = name; 10 | this.course = course; 11 | } 12 | 13 | public String getName() { 14 | return name; 15 | } 16 | 17 | public void setName(String name) { 18 | this.name = name; 19 | } 20 | 21 | public Course getCourse() { 22 | return course; 23 | } 24 | 25 | public void setCourse(Course course) { 26 | this.course = course; 27 | } 28 | 29 | @Override 30 | public Object clone() throws CloneNotSupportedException { 31 | Student clonedStudent = (Student) super.clone(); 32 | clonedStudent.course = (Course) course.clone(); 33 | return clonedStudent; 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /section_15/src/com/eazybytes/object/demo/VarDemo.java: -------------------------------------------------------------------------------- 1 | package com.eazybytes.object.demo; 2 | 3 | public class VarDemo { 4 | 5 | public static void main(String[] args) { 6 | var message = "Hello World !"; 7 | var person = new Person(); 8 | var arr = new ArrayIndexOutOfBoundsException(); 9 | } 10 | 11 | } 12 | -------------------------------------------------------------------------------- /section_16/.gitignore: -------------------------------------------------------------------------------- 1 | ### IntelliJ IDEA ### 2 | out/ 3 | !**/src/main/**/out/ 4 | !**/src/test/**/out/ 5 | 6 | ### Eclipse ### 7 | .apt_generated 8 | .classpath 9 | .factorypath 10 | .project 11 | .settings 12 | .springBeans 13 | .sts4-cache 14 | bin/ 15 | !**/src/main/**/bin/ 16 | !**/src/test/**/bin/ 17 | 18 | ### NetBeans ### 19 | /nbproject/private/ 20 | /nbbuild/ 21 | /dist/ 22 | /nbdist/ 23 | /.nb-gradle/ 24 | 25 | ### VS Code ### 26 | .vscode/ 27 | 28 | ### Mac OS ### 29 | .DS_Store -------------------------------------------------------------------------------- /section_16/src/com/eazybytes/wrapper/AutoboxingUnboxingDemo.java: -------------------------------------------------------------------------------- 1 | package com.eazybytes.wrapper; 2 | 3 | public class AutoboxingUnboxingDemo { 4 | 5 | public static void main(String[] args) { 6 | // Autoboxing 7 | Integer integer = 16; 8 | Character character = 'M'; 9 | Boolean boolObj = false; 10 | 11 | // Unboxing 12 | int num = integer; 13 | char m = character; 14 | boolean f = boolObj; 15 | 16 | System.out.println(num); 17 | System.out.println(m); 18 | System.out.println(f); 19 | 20 | Integer nullObj = null; 21 | int num1 = nullObj; 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /section_16/src/com/eazybytes/wrapper/BoxingDemo.java: -------------------------------------------------------------------------------- 1 | package com.eazybytes.wrapper; 2 | 3 | public class BoxingDemo { 4 | 5 | public static void main(String[] args) { 6 | int num = 16; 7 | 8 | // Approach 1 - With the help of Constructor 9 | Integer integer = new Integer(num); 10 | Double doubleObj = new Double(3.14); 11 | Long longObj = new Long("95657"); 12 | 13 | // Approach 2 - With the help of valueOf() 14 | Integer integer1 = Integer.valueOf(num); 15 | Double doubleObj1 = Double.valueOf("3.14"); 16 | Long longObj1 = Long.valueOf("95657"); 17 | 18 | // Parsing 19 | int num1 = Integer.parseInt("18"); 20 | System.out.println(num1); 21 | 22 | 23 | 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /section_16/src/com/eazybytes/wrapper/UnboxingDemo.java: -------------------------------------------------------------------------------- 1 | package com.eazybytes.wrapper; 2 | 3 | public class UnboxingDemo { 4 | 5 | public static void main(String[] args) { 6 | 7 | int num = 16; 8 | 9 | // Boxing 10 | Integer integer1 = Integer.valueOf(num); 11 | Double doubleObj1 = Double.valueOf("3.14"); 12 | Long longObj1 = Long.valueOf("95657"); 13 | 14 | // Unboxing 15 | int num1 = integer1.intValue(); 16 | double num2 = doubleObj1.doubleValue(); 17 | long num3 = longObj1.longValue(); 18 | 19 | System.out.println(num1); 20 | System.out.println(num2); 21 | System.out.println(num3); 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /section_16/src/com/eazybytes/wrapper/WrapperObjectsCaching.java: -------------------------------------------------------------------------------- 1 | package com.eazybytes.wrapper; 2 | 3 | /* 4 | Integer, Byte, Short and Long 5 | */ 6 | public class WrapperObjectsCaching { 7 | 8 | public static void main(String[] args) { 9 | Integer obj1 = 16; 10 | Integer obj2 = 16; 11 | System.out.println(obj1==obj2); 12 | 13 | Integer obj3 = 128; 14 | Integer obj4 = 128; 15 | System.out.println(obj3==obj4); 16 | 17 | Integer obj5 = new Integer(16); 18 | Integer obj6 = new Integer(16); 19 | System.out.println(obj5==obj6); 20 | } 21 | 22 | } 23 | -------------------------------------------------------------------------------- /section_17/.gitignore: -------------------------------------------------------------------------------- 1 | ### IntelliJ IDEA ### 2 | out/ 3 | !**/src/main/**/out/ 4 | !**/src/test/**/out/ 5 | 6 | ### Eclipse ### 7 | .apt_generated 8 | .classpath 9 | .factorypath 10 | .project 11 | .settings 12 | .springBeans 13 | .sts4-cache 14 | bin/ 15 | !**/src/main/**/bin/ 16 | !**/src/test/**/bin/ 17 | 18 | ### NetBeans ### 19 | /nbproject/private/ 20 | /nbbuild/ 21 | /dist/ 22 | /nbdist/ 23 | /.nb-gradle/ 24 | 25 | ### VS Code ### 26 | .vscode/ 27 | 28 | ### Mac OS ### 29 | .DS_Store -------------------------------------------------------------------------------- /section_17/src/com/eazybytes/list/ArrayListForEachExample.java: -------------------------------------------------------------------------------- 1 | package com.eazybytes.list; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | 6 | public class ArrayListForEachExample { 7 | 8 | public static void main(String[] args) { 9 | List countryNames = new ArrayList<>(); 10 | countryNames.add("India"); 11 | countryNames.add("Canada"); 12 | countryNames.add("USA"); 13 | countryNames.add("Germany"); 14 | countryNames.add("India"); 15 | 16 | for(String country:countryNames) { 17 | System.out.println(country); 18 | } 19 | 20 | } 21 | 22 | } 23 | -------------------------------------------------------------------------------- /section_17/src/com/eazybytes/list/ArrayListIteratorExample.java: -------------------------------------------------------------------------------- 1 | package com.eazybytes.list; 2 | 3 | import java.util.ArrayList; 4 | import java.util.Iterator; 5 | import java.util.List; 6 | 7 | public class ArrayListIteratorExample { 8 | 9 | public static void main(String[] args) { 10 | List countryNames = new ArrayList<>(); 11 | countryNames.add("India"); 12 | countryNames.add("Canada"); 13 | countryNames.add("USA"); 14 | countryNames.add("Germany"); 15 | countryNames.add("India"); 16 | Iterator iterator = countryNames.iterator(); 17 | while (iterator.hasNext()) { 18 | String country = iterator.next(); 19 | System.out.println(country); 20 | if(country.equals("India")) { 21 | iterator.remove(); 22 | } 23 | } 24 | System.out.println(countryNames); 25 | 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /section_17/src/com/eazybytes/list/ArrayListListIteratorExample.java: -------------------------------------------------------------------------------- 1 | package com.eazybytes.list; 2 | 3 | import java.util.*; 4 | 5 | public class ArrayListListIteratorExample { 6 | 7 | public static void main(String[] args) { 8 | List countryNames = new ArrayList<>(); 9 | countryNames.add("India"); 10 | countryNames.add("Canada"); 11 | countryNames.add("USA"); 12 | countryNames.add("Germany"); 13 | countryNames.add("India"); 14 | ListIterator listIterator = countryNames.listIterator(); 15 | while (listIterator.hasNext()) { 16 | String country = listIterator.next(); 17 | System.out.println(country); 18 | } 19 | while (listIterator.hasPrevious()) { 20 | String country = listIterator.previous(); 21 | System.out.println(country); 22 | } 23 | 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /section_17/src/com/eazybytes/list/ArrayVsArrayList.java: -------------------------------------------------------------------------------- 1 | package com.eazybytes.list; 2 | 3 | import java.util.ArrayList; 4 | import java.util.Arrays; 5 | import java.util.List; 6 | 7 | public class ArrayVsArrayList { 8 | 9 | public static void main(String[] args) { 10 | ArrayList countryNames = new ArrayList<>(); 11 | countryNames.add("India"); 12 | countryNames.add("Canada"); 13 | countryNames.add("USA"); 14 | countryNames.add("Germany"); 15 | countryNames.add("India"); 16 | 17 | String[] countries = countryNames.toArray(new String[countryNames.size()]); 18 | System.out.println(Arrays.toString(countries)); 19 | 20 | List newList = Arrays.asList(countries); 21 | System.out.println(newList); 22 | 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /section_17/src/com/eazybytes/list/DiamondOperator.java: -------------------------------------------------------------------------------- 1 | package com.eazybytes.list; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | 6 | public class DiamondOperator { 7 | 8 | public static void main(String[] args) { 9 | // DRY - Don't REPEAT Yourself 10 | ArrayList nums = new ArrayList<>(); 11 | List characters = new ArrayList<>(); 12 | var doubleNums = new ArrayList(); 13 | List countryNames = new ArrayList<>(); 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /section_17/src/com/eazybytes/list/ImmutableListDemo.java: -------------------------------------------------------------------------------- 1 | package com.eazybytes.list; 2 | 3 | import java.util.ArrayList; 4 | import java.util.Collections; 5 | import java.util.List; 6 | 7 | public class ImmutableListDemo { 8 | 9 | public static void main(String[] args) { 10 | List accountNums = new ArrayList<>(); 11 | accountNums.add(325454); 12 | accountNums.add(325455); 13 | accountNums.add(325456); 14 | accountNums = Collections.unmodifiableList(accountNums); 15 | List immutableAccountNums = List.of(325454, 325455, 325456); 16 | var arrayListObject = new ArrayList(immutableAccountNums); 17 | addTenDollars(arrayListObject); 18 | } 19 | 20 | private static List addTenDollars(List accountNums) { 21 | accountNums.add(545643); 22 | for(Integer account: accountNums) { 23 | System.out.println("Ten Dollars credited into the account : "+account); 24 | } 25 | return accountNums; 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /section_17/src/com/eazybytes/list/LastCharComparator.java: -------------------------------------------------------------------------------- 1 | package com.eazybytes.list; 2 | 3 | import java.util.Comparator; 4 | 5 | public class LastCharComparator implements Comparator { 6 | 7 | @Override 8 | public int compare(String o1, String o2) { 9 | char lastChar1 = o1.charAt(o1.length()-1); 10 | char lastChar2 = o2.charAt(o2.length()-1); 11 | return Character.compare(lastChar2,lastChar1); 12 | } 13 | 14 | } 15 | -------------------------------------------------------------------------------- /section_17/src/com/eazybytes/list/Student.java: -------------------------------------------------------------------------------- 1 | package com.eazybytes.list; 2 | 3 | public class Student implements Comparable { 4 | 5 | String name; 6 | int rollNumber; 7 | int marks; 8 | 9 | public Student(String name, int rollNumber, int marks) { 10 | this.name = name; 11 | this.rollNumber = rollNumber; 12 | this.marks = marks; 13 | } 14 | 15 | @Override 16 | public String toString() { 17 | return "Student{" + 18 | "name='" + name + '\'' + 19 | ", rollNumber=" + rollNumber + 20 | ", marks=" + marks + 21 | '}'; 22 | } 23 | 24 | @Override 25 | public int compareTo(Student o) { 26 | int marksComparision = Integer.compare(this.marks, o.marks); 27 | if(marksComparision==0) { 28 | return Integer.compare(this.rollNumber, o.rollNumber); 29 | } 30 | return marksComparision; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /section_17/src/com/eazybytes/list/StudentComparator.java: -------------------------------------------------------------------------------- 1 | package com.eazybytes.list; 2 | 3 | import java.util.Comparator; 4 | 5 | public class StudentComparator implements Comparator { 6 | 7 | @Override 8 | public int compare(Student o1, Student o2) { 9 | int marksComparision = Integer.compare(o1.marks, o2.marks); 10 | if(marksComparision==0) { 11 | return Integer.compare(o1.rollNumber, o2.rollNumber); 12 | } 13 | return marksComparision; 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /section_17/src/com/eazybytes/list/StudentMarkComparator.java: -------------------------------------------------------------------------------- 1 | package com.eazybytes.list; 2 | 3 | import java.util.Comparator; 4 | 5 | public class StudentMarkComparator implements Comparator { 6 | 7 | @Override 8 | public int compare(Student o1, Student o2) { 9 | return Integer.compare(o1.marks, o2.marks); 10 | } 11 | 12 | } 13 | -------------------------------------------------------------------------------- /section_17/src/com/eazybytes/list/StudentSortingDemo.java: -------------------------------------------------------------------------------- 1 | package com.eazybytes.list; 2 | 3 | import java.util.ArrayList; 4 | import java.util.Collections; 5 | 6 | public class StudentSortingDemo { 7 | 8 | public static void main(String[] args) { 9 | var students = new ArrayList(); 10 | students.add(new Student("John", 167, 97)); 11 | students.add(new Student("Smith", 168, 92)); 12 | students.add(new Student("Will", 169, 92)); 13 | students.add(new Student("Madan", 170, 99)); 14 | System.out.println(students); 15 | Collections.sort(students); 16 | System.out.println(students); 17 | 18 | var students1 = new ArrayList(); 19 | students1.add(new Student("John", 167, 97)); 20 | students1.add(new Student("Smith", 168, 92)); 21 | students1.add(new Student("Will", 169, 92)); 22 | students1.add(new Student("Madan", 170, 99)); 23 | Collections.sort(students1,new StudentMarkComparator()); 24 | // students1.sort(new StudentComparator()); 25 | System.out.println(students1); 26 | 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /section_18/.gitignore: -------------------------------------------------------------------------------- 1 | ### IntelliJ IDEA ### 2 | out/ 3 | !**/src/main/**/out/ 4 | !**/src/test/**/out/ 5 | 6 | ### Eclipse ### 7 | .apt_generated 8 | .classpath 9 | .factorypath 10 | .project 11 | .settings 12 | .springBeans 13 | .sts4-cache 14 | bin/ 15 | !**/src/main/**/bin/ 16 | !**/src/test/**/bin/ 17 | 18 | ### NetBeans ### 19 | /nbproject/private/ 20 | /nbbuild/ 21 | /dist/ 22 | /nbdist/ 23 | /.nb-gradle/ 24 | 25 | ### VS Code ### 26 | .vscode/ 27 | 28 | ### Mac OS ### 29 | .DS_Store -------------------------------------------------------------------------------- /section_18/src/com/eazybytes/list/LastCharComparator.java: -------------------------------------------------------------------------------- 1 | package com.eazybytes.list; 2 | 3 | import java.util.Comparator; 4 | 5 | public class LastCharComparator implements Comparator { 6 | 7 | @Override 8 | public int compare(String o1, String o2) { 9 | char lastChar1 = o1.charAt(o1.length()-1); 10 | char lastChar2 = o2.charAt(o2.length()-1); 11 | return Character.compare(lastChar2,lastChar1); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /section_18/src/com/eazybytes/list/LinkedListDemo.java: -------------------------------------------------------------------------------- 1 | package com.eazybytes.list; 2 | 3 | import java.util.LinkedList; 4 | import java.util.List; 5 | 6 | public class LinkedListDemo { 7 | 8 | public static void main(String[] args) { 9 | LinkedList nums = new LinkedList<>(); 10 | List doubleNums = new LinkedList<>(); 11 | var countryNames = new LinkedList(); 12 | countryNames.add("India"); 13 | countryNames.add("Canada"); 14 | countryNames.add("USA"); 15 | countryNames.add("Germany"); 16 | countryNames.add("India"); 17 | System.out.println(countryNames); 18 | countryNames.set(4, "Spain"); 19 | countryNames.remove("India"); 20 | String firstElement = countryNames.getFirst(); 21 | String lastElement = countryNames.getLast(); 22 | System.out.println(countryNames); 23 | LinkedList reversedCountryNames = countryNames.reversed(); 24 | System.out.println(reversedCountryNames); 25 | 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /section_19/.gitignore: -------------------------------------------------------------------------------- 1 | ### IntelliJ IDEA ### 2 | out/ 3 | !**/src/main/**/out/ 4 | !**/src/test/**/out/ 5 | 6 | ### Eclipse ### 7 | .apt_generated 8 | .classpath 9 | .factorypath 10 | .project 11 | .settings 12 | .springBeans 13 | .sts4-cache 14 | bin/ 15 | !**/src/main/**/bin/ 16 | !**/src/test/**/bin/ 17 | 18 | ### NetBeans ### 19 | /nbproject/private/ 20 | /nbbuild/ 21 | /dist/ 22 | /nbdist/ 23 | /.nb-gradle/ 24 | 25 | ### VS Code ### 26 | .vscode/ 27 | 28 | ### Mac OS ### 29 | .DS_Store -------------------------------------------------------------------------------- /section_19/src/com/eazybytes/generics/GenericCodeDemo.java: -------------------------------------------------------------------------------- 1 | package com.eazybytes.generics; 2 | 3 | public class GenericCodeDemo { 4 | 5 | public static void main(String[] args) { 6 | GenericPair stringIntPair = new GenericPair<>("Hello", 42); 7 | stringIntPair.setFirst("Another String"); 8 | stringIntPair.setSecond(123); 9 | String myString = stringIntPair.getFirst(); 10 | int myInt = stringIntPair.getSecond(); 11 | System.out.println(myString); 12 | System.out.println(myInt); 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /section_19/src/com/eazybytes/generics/GenericMethodDemo.java: -------------------------------------------------------------------------------- 1 | package com.eazybytes.generics; 2 | 3 | public class GenericMethodDemo { 4 | 5 | public static void main(String[] args) { 6 | String[] stringArray = {"Hello", "World"}; 7 | printArray(stringArray); 8 | Integer[] intArray = {1,2,3,4,5}; 9 | printArray(intArray); 10 | } 11 | 12 | public static void printArray(T[] array){ 13 | for(T element:array){ 14 | System.out.println(element); 15 | } 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /section_19/src/com/eazybytes/generics/GenericPair.java: -------------------------------------------------------------------------------- 1 | package com.eazybytes.generics; 2 | 3 | public class GenericPair { 4 | 5 | private T first; 6 | private U second; 7 | 8 | public GenericPair(T first, U second) { 9 | this.first = first; 10 | this.second = second; 11 | } 12 | 13 | public T getFirst() { 14 | return first; 15 | } 16 | 17 | public void setFirst(T first) { 18 | this.first = first; 19 | } 20 | 21 | public U getSecond() { 22 | return second; 23 | } 24 | 25 | public void setSecond(U second) { 26 | this.second = second; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /section_19/src/com/eazybytes/generics/LowerBoundWildCardDemo.java: -------------------------------------------------------------------------------- 1 | package com.eazybytes.generics; 2 | 3 | import java.util.ArrayList; 4 | import java.util.Arrays; 5 | import java.util.List; 6 | 7 | public class LowerBoundWildCardDemo { 8 | 9 | public static void main(String[] args) { 10 | addNumbers(new ArrayList<>()); 11 | } 12 | 13 | public static void addNumbers(List list) { 14 | for(int i=0;i<10;i++) { 15 | list.add(i); 16 | } 17 | // list.add(3.14); 18 | System.out.println(list); 19 | } 20 | 21 | } 22 | -------------------------------------------------------------------------------- /section_19/src/com/eazybytes/generics/NonGenericCodeDemo.java: -------------------------------------------------------------------------------- 1 | package com.eazybytes.generics; 2 | 3 | public class NonGenericCodeDemo { 4 | 5 | public static void main(String[] args) { 6 | Pair stringIntPair = new Pair("Hello", 42); 7 | stringIntPair.setFirst(16); 8 | String myString = (String) stringIntPair.getFirst(); // Requires casting 9 | int myInt = (Integer) stringIntPair.getSecond(); // Requires casting 10 | System.out.println(myString); 11 | System.out.println(myInt); 12 | } 13 | 14 | } 15 | -------------------------------------------------------------------------------- /section_19/src/com/eazybytes/generics/Pair.java: -------------------------------------------------------------------------------- 1 | package com.eazybytes.generics; 2 | 3 | 4 | public class Pair { 5 | 6 | private Object first; 7 | private Object second; 8 | 9 | public Pair(Object first, Object second) { 10 | this.first = first; 11 | this.second = second; 12 | } 13 | 14 | public Object getFirst() { 15 | return first; 16 | } 17 | 18 | public void setFirst(Object first) { 19 | this.first = first; 20 | } 21 | 22 | public Object getSecond() { 23 | return second; 24 | } 25 | 26 | public void setSecond(Object second) { 27 | this.second = second; 28 | } 29 | 30 | } 31 | -------------------------------------------------------------------------------- /section_19/src/com/eazybytes/generics/UnBoundedWildCardDemo.java: -------------------------------------------------------------------------------- 1 | package com.eazybytes.generics; 2 | 3 | import java.util.Arrays; 4 | import java.util.List; 5 | 6 | public class UnBoundedWildCardDemo { 7 | 8 | public static void main(String[] args) { 9 | List li = Arrays.asList(1, 2, 3); 10 | List ls = Arrays.asList("One", "Two", "Three"); 11 | printList(li); 12 | printList(ls); 13 | } 14 | 15 | public static void printList(List list) { 16 | for (Object obj : list) { 17 | System.out.println(obj); 18 | } 19 | System.out.println(list.size()); 20 | } 21 | 22 | } 23 | -------------------------------------------------------------------------------- /section_19/src/com/eazybytes/generics/UpperBoundWildCardDemo.java: -------------------------------------------------------------------------------- 1 | package com.eazybytes.generics; 2 | 3 | import com.eazybytes.generics.model.Developer; 4 | import com.eazybytes.generics.model.Employee; 5 | import com.eazybytes.generics.model.Manager; 6 | 7 | import java.util.ArrayList; 8 | import java.util.List; 9 | 10 | public class UpperBoundWildCardDemo { 11 | 12 | public static void main(String[] args) { 13 | 14 | List employees = List.of(new Employee(), new Employee()); 15 | printEmployeeNames(employees); 16 | List developers = List.of(new Developer(), new Developer()); 17 | printEmployeeNames(developers); 18 | List managers = List.of(new Manager(), new Manager()); 19 | printEmployeeNames(managers); 20 | } 21 | 22 | public static void printEmployeeNames(List employees) { 23 | for(Employee employee: employees) { 24 | System.out.println(employee); 25 | } 26 | } 27 | 28 | 29 | 30 | } 31 | -------------------------------------------------------------------------------- /section_19/src/com/eazybytes/generics/WithOutGenericsDemo.java: -------------------------------------------------------------------------------- 1 | package com.eazybytes.generics; 2 | 3 | import java.util.ArrayList; 4 | 5 | public class WithOutGenericsDemo { 6 | 7 | public static void main(String[] args) { 8 | ArrayList list = new ArrayList(); 9 | list.add("Hello"); 10 | list.add(123); 11 | list.add(true); 12 | 13 | String greeting = (String) list.get(0); 14 | int number = (Integer) list.get(1); 15 | boolean flag = (Boolean) list.get(2); 16 | 17 | ArrayList list1 = new ArrayList<>(); 18 | list1.add("Hello"); 19 | // list1.add(123); 20 | // list1.add(true); 21 | 22 | String greeting1 = list1.get(0); 23 | // int number = (Integer) list.get(1); 24 | // boolean flag = (Boolean) list.get(0); 25 | 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /section_19/src/com/eazybytes/generics/model/Developer.java: -------------------------------------------------------------------------------- 1 | package com.eazybytes.generics.model; 2 | 3 | public class Developer extends Employee { 4 | 5 | @Override 6 | public String toString() { 7 | return "Developer{}"; 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /section_19/src/com/eazybytes/generics/model/Employee.java: -------------------------------------------------------------------------------- 1 | package com.eazybytes.generics.model; 2 | 3 | public class Employee { 4 | 5 | @Override 6 | public String toString() { 7 | return "Employee{}"; 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /section_19/src/com/eazybytes/generics/model/Manager.java: -------------------------------------------------------------------------------- 1 | package com.eazybytes.generics.model; 2 | 3 | public class Manager extends Employee { 4 | 5 | @Override 6 | public String toString() { 7 | return "Manager{}"; 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /section_20/.gitignore: -------------------------------------------------------------------------------- 1 | ### IntelliJ IDEA ### 2 | out/ 3 | !**/src/main/**/out/ 4 | !**/src/test/**/out/ 5 | 6 | ### Eclipse ### 7 | .apt_generated 8 | .classpath 9 | .factorypath 10 | .project 11 | .settings 12 | .springBeans 13 | .sts4-cache 14 | bin/ 15 | !**/src/main/**/bin/ 16 | !**/src/test/**/bin/ 17 | 18 | ### NetBeans ### 19 | /nbproject/private/ 20 | /nbbuild/ 21 | /dist/ 22 | /nbdist/ 23 | /.nb-gradle/ 24 | 25 | ### VS Code ### 26 | .vscode/ 27 | 28 | ### Mac OS ### 29 | .DS_Store -------------------------------------------------------------------------------- /section_20/src/com/eazybytes/map/HashMapDemo.java: -------------------------------------------------------------------------------- 1 | package com.eazybytes.map; 2 | 3 | import java.util.HashMap; 4 | import java.util.Map; 5 | 6 | public class HashMapDemo { 7 | 8 | public static void main(String[] args) { 9 | var countryMap = new HashMap(); 10 | countryMap.put("India", "New Delhi"); 11 | countryMap.put("USA", "Washington, DC"); 12 | countryMap.put("France", "Paris"); 13 | countryMap.put(null, null); 14 | 15 | System.out.println(countryMap.get("India")); 16 | countryMap.remove(null); 17 | System.out.println(countryMap.size()); 18 | 19 | } 20 | 21 | } 22 | -------------------------------------------------------------------------------- /section_20/src/com/eazybytes/map/ImmutableMapDemo.java: -------------------------------------------------------------------------------- 1 | package com.eazybytes.map; 2 | 3 | import java.util.Map; 4 | import static java.util.Map.entry; 5 | 6 | public class ImmutableMapDemo { 7 | 8 | public static void main(String[] args) { 9 | Map stringIntegerMap = Map.of("a",1,"b",2,"c",3); 10 | processMap(stringIntegerMap); 11 | 12 | Map integerStringMap = Map.ofEntries(entry(1, "Tom"), 13 | entry(2, "Dick"), 14 | entry(3, "Harry")); 15 | processMap1(integerStringMap); 16 | 17 | } 18 | 19 | public static void processMap(Map stringIntegerMap) { 20 | for(Map.Entry entry : stringIntegerMap.entrySet()){ 21 | System.out.println(entry.getKey()+":"+entry.getValue()); 22 | } 23 | } 24 | 25 | public static void processMap1(Map integerStringMap) { 26 | for(Map.Entry entry : integerStringMap.entrySet()){ 27 | System.out.println(entry.getKey()+":"+entry.getValue()); 28 | } 29 | } 30 | 31 | 32 | } 33 | -------------------------------------------------------------------------------- /section_20/src/com/eazybytes/map/LinkedHashMapDemo.java: -------------------------------------------------------------------------------- 1 | package com.eazybytes.map; 2 | 3 | import java.util.LinkedHashMap; 4 | import java.util.Map; 5 | import java.util.SequencedMap; 6 | 7 | public class LinkedHashMapDemo { 8 | 9 | public static void main(String[] args) { 10 | LinkedHashMap linkedHashMap = new LinkedHashMap<>(); 11 | 12 | linkedHashMap.put(4, "Four"); 13 | linkedHashMap.put(1, "One"); 14 | linkedHashMap.put(7, "Seven"); 15 | linkedHashMap.put(2, "Two"); 16 | 17 | for(Map.Entry entry : linkedHashMap.entrySet()) { 18 | System.out.println(entry.getKey()+":"+entry.getValue()); 19 | } 20 | SequencedMap reversedLinkedHashMap = linkedHashMap.reversed(); 21 | 22 | for(Map.Entry entry : reversedLinkedHashMap.entrySet()) { 23 | System.out.println(entry.getKey()+":"+entry.getValue()); 24 | } 25 | 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /section_20/src/com/eazybytes/map/TreeMapDemo.java: -------------------------------------------------------------------------------- 1 | package com.eazybytes.map; 2 | 3 | import java.util.Map; 4 | import java.util.TreeMap; 5 | 6 | public class TreeMapDemo { 7 | 8 | public static void main(String[] args) { 9 | Map numbers = new TreeMap<>(); 10 | numbers.put(23, "Twenty three"); 11 | numbers.put(12, "Twelve"); 12 | numbers.put(42, "Forty two"); 13 | numbers.put(3, "Three"); 14 | numbers.put(19, "Nineteen"); 15 | numbers.put(48, "Forty eight"); 16 | numbers.put(76, "Seventy six"); 17 | 18 | for(Map.Entry entry : numbers.entrySet()){ 19 | System.out.println(entry.getKey()+"-"+entry.getValue()); 20 | } 21 | 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /section_21/.gitignore: -------------------------------------------------------------------------------- 1 | ### IntelliJ IDEA ### 2 | out/ 3 | !**/src/main/**/out/ 4 | !**/src/test/**/out/ 5 | 6 | ### Eclipse ### 7 | .apt_generated 8 | .classpath 9 | .factorypath 10 | .project 11 | .settings 12 | .springBeans 13 | .sts4-cache 14 | bin/ 15 | !**/src/main/**/bin/ 16 | !**/src/test/**/bin/ 17 | 18 | ### NetBeans ### 19 | /nbproject/private/ 20 | /nbbuild/ 21 | /dist/ 22 | /nbdist/ 23 | /.nb-gradle/ 24 | 25 | ### VS Code ### 26 | .vscode/ 27 | 28 | ### Mac OS ### 29 | .DS_Store -------------------------------------------------------------------------------- /section_21/src/com/eazybytes/set/HashSetDemo.java: -------------------------------------------------------------------------------- 1 | package com.eazybytes.set; 2 | 3 | import java.util.HashSet; 4 | import java.util.Set; 5 | 6 | public class HashSetDemo { 7 | 8 | public static void main(String[] args) { 9 | Set visitedCountries = new HashSet<>(); 10 | visitedCountries.add("India"); 11 | visitedCountries.add("USA"); 12 | visitedCountries.add("Dubai"); 13 | visitedCountries.add("Singapore"); 14 | visitedCountries.add("France"); 15 | visitedCountries.add("India"); 16 | System.out.println(visitedCountries.size()); 17 | System.out.println(visitedCountries); 18 | boolean isDubai = visitedCountries.contains("Germany"); 19 | System.out.println(isDubai); 20 | boolean isRemoved = visitedCountries.remove("Singapore"); 21 | System.out.println(isRemoved); 22 | System.out.println(visitedCountries); 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /section_21/src/com/eazybytes/set/ImmutableSetDemo.java: -------------------------------------------------------------------------------- 1 | package com.eazybytes.set; 2 | 3 | import java.util.Arrays; 4 | import java.util.Collections; 5 | import java.util.HashSet; 6 | import java.util.Set; 7 | 8 | public class ImmutableSetDemo { 9 | 10 | public static void main(String[] args) { 11 | Set stringSet = new HashSet<>(Arrays.asList("a","b","c")); 12 | stringSet = Collections.unmodifiableSet(stringSet); 13 | Set stringSet1 = Set.of("a","b","c"); 14 | processSet(stringSet1); 15 | } 16 | 17 | public static void processSet(Set stringSet) { 18 | // stringSet.add("d"); 19 | for (String element:stringSet) { 20 | System.out.println(element.toUpperCase()); 21 | } 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /section_21/src/com/eazybytes/set/LinkedHashSetDemo.java: -------------------------------------------------------------------------------- 1 | package com.eazybytes.set; 2 | 3 | import java.util.LinkedHashSet; 4 | import java.util.SequencedSet; 5 | 6 | public class LinkedHashSetDemo { 7 | 8 | public static void main(String[] args) { 9 | var visitedCountries = new LinkedHashSet(); 10 | visitedCountries.add("India"); 11 | visitedCountries.add("USA"); 12 | visitedCountries.add("Dubai"); 13 | visitedCountries.add("Singapore"); 14 | visitedCountries.add("France"); 15 | 16 | for (String countryName: visitedCountries) { 17 | System.out.println(countryName); 18 | } 19 | 20 | SequencedSet reversedVisitedCountries = visitedCountries.reversed(); 21 | System.out.println(reversedVisitedCountries); 22 | 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /section_21/src/com/eazybytes/set/SetOperationsDemo.java: -------------------------------------------------------------------------------- 1 | package com.eazybytes.set; 2 | 3 | import java.util.HashSet; 4 | import java.util.Set; 5 | 6 | public class SetOperationsDemo { 7 | 8 | public static void main(String[] args) { 9 | Set hashSet1 = new HashSet<>(); 10 | hashSet1.add(7); 11 | hashSet1.add(4); 12 | hashSet1.add(1); 13 | 14 | Set hashSet2 = new HashSet<>(); 15 | hashSet2.add(1); 16 | hashSet2.add(7); 17 | 18 | // Union 19 | // hashSet1.addAll(hashSet2); 20 | // Intersection 21 | // hashSet1.retainAll(hashSet2); 22 | // Difference 23 | // hashSet1.removeAll(hashSet2); 24 | // Subset 25 | boolean isSubSet = hashSet1.containsAll(hashSet2); 26 | System.out.println(isSubSet); 27 | System.out.println(hashSet1); 28 | System.out.println(hashSet2); 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /section_21/src/com/eazybytes/set/TreeSetDemo.java: -------------------------------------------------------------------------------- 1 | package com.eazybytes.set; 2 | 3 | import java.util.TreeSet; 4 | 5 | public class TreeSetDemo { 6 | 7 | public static void main(String[] args) { 8 | TreeSet treeSet = new TreeSet<>(); 9 | treeSet.add("India"); 10 | treeSet.add("USA"); 11 | treeSet.add("Germany"); 12 | 13 | System.out.println(treeSet); 14 | treeSet.remove("Germany"); 15 | System.out.println("TreeSet after removal : "+treeSet); 16 | System.out.println("Size of TreeSet : "+treeSet.size()); 17 | System.out.println("Is India present in TreeSet : "+treeSet.contains("India")); 18 | System.out.println("First element of TreeSet : "+treeSet.first()); 19 | System.out.println("Last element of TreeSet : "+treeSet.last()); 20 | 21 | 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /section_22/.gitignore: -------------------------------------------------------------------------------- 1 | ### IntelliJ IDEA ### 2 | out/ 3 | !**/src/main/**/out/ 4 | !**/src/test/**/out/ 5 | 6 | ### Eclipse ### 7 | .apt_generated 8 | .classpath 9 | .factorypath 10 | .project 11 | .settings 12 | .springBeans 13 | .sts4-cache 14 | bin/ 15 | !**/src/main/**/bin/ 16 | !**/src/test/**/bin/ 17 | 18 | ### NetBeans ### 19 | /nbproject/private/ 20 | /nbbuild/ 21 | /dist/ 22 | /nbdist/ 23 | /.nb-gradle/ 24 | 25 | ### VS Code ### 26 | .vscode/ 27 | 28 | ### Mac OS ### 29 | .DS_Store -------------------------------------------------------------------------------- /section_22/src/com/eazybytes/enumeration/AdvancedPriorityEnum.java: -------------------------------------------------------------------------------- 1 | package com.eazybytes.enumeration; 2 | 3 | public enum AdvancedPriorityEnum { 4 | LOW(7), MEDIUM(5), HIGH(2), URGENT(1); 5 | 6 | private int estimatedCompletionDays; 7 | 8 | AdvancedPriorityEnum(int estimatedCompletionDays) { 9 | this.estimatedCompletionDays = estimatedCompletionDays; 10 | } 11 | 12 | public int getEstimatedCompletionDays() { 13 | return estimatedCompletionDays; 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /section_22/src/com/eazybytes/enumeration/AdvancedPriorityEnumTest.java: -------------------------------------------------------------------------------- 1 | package com.eazybytes.enumeration; 2 | 3 | public class AdvancedPriorityEnumTest { 4 | 5 | public static void main(String[] args) { 6 | 7 | for(AdvancedPriorityEnum priorityEnum : AdvancedPriorityEnum.values()){ 8 | String name = priorityEnum.name(); 9 | int ordinal = priorityEnum.ordinal(); 10 | int days = priorityEnum.getEstimatedCompletionDays(); 11 | System.out.println("name = " + name + ", ordinal = "+ordinal 12 | +", days = "+ days); 13 | } 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /section_22/src/com/eazybytes/enumeration/Car.java: -------------------------------------------------------------------------------- 1 | package com.eazybytes.enumeration; 2 | 3 | public class Car { 4 | public enum Model { 5 | SEDAN, SUV, HATCHBACK 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /section_22/src/com/eazybytes/enumeration/Day.java: -------------------------------------------------------------------------------- 1 | package com.eazybytes.enumeration; 2 | 3 | public enum Day { 4 | MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY, SUNDAY 5 | } 6 | -------------------------------------------------------------------------------- /section_22/src/com/eazybytes/enumeration/EnumSetDemo.java: -------------------------------------------------------------------------------- 1 | package com.eazybytes.enumeration; 2 | 3 | import java.util.EnumSet; 4 | 5 | public class EnumSetDemo { 6 | 7 | public static void main(String[] args) { 8 | EnumSet allDays = EnumSet.allOf(Day.class); 9 | EnumSet someDays = EnumSet.of(Day.MONDAY, Day.TUESDAY, Day.WEDNESDAY); 10 | for(Day day : someDays){ 11 | System.out.println(day); 12 | } 13 | 14 | EnumSet passGrades = EnumSet.range(Grades.A, Grades.C); 15 | for(Grades grade : passGrades){ 16 | System.out.println(grade); 17 | } 18 | 19 | EnumSet failGrades = EnumSet.complementOf(passGrades); 20 | for(Grades grade : failGrades){ 21 | System.out.println(grade); 22 | } 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /section_22/src/com/eazybytes/enumeration/Grades.java: -------------------------------------------------------------------------------- 1 | package com.eazybytes.enumeration; 2 | 3 | public enum Grades { 4 | 5 | A, B, C, D, E 6 | 7 | } 8 | -------------------------------------------------------------------------------- /section_22/src/com/eazybytes/enumeration/InternalEnumMethodsDemo.java: -------------------------------------------------------------------------------- 1 | package com.eazybytes.enumeration; 2 | 3 | public class InternalEnumMethodsDemo { 4 | 5 | public static void main(String[] args) { 6 | for(PriorityEnum priorityEnum : PriorityEnum.values()) { 7 | String name = priorityEnum.name(); 8 | int ordinal = priorityEnum.ordinal(); 9 | System.out.println(name+ "(" + ordinal + ")"); 10 | } 11 | PriorityEnum low = PriorityEnum.valueOf("LOW"); 12 | System.out.println(low); 13 | PriorityEnum high = PriorityEnum.values() [2]; 14 | System.out.println(high); 15 | } 16 | 17 | } 18 | -------------------------------------------------------------------------------- /section_22/src/com/eazybytes/enumeration/Priority.java: -------------------------------------------------------------------------------- 1 | package com.eazybytes.enumeration; 2 | 3 | public class Priority { 4 | 5 | public static final int LOW = 0; 6 | public static final int MEDIUM = 1; 7 | public static final int HIGH = 2; 8 | public static final int URGENT = 3; 9 | 10 | } 11 | -------------------------------------------------------------------------------- /section_22/src/com/eazybytes/enumeration/PriorityEnum.java: -------------------------------------------------------------------------------- 1 | package com.eazybytes.enumeration; 2 | 3 | public enum PriorityEnum { 4 | LOW, MEDIUM, HIGH, URGENT 5 | } 6 | -------------------------------------------------------------------------------- /section_22/src/com/eazybytes/enumeration/Size.java: -------------------------------------------------------------------------------- 1 | package com.eazybytes.enumeration; 2 | 3 | public enum Size { 4 | SMALL, MEDIUM, LARGE, EXTRA_LARGE 5 | } 6 | -------------------------------------------------------------------------------- /section_22/src/com/eazybytes/enumeration/TaskPriorityConstantDemo.java: -------------------------------------------------------------------------------- 1 | package com.eazybytes.enumeration; 2 | 3 | public class TaskPriorityConstantDemo { 4 | 5 | private PriorityEnum priority; 6 | 7 | public static void main(String[] args) { 8 | PriorityEnum priorityEnum = null; 9 | System.out.println(TaskUtil.getEstimatedCompletionTime(PriorityEnum.LOW)); 10 | System.out.println(TaskUtil.getEstimatedCompletionTime(PriorityEnum.MEDIUM)); 11 | System.out.println(TaskUtil.getEstimatedCompletionTime(PriorityEnum.HIGH)); 12 | System.out.println(TaskUtil.getEstimatedCompletionTime(PriorityEnum.URGENT)); 13 | System.out.println(PriorityEnum.URGENT); 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /section_22/src/com/eazybytes/enumeration/TaskUtil.java: -------------------------------------------------------------------------------- 1 | package com.eazybytes.enumeration; 2 | 3 | public class TaskUtil { 4 | 5 | public static int getEstimatedCompletionTime(PriorityEnum priority) { 6 | return switch (priority) { 7 | case LOW -> 7; 8 | case MEDIUM -> 5; 9 | case HIGH -> 3; 10 | case URGENT -> 1; 11 | }; 12 | } 13 | 14 | } 15 | -------------------------------------------------------------------------------- /section_23/.gitignore: -------------------------------------------------------------------------------- 1 | ### IntelliJ IDEA ### 2 | out/ 3 | !**/src/main/**/out/ 4 | !**/src/test/**/out/ 5 | 6 | ### Eclipse ### 7 | .apt_generated 8 | .classpath 9 | .factorypath 10 | .project 11 | .settings 12 | .springBeans 13 | .sts4-cache 14 | bin/ 15 | !**/src/main/**/bin/ 16 | !**/src/test/**/bin/ 17 | 18 | ### NetBeans ### 19 | /nbproject/private/ 20 | /nbbuild/ 21 | /dist/ 22 | /nbdist/ 23 | /.nb-gradle/ 24 | 25 | ### VS Code ### 26 | .vscode/ 27 | 28 | ### Mac OS ### 29 | .DS_Store -------------------------------------------------------------------------------- /section_23/src/com/eazybytes/legacy/DateFormattingDemo.java: -------------------------------------------------------------------------------- 1 | package com.eazybytes.legacy; 2 | 3 | import java.text.ParseException; 4 | import java.text.SimpleDateFormat; 5 | import java.util.Date; 6 | 7 | public class DateFormattingDemo { 8 | 9 | public static void main(String[] args) throws ParseException { 10 | Date currentDate = new Date(); 11 | System.out.println(currentDate); // Fri Feb 09 14:52:01 IST 2024 12 | SimpleDateFormat dateFormat = new SimpleDateFormat("yy-MMMM-dd HH:mm:ss"); 13 | String formattedDate = dateFormat.format(currentDate); 14 | System.out.println(formattedDate); 15 | 16 | SimpleDateFormat dateFormat1 = new SimpleDateFormat("MM/dd/yyyy"); 17 | String formattedDate1 = dateFormat1.format(currentDate); 18 | System.out.println(formattedDate1); 19 | 20 | String dateString = "2100-09-26 14:30:00"; 21 | SimpleDateFormat dateFormat2 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); 22 | Date parsedDate = dateFormat2.parse(dateString); 23 | System.out.println(parsedDate); 24 | 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /section_23/src/com/eazybytes/legacy/JavaSQLDate.java: -------------------------------------------------------------------------------- 1 | package com.eazybytes.legacy; 2 | 3 | import java.sql.Date; 4 | 5 | public class JavaSQLDate { 6 | 7 | public static void main(String[] args) { 8 | Date currentDate = new Date(System.currentTimeMillis()); 9 | java.util.Date currentDate1 = new java.util.Date(System.currentTimeMillis()); 10 | System.out.println(currentDate); 11 | System.out.println(currentDate1); 12 | } 13 | 14 | } 15 | -------------------------------------------------------------------------------- /section_23/src/com/eazybytes/legacy/JavaUtilDate.java: -------------------------------------------------------------------------------- 1 | package com.eazybytes.legacy; 2 | 3 | import java.util.Date; 4 | 5 | public class JavaUtilDate { 6 | 7 | public static void main(String[] args) { 8 | 9 | Date currentDate = new Date(); // Current Date and time value 10 | currentDate.setYear(200); 11 | System.out.println(currentDate); 12 | long timeInms = currentDate.getTime(); 13 | System.out.println(timeInms); 14 | 15 | Date futureDate = new Date(200, 8, 26, 8, 15,39); 16 | System.out.println(futureDate); //Sun Sep 26 08:15:39 IST 2100 17 | long timeInms1 = futureDate.getTime(); 18 | System.out.println(timeInms1); 19 | Date date = new Date(timeInms1+86400000); 20 | System.out.println(date); 21 | 22 | boolean isAfter = date.after(futureDate); 23 | System.out.println(isAfter); 24 | /* 25 | In computing, an epoch is a fixed date and time used as a reference from 26 | which a computer measures system time. 27 | */ 28 | 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /section_23/src/com/eazybytes/legacy/LegacyDateAPIDemo.java: -------------------------------------------------------------------------------- 1 | package com.eazybytes.legacy; 2 | 3 | import java.util.Date; 4 | 5 | public class LegacyDateAPIDemo { 6 | 7 | public static void main(String[] args) { 8 | Date date = new Date(); 9 | Date date1 = new Date(200, 8, 26); 10 | System.out.println(date1); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /section_23/src/com/eazybytes/legacy/TimeZoneIDsList.java: -------------------------------------------------------------------------------- 1 | package com.eazybytes.legacy; 2 | 3 | import java.util.TimeZone; 4 | 5 | public class TimeZoneIDsList { 6 | 7 | public static void main(String[] args) { 8 | String[] timeZoneIds = TimeZone.getAvailableIDs(); 9 | 10 | for(String timeZoneId : timeZoneIds){ 11 | System.out.println(timeZoneId); 12 | } 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /section_23/src/com/eazybytes/newapi/FromAndWithMethodsDemo.java: -------------------------------------------------------------------------------- 1 | package com.eazybytes.newapi; 2 | 3 | import java.time.LocalDate; 4 | import java.time.LocalDateTime; 5 | import java.time.LocalTime; 6 | import java.time.Month; 7 | 8 | public class FromAndWithMethodsDemo { 9 | 10 | public static void main(String[] args) { 11 | LocalDateTime dateTime = LocalDateTime.of(2015, Month.MARCH, 18, 22, 30); 12 | System.out.println(dateTime); 13 | 14 | LocalDate derivedDate = LocalDate.from(dateTime); 15 | LocalTime derivedTime = LocalTime.from(dateTime); 16 | System.out.println(derivedDate); 17 | System.out.println(derivedTime); 18 | 19 | LocalDateTime dateTime1 = dateTime.withYear(2030); 20 | LocalDateTime dateTime2 = dateTime.withYear(2030).withMonth(10); 21 | System.out.println(dateTime1); 22 | System.out.println(dateTime2); 23 | 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /section_23/src/com/eazybytes/newapi/JapaneseCalendarDemo.java: -------------------------------------------------------------------------------- 1 | package com.eazybytes.newapi; 2 | 3 | import java.time.LocalDate; 4 | import java.time.chrono.JapaneseDate; 5 | 6 | public class JapaneseCalendarDemo { 7 | 8 | public static void main(String[] args) { 9 | JapaneseDate japaneseDate = JapaneseDate.now(); 10 | LocalDate localDate = LocalDate.now(); 11 | 12 | JapaneseDate japaneseDate1 = JapaneseDate.from(localDate); 13 | LocalDate localDate1 = LocalDate.from(japaneseDate); 14 | 15 | } 16 | 17 | } 18 | -------------------------------------------------------------------------------- /section_23/src/com/eazybytes/newapi/MultiDivNegateDemo.java: -------------------------------------------------------------------------------- 1 | package com.eazybytes.newapi; 2 | 3 | import java.time.Duration; 4 | import java.time.Period; 5 | 6 | public class MultiDivNegateDemo { 7 | 8 | public static void main(String[] args) { 9 | Duration originalDuration = Duration.ofMinutes(30); // PT30M 10 | Duration multipliedDuration = originalDuration.multipliedBy(3); // PT1H30M 11 | Duration dividedDuration = originalDuration.dividedBy(2); // PT15M 12 | Duration negatedDuration = originalDuration.negated(); // PT-30M 13 | 14 | Period originalPeriod = Period.ofDays(3); // P3D 15 | Period multipliedPeriod = originalPeriod.multipliedBy(3); // P9D 16 | Period negatedPeriod = originalPeriod.negated(); // P-3D 17 | } 18 | 19 | } 20 | -------------------------------------------------------------------------------- /section_23/src/com/eazybytes/newapi/NewDateTimeAPIDemo.java: -------------------------------------------------------------------------------- 1 | package com.eazybytes.newapi; 2 | 3 | import java.time.LocalDate; 4 | import java.time.LocalDateTime; 5 | import java.time.LocalTime; 6 | import java.time.ZonedDateTime; 7 | 8 | public class NewDateTimeAPIDemo { 9 | 10 | public static void main(String[] args) { 11 | LocalDate dateOnly = LocalDate.now(); 12 | LocalTime timeOnly = LocalTime.now(); 13 | LocalDateTime dateTime = LocalDateTime.now(); 14 | ZonedDateTime dateTimeWithZone = ZonedDateTime.now(); 15 | System.out.println(dateOnly); 16 | System.out.println(timeOnly); 17 | System.out.println(dateTime); 18 | System.out.println(dateTimeWithZone); 19 | } 20 | 21 | } 22 | -------------------------------------------------------------------------------- /section_23/src/com/eazybytes/newapi/OfMethodsDemo.java: -------------------------------------------------------------------------------- 1 | package com.eazybytes.newapi; 2 | 3 | import java.time.*; 4 | 5 | public class OfMethodsDemo { 6 | 7 | public static void main(String[] args) { 8 | LocalDate date = LocalDate.of(2015, Month.MARCH, 18); 9 | LocalTime time = LocalTime.of(14, 30); 10 | LocalDateTime dateTime = LocalDateTime.of(2015,3,18,14,30); 11 | ZoneId newYorkTimeZone = ZoneId.of("America/New_York"); 12 | ZonedDateTime zonedDateTime = ZonedDateTime.of(2015,3,18,14,30,0, 0, newYorkTimeZone); 13 | System.out.println(date); 14 | System.out.println(time); 15 | System.out.println(dateTime); 16 | System.out.println(zonedDateTime); 17 | 18 | LocalDate someDate = LocalDate.ofEpochDay(1000); 19 | LocalDate dayIn2000 = LocalDate.ofYearDay(2001, 100); 20 | System.out.println(someDate); 21 | System.out.println(dayIn2000); 22 | 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /section_23/src/com/eazybytes/newapi/OffsetDateTimeDemo.java: -------------------------------------------------------------------------------- 1 | package com.eazybytes.newapi; 2 | 3 | import java.time.OffsetDateTime; 4 | import java.time.ZoneOffset; 5 | 6 | public class OffsetDateTimeDemo { 7 | 8 | public static void main(String[] args) { 9 | ZoneOffset offset = ZoneOffset.ofHours(2); 10 | ZoneOffset destOffset = ZoneOffset.ofHours(-8); 11 | 12 | OffsetDateTime offsetDateTime = OffsetDateTime.now(offset); 13 | OffsetDateTime destOffsetDateTime = offsetDateTime.withOffsetSameInstant(destOffset); 14 | System.out.println(offsetDateTime); 15 | System.out.println(destOffsetDateTime); 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /section_23/src/com/eazybytes/newapi/OffsetTimeDemo.java: -------------------------------------------------------------------------------- 1 | package com.eazybytes.newapi; 2 | 3 | import java.time.OffsetTime; 4 | import java.time.ZoneOffset; 5 | 6 | public class OffsetTimeDemo { 7 | 8 | public static void main(String[] args) { 9 | OffsetTime offsetTime = OffsetTime.of(15, 30, 0, 0, ZoneOffset.ofHours(2)); 10 | System.out.println(offsetTime); 11 | int hour = offsetTime.getHour(); 12 | int minutes = offsetTime.getMinute(); 13 | int second = offsetTime.getSecond(); 14 | ZoneOffset offset = offsetTime.getOffset(); 15 | OffsetTime laterTime = offsetTime.plusHours(2); 16 | boolean isBefore = offsetTime.isBefore(laterTime); 17 | 18 | } 19 | 20 | } 21 | -------------------------------------------------------------------------------- /section_23/src/com/eazybytes/newapi/ParsingDemo.java: -------------------------------------------------------------------------------- 1 | package com.eazybytes.newapi; 2 | 3 | import java.time.LocalDate; 4 | import java.time.LocalDateTime; 5 | import java.time.LocalTime; 6 | import java.time.format.DateTimeFormatter; 7 | 8 | public class ParsingDemo { 9 | 10 | public static void main(String[] args) { 11 | DateTimeFormatter dateFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd"); 12 | DateTimeFormatter timeFormatter = DateTimeFormatter.ofPattern("HH:mm:ss"); 13 | DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("dd/MM/yyyy HH:mm:ss"); 14 | 15 | String dateString = "2015-03-18"; 16 | String timeString = "15:30:00"; 17 | String dateTimeString = "18/03/2015 15:30:00"; 18 | 19 | LocalDate localDate = LocalDate.parse(dateString,dateFormatter); 20 | LocalTime localTime = LocalTime.parse(timeString,timeFormatter); 21 | LocalDateTime localDateTime = LocalDateTime.parse(dateTimeString,dateTimeFormatter); 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /section_23/src/com/eazybytes/newapi/PeriodDemo.java: -------------------------------------------------------------------------------- 1 | package com.eazybytes.newapi; 2 | 3 | import java.time.LocalDate; 4 | import java.time.Period; 5 | 6 | public class PeriodDemo { 7 | 8 | public static void main(String[] args) { 9 | LocalDate localDate1 = LocalDate.of(2013,1,1); // 2013-01-01 10 | LocalDate localDate2 = LocalDate.of(2015,3,18); // 2015-03-18 11 | Period period = Period.between(localDate1,localDate2); // P2Y2M17D 12 | System.out.println(period); 13 | 14 | Period oneYearTwoMonths = Period.of(1,2,0); // P1Y2M 15 | System.out.println(oneYearTwoMonths); 16 | Period threeDays = Period.ofDays(3); // P3D 17 | LocalDate localDate3 = localDate1.plus(oneYearTwoMonths); // 2014-03-01 18 | System.out.println(localDate3); 19 | } 20 | 21 | } 22 | -------------------------------------------------------------------------------- /section_23/src/com/eazybytes/newapi/ToAndAtMethodsDemo.java: -------------------------------------------------------------------------------- 1 | package com.eazybytes.newapi; 2 | 3 | import java.time.LocalDate; 4 | import java.time.LocalDateTime; 5 | import java.time.LocalTime; 6 | import java.time.Month; 7 | 8 | public class ToAndAtMethodsDemo { 9 | 10 | public static void main(String[] args) { 11 | LocalDateTime dateTime = LocalDateTime.of(2015, Month.MARCH, 18, 22, 30); 12 | System.out.println(dateTime); 13 | 14 | LocalDate date = dateTime.toLocalDate(); 15 | LocalTime time = dateTime.toLocalTime(); 16 | 17 | System.out.println(date); 18 | System.out.println(time); 19 | 20 | LocalDate localDate = LocalDate.of(2015, 3, 18); 21 | LocalDateTime startOfDay = localDate.atStartOfDay(); 22 | System.out.println(startOfDay); 23 | LocalDateTime localDateTime = localDate.atTime(18, 20); 24 | System.out.println(localDateTime); 25 | 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /section_23/src/com/eazybytes/newapi/TruncatedToMethodDemo.java: -------------------------------------------------------------------------------- 1 | package com.eazybytes.newapi; 2 | 3 | import java.time.Duration; 4 | import java.time.temporal.ChronoUnit; 5 | 6 | public class TruncatedToMethodDemo { 7 | 8 | public static void main(String[] args) { 9 | Duration duration = Duration.ofDays(28).plusHours(6).plusMinutes(56).plusSeconds(19); // PT678H56M19S 10 | Duration daysTruncated = duration.truncatedTo(ChronoUnit.DAYS); // PT672H 11 | Duration hoursTruncated = duration.truncatedTo(ChronoUnit.HOURS); // PT678H 12 | Duration minutesTruncated = duration.truncatedTo(ChronoUnit.MINUTES); // PT678H56M 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /section_23/src/com/eazybytes/newapi/ZoneIDListDemo.java: -------------------------------------------------------------------------------- 1 | package com.eazybytes.newapi; 2 | 3 | import java.time.ZoneId; 4 | import java.util.Set; 5 | 6 | public class ZoneIDListDemo { 7 | 8 | public static void main(String[] args) { 9 | Set allZones = ZoneId.getAvailableZoneIds(); 10 | 11 | for(String zoneId : allZones) { 12 | System.out.println(zoneId); 13 | } 14 | 15 | } 16 | 17 | } 18 | -------------------------------------------------------------------------------- /section_23/src/com/eazybytes/newapi/ZonedDateTimeDSTDemo.java: -------------------------------------------------------------------------------- 1 | package com.eazybytes.newapi; 2 | 3 | import java.time.ZoneId; 4 | import java.time.ZonedDateTime; 5 | 6 | public class ZonedDateTimeDSTDemo { 7 | 8 | public static void main(String[] args) { 9 | // Flight departure in PST 10 | ZonedDateTime departure = ZonedDateTime.of(2024, 3, 9, 21, 0, 0, 0, ZoneId.of("America/Los_Angeles")); 11 | // Expected arrival in NYC (assuming flight duration is 4 hours) 12 | ZonedDateTime arrival = departure.plusHours(4).withZoneSameInstant(ZoneId.of("America/New_York")); 13 | System.out.println("Departure (PST): " + departure); 14 | System.out.println("Arrival (EST): " + arrival); 15 | 16 | // Departure (PST): 2024-02-02T21:00-08:00[America/Los_Angeles] 17 | //Arrival (EST): 2024-02-03T04:00-05:00[America/New_York] 18 | 19 | // Departure (PST): 2024-03-09T21:00-08:00[America/Los_Angeles] 20 | // Arrival (EST): 2024-03-10T05:00-04:00[America/New_York] 21 | } 22 | 23 | } 24 | -------------------------------------------------------------------------------- /section_23/src/com/eazybytes/newapi/ZonedDateTimeDemo.java: -------------------------------------------------------------------------------- 1 | package com.eazybytes.newapi; 2 | 3 | import java.time.ZoneId; 4 | import java.time.ZoneOffset; 5 | import java.time.ZonedDateTime; 6 | 7 | public class ZonedDateTimeDemo { 8 | 9 | public static void main(String[] args) { 10 | ZoneId zone = ZoneId.of("Asia/Kolkata"); 11 | ZoneId destZone = ZoneId.of("America/Chicago"); 12 | 13 | ZonedDateTime indiaDateTime = ZonedDateTime.now(zone); 14 | ZonedDateTime chicagoDateTime = indiaDateTime.withZoneSameInstant(destZone); 15 | System.out.println(indiaDateTime); 16 | System.out.println(chicagoDateTime); 17 | 18 | ZoneOffset offset = ZoneOffset.ofHours(2); 19 | ZoneOffset destOffset = ZoneOffset.ofHours(-8); 20 | 21 | ZonedDateTime utc2DateTime = ZonedDateTime.now(offset); 22 | ZonedDateTime utcDestDateTime = indiaDateTime.withZoneSameInstant(destOffset); 23 | System.out.println(utc2DateTime); 24 | System.out.println(utcDestDateTime); 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /section_24/.gitignore: -------------------------------------------------------------------------------- 1 | ### IntelliJ IDEA ### 2 | out/ 3 | !**/src/main/**/out/ 4 | !**/src/test/**/out/ 5 | 6 | ### Eclipse ### 7 | .apt_generated 8 | .classpath 9 | .factorypath 10 | .project 11 | .settings 12 | .springBeans 13 | .sts4-cache 14 | bin/ 15 | !**/src/main/**/bin/ 16 | !**/src/test/**/bin/ 17 | 18 | ### NetBeans ### 19 | /nbproject/private/ 20 | /nbbuild/ 21 | /dist/ 22 | /nbdist/ 23 | /.nb-gradle/ 24 | 25 | ### VS Code ### 26 | .vscode/ 27 | 28 | ### Mac OS ### 29 | .DS_Store -------------------------------------------------------------------------------- /section_24/src/com/eazybytes/lambda/AnonymousClassDemo.java: -------------------------------------------------------------------------------- 1 | package com.eazybytes.lambda; 2 | 3 | public class AnonymousClassDemo { 4 | 5 | public static void main(String[] args) { 6 | Hello hello = new Hello() { 7 | @Override 8 | public void sayHello() { 9 | System.out.println("Anonymous"); 10 | } 11 | }; 12 | process(hello); 13 | process(new Hello() { 14 | @Override 15 | public void sayHello() { 16 | System.out.println("Anonymous 1"); 17 | } 18 | }); 19 | } 20 | 21 | public static void process(Hello h) { 22 | h.sayHello(); 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /section_24/src/com/eazybytes/lambda/ArithmeticOperation.java: -------------------------------------------------------------------------------- 1 | package com.eazybytes.lambda; 2 | 3 | @FunctionalInterface 4 | public interface ArithmeticOperation { 5 | 6 | int operation(int num1, int num2); 7 | 8 | } 9 | -------------------------------------------------------------------------------- /section_24/src/com/eazybytes/lambda/ConsumerDemo.java: -------------------------------------------------------------------------------- 1 | package com.eazybytes.lambda; 2 | 3 | import java.util.Arrays; 4 | import java.util.List; 5 | import java.util.function.Consumer; 6 | 7 | public class ConsumerDemo { 8 | 9 | public static void main(String[] args) { 10 | Consumer convertAndDisplay = input -> System.out.println(input.toUpperCase()); 11 | convertAndDisplay.accept("Eazy Bytes"); 12 | 13 | Consumer squareOf = num -> System.out.println(num * num); 14 | List numbersList = Arrays.asList(1,2,3,4,5,6,7,8,9,10); 15 | numbersList.forEach(squareOf); 16 | 17 | Consumer appendInput = input -> System.out.println("New value after appending is : HELLO " + input); 18 | appendInput.andThen(convertAndDisplay).accept("Lambda Expression"); 19 | } 20 | 21 | } 22 | -------------------------------------------------------------------------------- /section_24/src/com/eazybytes/lambda/FunctionDemo.java: -------------------------------------------------------------------------------- 1 | package com.eazybytes.lambda; 2 | 3 | import java.util.function.Function; 4 | 5 | public class FunctionDemo { 6 | 7 | public static void main(String[] args) { 8 | Function convertStr = input -> input.toUpperCase(); 9 | System.out.println(convertStr.apply("Eazy Bytes")); 10 | 11 | Function getStrLength = input -> input.length(); 12 | System.out.println(getStrLength.apply("Eazy Bytes")); 13 | 14 | Function sameValue = Function.identity(); 15 | System.out.println(sameValue.apply("Hi Madan")); 16 | 17 | Function doubleValue = num -> num * 2; 18 | Function addThree = num -> num + 3; 19 | 20 | Function output1 = doubleValue.andThen(addThree); 21 | Function output2 = doubleValue.compose(addThree); 22 | System.out.println(output1.apply(5)); // 13 23 | System.out.println(output2.apply(5)); // 16 24 | 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /section_24/src/com/eazybytes/lambda/Hello.java: -------------------------------------------------------------------------------- 1 | package com.eazybytes.lambda; 2 | 3 | @FunctionalInterface 4 | public interface Hello { 5 | 6 | void sayHello(); 7 | 8 | } 9 | -------------------------------------------------------------------------------- /section_24/src/com/eazybytes/lambda/LamdaExpressionDemo.java: -------------------------------------------------------------------------------- 1 | package com.eazybytes.lambda; 2 | 3 | public class LamdaExpressionDemo { 4 | 5 | public static void main(String[] args) { 6 | Hello hello = () -> System.out.println("Hello"); 7 | Hello hello1 = () -> System.out.println("Hello World"); // Approach 1 8 | process(hello); 9 | process(hello1); 10 | process(() -> System.out.println("Hi")); // Approach 2 11 | 12 | ArithmeticOperation addition = (a, b) -> a + b; 13 | System.out.println(addition.operation(5, 5)); 14 | 15 | ArithmeticOperation subtraction = (a, b) -> a - b; 16 | System.out.println(subtraction.operation(5, 5)); 17 | 18 | ArithmeticOperation product = (a, b) -> a * b; 19 | System.out.println(product.operation(5, 5)); 20 | 21 | ArithmeticOperation division = (a, b) -> a / b; 22 | System.out.println(division.operation(5, 5)); 23 | } 24 | 25 | public static void process(Hello h) { 26 | h.sayHello(); 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /section_24/src/com/eazybytes/lambda/LexicalScopeTest.java: -------------------------------------------------------------------------------- 1 | package com.eazybytes.lambda; 2 | 3 | public class LexicalScopeTest { 4 | 5 | public static void main(String[] args) { 6 | String input = "Hello World"; 7 | Printer printer = input1 -> { 8 | String msg = "Hi"; 9 | System.out.println(input1+input+msg); 10 | }; 11 | printer.print(input); 12 | 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /section_24/src/com/eazybytes/lambda/Printer.java: -------------------------------------------------------------------------------- 1 | package com.eazybytes.lambda; 2 | 3 | @FunctionalInterface 4 | public interface Printer { 5 | 6 | void print(String input); 7 | 8 | } 9 | -------------------------------------------------------------------------------- /section_24/src/com/eazybytes/lambda/SupplierDemo.java: -------------------------------------------------------------------------------- 1 | package com.eazybytes.lambda; 2 | 3 | import java.time.LocalDate; 4 | import java.util.function.Supplier; 5 | 6 | public class SupplierDemo { 7 | 8 | public static void main(String[] args) { 9 | Supplier getCurrentMonth = () -> LocalDate.now().getMonthValue(); 10 | System.out.println(getCurrentMonth.get()); 11 | 12 | Supplier getCurrentDayOfMonth = () -> LocalDate.now().getDayOfMonth(); 13 | System.out.println(getCurrentDayOfMonth.get()); 14 | 15 | Supplier getCurrentDayName = () -> LocalDate.now().getDayOfWeek().name(); 16 | System.out.println(getCurrentDayName.get()); 17 | } 18 | 19 | } 20 | -------------------------------------------------------------------------------- /section_24/src/com/eazybytes/lambda/ThisDemo.java: -------------------------------------------------------------------------------- 1 | package com.eazybytes.lambda; 2 | 3 | public class ThisDemo { 4 | 5 | public static void main(String[] args) { 6 | ThisDemo thisDemo = new ThisDemo(); 7 | Printer lambdaPrinter = thisDemo.getLambdaPrinter(); 8 | lambdaPrinter.print("Lambda Expression"); 9 | Printer anonymousPrinter = thisDemo.getAnonymousPrinter(); 10 | anonymousPrinter.print("Anonymous Inner Class"); 11 | } 12 | 13 | public Printer getLambdaPrinter() { 14 | Printer printer = msg -> System.out.println(msg + " : " + this.getClass()); 15 | return printer; 16 | } 17 | 18 | public Printer getAnonymousPrinter() { 19 | Printer printer = new Printer() { 20 | @Override 21 | public void print(String input) { 22 | System.out.println(input + " : " + this.getClass()); 23 | } 24 | }; 25 | return printer; 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /section_24/src/com/eazybytes/lambda/UnaryOperatorDemo.java: -------------------------------------------------------------------------------- 1 | package com.eazybytes.lambda; 2 | 3 | import java.util.function.Function; 4 | import java.util.function.UnaryOperator; 5 | 6 | public class UnaryOperatorDemo { 7 | 8 | public static void main(String[] args) { 9 | UnaryOperator convertStr = input -> input.toUpperCase(); 10 | System.out.println(convertStr.apply("Eazy Bytes")); 11 | 12 | UnaryOperator sameValue = UnaryOperator.identity(); 13 | System.out.println(sameValue.apply("Hi Madan")); 14 | 15 | UnaryOperator doubleValue = num -> num * 2; 16 | UnaryOperator addThree = num -> num + 3; 17 | 18 | Function output1 = doubleValue.andThen(addThree); 19 | Function output2 = doubleValue.compose(addThree); 20 | System.out.println(output1.apply(5)); // 13 21 | System.out.println(output2.apply(5)); // 16 22 | 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /section_25/.gitignore: -------------------------------------------------------------------------------- 1 | ### IntelliJ IDEA ### 2 | out/ 3 | !**/src/main/**/out/ 4 | !**/src/test/**/out/ 5 | 6 | ### Eclipse ### 7 | .apt_generated 8 | .classpath 9 | .factorypath 10 | .project 11 | .settings 12 | .springBeans 13 | .sts4-cache 14 | bin/ 15 | !**/src/main/**/bin/ 16 | !**/src/test/**/bin/ 17 | 18 | ### NetBeans ### 19 | /nbproject/private/ 20 | /nbbuild/ 21 | /dist/ 22 | /nbdist/ 23 | /.nb-gradle/ 24 | 25 | ### VS Code ### 26 | .vscode/ 27 | 28 | ### Mac OS ### 29 | .DS_Store -------------------------------------------------------------------------------- /section_25/src/com/eazybytes/method/reference/ArithmeticOperation.java: -------------------------------------------------------------------------------- 1 | package com.eazybytes.method.reference; 2 | 3 | @FunctionalInterface 4 | public interface ArithmeticOperation { 5 | 6 | public int performOperation(int a, int b); 7 | 8 | } 9 | -------------------------------------------------------------------------------- /section_25/src/com/eazybytes/method/reference/ClassMethodReference.java: -------------------------------------------------------------------------------- 1 | package com.eazybytes.method.reference; 2 | 3 | import java.util.List; 4 | 5 | public class ClassMethodReference { 6 | 7 | public static void main(String[] args) { 8 | var list = List.of("Supply", "HR", "Sales", "Marketing"); 9 | list.forEach(department -> System.out.println(department)); 10 | list.forEach(System.out::println); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /section_25/src/com/eazybytes/method/reference/ConstructorReferenceDemo.java: -------------------------------------------------------------------------------- 1 | package com.eazybytes.method.reference; 2 | 3 | public class ConstructorReferenceDemo { 4 | 5 | public static void main(String[] args) { 6 | ProductInterface productInterface = (name, price) -> new Product(name, price); 7 | System.out.println(productInterface.getProduct("Apple Mac", 2000)); 8 | 9 | ProductInterface constructorReference = Product::new; 10 | System.out.println(constructorReference.getProduct("Apple Iphone", 1000)); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /section_25/src/com/eazybytes/method/reference/InstanceMethodReference.java: -------------------------------------------------------------------------------- 1 | package com.eazybytes.method.reference; 2 | 3 | public class InstanceMethodReference { 4 | 5 | public static void main(String[] args) { 6 | ArithmeticOperation operation = (a,b) -> { 7 | int sum = a + b; 8 | System.out.println(sum); 9 | return sum; 10 | }; 11 | operation.performOperation(2,3); 12 | 13 | InstanceMethodReference instanceMethodReference = new InstanceMethodReference(); 14 | ArithmeticOperation methodReference = instanceMethodReference::performAddition; 15 | methodReference.performOperation(2,3); 16 | 17 | ArithmeticOperation methodReferenceSub = instanceMethodReference::performSubtraction; 18 | methodReferenceSub.performOperation(2,3); 19 | 20 | } 21 | 22 | public int performAddition(int a, int b){ 23 | int sum = a + b; 24 | System.out.println(sum); 25 | return sum; 26 | } 27 | 28 | public int performSubtraction(int a, int b){ 29 | int diff = a - b; 30 | System.out.println(diff); 31 | return diff; 32 | } 33 | 34 | } 35 | -------------------------------------------------------------------------------- /section_25/src/com/eazybytes/method/reference/Product.java: -------------------------------------------------------------------------------- 1 | package com.eazybytes.method.reference; 2 | 3 | public class Product { 4 | 5 | private String name; 6 | private int price; 7 | 8 | public Product(String name, int price) { 9 | this.name = name; 10 | this.price = price; 11 | } 12 | 13 | public String getName() { 14 | return name; 15 | } 16 | 17 | public void setName(String name) { 18 | this.name = name; 19 | } 20 | 21 | public int getPrice() { 22 | return price; 23 | } 24 | 25 | public void setPrice(int price) { 26 | this.price = price; 27 | } 28 | 29 | @Override 30 | public String toString() { 31 | return "Product{" + 32 | "name='" + name + '\'' + 33 | ", price=" + price + 34 | '}'; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /section_25/src/com/eazybytes/method/reference/ProductInterface.java: -------------------------------------------------------------------------------- 1 | package com.eazybytes.method.reference; 2 | 3 | @FunctionalInterface 4 | public interface ProductInterface { 5 | 6 | Product getProduct(String name, int price); 7 | 8 | } 9 | -------------------------------------------------------------------------------- /section_25/src/com/eazybytes/method/reference/StaticMethodReference.java: -------------------------------------------------------------------------------- 1 | package com.eazybytes.method.reference; 2 | 3 | public class StaticMethodReference { 4 | 5 | public static void main(String[] args) { 6 | ArithmeticOperation operation = (a,b) -> { 7 | int sum = a + b; 8 | System.out.println(sum); 9 | return sum; 10 | }; 11 | operation.performOperation(2,3); 12 | 13 | ArithmeticOperation methodReference = StaticMethodReference::performAddition; 14 | methodReference.performOperation(2,3); 15 | 16 | } 17 | 18 | public static int performAddition(int a, int b){ 19 | int sum = a + b; 20 | System.out.println(sum); 21 | return sum; 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /section_26/.gitignore: -------------------------------------------------------------------------------- 1 | ### IntelliJ IDEA ### 2 | out/ 3 | !**/src/main/**/out/ 4 | !**/src/test/**/out/ 5 | 6 | ### Eclipse ### 7 | .apt_generated 8 | .classpath 9 | .factorypath 10 | .project 11 | .settings 12 | .springBeans 13 | .sts4-cache 14 | bin/ 15 | !**/src/main/**/bin/ 16 | !**/src/test/**/bin/ 17 | 18 | ### NetBeans ### 19 | /nbproject/private/ 20 | /nbbuild/ 21 | /dist/ 22 | /nbdist/ 23 | /.nb-gradle/ 24 | 25 | ### VS Code ### 26 | .vscode/ 27 | 28 | ### Mac OS ### 29 | .DS_Store -------------------------------------------------------------------------------- /section_26/src/com/eazybytes/streams/Item.java: -------------------------------------------------------------------------------- 1 | package com.eazybytes.streams; 2 | 3 | public class Item { 4 | 5 | private String name; 6 | private double price; 7 | private boolean inStock; 8 | private boolean onSale; 9 | 10 | public Item(String name, double price, boolean inStock, boolean onSale) { 11 | this.name = name; 12 | this.price = price; 13 | this.inStock = inStock; 14 | this.onSale = onSale; 15 | } 16 | 17 | public String getName() { 18 | return name; 19 | } 20 | 21 | public double getPrice() { 22 | return price; 23 | } 24 | 25 | public boolean isInStock() { 26 | return inStock; 27 | } 28 | 29 | public boolean isOnSale() { 30 | return onSale; 31 | } 32 | 33 | @Override 34 | public String toString() { 35 | return "Item{" + 36 | "name='" + name + '\'' + 37 | ", price=" + price + 38 | ", inStock=" + inStock + 39 | ", onSale=" + onSale + 40 | '}'; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /section_26/src/com/eazybytes/streams/ParallelStreamDemo.java: -------------------------------------------------------------------------------- 1 | package com.eazybytes.streams; 2 | 3 | import java.util.stream.Collectors; 4 | import java.util.stream.Stream; 5 | 6 | public class ParallelStreamDemo { 7 | 8 | public static void main(String[] args) { 9 | Stream numStream = Stream.iterate(1, num -> num+1).limit(100).parallel(); 10 | long startTime = System.currentTimeMillis(); 11 | System.out.println(numStream.map( num -> { 12 | try { 13 | Thread.sleep(10); 14 | } catch (InterruptedException e) { 15 | throw new RuntimeException(e); 16 | } 17 | return num * 2; 18 | }).collect(Collectors.toList())); 19 | long endTime = System.currentTimeMillis(); 20 | System.out.println(endTime-startTime); 21 | } 22 | 23 | } 24 | -------------------------------------------------------------------------------- /section_26/src/com/eazybytes/streams/Person.java: -------------------------------------------------------------------------------- 1 | package com.eazybytes.streams; 2 | 3 | import java.util.List; 4 | 5 | public class Person { 6 | 7 | private String name; 8 | private List phoneNumbers; 9 | 10 | public Person(String name, List phoneNumbers) { 11 | this.name = name; 12 | this.phoneNumbers = phoneNumbers; 13 | } 14 | 15 | public String getName() { 16 | return name; 17 | } 18 | 19 | public List getPhoneNumbers() { 20 | return phoneNumbers; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /section_26/src/com/eazybytes/streams/Product.java: -------------------------------------------------------------------------------- 1 | package com.eazybytes.streams; 2 | 3 | public class Product { 4 | 5 | private String name; 6 | private int price; 7 | 8 | public Product(String name, int price) { 9 | this.name = name; 10 | this.price = price; 11 | } 12 | 13 | public String getName() { 14 | return name; 15 | } 16 | 17 | public int getPrice() { 18 | return price; 19 | } 20 | 21 | @Override 22 | public String toString() { 23 | return "Product{" + 24 | "name='" + name + '\'' + 25 | ", price=" + price + 26 | '}'; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /section_26/src/com/eazybytes/streams/StreamCollectOperationDemo.java: -------------------------------------------------------------------------------- 1 | package com.eazybytes.streams; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | import java.util.Set; 6 | import java.util.TreeSet; 7 | import java.util.stream.Collectors; 8 | 9 | public class StreamCollectOperationDemo { 10 | 11 | public static void main(String[] args) { 12 | List departmentList = new ArrayList<>(); 13 | departmentList.add("Supply"); 14 | departmentList.add("HR"); 15 | departmentList.add("Sales"); 16 | departmentList.add("Marketing"); 17 | 18 | Set newDepartmentList = departmentList.stream() 19 | .filter(word -> word.startsWith("S")) 20 | .collect(Collectors.toCollection(TreeSet::new)); 21 | 22 | newDepartmentList.forEach(System.out::println); 23 | 24 | long totalCount = departmentList.stream() 25 | .filter(word -> word.startsWith("S")) 26 | .collect(Collectors.counting()); 27 | System.out.println(totalCount); 28 | } 29 | 30 | } 31 | -------------------------------------------------------------------------------- /section_26/src/com/eazybytes/streams/StreamCollectingAndThenDemo.java: -------------------------------------------------------------------------------- 1 | package com.eazybytes.streams; 2 | 3 | import java.util.Arrays; 4 | import java.util.Comparator; 5 | import java.util.List; 6 | import java.util.Optional; 7 | import java.util.stream.Collectors; 8 | 9 | public class StreamCollectingAndThenDemo { 10 | 11 | public static void main(String[] args) { 12 | List productList = Arrays.asList(new Product("Apple", 1200), 13 | new Product("Samsung", 1000), new Product("Nokia", 600), 14 | new Product("BlackBerry", 1000), new Product("Apple Pro Max", 1500), 15 | new Product("Mi", 800), new Product("OnePlus", 1000)); 16 | 17 | String maxPriceProduct = productList.stream().collect(Collectors.collectingAndThen( 18 | Collectors.maxBy(Comparator.comparing(Product::getPrice)), 19 | (productOptional -> productOptional.isPresent() ? productOptional.get().getName() : "None") 20 | )); 21 | 22 | System.out.println(maxPriceProduct); 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /section_26/src/com/eazybytes/streams/StreamFilterOperationDemo.java: -------------------------------------------------------------------------------- 1 | package com.eazybytes.streams; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | 6 | public class StreamFilterOperationDemo { 7 | 8 | public static void main(String[] args) { 9 | List departmentList = new ArrayList<>(); 10 | departmentList.add("Supply"); 11 | departmentList.add("HR"); 12 | departmentList.add("Sales"); 13 | departmentList.add("Marketing"); 14 | 15 | departmentList.stream() 16 | .map(word -> word.toUpperCase()) 17 | .filter(word -> word.startsWith("S")) 18 | .forEach(System.out::println); 19 | 20 | } 21 | 22 | 23 | } 24 | -------------------------------------------------------------------------------- /section_26/src/com/eazybytes/streams/StreamGroupingByDemo.java: -------------------------------------------------------------------------------- 1 | package com.eazybytes.streams; 2 | 3 | import java.util.Arrays; 4 | import java.util.List; 5 | import java.util.Map; 6 | import java.util.stream.Collectors; 7 | 8 | public class StreamGroupingByDemo { 9 | 10 | public static void main(String[] args) { 11 | List productList = Arrays.asList(new Product("Apple", 1200), 12 | new Product("Samsung", 1000), new Product("Nokia", 600), 13 | new Product("BlackBerry", 1000), new Product("Apple Pro Max", 1500), 14 | new Product("Mi", 800), new Product("OnePlus", 1000)); 15 | 16 | Map> groupingByPriceMap = productList.stream() 17 | .collect(Collectors.groupingBy(Product::getPrice)); 18 | 19 | System.out.println(groupingByPriceMap); 20 | 21 | } 22 | 23 | } 24 | -------------------------------------------------------------------------------- /section_26/src/com/eazybytes/streams/StreamLimitOperationDemo.java: -------------------------------------------------------------------------------- 1 | package com.eazybytes.streams; 2 | 3 | import java.util.Random; 4 | import java.util.stream.Stream; 5 | 6 | public class StreamLimitOperationDemo { 7 | 8 | public static void main(String[] args) { 9 | Stream.generate(new Random()::nextInt) 10 | .limit(10) 11 | .map(num -> num *2) 12 | .forEach(System.out::println); 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /section_26/src/com/eazybytes/streams/StreamMapOperationDemo.java: -------------------------------------------------------------------------------- 1 | package com.eazybytes.streams; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | 6 | public class StreamMapOperationDemo { 7 | 8 | public static void main(String[] args) { 9 | List departmentList = new ArrayList<>(); 10 | departmentList.add("Supply"); 11 | departmentList.add("HR"); 12 | departmentList.add("Sales"); 13 | departmentList.add("Marketing"); 14 | 15 | departmentList.stream().map(word -> word.toUpperCase()).forEach(System.out::println); 16 | 17 | departmentList.stream() 18 | .map(word -> word.toUpperCase()) 19 | .map(word -> "Hi "+word) 20 | .forEach(System.out::println); 21 | 22 | } 23 | 24 | 25 | } 26 | -------------------------------------------------------------------------------- /section_26/src/com/eazybytes/streams/StreamPartitioningByDemo.java: -------------------------------------------------------------------------------- 1 | package com.eazybytes.streams; 2 | 3 | import java.util.Arrays; 4 | import java.util.List; 5 | import java.util.Map; 6 | import java.util.stream.Collectors; 7 | 8 | public class StreamPartitioningByDemo { 9 | 10 | public static void main(String[] args) { 11 | List productList = Arrays.asList(new Product("Apple", 1200), 12 | new Product("Samsung", 1000), new Product("Nokia", 600), 13 | new Product("BlackBerry", 1000), new Product("Apple Pro Max", 1500), 14 | new Product("Mi", 800), new Product("OnePlus", 1000)); 15 | 16 | Map> partitioningByPriceMap = productList.stream() 17 | .collect(Collectors.partitioningBy(product -> product.getPrice()>1000)); 18 | 19 | System.out.println(partitioningByPriceMap); 20 | 21 | } 22 | 23 | } 24 | -------------------------------------------------------------------------------- /section_26/src/com/eazybytes/streams/StreamReduceOperationDemo.java: -------------------------------------------------------------------------------- 1 | package com.eazybytes.streams; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | import java.util.OptionalInt; 6 | 7 | public class StreamReduceOperationDemo { 8 | 9 | public static void main(String[] args) { 10 | List departmentList = new ArrayList<>(); 11 | departmentList.add("Supply"); 12 | departmentList.add("HR"); 13 | departmentList.add("Sales"); 14 | departmentList.add("Marketing"); 15 | System.out.println(departmentList.stream().count()); 16 | 17 | List numbers = List.of(1, 2, 3, 4, 5); 18 | int sum = numbers.stream() 19 | .reduce(0 , Integer::sum); 20 | System.out.println(sum); 21 | 22 | OptionalInt result = numbers.stream() 23 | .filter(num -> num%2==0) 24 | .mapToInt(num -> num).max(); 25 | System.out.println(result.getAsInt()); 26 | 27 | 28 | } 29 | 30 | } 31 | -------------------------------------------------------------------------------- /section_26/src/com/eazybytes/streams/StreamSkipOperationDemo.java: -------------------------------------------------------------------------------- 1 | package com.eazybytes.streams; 2 | 3 | import java.util.stream.Stream; 4 | 5 | public class StreamSkipOperationDemo { 6 | 7 | public static void main(String[] args) { 8 | Stream.iterate(1, n -> n +1) 9 | .skip(5) 10 | .limit(5) 11 | .forEach(System.out::println); 12 | } 13 | 14 | } 15 | -------------------------------------------------------------------------------- /section_26/src/com/eazybytes/streams/StreamTraverseDemo.java: -------------------------------------------------------------------------------- 1 | package com.eazybytes.streams; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | import java.util.stream.Stream; 6 | 7 | public class StreamTraverseDemo { 8 | 9 | public static void main(String[] args) { 10 | List departmentList = new ArrayList<>(); 11 | departmentList.add("Supply"); 12 | departmentList.add("HR"); 13 | departmentList.add("Sales"); 14 | departmentList.add("Marketing"); 15 | 16 | Stream depStream = departmentList.stream(); 17 | depStream.forEach(System.out::println); 18 | depStream.forEach(System.out::println); 19 | } 20 | 21 | } 22 | -------------------------------------------------------------------------------- /section_27/.gitignore: -------------------------------------------------------------------------------- 1 | ### IntelliJ IDEA ### 2 | out/ 3 | !**/src/main/**/out/ 4 | !**/src/test/**/out/ 5 | 6 | ### Eclipse ### 7 | .apt_generated 8 | .classpath 9 | .factorypath 10 | .project 11 | .settings 12 | .springBeans 13 | .sts4-cache 14 | bin/ 15 | !**/src/main/**/bin/ 16 | !**/src/test/**/bin/ 17 | 18 | ### NetBeans ### 19 | /nbproject/private/ 20 | /nbbuild/ 21 | /dist/ 22 | /nbdist/ 23 | /.nb-gradle/ 24 | 25 | ### VS Code ### 26 | .vscode/ 27 | 28 | ### Mac OS ### 29 | .DS_Store -------------------------------------------------------------------------------- /section_27/src/com/eazybytes/optional/StreamsAPINullCheckTip.java: -------------------------------------------------------------------------------- 1 | package com.eazybytes.optional; 2 | 3 | import java.util.Arrays; 4 | import java.util.List; 5 | import java.util.Objects; 6 | import java.util.stream.Collectors; 7 | 8 | public class StreamsAPINullCheckTip { 9 | 10 | public static void main(String[] args) { 11 | List countryNames = Arrays.asList("USA", "India", null, "Canada", null, "UK", null, null, "Germany"); 12 | List capitalNames =countryNames.stream() 13 | .filter(Objects::nonNull) 14 | .map(String::toUpperCase).collect(Collectors.toList()); 15 | System.out.println(capitalNames); 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /section_28/.gitignore: -------------------------------------------------------------------------------- 1 | ### IntelliJ IDEA ### 2 | out/ 3 | !**/src/main/**/out/ 4 | !**/src/test/**/out/ 5 | 6 | ### Eclipse ### 7 | .apt_generated 8 | .classpath 9 | .factorypath 10 | .project 11 | .settings 12 | .springBeans 13 | .sts4-cache 14 | bin/ 15 | !**/src/main/**/bin/ 16 | !**/src/test/**/bin/ 17 | 18 | ### NetBeans ### 19 | /nbproject/private/ 20 | /nbbuild/ 21 | /dist/ 22 | /nbdist/ 23 | /.nb-gradle/ 24 | 25 | ### VS Code ### 26 | .vscode/ 27 | 28 | ### Mac OS ### 29 | .DS_Store -------------------------------------------------------------------------------- /section_28/src/com/eazybytes/multithreading/Counter.java: -------------------------------------------------------------------------------- 1 | package com.eazybytes.multithreading; 2 | 3 | public class Counter { 4 | 5 | private int count = 0; 6 | 7 | public void incrementUnSynchronized (){ 8 | count++; 9 | } 10 | 11 | public synchronized void incrementSynchronized (){ 12 | count++; 13 | /*synchronized (Counter.class){ 14 | count++; 15 | }*/ 16 | } 17 | 18 | public int getCount() { 19 | return count; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /section_28/src/com/eazybytes/multithreading/CurrentThreadDemo.java: -------------------------------------------------------------------------------- 1 | package com.eazybytes.multithreading; 2 | 3 | public class CurrentThreadDemo { 4 | 5 | public static void main(String[] args) { 6 | Thread mainThread = Thread.currentThread(); 7 | System.out.println(mainThread.threadId()); 8 | System.out.println(mainThread.getName()); 9 | } 10 | 11 | } 12 | -------------------------------------------------------------------------------- /section_28/src/com/eazybytes/multithreading/DeadLockDemo.java: -------------------------------------------------------------------------------- 1 | package com.eazybytes.multithreading; 2 | 3 | public class DeadLockDemo { 4 | public static final String R1 = "Hello"; 5 | public static final String R2 = "Hi"; 6 | 7 | public static void main(String[] args) { 8 | Thread thread1 = new Thread(() -> { 9 | synchronized (R1) { 10 | System.out.println("Thread T1 locked : Resource R1"); 11 | synchronized (R2) { 12 | System.out.println("Thread T1 locked : Resource R2"); 13 | } 14 | } 15 | }); 16 | 17 | Thread thread2 = new Thread(() -> { 18 | synchronized (R2) { 19 | System.out.println("Thread T2 locked : Resource R2"); 20 | synchronized (R1) { 21 | System.out.println("Thread T2 locked : Resource R1"); 22 | } 23 | } 24 | }); 25 | thread1.start(); 26 | thread2.start(); 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /section_28/src/com/eazybytes/multithreading/Hello.java: -------------------------------------------------------------------------------- 1 | package com.eazybytes.multithreading; 2 | 3 | public class Hello { 4 | 5 | public static void sayHello() { 6 | System.out.println("Hello from Method Reference approach"); 7 | } 8 | 9 | } 10 | -------------------------------------------------------------------------------- /section_28/src/com/eazybytes/multithreading/HelloThread.java: -------------------------------------------------------------------------------- 1 | package com.eazybytes.multithreading; 2 | 3 | public class HelloThread extends Thread { 4 | 5 | @Override 6 | public void run () { 7 | System.out.println("Hello from HelloThread class " + 8 | " which extends Thread"); 9 | } 10 | 11 | } 12 | -------------------------------------------------------------------------------- /section_28/src/com/eazybytes/multithreading/HelloThread1.java: -------------------------------------------------------------------------------- 1 | package com.eazybytes.multithreading; 2 | 3 | public class HelloThread1 implements Runnable { 4 | 5 | @Override 6 | public void run () { 7 | System.out.println("Hello from HelloThread1 class " + 8 | " which implements Runnable"); 9 | } 10 | 11 | } 12 | -------------------------------------------------------------------------------- /section_28/src/com/eazybytes/multithreading/JoinExample.java: -------------------------------------------------------------------------------- 1 | package com.eazybytes.multithreading; 2 | 3 | public class JoinExample { 4 | 5 | public static void main(String[] args) { 6 | Thread threadA = new Thread( 7 | () -> { 8 | for(int i=1;i<=5;i++) { 9 | System.out.println("Thread A - count : "+i); 10 | try { 11 | Thread.sleep(500); 12 | } catch (InterruptedException e) { 13 | throw new RuntimeException(e); 14 | } 15 | } 16 | } 17 | ); 18 | threadA.start(); 19 | try { 20 | threadA.join(); 21 | } catch (InterruptedException e) { 22 | throw new RuntimeException(e); 23 | } 24 | System.out.println("Main thread ended"); 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /section_28/src/com/eazybytes/multithreading/NonThreadDemo.java: -------------------------------------------------------------------------------- 1 | package com.eazybytes.multithreading; 2 | 3 | public class NonThreadDemo { 4 | 5 | public static void main(String[] args) { 6 | for (int i=0;i<100;i++){ 7 | System.out.println(i); 8 | } 9 | 10 | for (int i=100;i<201;i++){ 11 | System.out.println(i); 12 | } 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /section_28/src/com/eazybytes/multithreading/PriorityExample.java: -------------------------------------------------------------------------------- 1 | package com.eazybytes.multithreading; 2 | 3 | public class PriorityExample implements Runnable { 4 | 5 | private final String name; 6 | 7 | public PriorityExample(String name) { 8 | this.name = name; 9 | } 10 | 11 | /** 12 | * Runs this operation. 13 | */ 14 | @Override 15 | public void run() { 16 | for(int i=1;i<=5;i++) { 17 | System.out.println(name + " - Count: "+i+", Priority : " + Thread.currentThread().getPriority()); 18 | try { 19 | Thread.sleep(500); 20 | } catch (InterruptedException e) { 21 | throw new RuntimeException(e); 22 | } 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /section_28/src/com/eazybytes/multithreading/SharedBooleanResource.java: -------------------------------------------------------------------------------- 1 | package com.eazybytes.multithreading; 2 | 3 | public class SharedBooleanResource { 4 | 5 | private volatile boolean stopFlag = false; 6 | 7 | public void setStopFlag () { 8 | stopFlag = true; 9 | } 10 | 11 | public void doWork () { 12 | while(!stopFlag){ 13 | System.out.println("Working..."); 14 | } 15 | System.out.println("Work stopped"); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /section_28/src/com/eazybytes/multithreading/SleepDemo.java: -------------------------------------------------------------------------------- 1 | package com.eazybytes.multithreading; 2 | 3 | public class SleepDemo { 4 | 5 | public static void main(String[] args) throws InterruptedException { 6 | long startTime = System.currentTimeMillis(); 7 | for(int i=0;i<5;i++){ 8 | System.out.println("Hello from Main method : " + i); 9 | Thread.sleep(1000); 10 | } 11 | long endTime = System.currentTimeMillis(); 12 | System.out.println("Total time taken : " + (endTime-startTime)); 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /section_28/src/com/eazybytes/multithreading/SumOfIntsDemo.java: -------------------------------------------------------------------------------- 1 | package com.eazybytes.multithreading; 2 | 3 | public class SumOfIntsDemo { 4 | 5 | public static void main(String[] args) { 6 | long startTime = System.currentTimeMillis(); 7 | long result = 0; 8 | for(long i =0; i<=Integer.MAX_VALUE;i++) { 9 | result = result + i; 10 | } 11 | System.out.println(result); 12 | long endTime = System.currentTimeMillis(); 13 | System.out.println("Total time taken by normal Java class is : "+ (endTime-startTime)); 14 | 15 | } 16 | 17 | } 18 | -------------------------------------------------------------------------------- /section_28/src/com/eazybytes/multithreading/SumOfIntsThreadDemo.java: -------------------------------------------------------------------------------- 1 | package com.eazybytes.multithreading; 2 | 3 | public class SumOfIntsThreadDemo { 4 | 5 | public static void main(String[] args) throws InterruptedException { 6 | long startTime = System.currentTimeMillis(); 7 | long result = 0; 8 | SumThread thread1 = new SumThread(0, Integer.MAX_VALUE/2); 9 | SumThread thread2 = new SumThread((Integer.MAX_VALUE/2)+1, Integer.MAX_VALUE); 10 | thread1.start(); 11 | thread2.start(); 12 | thread1.join(); 13 | thread2.join(); 14 | result = thread1.getResult() + thread2.getResult(); 15 | System.out.println(result); 16 | long endTime = System.currentTimeMillis(); 17 | System.out.println("Total time taken by multiple thread Java class is : "+ (endTime-startTime)); 18 | } 19 | 20 | } 21 | -------------------------------------------------------------------------------- /section_28/src/com/eazybytes/multithreading/SumThread.java: -------------------------------------------------------------------------------- 1 | package com.eazybytes.multithreading; 2 | 3 | public class SumThread extends Thread { 4 | 5 | private int startIndex; 6 | private int endIndex; 7 | private long result; 8 | 9 | public SumThread(int startIndex, int endIndex) { 10 | this.startIndex = startIndex; 11 | this.endIndex =endIndex; 12 | } 13 | 14 | @Override 15 | public void run() { 16 | for(long i =startIndex; i<=endIndex;i++) { 17 | result = result + i; 18 | } 19 | } 20 | 21 | public long getResult(){ 22 | return result; 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /section_28/src/com/eazybytes/multithreading/SynchronizationExample.java: -------------------------------------------------------------------------------- 1 | package com.eazybytes.multithreading; 2 | 3 | public class SynchronizationExample { 4 | 5 | public static void main(String[] args) throws InterruptedException { 6 | Counter counter = new Counter(); 7 | Runnable synchronizedTask = () -> { 8 | for(int i=0;i<1000;i++) { 9 | counter.incrementSynchronized(); 10 | } 11 | }; 12 | 13 | Thread thread1 = new Thread(synchronizedTask); 14 | Thread thread2 = new Thread(synchronizedTask); 15 | 16 | thread1.start(); 17 | thread2.start(); 18 | 19 | thread1.join(); 20 | thread2.join(); 21 | 22 | System.out.println("Synchronized Count value : " + counter.getCount()); 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /section_28/src/com/eazybytes/multithreading/ThreadDemo.java: -------------------------------------------------------------------------------- 1 | package com.eazybytes.multithreading; 2 | 3 | public class ThreadDemo { 4 | 5 | public static void main(String[] args) { 6 | Thread thread = new Thread(); 7 | thread.start(); 8 | 9 | Thread thread1 = new Thread(() -> System.out.println("Hello from Java Thread")); 10 | thread1.start(); 11 | 12 | Runnable runnable = () -> System.out.println("Hi from Java Thread"); 13 | Thread thread2 = new Thread(runnable); 14 | thread2.start(); 15 | 16 | HelloThread thread3 = new HelloThread(); 17 | thread3.start(); 18 | 19 | Thread thread4 = new Thread(new HelloThread1()); 20 | thread4.start(); 21 | 22 | Thread thread5 = new Thread(Hello::sayHello); 23 | thread5.start(); 24 | 25 | 26 | System.out.println("Hello from Main Thread"); 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /section_28/src/com/eazybytes/multithreading/ThreadIDNameDemo.java: -------------------------------------------------------------------------------- 1 | package com.eazybytes.multithreading; 2 | 3 | public class ThreadIDNameDemo { 4 | 5 | public static void main(String[] args) { 6 | Thread t1 = new Thread(); 7 | Thread t2 = new Thread(); 8 | Thread t3 = new Thread(); 9 | t3.setName("MyThread"); 10 | 11 | System.out.println("Thread 1 ID is : " + t1.getId() + ", name : "+ t1.getName()); 12 | System.out.println("Thread 2 ID is : " + t2.threadId() + ", name : "+ t2.getName()); 13 | System.out.println("Thread 3 ID is : " + t3.threadId() + ", name : "+ t3.getName()); 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /section_28/src/com/eazybytes/multithreading/ThreadPriorityDemo.java: -------------------------------------------------------------------------------- 1 | package com.eazybytes.multithreading; 2 | 3 | public class ThreadPriorityDemo { 4 | 5 | public static void main(String[] args) { 6 | Thread thread1 = new Thread(new PriorityExample("Thread A")); 7 | Thread thread2 = new Thread(new PriorityExample("Thread B")); 8 | Thread thread3 = new Thread(new PriorityExample("Thread C")); 9 | 10 | thread1.setPriority(Thread.MIN_PRIORITY); 11 | thread2.setPriority(Thread.NORM_PRIORITY); 12 | thread3.setPriority(Thread.MAX_PRIORITY); 13 | 14 | thread1.start(); 15 | thread2.start(); 16 | thread3.start(); 17 | } 18 | 19 | } 20 | -------------------------------------------------------------------------------- /section_28/src/com/eazybytes/multithreading/UnSynchronizationExample.java: -------------------------------------------------------------------------------- 1 | package com.eazybytes.multithreading; 2 | 3 | public class UnSynchronizationExample { 4 | 5 | public static void main(String[] args) throws InterruptedException { 6 | Counter counter = new Counter(); 7 | Runnable unSynchronizedTask = () -> { 8 | for(int i=0;i<1000;i++) { 9 | counter.incrementUnSynchronized(); 10 | } 11 | }; 12 | 13 | Thread thread1 = new Thread(unSynchronizedTask); 14 | Thread thread2 = new Thread(unSynchronizedTask); 15 | 16 | thread1.start(); 17 | thread2.start(); 18 | 19 | thread1.join(); 20 | thread2.join(); 21 | 22 | System.out.println("UnSynchronized Count value : " + counter.getCount()); 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /section_28/src/com/eazybytes/multithreading/VirtualThreadDemo.java: -------------------------------------------------------------------------------- 1 | package com.eazybytes.multithreading; 2 | 3 | import java.util.Random; 4 | 5 | public class VirtualThreadDemo { 6 | 7 | public static void main(String[] args) throws InterruptedException { 8 | long startTime = System.currentTimeMillis(); 9 | Random random = new Random(); 10 | Runnable runnable = () -> { 11 | double result = random.nextDouble(1000) * random.nextDouble(1000); 12 | System.out.println(result); 13 | }; 14 | for (int i =0; i<500000; i++) { 15 | Thread.ofVirtual().start(runnable).join(); //8828 16 | // Thread.startVirtualThread(runnable).join(); // 8844 17 | // Thread thread = new Thread(runnable); // 30563 18 | // thread.start(); 19 | // thread.join(); 20 | } 21 | long endTime = System.currentTimeMillis(); 22 | System.out.println("Total time : " + (endTime-startTime)); 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /section_28/src/com/eazybytes/multithreading/VolatileExample.java: -------------------------------------------------------------------------------- 1 | package com.eazybytes.multithreading; 2 | 3 | public class VolatileExample { 4 | 5 | public static void main(String[] args) throws InterruptedException { 6 | SharedBooleanResource sharedBooleanResource = new SharedBooleanResource(); 7 | Thread workerThread = new Thread(() -> sharedBooleanResource.doWork()); 8 | 9 | Thread stopperThread = new Thread(() -> { 10 | try { 11 | Thread.sleep(3000); 12 | sharedBooleanResource.setStopFlag(); 13 | } catch (InterruptedException e) { 14 | throw new RuntimeException(e); 15 | } 16 | }) ; 17 | workerThread.start(); 18 | stopperThread.start(); 19 | workerThread.join(); 20 | stopperThread.join(); 21 | } 22 | 23 | } 24 | -------------------------------------------------------------------------------- /section_29/.gitignore: -------------------------------------------------------------------------------- 1 | ### IntelliJ IDEA ### 2 | out/ 3 | !**/src/main/**/out/ 4 | !**/src/test/**/out/ 5 | 6 | ### Eclipse ### 7 | .apt_generated 8 | .classpath 9 | .factorypath 10 | .project 11 | .settings 12 | .springBeans 13 | .sts4-cache 14 | bin/ 15 | !**/src/main/**/bin/ 16 | !**/src/test/**/bin/ 17 | 18 | ### NetBeans ### 19 | /nbproject/private/ 20 | /nbbuild/ 21 | /dist/ 22 | /nbdist/ 23 | /.nb-gradle/ 24 | 25 | ### VS Code ### 26 | .vscode/ 27 | 28 | ### Mac OS ### 29 | .DS_Store -------------------------------------------------------------------------------- /section_29/src/com/eazybytes/java22/UnnamedPatterns.java: -------------------------------------------------------------------------------- 1 | package com.eazybytes.java22; 2 | 3 | public class UnnamedPatterns { 4 | 5 | public static void main(String[] args) { 6 | Vehicle vehicle = new Truck("Toyota"); 7 | 8 | switch (vehicle) { 9 | case Car _ -> processCar(vehicle); 10 | case Bike _ -> processBike(vehicle); 11 | case Truck _ -> processTruck(vehicle); 12 | } 13 | } 14 | 15 | public static void processCar(Vehicle vehicle) { 16 | if(vehicle instanceof Car car) { 17 | System.out.println("Processing car model: " + car.getModel()); 18 | } 19 | } 20 | 21 | public static void processBike(Vehicle vehicle) { 22 | if(vehicle instanceof Bike bike) { 23 | System.out.println("Processing bike brand: " + bike.getBrand()); 24 | } 25 | } 26 | 27 | public static void processTruck(Vehicle vehicle) { 28 | if(vehicle instanceof Truck truck) { 29 | System.out.println("Processing truck manufacturer: " + truck.getManufacturer()); 30 | } 31 | } 32 | 33 | } 34 | 35 | 36 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /section_29/src/com/eazybytes/java22/Vehicle.java: -------------------------------------------------------------------------------- 1 | package com.eazybytes.java22; 2 | 3 | public sealed interface Vehicle permits Car, Bike, Truck { 4 | 5 | } 6 | 7 | final class Bike implements Vehicle { 8 | private final String brand; 9 | 10 | public Bike(String brand) { 11 | this.brand = brand; 12 | } 13 | 14 | public String getBrand() { 15 | return brand; 16 | } 17 | } 18 | 19 | final class Car implements Vehicle { 20 | private final String model; 21 | 22 | public Car(String model) { 23 | this.model = model; 24 | } 25 | 26 | public String getModel() { 27 | return model; 28 | } 29 | } 30 | 31 | final class Truck implements Vehicle { 32 | private final String manufacturer; 33 | 34 | public Truck(String manufacturer) { 35 | this.manufacturer = manufacturer; 36 | } 37 | 38 | public String getManufacturer() { 39 | return manufacturer; 40 | } 41 | } 42 | --------------------------------------------------------------------------------