├── .DS_Store ├── LICENSE ├── README.md ├── Section 1 ├── ArithmeticOperators.txt ├── Assignment.docx ├── Fibonacci.txt ├── For_Loop.txt ├── If_Condition.txt ├── Java Basics Assignment.pdf ├── LogicalAndBitwiseOperators.txt ├── Loop_Break_And_Continue.txt ├── Nested_For.txt ├── Nested_For_Program.txt ├── Nested_If.txt ├── Primitive Data Types in Java.pdf ├── PrimitiveDataTypes.txt ├── RelationalOperators.txt └── While_Loop.txt ├── Section 10 ├── Bracket_Expressions.txt ├── Charcter_Classes.txt ├── Dot_Operator.txt ├── Escape_Character.txt ├── GreedyAndLazyMatch.txt ├── Intro.txt ├── Number_Range.txt ├── OR_Operator.txt ├── Quantifiers.txt ├── RegEx_Example_1.txt ├── RegEx_Example_2.txt └── Regular Expression Cheat Sheet.pdf ├── Section 11 ├── CheckedVsUnchecked.txt ├── ErrorVsException.txt ├── Finally_Block.txt ├── Intro.txt ├── Throwable.docx ├── Throwable.pdf ├── Throws_Declaration.txt └── Try_Catch.txt ├── Section 12 ├── Custom_Date_Time.txt ├── DateTime_Formatter.txt ├── Date_Add_Subtract.txt ├── Date_Difference.txt ├── Intro.txt ├── Time_Add_Subtract.txt └── Time_Difference.txt ├── Section 13 ├── Edit-Text-File.txt ├── File_Copy.txt ├── Read_Text_File.txt ├── Remove_Duplicate_Words.txt └── Sort_Lines.txt ├── Section 14 ├── Read_Excel.txt ├── Read_Excel_Into_2D_Array.txt └── Write_Excel2.txt ├── Section 2 ├── String_Basics.txt ├── String_Comparison.txt ├── String_Conversion.txt ├── String_Replace.txt ├── String_Search.txt └── String_Slice.txt ├── Section 3 ├── Access Specifiers in Java.pdf ├── Access_Main2.txt ├── Access_Specifiers.txt ├── Aceess_Main.txt ├── BankAccount_Main.txt ├── Bank_Account.txt ├── Cars.txt ├── Classroom.txt ├── Classroom_Main.txt ├── Constructor.txt ├── Data_Encapsulation.txt ├── Employee.txt ├── Employee_Main.txt ├── Main_Method.txt ├── Method_Overloading.txt ├── Methods.txt ├── RoadToll_Main.txt ├── Road_Toll.txt ├── Static_Keyword.txt ├── Static_Main.txt └── Temp.txt ├── Section 4 ├── MathClass.txt ├── RandomClass.txt ├── ScannerClass.txt ├── StringBuilderClass1.txt ├── StringBuilderClass2.txt ├── StringReverseProgram.txt └── UUIDClass.txt ├── Section 5 └── DS_Store ├── Section 6 ├── Access Specifiers in Java.pdf ├── Android.txt ├── Animal.txt ├── Animal_Main.txt ├── Cars.txt ├── Cat.txt ├── Class1.txt ├── Class2.txt ├── Class2_Final.txt ├── Dog.txt ├── Final_Keyword.txt ├── German_Cars.txt ├── Hotel_Booking.txt ├── IOS.txt ├── Interfaces │ ├── Class1.txt │ ├── Class2.txt │ ├── Class3.txt │ ├── Class4.txt │ ├── Int1.txt │ ├── Int2.txt │ └── Interface_Main.txt ├── Japanese_Cars.txt ├── Main.txt ├── Mobile.txt ├── Mobile_Main.txt ├── PolyMain.txt ├── Polygon.txt ├── Rectangle.txt ├── Super Keyword │ ├── A.txt │ ├── B.txt │ ├── Class1.txt │ ├── Class2.txt │ └── Main_Class.txt ├── Travel_Booking.txt ├── Travel_Main.txt └── Triangle.txt ├── Section 7 ├── 2-Dimensional Array.pdf ├── Array Exercise.docx ├── Array Structure.png ├── Array_2D.txt ├── Array_2D_Exercise.txt ├── Array_Exercise.txt ├── Array_Object.txt ├── Array_Of_Object.txt ├── Arrays.txt ├── Enhanced_For_Loop.txt └── Frequently Asked Interview Programs on Arrays.pdf ├── Section 8 ├── Array List Structure.pdf ├── ArrayList Vs LinkedList.pdf ├── Array_List.txt ├── Linked List Structure.pdf ├── Linked_List.txt ├── List_Iterator.txt ├── List_Iterator_Program1.txt └── List_Iterator_Program2.txt └── Section 9 ├── Hash_Map.txt ├── Hash_Set.txt ├── Iterating_Over_Set.txt ├── Linked_Hash_Set.txt ├── Map_Iterating.txt ├── Tree_Map.txt └── Tree_Set.txt /.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Learn-How-to-Code-The-Complete-Core-Java-Programming-Course/eb54411c83978b2252257adc9d2be7f2a973188c/.DS_Store -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 Packt 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | # Learn-How-to-Code-The-Complete-Core-Java-Programming-Course 5 | Learn How to Code: The Complete Core Java Programming Course, by Packt Publishing 6 | -------------------------------------------------------------------------------- /Section 1/ArithmeticOperators.txt: -------------------------------------------------------------------------------- 1 | package java_basics; 2 | 3 | public class ArithmeticOperators { 4 | 5 | public static void main(String[] args) { 6 | 7 | /* 8 | * + - Add 9 | * 10 | * - - Sub 11 | * 12 | * * - Mul 13 | * 14 | * / - Div 15 | * 16 | * % - Mod 17 | * 18 | * ++ - Inc 19 | * 20 | * -- - Dec 21 | * 22 | */ 23 | 24 | int num1 = 1; 25 | 26 | num1++; 27 | num1 = num1 + 1; 28 | 29 | num1--; 30 | num1 = num1 - 1; 31 | 32 | num1+=5; 33 | num1 = num1 + 5; 34 | 35 | num1-=10; 36 | num1 = num1 - 10; 37 | 38 | num1*=2; 39 | num1 = num1 * 2; 40 | 41 | num1/=5; 42 | num1 = num1 / 5; 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | } 52 | 53 | } 54 | -------------------------------------------------------------------------------- /Section 1/Assignment.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Learn-How-to-Code-The-Complete-Core-Java-Programming-Course/eb54411c83978b2252257adc9d2be7f2a973188c/Section 1/Assignment.docx -------------------------------------------------------------------------------- /Section 1/Fibonacci.txt: -------------------------------------------------------------------------------- 1 | package java_basics; 2 | 3 | public class Fibonacci { 4 | 5 | public static void main(String[] args) { 6 | 7 | /* 8 | * Write a program to find first 20 numbers of Fibonacci Series 9 | * 0 1 1 2 3 5 8 13 21 10 | */ 11 | int num1 = 0; 12 | int num2 = 1; 13 | int num3 = 0; 14 | 15 | System.out.println(num1); 16 | System.out.println(num2); 17 | 18 | for(int i = 1; i <= 18; i++) { 19 | num3 = num1 + num2; 20 | System.out.println(num3); 21 | num1 = num2; 22 | num2 = num3; 23 | } 24 | 25 | 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /Section 1/For_Loop.txt: -------------------------------------------------------------------------------- 1 | package java_basics; 2 | 3 | public class For_Loop { 4 | 5 | public static void main(String[] args) { 6 | 7 | for (int i = 1; i <= 100; i++) { 8 | if (i % 2 == 0) { 9 | System.out.println("Even Number:" + i); 10 | } 11 | 12 | } 13 | 14 | /** 15 | * 16 | * Even Numbers 1 and 100 17 | * 18 | * num % 2 19 | * 20 | * 21 | */ 22 | 23 | 24 | 25 | 26 | 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /Section 1/If_Condition.txt: -------------------------------------------------------------------------------- 1 | package java_basics; 2 | 3 | public class If_Condition { 4 | 5 | public static void main(String[] args) { 6 | 7 | int num1 = 100; 8 | int num2 = 200; 9 | 10 | if (num1 > num2) { 11 | System.out.println("num1 is bigger"); 12 | } else { 13 | System.out.println("num1 is not bigger"); 14 | } 15 | 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /Section 1/Java Basics Assignment.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Learn-How-to-Code-The-Complete-Core-Java-Programming-Course/eb54411c83978b2252257adc9d2be7f2a973188c/Section 1/Java Basics Assignment.pdf -------------------------------------------------------------------------------- /Section 1/LogicalAndBitwiseOperators.txt: -------------------------------------------------------------------------------- 1 | package java_basics; 2 | 3 | public class LogicalAndBitwiseOperators { 4 | 5 | public static void main(String[] args) { 6 | 7 | /* 8 | * 9 | * Logical AND - && 10 | * 11 | * Logical OR - || 12 | * 13 | * Logical Not - ! 14 | * 15 | * Bitwise And - & 16 | * 17 | * Bitwise Or - | 18 | * 19 | * Bitwise Compliment - ~ 20 | * 21 | * 22 | * 23 | * 24 | */ 25 | 26 | int num1 = 60; //111100 => 000011 27 | int num2 = 42; //101010 28 | //101000 => 40 29 | //111110 => 62 30 | 31 | System.out.println(num1 | num2); 32 | 33 | System.out.println(~num1); 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /Section 1/Loop_Break_And_Continue.txt: -------------------------------------------------------------------------------- 1 | package java_basics; 2 | 3 | public class Loop_Break_And_Continue { 4 | 5 | public static void main(String[] args) { 6 | 7 | int a = 100; 8 | 9 | while (a > 50) { 10 | a-=5; 11 | if (a == 75) { 12 | continue; 13 | } 14 | System.out.println(a); 15 | } 16 | 17 | } 18 | 19 | } 20 | -------------------------------------------------------------------------------- /Section 1/Nested_For.txt: -------------------------------------------------------------------------------- 1 | package java_basics; 2 | 3 | public class Nested_For { 4 | 5 | public static void main(String[] args) { 6 | 7 | for (int i = 1; i <= 10; i++) { 8 | for (int j = 1; j <= 5; j++) { 9 | System.out.println(i + "," + j); 10 | } 11 | System.out.println("All Iterations of J are Done"); 12 | } 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /Section 1/Nested_For_Program.txt: -------------------------------------------------------------------------------- 1 | package java_basics; 2 | 3 | public class Nested_For_Program { 4 | 5 | public static void main(String[] args) { 6 | 7 | /** 8 | * Write a program to create pattern: 9 | * 10 | * * 11 | * ** 12 | * *** 13 | * **** 14 | * ***** 15 | * ****** 16 | * 17 | */ 18 | for (int i = 1; i <= 6; i++) { 19 | for (int j = 1; j <= i; j++) { 20 | System.out.print("*"); 21 | } 22 | System.out.println("\n"); 23 | } 24 | 25 | 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /Section 1/Nested_If.txt: -------------------------------------------------------------------------------- 1 | package java_basics; 2 | 3 | public class Nested_If { 4 | 5 | public static void main(String[] args) { 6 | 7 | /* 8 | * Create a program to find the grade of a student 9 | * marks >= 90 => A Grade 10 | * marks >= 75 => B Grade 11 | * marks >= 60 => C Grade 12 | * marks >= 40 => D Grade 13 | * marks < 40 => Fail 14 | * 15 | */ 16 | int marks = 66; 17 | 18 | if (marks > 90) { 19 | System.out.println("A Grade"); 20 | } else if (marks > 75) { 21 | System.out.println("B Grade"); 22 | } else if (marks > 60) { 23 | System.out.println("C Grade"); 24 | } else if (marks > 40) { 25 | System.out.println("D Grade"); 26 | } else { 27 | System.out.println("Fail"); 28 | } 29 | 30 | 31 | /* 32 | * 33 | * int num1, num2, num3 34 | * 100, 400, 300 35 | * 36 | * 37 | */ 38 | 39 | } 40 | 41 | } 42 | -------------------------------------------------------------------------------- /Section 1/Primitive Data Types in Java.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Learn-How-to-Code-The-Complete-Core-Java-Programming-Course/eb54411c83978b2252257adc9d2be7f2a973188c/Section 1/Primitive Data Types in Java.pdf -------------------------------------------------------------------------------- /Section 1/PrimitiveDataTypes.txt: -------------------------------------------------------------------------------- 1 | package java_basics; 2 | 3 | public class PrimitiveDataTypes { 4 | 5 | public static void main(String[] args) { 6 | 7 | byte b1 = 123; 8 | 9 | short sh1 = 7654; 10 | 11 | int num1 = 456789; 12 | 13 | long l1 = 3456789; 14 | 15 | float f1 = 12.5678f; 16 | 17 | double d1 = 234.456789; 18 | 19 | char ch1 = 'A'; 20 | 21 | String str1 = "ASDFGHJKrtghjkl123456789(*&^%$#"; 22 | 23 | boolean b2 = true; 24 | 25 | System.out.println(b1); 26 | 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /Section 1/RelationalOperators.txt: -------------------------------------------------------------------------------- 1 | package java_basics; 2 | 3 | public class RelationalOperators { 4 | 5 | public static void main(String[] args) { 6 | 7 | /* 8 | * == (num1 == num2) 9 | * 10 | * != (num1!=num2) 11 | * 12 | * > (num1 >= num2) 13 | * 14 | * < (num1 <= num2) 15 | * 16 | * 17 | * 18 | * 19 | * 20 | * 21 | * 22 | */ 23 | 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /Section 1/While_Loop.txt: -------------------------------------------------------------------------------- 1 | package java_basics; 2 | 3 | public class While_Loop { 4 | 5 | public static void main(String[] args) { 6 | 7 | int a = 100; 8 | 9 | /* 10 | while (a > 50) { 11 | a-=5; 12 | System.out.println(a); 13 | } 14 | */ 15 | 16 | do { 17 | 18 | a-=5; 19 | System.out.println(a); 20 | 21 | } while (a > 500); 22 | 23 | 24 | 25 | 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /Section 10/Bracket_Expressions.txt: -------------------------------------------------------------------------------- 1 | package regex; 2 | 3 | public class Bracket_Expressions { 4 | 5 | public static void main(String[] args) { 6 | 7 | /* 8 | * 1. Adding literals in brackets [aeiou] 9 | * 2. Adding ranges in brackets [A-Z0-9] 10 | * 3. Usage of '^' in brackets [^a-z] 11 | */ 12 | 13 | 14 | String patt = "[A-Za-z0-9_]{3}at"; //[afg] 15 | 16 | String str1 = "A8tat"; 17 | 18 | System.out.println(str1.matches(patt)); 19 | 20 | 21 | 22 | 23 | 24 | 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /Section 10/Charcter_Classes.txt: -------------------------------------------------------------------------------- 1 | package regex; 2 | 3 | public class Charcter_Classes { 4 | 5 | public static void main(String[] args) { 6 | 7 | /* 8 | * 1. \d - matches a single digit character 9 | * 2. \w - matches a single word character 10 | * 3. \s - matches a single whitespace character 11 | * 4. \D - matches a single non-digit character 12 | * 5. \W - matches a single non-digit and non-word character 13 | */ 14 | 15 | 16 | String patt = "\\w{2,6}\\W{2}"; 17 | 18 | String str1 = "rtTYUIOY*("; 19 | 20 | System.out.println(str1.matches(patt)); 21 | 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /Section 10/Dot_Operator.txt: -------------------------------------------------------------------------------- 1 | package regex; 2 | 3 | public class Dot_Operator { 4 | 5 | public static void main(String[] args) { 6 | 7 | /* 8 | * (DOT) '.' -> Matches Any Single Character 9 | */ 10 | 11 | String patt = "ABC."; 12 | 13 | String str1 = "ABC9"; 14 | 15 | String patt1 = "ABC.*"; 16 | 17 | String str2 = "ABC^&*IJHG987"; 18 | 19 | System.out.println(str2.matches(patt1)); 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /Section 10/Escape_Character.txt: -------------------------------------------------------------------------------- 1 | package regex; 2 | 3 | import java.util.regex.Matcher; 4 | import java.util.regex.Pattern; 5 | 6 | public class Escape_Character { 7 | 8 | public static void main(String[] args) { 9 | 10 | /* 11 | * Escape character (\) specifies the next character 12 | * as either a special character, a literal 13 | */ 14 | 15 | String str1 = "Q_How are you? I am doing good! Thank you. Q_Where are you from? I am from Atlanta." 16 | + "Q_What do you do? I teach computer programming. "; 17 | 18 | String patt = "Q_.*?\\?"; 19 | 20 | Pattern p = Pattern.compile(patt); 21 | 22 | Matcher m = p.matcher(str1); 23 | 24 | while(m.find()) { 25 | System.out.println(m.group()); 26 | } 27 | 28 | } 29 | 30 | } 31 | -------------------------------------------------------------------------------- /Section 10/GreedyAndLazyMatch.txt: -------------------------------------------------------------------------------- 1 | package regex; 2 | 3 | import java.util.regex.Matcher; 4 | import java.util.regex.Pattern; 5 | 6 | public class GreedyAndLazyMatch { 7 | 8 | public static void main(String[] args) { 9 | 10 | /* 11 | * * - Greedy *? - Non Greedy 12 | * + - Greedy +? - Non Greedy 13 | * {} - Greedy {}? - Non Greedy 14 | */ 15 | 16 | String str1 = "XXfdugshYYyfuwgXXytufgh678ijYYgusdfhXXwwuygriehkYYdhjgkfd"; 17 | 18 | String patt = "XX.*?YY"; 19 | 20 | Pattern p = Pattern.compile(patt); 21 | 22 | Matcher m = p.matcher(str1); 23 | 24 | System.out.println(m.results().count()); 25 | 26 | m.reset(); 27 | 28 | while(m.find()) { 29 | System.out.println("Starts at:"+m.start()); 30 | System.out.println(m.group()); 31 | } 32 | 33 | 34 | 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /Section 10/Intro.txt: -------------------------------------------------------------------------------- 1 | package regex; 2 | 3 | public class Intro { 4 | 5 | public static void main(String[] args) { 6 | 7 | /* 8 | * What is regular expressions? 9 | * A regular expression (regex) defines a search pattern for strings. 10 | * The pattern can be a simple character, a fixed string or a 11 | * complex expression containing special characters, numbers etc. 12 | */ 13 | 14 | String str1 = "+1#6(78-%6&75*-(8765)"; 15 | 16 | String str2 = str1.replace("+", "").replace("-", "").replace("(", "").replace(")", ""); 17 | 18 | System.out.println(str2); 19 | 20 | String patt = "[^A-Za-z0-9]"; 21 | 22 | String str3 = str1.replaceAll(patt, ""); 23 | 24 | System.out.println(str3); 25 | 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /Section 10/Number_Range.txt: -------------------------------------------------------------------------------- 1 | package regex; 2 | 3 | public class Number_Range { 4 | 5 | public static void main(String[] args) { 6 | 7 | /* 8 | * Create a RegEx pattern to represent following number ranges 9 | * 1. 0-99 10 | * 2. 0-1000 11 | * 3. 99-9999 12 | * 4. 25-75 13 | * 5. 220-240 14 | */ 15 | 16 | String patt = "2[2-3][0-9]|240"; 17 | 18 | String str1 = "100"; 19 | 20 | System.out.println(str1.matches(patt)); 21 | 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /Section 10/OR_Operator.txt: -------------------------------------------------------------------------------- 1 | package regex; 2 | 3 | public class OR_Operator { 4 | 5 | public static void main(String[] args) { 6 | 7 | /* 8 | * OR - Operator [|] 9 | */ 10 | 11 | String patt = "a(b|c|d|xyz|123)"; 12 | 13 | String str1 = "acd"; 14 | 15 | System.out.println(str1.matches(patt)); 16 | 17 | } 18 | 19 | } 20 | -------------------------------------------------------------------------------- /Section 10/Quantifiers.txt: -------------------------------------------------------------------------------- 1 | package regex; 2 | 3 | public class Quantifiers { 4 | 5 | public static void main(String[] args) { 6 | 7 | /* 8 | * 1. * - Matches 0 or more instances of preceding character 9 | * 2. + - Matches 1 or more instances of preceding character 10 | * 3. ? - Matches 0 or 1 instances of preceding character 11 | * 4. {n} - Matches exactly 'n' number instances of preceding character 12 | * 5. {n,m} - Matches minimum 'n' or maximum 'm' instances of preceding character 13 | * 6. {n,} - Matches minimum 'n' or more instances of preceding character 14 | */ 15 | 16 | String patt = "ab(xyz){2,}"; 17 | 18 | String str1 = "abxyzxyzxyzxyzxyzxyz"; 19 | 20 | System.out.println(str1.matches(patt)); 21 | 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /Section 10/RegEx_Example_1.txt: -------------------------------------------------------------------------------- 1 | package regex; 2 | 3 | public class RegEx_Example_1 { 4 | 5 | public static void main(String[] args) { 6 | 7 | /* 8 | * Create a RegEx pattern to represent following web sites 9 | * 1. www.dezlearn.com 10 | * 3. www.dezlearn.us 11 | * 2. www.dez.com 12 | * 3. www.dez.us 13 | */ 14 | String patt = "www\\.(dezlearn|dez)\\.(com|us)"; 15 | String str1 = "www.dez.com"; 16 | 17 | System.out.println(str1.matches(patt)); 18 | 19 | } 20 | 21 | } 22 | -------------------------------------------------------------------------------- /Section 10/RegEx_Example_2.txt: -------------------------------------------------------------------------------- 1 | package regex; 2 | 3 | import java.util.regex.Matcher; 4 | import java.util.regex.Pattern; 5 | 6 | public class RegEx_Example_2 { 7 | 8 | public static void main(String[] args) { 9 | 10 | /* 11 | * Create a RegEx pattern to extract all prices from a string 12 | * e.g. "Your total cost is $24.99 after $0.99 sale discount and $12.09 coupon1 discount and $0.00 coupon2 discount" 13 | * RegEx pattern should be able to match all prices from the above string. 14 | */ 15 | 16 | String str1 = "Your total cost is $2400997.999009 after $000.90009 sale discount and $12.09 coupon1 discount and $01.010 coupon2 discount"; 17 | 18 | String patt = "\\${1}\\d{1,}\\.\\d{1,}"; 19 | 20 | Pattern p = Pattern.compile(patt); 21 | 22 | Matcher m = p.matcher(str1); 23 | 24 | while(m.find()) { 25 | System.out.println(m.group()); 26 | } 27 | 28 | 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /Section 10/Regular Expression Cheat Sheet.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Learn-How-to-Code-The-Complete-Core-Java-Programming-Course/eb54411c83978b2252257adc9d2be7f2a973188c/Section 10/Regular Expression Cheat Sheet.pdf -------------------------------------------------------------------------------- /Section 11/CheckedVsUnchecked.txt: -------------------------------------------------------------------------------- 1 | package exceptions; 2 | 3 | import java.io.FileInputStream; 4 | 5 | public class CheckedVsUnchecked { 6 | 7 | public static void main(String[] args) { 8 | 9 | /* 10 | * Checked Exceptions : Checked at Compile-Time 11 | * e.g. IOException, SQLException, ClassNotFoundException etc. 12 | * 13 | * Unchecked Exceptions (RunTime Exceptions): Checked at Run-Time 14 | * e.g. ArithmeticException, ArrayIndexOutOfBoundsException etc. 15 | */ 16 | 17 | //FileInputStream x = new FileInputStream("Users⁩/md/⁨Downloads⁩/abc.txt"); 18 | 19 | System.out.println(100/0); 20 | 21 | 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /Section 11/ErrorVsException.txt: -------------------------------------------------------------------------------- 1 | package exceptions; 2 | 3 | public class ErrorVsException { 4 | 5 | public static void main(String[] args) { 6 | 7 | /* 8 | * Error : A serious problems that a reasonable application should not try to catch 9 | * e.g. OutOfMemoryError, StackOverflowError, LinkageError 10 | * 11 | * Exception : A conditions that a reasonable application might want to catch 12 | * e.g. FileNotFoundException, ParseException, SQLException 13 | * 14 | * Throwable : The Throwable class is the superclass of all errors and exceptions 15 | */ 16 | 17 | 18 | 19 | 20 | } 21 | 22 | } 23 | -------------------------------------------------------------------------------- /Section 11/Finally_Block.txt: -------------------------------------------------------------------------------- 1 | package exceptions; 2 | 3 | public class Finally_Block { 4 | 5 | public static void main(String[] args) { 6 | 7 | /* 8 | * The finally block gets executed after successful run of the 9 | * try block or after one of the catch blocks handled an exception 10 | */ 11 | 12 | int num1 = 100; 13 | int num2 = 10; 14 | 15 | try { 16 | int num3 = num1 / num2; 17 | } finally { 18 | System.out.println("Finally Block Code"); 19 | } 20 | } 21 | 22 | } 23 | -------------------------------------------------------------------------------- /Section 11/Intro.txt: -------------------------------------------------------------------------------- 1 | package exceptions; 2 | 3 | public class Intro { 4 | 5 | public static void main(String[] args) { 6 | 7 | /* 8 | * 1. What is an Exception? 9 | * Exceptions are events which occur during the execution of 10 | * programs that disrupt the normal flow of the application. 11 | * e.g. String Index Out Of Boundaries, Dividing by Zero, Null Pointer 12 | * 13 | * 2. What is Exception Object? 14 | * An exception object is an instance of an exception class. It gets 15 | * created and handed over to the Java runtime when an exceptional event 16 | * occurs. 17 | * Exception Object contains: 18 | * a) Information about the error 19 | * b) The state of the program 20 | * 21 | */ 22 | 23 | String x = null; 24 | 25 | System.out.println(100/0); 26 | 27 | System.out.println("Hello World"); 28 | 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /Section 11/Throwable.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Learn-How-to-Code-The-Complete-Core-Java-Programming-Course/eb54411c83978b2252257adc9d2be7f2a973188c/Section 11/Throwable.docx -------------------------------------------------------------------------------- /Section 11/Throwable.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Learn-How-to-Code-The-Complete-Core-Java-Programming-Course/eb54411c83978b2252257adc9d2be7f2a973188c/Section 11/Throwable.pdf -------------------------------------------------------------------------------- /Section 11/Throws_Declaration.txt: -------------------------------------------------------------------------------- 1 | package exceptions; 2 | 3 | import java.io.FileInputStream; 4 | import java.io.FileNotFoundException; 5 | import java.io.IOException; 6 | 7 | public class Throws_Declaration { 8 | 9 | public static void main(String[] args) throws IOException { 10 | 11 | abc(); 12 | } 13 | 14 | public static void abc() throws IOException { 15 | FileInputStream x = new FileInputStream("Users⁩/md/⁨Downloads⁩/abc.txt"); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Section 11/Try_Catch.txt: -------------------------------------------------------------------------------- 1 | package exceptions; 2 | 3 | import java.io.FileInputStream; 4 | import java.io.FileNotFoundException; 5 | import java.io.IOException; 6 | 7 | public class Try_Catch { 8 | 9 | public static void main(String[] args) { 10 | 11 | abc(); 12 | 13 | System.out.println("Hello World"); 14 | } 15 | 16 | public static void abc() { 17 | try { 18 | FileInputStream x = new FileInputStream("Users⁩/md/⁨Downloads⁩/abc.txt"); 19 | } 20 | catch (FileNotFoundException e) { 21 | System.out.println(e.getMessage()); 22 | System.out.println(e.toString()); 23 | e.printStackTrace(); 24 | } 25 | catch (IOException e2) { 26 | System.out.println(e2.getMessage()); 27 | } 28 | catch (Exception e1) { 29 | System.out.println(e1.getMessage()); 30 | } 31 | } 32 | 33 | 34 | 35 | } 36 | -------------------------------------------------------------------------------- /Section 12/Custom_Date_Time.txt: -------------------------------------------------------------------------------- 1 | package date_time; 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 Custom_Date_Time { 9 | 10 | public static void main(String[] args) { 11 | 12 | LocalDate d1 = LocalDate.of(2020, 12, 31); 13 | 14 | LocalDate d2 = LocalDate.of(2020, Month.DECEMBER, 31); 15 | 16 | System.out.println(d1); 17 | System.out.println(d2); 18 | 19 | LocalTime t1 = LocalTime.of(20, 45); 20 | LocalTime t2 = LocalTime.of(15, 30, 20); 21 | LocalTime t3 = LocalTime.of(12, 15, 24, 123); 22 | 23 | System.out.println(t1); 24 | System.out.println(t2); 25 | System.out.println(t3); 26 | 27 | LocalDateTime dt1 = LocalDateTime.of(d2, t2); 28 | LocalDateTime dt2 = LocalDateTime.of(2022, 06, 24, 12, 30, 45, 333); 29 | 30 | System.out.println(dt1); 31 | System.out.println(dt2); 32 | 33 | 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /Section 12/DateTime_Formatter.txt: -------------------------------------------------------------------------------- 1 | package date_time; 2 | 3 | import java.time.LocalDate; 4 | import java.time.format.DateTimeFormatter; 5 | 6 | public class DateTime_Formatter { 7 | 8 | public static void main(String[] args) { 9 | 10 | /* 11 | * yyyy - YEAR 12 | * yy - YEAR 13 | * MM - MONTH 14 | * MMM - MONTH 15 | * dd - DAY 16 | */ 17 | 18 | String str1 = "24/04/86"; 19 | 20 | DateTimeFormatter formatter = DateTimeFormatter.ofPattern("[MM-dd-yyyy][MMM-dd-yyyy][dd/MM/yy]"); 21 | 22 | LocalDate d1 = LocalDate.parse(str1,formatter); 23 | 24 | System.out.println(d1); 25 | 26 | 27 | 28 | } 29 | 30 | } 31 | -------------------------------------------------------------------------------- /Section 12/Date_Add_Subtract.txt: -------------------------------------------------------------------------------- 1 | package date_time; 2 | 3 | import java.time.LocalDate; 4 | import java.time.temporal.ChronoUnit; 5 | 6 | public class Date_Add_Subtract { 7 | 8 | public static void main(String[] args) { 9 | 10 | /* 11 | * 1. Plus / Minus Methods 12 | * 2. ChronoUnit 13 | */ 14 | 15 | LocalDate d1 = LocalDate.now().plus(10, ChronoUnit.DECADES); 16 | 17 | System.out.println(d1); 18 | 19 | 20 | } 21 | 22 | } 23 | -------------------------------------------------------------------------------- /Section 12/Date_Difference.txt: -------------------------------------------------------------------------------- 1 | package date_time; 2 | 3 | import java.time.LocalDate; 4 | import java.time.Period; 5 | 6 | public class Date_Difference { 7 | 8 | public static void main(String[] args) { 9 | 10 | LocalDate d1 = LocalDate.of(1947, 8, 15); 11 | 12 | Period p = Period.between(d1, LocalDate.now()); 13 | 14 | System.out.println("The Difference is " + p.getYears() + " years " 15 | + p.getMonths() + " months and " + p.getDays() + " days"); 16 | 17 | System.out.println(p.toTotalMonths()); 18 | 19 | System.out.println(p); 20 | 21 | } 22 | 23 | } 24 | -------------------------------------------------------------------------------- /Section 12/Intro.txt: -------------------------------------------------------------------------------- 1 | package date_time; 2 | 3 | import java.time.LocalDate; 4 | import java.time.LocalDateTime; 5 | import java.time.LocalTime; 6 | 7 | public class Intro { 8 | 9 | public static void main(String[] args) { 10 | 11 | /* 12 | * How to get current date? 13 | * How to get current time? 14 | * How to get current date and time? 15 | */ 16 | 17 | System.out.println(LocalDate.now()); 18 | System.out.println(LocalTime.now()); 19 | System.out.println(LocalDateTime.now()); 20 | 21 | 22 | } 23 | } -------------------------------------------------------------------------------- /Section 12/Time_Add_Subtract.txt: -------------------------------------------------------------------------------- 1 | package date_time; 2 | 3 | import java.time.LocalTime; 4 | import java.time.temporal.ChronoUnit; 5 | 6 | public class Time_Add_Subtract { 7 | 8 | public static void main(String[] args) { 9 | 10 | /* 11 | * Plus / Minus 12 | * ChronoUnit 13 | */ 14 | 15 | 16 | LocalTime t1 = LocalTime.now().plus(5, ChronoUnit.MINUTES); 17 | 18 | System.out.println(t1); 19 | 20 | } 21 | 22 | } 23 | -------------------------------------------------------------------------------- /Section 12/Time_Difference.txt: -------------------------------------------------------------------------------- 1 | package date_time; 2 | 3 | import java.time.Duration; 4 | import java.time.LocalTime; 5 | 6 | public class Time_Difference { 7 | 8 | public static void main(String[] args) { 9 | 10 | LocalTime t1 = LocalTime.of(19, 15); 11 | 12 | Duration d = Duration.between(t1, LocalTime.now()); 13 | 14 | System.out.println(d); 15 | 16 | System.out.println(d.toHours()); 17 | System.out.println(d.toMinutes()); 18 | 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /Section 13/Edit-Text-File.txt: -------------------------------------------------------------------------------- 1 | package text_files; 2 | 3 | import java.io.File; 4 | import java.io.IOException; 5 | 6 | import org.apache.commons.io.FileUtils; 7 | 8 | public class Edit_Text_File { 9 | 10 | public static void main(String[] args) throws IOException { 11 | 12 | File file = new File("/Users/mayurdeshmukh/Documents/TextFiles/File1.txt"); 13 | 14 | FileUtils.write(file, "Learning is Growing", "UTF-8", false); 15 | } 16 | 17 | } 18 | -------------------------------------------------------------------------------- /Section 13/File_Copy.txt: -------------------------------------------------------------------------------- 1 | package text_files; 2 | 3 | import java.io.File; 4 | import java.io.IOException; 5 | 6 | import org.apache.commons.io.FileUtils; 7 | 8 | public class File_Copy { 9 | 10 | public static void main(String[] args) throws IOException { 11 | 12 | /* 13 | * 1. Copy contents of one file to another 14 | * 2. Copy a file to directory 15 | * 3. Rename / Move a file 16 | */ 17 | 18 | File file1 = new File("/Users/mayurdeshmukh/Documents/TextFiles/File1.txt"); 19 | File file2 = new File("/Users/mayurdeshmukh/Documents/TextFiles/File2.txt"); 20 | File dir = new File("/Users/mayurdeshmukh/Documents/TextFiles/Dir1"); 21 | File file3 = new File("/Users/mayurdeshmukh/Documents/TextFiles/File3.txt"); 22 | 23 | FileUtils.copyFile(file1, file2); 24 | FileUtils.copyFileToDirectory(file1, dir); 25 | FileUtils.moveFile(file1, file3); 26 | 27 | 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /Section 13/Read_Text_File.txt: -------------------------------------------------------------------------------- 1 | package text_files; 2 | 3 | import java.io.File; 4 | import java.io.IOException; 5 | import java.util.List; 6 | 7 | import org.apache.commons.io.FileUtils; 8 | 9 | public class Read_Text_File { 10 | 11 | public static void main(String[] args) throws IOException { 12 | 13 | /* 14 | * Working with Text Files using Apache Commons IO 15 | * 16 | * 1. Download Apache Commons IO from: 17 | * https://commons.apache.org/proper/commons-io/download_io.cgi 2. Add Commons 18 | * IO jar files to Java Build Path 3. Use FileUtils from commons-io to read a 19 | * text file 20 | */ 21 | 22 | File file = new File("/Users/mayurdeshmukh/Documents/TextFiles/File1.txt"); 23 | 24 | String x = FileUtils.readFileToString(file, "UTF-8"); 25 | 26 | System.out.println(x); 27 | 28 | List list = FileUtils.readLines(file,"UTF-8"); 29 | 30 | System.out.println(list); 31 | 32 | } 33 | 34 | } 35 | 36 | Okay, I just opened up registration for 37 | my Selenium WebDriver Coaching Program. 38 | 39 | CLICK HERE for Selenium WebDriver Coaching Program 40 | 41 | (I opened it up a bit early to avoid any 42 | bottlenecks and spread the load on the server.) 43 | 44 | Best regards, 45 | Mayur 46 | 47 | P.S. Remember...you don't need to panic. 48 | I don't expect to sell out immediately. 49 | However, if you want one of those spots 50 | at my Selenium Live Workshop, then please 51 | don't delay. They are going to go fast. 52 | Here's the link: 53 | 54 | CLICK HERE for Selenium WebDriver Coaching Program 55 | -------------------------------------------------------------------------------- /Section 13/Remove_Duplicate_Words.txt: -------------------------------------------------------------------------------- 1 | package text_files; 2 | 3 | import java.io.File; 4 | import java.io.IOException; 5 | 6 | import org.apache.commons.io.FileUtils; 7 | 8 | public class Remove_Duplicate_Words { 9 | 10 | public static void main(String[] args) throws IOException { 11 | 12 | /* Interview Question: 13 | * Remove all duplicate words from a text file 14 | */ 15 | 16 | File file = new File("/Users/mayurdeshmukh/Documents/TextFiles/File1.txt"); 17 | 18 | String str1 = FileUtils.readFileToString(file, "UTF-8"); 19 | 20 | str1 = str1.replaceAll("\n", " "); 21 | 22 | String [] arr = str1.split(" "); 23 | 24 | String str2 = ""; 25 | 26 | for (String x : arr) { 27 | if (!str2.contains(x) && x.trim()!="") { 28 | str2 = str2 + " " + x; 29 | } 30 | } 31 | 32 | FileUtils.write(file, str2,"UTF-8",false); 33 | 34 | } 35 | } 36 | 37 | -------------------------------------------------------------------------------- /Section 13/Sort_Lines.txt: -------------------------------------------------------------------------------- 1 | package text_files; 2 | 3 | import java.io.File; 4 | import java.io.IOException; 5 | import java.util.Collections; 6 | import java.util.List; 7 | 8 | import org.apache.commons.io.FileUtils; 9 | 10 | public class Sort_Lines { 11 | 12 | public static void main(String[] args) throws IOException { 13 | 14 | /* 15 | * Interview Question: 16 | * Alphabetically sort the lines of a text file 17 | */ 18 | File file = new File("/Users/mayurdeshmukh/Documents/TextFiles/File1.txt"); 19 | 20 | List list = FileUtils.readLines(file, "UTF-8"); 21 | 22 | Collections.sort(list); 23 | 24 | FileUtils.write(file, "", "UTF-8",false); 25 | 26 | for(String x : list) { 27 | FileUtils.write(file, x+"\n", "UTF-8",true); 28 | System.out.println(x); 29 | } 30 | } 31 | 32 | } 33 | -------------------------------------------------------------------------------- /Section 14/Read_Excel.txt: -------------------------------------------------------------------------------- 1 | package excel_files; 2 | 3 | import java.io.File; 4 | import java.io.FileInputStream; 5 | import java.io.IOException; 6 | 7 | import org.apache.poi.xssf.usermodel.XSSFSheet; 8 | import org.apache.poi.xssf.usermodel.XSSFWorkbook; 9 | 10 | public class Read_Excel { 11 | 12 | public static void main(String[] args) { 13 | 14 | File file = new File("/Users/mayurdeshmukh/Documents/ExcelFiles/File1.xlsx"); 15 | 16 | XSSFWorkbook wkbook; 17 | XSSFSheet sheet; 18 | 19 | try { 20 | FileInputStream excel = new FileInputStream(file); 21 | wkbook = new XSSFWorkbook(excel); 22 | sheet = wkbook.getSheet("Sheet1"); 23 | int start = sheet.getFirstRowNum(); 24 | int end = sheet.getLastRowNum(); 25 | for(int i = start; i <= end; i++) { 26 | System.out.print(sheet.getRow(i).getCell(0).getStringCellValue() + "\t"); 27 | System.out.print(sheet.getRow(i).getCell(1).getNumericCellValue() + "\t"); 28 | System.out.print(sheet.getRow(i).getCell(2).getBooleanCellValue() + "\t"); 29 | System.out.println(sheet.getRow(i).getCell(3).getStringCellValue()); 30 | } 31 | 32 | } catch(IOException e) { 33 | System.out.println(e.getMessage()); 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /Section 14/Read_Excel_Into_2D_Array.txt: -------------------------------------------------------------------------------- 1 | package excel_files; 2 | 3 | import java.io.File; 4 | import java.io.FileInputStream; 5 | import java.io.IOException; 6 | 7 | import org.apache.poi.xssf.usermodel.XSSFSheet; 8 | import org.apache.poi.xssf.usermodel.XSSFWorkbook; 9 | 10 | public class Read_Excel_Into_2D_Array { 11 | 12 | public static void main(String[] args) { 13 | 14 | Object [][] arr2 = Read_Excel_Data(); 15 | 16 | System.out.println(arr2[0][0]); 17 | System.out.println(arr2[2][2]); 18 | System.out.println(arr2[3][1]); 19 | System.out.println(arr2[9][3]); 20 | } 21 | 22 | public static Object [][] Read_Excel_Data(){ 23 | 24 | File file = new File("/Users/mayurdeshmukh/Documents/ExcelFiles/File1.xlsx"); 25 | 26 | XSSFWorkbook wkbook; 27 | XSSFSheet sheet; 28 | Object [][] arr = new Object[0][0]; 29 | 30 | try { 31 | FileInputStream excel = new FileInputStream(file); 32 | wkbook = new XSSFWorkbook(excel); 33 | sheet = wkbook.getSheet("Sheet1"); 34 | int start = sheet.getFirstRowNum(); 35 | int end = sheet.getLastRowNum(); 36 | arr = new Object[end-start+1][4]; 37 | for(int i = start; i <= end; i++) { 38 | arr[i][0] = sheet.getRow(i).getCell(0).getStringCellValue(); 39 | arr[i][1] = sheet.getRow(i).getCell(1).getNumericCellValue(); 40 | arr[i][2] = sheet.getRow(i).getCell(2).getBooleanCellValue(); 41 | arr[i][3] = sheet.getRow(i).getCell(3).getStringCellValue(); 42 | } 43 | 44 | } catch(IOException e) { 45 | System.out.println(e.getMessage()); 46 | } 47 | 48 | return arr; 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /Section 14/Write_Excel2.txt: -------------------------------------------------------------------------------- 1 | package excel_files; 2 | 3 | import java.io.File; 4 | import java.io.FileOutputStream; 5 | import java.io.IOException; 6 | 7 | import org.apache.poi.ss.usermodel.Cell; 8 | import org.apache.poi.ss.usermodel.Row; 9 | import org.apache.poi.xssf.usermodel.XSSFSheet; 10 | import org.apache.poi.xssf.usermodel.XSSFWorkbook; 11 | 12 | public class Write_Excel { 13 | 14 | public static void main(String[] args) { 15 | 16 | /* 17 | * Write a program to an Excel File and 18 | * add the table of 1 to 10 to Sheet1 19 | */ 20 | 21 | File file = new File("/Users/mayurdeshmukh/Documents/ExcelFiles/File2.xlsx"); 22 | 23 | XSSFWorkbook wkbook = new XSSFWorkbook(); 24 | XSSFSheet sheet = wkbook.createSheet("Sheet1"); 25 | Row row; 26 | Cell cell; 27 | 28 | for (int i = 0; i <= 9; i++) { 29 | row = sheet.createRow(i); 30 | for (int j = 0; j <= 9; j++) { 31 | cell = row.createCell(j); 32 | cell.setCellValue((i+1) * (j+1)); 33 | } 34 | } 35 | 36 | try { 37 | FileOutputStream excel = new FileOutputStream(file); 38 | wkbook.write(excel); 39 | excel.close(); 40 | wkbook.close(); 41 | } catch (IOException e) { 42 | System.out.println(e.getMessage()); 43 | } 44 | 45 | 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /Section 2/String_Basics.txt: -------------------------------------------------------------------------------- 1 | package string_operations; 2 | 3 | public class String_Basics { 4 | 5 | public static void main(String[] args) { 6 | 7 | /** 8 | * Concatenate 9 | * Length 10 | * Trim 11 | * Upper Case 12 | * Lower Case 13 | * Empty 14 | */ 15 | 16 | String str1 = "De Zinnia"; 17 | String str2 = " Institutes"; 18 | 19 | String str3 = str1 + str2; 20 | System.out.println(str3); 21 | 22 | String str4 = str1.concat(str2); 23 | System.out.println(str4); 24 | 25 | int num1 = 100; 26 | 27 | System.out.println(str1 + num1); 28 | 29 | System.out.println(str1.length()); 30 | 31 | String str5 = " LYUUxfcgvhbjknl TYHJ cbhjnkl hvjbkn "; 32 | 33 | System.out.println(str5); 34 | 35 | System.out.println(str5.trim()); 36 | 37 | System.out.println(str5.toUpperCase()); 38 | 39 | System.out.println(str5.toLowerCase()); 40 | 41 | System.out.println(str5.isEmpty()); 42 | 43 | String str6 = ""; 44 | 45 | System.out.println(str6.isEmpty()); 46 | 47 | } 48 | 49 | } 50 | -------------------------------------------------------------------------------- /Section 2/String_Comparison.txt: -------------------------------------------------------------------------------- 1 | package string_operations; 2 | 3 | public class String_Comparison { 4 | 5 | public static void main(String[] args) { 6 | 7 | /** 8 | * Equals 9 | * Compare To 10 | * Matches 11 | */ 12 | String str1 = "ABCDE"; 13 | String str2 = "aBCDE"; 14 | 15 | System.out.println(str1.equals(str2)); 16 | System.out.println(str1.equalsIgnoreCase(str2)); 17 | 18 | if (str1.equals(str2)) { 19 | System.out.println("Strings are equal"); 20 | } else { 21 | System.out.println("Strings not equal"); 22 | } 23 | 24 | System.out.println(str1.compareTo(str2)); 25 | System.out.println(str1.compareToIgnoreCase(str2)); 26 | 27 | String patt = "[A-Z]{1,}"; 28 | 29 | System.out.println(str1.matches(patt)); 30 | 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /Section 2/String_Conversion.txt: -------------------------------------------------------------------------------- 1 | package string_operations; 2 | 3 | public class String_Conversion { 4 | 5 | public static void main(String[] args) { 6 | 7 | /** 8 | * toString 9 | * toBinaryString 10 | * toHexString 11 | * toOctalString 12 | * parseInt 13 | */ 14 | int num1 = 100; 15 | 16 | System.out.println(Integer.toString(num1)); 17 | System.out.println(Integer.toBinaryString(num1)); 18 | System.out.println(Integer.toHexString(num1)); 19 | System.out.println(Integer.toOctalString(num1)); 20 | 21 | String str1 = "100"; 22 | String str2 = "1010101"; 23 | String str3 = "64"; 24 | String str4 = "144"; 25 | 26 | System.out.println(Integer.parseInt(str1)); 27 | System.out.println(Integer.parseInt(str2, 2)); 28 | System.out.println(Integer.parseInt(str3, 16)); 29 | System.out.println(Integer.parseInt(str4, 8)); 30 | 31 | 32 | 33 | 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /Section 2/String_Replace.txt: -------------------------------------------------------------------------------- 1 | package string_operations; 2 | 3 | public class String_Replace { 4 | 5 | public static void main(String[] args) { 6 | 7 | /** 8 | * Replace - Normal 9 | * ReplaceAll - RegEx 10 | */ 11 | String str1 = "CONCENTRAT1234ON 1234MPROVES W1234TH PRACT1234CE"; 12 | String str2 = "1234"; 13 | String str3 = "I"; 14 | 15 | System.out.println(str1.replace(str2, str3)); 16 | 17 | String str4 = "EI#$T%HER #YO&*U CON#@$TR^O(L Y$O&U*R* #M%I^N^D O^R& I&*(T W&I(*)L%L ()C^O#N%T&R@$%@OL @Y$O$U%"; 18 | String patt = "[^A-Za-z0-9\\s]"; 19 | 20 | System.out.println(str4.replaceAll(patt, "")); 21 | } 22 | 23 | } 24 | -------------------------------------------------------------------------------- /Section 2/String_Search.txt: -------------------------------------------------------------------------------- 1 | package string_operations; 2 | 3 | public class String_Search { 4 | 5 | public static void main(String[] args) { 6 | 7 | /** 8 | * Contains 9 | * Starts with 10 | * Ends with 11 | * Index of 12 | * Last Index of 13 | */ 14 | 15 | String str1 = "I love Java love and Selenium"; 16 | 17 | String str2 = "java"; 18 | 19 | System.out.println(str1.toLowerCase().contains(str2.toLowerCase())); 20 | 21 | System.out.println(str1.startsWith("I")); 22 | 23 | System.out.println(str1.endsWith("Selenium1")); 24 | 25 | System.out.println(str1.indexOf("love")); 26 | 27 | System.out.println(str1.indexOf("love", 6)); 28 | 29 | System.out.println(str1.lastIndexOf("love")); 30 | 31 | 32 | } 33 | 34 | } 35 | -------------------------------------------------------------------------------- /Section 2/String_Slice.txt: -------------------------------------------------------------------------------- 1 | package string_operations; 2 | 3 | public class String_Slice { 4 | 5 | public static void main(String[] args) { 6 | 7 | /** 8 | * Char at 9 | * Substring 10 | * Split 11 | */ 12 | 13 | String str1 = "ABCDEFG"; 14 | System.out.println(str1.charAt(3)); 15 | 16 | //Write a program to reverse a string 17 | //GFEDCBA 18 | 19 | String temp = ""; 20 | for (int i = 0; i <= str1.length()-1; i++) { 21 | temp = str1.charAt(i) + temp; 22 | } 23 | System.out.println(temp); 24 | 25 | System.out.println(str1.substring(2)); 26 | 27 | System.out.println(str1.substring(2, 4)); 28 | 29 | String str2 = "A_B_C_D"; 30 | 31 | String str3 = "B"; 32 | 33 | String [] arr = str2.split(str3); 34 | 35 | for (String x : arr) { 36 | System.out.println(x); 37 | } 38 | 39 | } 40 | 41 | } 42 | -------------------------------------------------------------------------------- /Section 3/Access Specifiers in Java.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Learn-How-to-Code-The-Complete-Core-Java-Programming-Course/eb54411c83978b2252257adc9d2be7f2a973188c/Section 3/Access Specifiers in Java.pdf -------------------------------------------------------------------------------- /Section 3/Access_Main2.txt: -------------------------------------------------------------------------------- 1 | package temp; 2 | 3 | import oops_concepts.Access_Specifiers; 4 | 5 | public class Access_Main2 { 6 | 7 | public static void main(String[] args) { 8 | 9 | Access_Specifiers ac2 = new Access_Specifiers(); 10 | 11 | ac2.doThisPublic(); 12 | //ac2.doThisDefault(); //Not allowed 13 | 14 | 15 | } 16 | 17 | } 18 | -------------------------------------------------------------------------------- /Section 3/Access_Specifiers.txt: -------------------------------------------------------------------------------- 1 | package oops_concepts; 2 | 3 | public class Access_Specifiers { 4 | 5 | /** 6 | * Public Access 7 | * Default Access / No Access Specifier 8 | * Private Access 9 | * Protected Access 10 | */ 11 | 12 | public int a = 100; 13 | int b = 200; 14 | private int c = 300; 15 | 16 | 17 | public void doThisPublic() { 18 | System.out.println("Public Method"); 19 | } 20 | 21 | private void doThisPrivate() { 22 | System.out.println("Private Method"); 23 | } 24 | 25 | void doThisDefault() { 26 | System.out.println("Private Method"); 27 | } 28 | 29 | 30 | } 31 | -------------------------------------------------------------------------------- /Section 3/Aceess_Main.txt: -------------------------------------------------------------------------------- 1 | package oops_concepts; 2 | 3 | public class Aceess_Main { 4 | 5 | public static void main(String[] args) { 6 | 7 | Access_Specifiers ac = new Access_Specifiers(); 8 | ac.doThisPublic(); 9 | ac.doThisDefault(); 10 | // ac.doThisPrivate(); //Not Allowed 11 | 12 | 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /Section 3/BankAccount_Main.txt: -------------------------------------------------------------------------------- 1 | package oops_concepts; 2 | 3 | public class BankAccount_Main { 4 | 5 | public static void main(String[] args) { 6 | 7 | Bank_Account b1 = new Bank_Account(123456,"De ZINNIA",100000); 8 | 9 | b1.displayCurrentBalance(); 10 | 11 | b1.withdraw(2000); 12 | 13 | b1.displayCurrentBalance(); 14 | 15 | b1.deposit(-1000); 16 | 17 | b1.displayCurrentBalance(); 18 | 19 | b1.deposit(20000); 20 | 21 | b1.displayCurrentBalance(); 22 | 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /Section 3/Bank_Account.txt: -------------------------------------------------------------------------------- 1 | package oops_concepts; 2 | 3 | public class Bank_Account { 4 | 5 | /** 6 | * ***Exercise**** 7 | * 1. Create a Bank_Account class 8 | * 2. Create private member variables for Account Number, Account Name and Account Balance 9 | * 3. Create methods to deposit and withdraw the amount and to display the current Balance 10 | * 4. Create an constructor with arguments for Account Number, Name and Balance 11 | * 4. Create a class BankAccount_Main with a main method 12 | * 5. Create an object of Bank_Account 13 | * 6. Call the methods to deposit and withdraw the money from Bank Account and Display the current Balance 14 | */ 15 | 16 | private long acNo; 17 | private String acName; 18 | private double acBalance; 19 | 20 | public void deposit(double amt) { 21 | if (amt > 0) { 22 | acBalance = acBalance + amt; 23 | System.out.println("Successfully deposited $ " + amt ); 24 | } else { 25 | System.out.println("Cannot deposit " + amt); 26 | } 27 | } 28 | 29 | public void withdraw(double amt) { 30 | if (amt > 0) { 31 | acBalance = acBalance - amt; 32 | System.out.println("Successfully withdrawn $ " + amt ); 33 | } else { 34 | System.out.println("Cannot withdraw " + amt); 35 | } 36 | } 37 | 38 | public void displayCurrentBalance() { 39 | System.out.println("Your current balance is $ " + acBalance ); 40 | } 41 | 42 | public Bank_Account(long acNo,String acName,double acBalance) { 43 | this.acNo = acNo; 44 | this.acName = acName; 45 | this.acBalance = acBalance; 46 | } 47 | 48 | 49 | } 50 | -------------------------------------------------------------------------------- /Section 3/Cars.txt: -------------------------------------------------------------------------------- 1 | package oops_concepts; 2 | 3 | public class Cars { 4 | 5 | String color = "White"; 6 | String make = "Honda"; 7 | String type = "SUV"; 8 | 9 | public void displayDetails() { 10 | System.out.println("I have a " + make + " " + type + " of " + color + " color"); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /Section 3/Classroom.txt: -------------------------------------------------------------------------------- 1 | package oops_concepts; 2 | 3 | public class Classroom { 4 | 5 | private String sub1; 6 | private int stdCount1; 7 | 8 | 9 | public String getSub() { 10 | return sub1; 11 | } 12 | 13 | 14 | public void setSub(String sub) { 15 | this.sub1 = sub; 16 | } 17 | 18 | 19 | public int getStdCount() { 20 | return stdCount1; 21 | } 22 | 23 | 24 | public void setStdCount(int stdCount) { 25 | this.stdCount1 = stdCount; 26 | } 27 | 28 | 29 | public void displayDetails() { 30 | System.out.println("This is a " + sub1 + " classroom and it has " + stdCount1 + " students"); 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /Section 3/Classroom_Main.txt: -------------------------------------------------------------------------------- 1 | package oops_concepts; 2 | 3 | public class Classroom_Main { 4 | 5 | public static void main(String[] args) { 6 | 7 | Classroom cs1 = new Classroom(); 8 | 9 | cs1.setSub("Math"); 10 | cs1.setStdCount(50); 11 | cs1.displayDetails(); 12 | } 13 | 14 | } 15 | -------------------------------------------------------------------------------- /Section 3/Constructor.txt: -------------------------------------------------------------------------------- 1 | package oops_concepts; 2 | 3 | public class Constructor { 4 | 5 | /** 6 | ***Concept of Constructor*** 7 | * A block of code similar to method which gets executed when an instance (object) of the class is created 8 | * Generally used to initialize member variables of a class 9 | * Constructor name is same as that of class name 10 | * Constructor does not have return type (It does not return any value) 11 | * Default Constructor - The default constructor is the no-argument constructor 12 | * created automatically unless you define another constructor 13 | * Constructor overloading 14 | */ 15 | 16 | /** 17 | ***Example:*** 18 | * 1. Create a Road_Toll class 19 | * 2. Create member variables for Type of Vehicle, Number of Tires 20 | * 3. Create a method to calculate the toll amount depending upon the number of tires for a vehicle 21 | * If tires count == 2 Then Toll Amount is 0 22 | * If tires count == 4 Then Toll Amount is 10 23 | * If tires count > 4 Then Toll Amount is 20 24 | * 4. Create a RoadToll_Main class with Main Method 25 | * 5. Create Object of Road_Toll 26 | * 6. Assign values to member variables of class and call the method to calculate the toll 27 | * 7. Create a constructor in Road_Toll class 28 | * 8. Create object of Road_Toll class using new constructor 29 | */ 30 | 31 | } 32 | -------------------------------------------------------------------------------- /Section 3/Data_Encapsulation.txt: -------------------------------------------------------------------------------- 1 | package oops_concepts; 2 | 3 | public class Data_Encapsulation { 4 | 5 | /** 6 | * Data Encapsulation also called as Data Hiding 7 | * Hiding the member variables of a class from other classes 8 | */ 9 | 10 | } 11 | -------------------------------------------------------------------------------- /Section 3/Employee.txt: -------------------------------------------------------------------------------- 1 | package oops_concepts; 2 | 3 | public class Employee { 4 | 5 | /** 6 | * ****Class Example**** 7 | * 1. Create an Employee Class 8 | * 2. Create class variables for Employee Name, Employee ID, Employee Salary 9 | * 3. Create a method to calculate and display Employee bonus (20% of Employee Salary) 10 | * 4. Create an Employee_Main class with a Main Method 11 | * 5. Create 2 Objects of Employee Class in Employee_Main 12 | * 6. Assign values to variables and call the method from Employee Class by using the objects created in step 5 13 | */ 14 | 15 | String empName = "ABC"; 16 | int empId = 100; 17 | int empSalary = 1000; 18 | 19 | public void displayEmployeebonus() { 20 | System.out.println("Employee " + empName + " gets the bonus of " + (empSalary * 0.20) ); 21 | } 22 | 23 | } 24 | -------------------------------------------------------------------------------- /Section 3/Employee_Main.txt: -------------------------------------------------------------------------------- 1 | package oops_concepts; 2 | 3 | public class Employee_Main { 4 | 5 | public static void main(String[] args) { 6 | 7 | Employee emp1 = new Employee(); 8 | 9 | Employee emp2 = new Employee(); 10 | 11 | emp1.empName = "Rob"; 12 | emp1.empId = 200; 13 | emp1.empSalary = 12345; 14 | 15 | emp1.displayEmployeebonus(); 16 | 17 | emp2.empName = "Siva"; 18 | emp2.empId = 300; 19 | emp2.empSalary = 98765; 20 | 21 | emp2.displayEmployeebonus(); 22 | 23 | 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /Section 3/Main_Method.txt: -------------------------------------------------------------------------------- 1 | package oops_concepts; 2 | 3 | public class Main_Method { 4 | 5 | public static void main(String[] args) { 6 | 7 | /** 8 | * What is JVM? 9 | * What is main method? 10 | * Why is main method declared as static? 11 | * What is String[] args? 12 | * What is NoSuchMethodError:main? 13 | */ 14 | 15 | } 16 | 17 | } 18 | -------------------------------------------------------------------------------- /Section 3/Method_Overloading.txt: -------------------------------------------------------------------------------- 1 | package oops_concepts; 2 | 3 | public class Method_Overloading { 4 | 5 | /** 6 | * Method Overloading 7 | * Data Type 8 | * Number of Args 9 | * Order 10 | * 11 | */ 12 | 13 | public void addition(int num1, int num2) { 14 | System.out.println(num1 + num2); 15 | } 16 | 17 | public void addition(double num1, double num2) { 18 | System.out.println(num1 + num2); 19 | } 20 | 21 | public void addition(int num1, double num2) { 22 | System.out.println(num1 + num2); 23 | } 24 | 25 | public void addition(double num1, int num2) { 26 | System.out.println(num1 + num2); 27 | } 28 | 29 | public void addition(int num1, int num2, int num3) { 30 | System.out.println(num1 + num2 + num3); 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /Section 3/Methods.txt: -------------------------------------------------------------------------------- 1 | package oops_concepts; 2 | 3 | public class Methods { 4 | 5 | public static void main(String[] args) { 6 | 7 | /** 8 | * Creating methods in Java 9 | * How does a method return value? 10 | */ 11 | 12 | Methods m = new Methods(); 13 | m.doThis(); 14 | m.addition(100, 200); 15 | int x = m.multiply(10, 20); 16 | System.out.println(x); 17 | } 18 | 19 | public void doThis() { 20 | System.out.println("Do This Executed"); 21 | } 22 | 23 | public void addition(int num1, int num2) { 24 | System.out.println(num1 + num2); 25 | } 26 | 27 | public int multiply(int num1, int num2) { 28 | int num3 = num1 * num2; 29 | return num3; 30 | } 31 | 32 | } 33 | -------------------------------------------------------------------------------- /Section 3/RoadToll_Main.txt: -------------------------------------------------------------------------------- 1 | package oops_concepts; 2 | 3 | public class RoadToll_Main { 4 | 5 | public static void main(String[] args) { 6 | 7 | Road_Toll rt1 = new Road_Toll(); 8 | 9 | rt1.type = "Sadan"; 10 | rt1.tiresCount = 4; 11 | rt1.calculateToll(); 12 | 13 | Road_Toll rt2 = new Road_Toll("Truck", 6); 14 | rt2.calculateToll(); 15 | 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /Section 3/Road_Toll.txt: -------------------------------------------------------------------------------- 1 | package oops_concepts; 2 | 3 | public class Road_Toll { 4 | String type; 5 | int tiresCount; 6 | 7 | public void calculateToll() { 8 | if (tiresCount == 2) { 9 | System.out.println("Your toll amount is 0"); 10 | } else if (tiresCount == 4) { 11 | System.out.println("Your toll amount is 10"); 12 | } else if (tiresCount > 4) { 13 | System.out.println("Your toll amount is 20"); 14 | } else { 15 | System.out.println("Incorrect tire count"); 16 | } 17 | } 18 | 19 | public Road_Toll() { 20 | System.out.println("Constructor is executed"); 21 | } 22 | 23 | public Road_Toll(String type, int tiresCount) { 24 | this.type = type; 25 | this.tiresCount = tiresCount; 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /Section 3/Static_Keyword.txt: -------------------------------------------------------------------------------- 1 | package oops_concepts; 2 | 3 | public class Static_Keyword { 4 | 5 | /** 6 | * Static Keyword 7 | * Static Members Belong to Class (Type) and not to Object 8 | */ 9 | 10 | static String name = "ABC"; 11 | byte age = 6; 12 | String grade = "1st"; 13 | 14 | public void displayDetails() { 15 | System.out.println("Student " + name + " is " + age + " years old and in " + grade + " grade."); 16 | } 17 | 18 | public static void doThis() { 19 | System.out.println("Do This Executed"); 20 | } 21 | 22 | 23 | } 24 | -------------------------------------------------------------------------------- /Section 3/Static_Main.txt: -------------------------------------------------------------------------------- 1 | package oops_concepts; 2 | 3 | public class Static_Main { 4 | 5 | public static void main(String[] args) { 6 | 7 | Static_Keyword sk1 = new Static_Keyword(); 8 | 9 | Static_Keyword sk2 = new Static_Keyword(); 10 | 11 | sk1.age = 7; 12 | sk1.grade = "2nd"; 13 | Static_Keyword.name = "Rob"; 14 | Static_Keyword.doThis(); 15 | 16 | sk2.age = 8; 17 | sk2.grade = "3rd"; 18 | Static_Keyword.name = "Shyam"; 19 | Static_Keyword.doThis(); 20 | 21 | sk1.displayDetails(); 22 | sk2.displayDetails(); 23 | 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /Section 3/Temp.txt: -------------------------------------------------------------------------------- 1 | package oops_concepts; 2 | 3 | public class Temp { 4 | 5 | public static void main(String[] args) { 6 | 7 | Cars c1 = new Cars(); 8 | 9 | c1.color = "Red"; 10 | c1.make = "BMW"; 11 | 12 | c1.displayDetails(); 13 | 14 | Cars c2 = new Cars(); 15 | 16 | c2.color = "Orange"; 17 | c2.make = "Toyota"; 18 | c2.type = "Sadan"; 19 | 20 | c2.displayDetails(); 21 | 22 | 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /Section 4/MathClass.txt: -------------------------------------------------------------------------------- 1 | package special_classes; 2 | 3 | public class MathClass { 4 | 5 | public static void main(String[] args) { 6 | 7 | /* 8 | * Math Class is provided in java.lang package. java.lang package provides 9 | * classes that are fundamental to the design of the Java programming language. 10 | * Math class contains methods for performing basic numeric 11 | * operations such as the elementary exponential, logarithm, 12 | * square root, and trigonometric functions. 13 | * 14 | * Math.min, Math.max, Math.E, Math.PI, 15 | * Math.pow, Math.sqrt, Math.cbrt 16 | * Math.ceil, Math.floor, Math.round 17 | * Math.sin, Math.cos, Math.tan, Math.log10 18 | * Math.random 19 | */ 20 | 21 | int num1 = 100; 22 | int num2 = 200; 23 | 24 | System.out.println(Math.min(num1, num2)); 25 | System.out.println(Math.max(num1, num2)); 26 | System.out.println(Math.PI); 27 | System.out.println(Math.E); 28 | 29 | System.out.println(Math.pow(2, 10)); 30 | System.out.println(Math.sqrt(200)); 31 | System.out.println(Math.cbrt(300)); 32 | 33 | 34 | System.out.println("-------------------------"); 35 | 36 | double x = 12.98; 37 | double y = 10.24; 38 | 39 | System.out.println(Math.ceil(x)); 40 | System.out.println(Math.ceil(y)); 41 | 42 | System.out.println(Math.floor(x)); 43 | System.out.println(Math.floor(y)); 44 | 45 | System.out.println(Math.round(x)); 46 | System.out.println(Math.round(y)); 47 | 48 | System.out.println("-------------------------"); 49 | 50 | System.out.println(Math.random()); 51 | } 52 | 53 | } 54 | -------------------------------------------------------------------------------- /Section 4/RandomClass.txt: -------------------------------------------------------------------------------- 1 | package special_classes; 2 | 3 | import java.util.Random; 4 | 5 | public class RandomClass { 6 | 7 | public static void main(String[] args) { 8 | 9 | Random r1 = new Random(); 10 | 11 | for(int i = 1; i <= 100; i++) { 12 | //System.out.println(r1.nextInt(9000) + 1000); 13 | System.out.println((int)(Math.random() * 40000) + 10000); 14 | } 15 | 16 | 17 | } 18 | 19 | } 20 | -------------------------------------------------------------------------------- /Section 4/ScannerClass.txt: -------------------------------------------------------------------------------- 1 | package special_classes; 2 | 3 | import java.util.Scanner; 4 | 5 | public class ScannerClass { 6 | 7 | public static void main(String[] args) { 8 | 9 | /* 10 | * Scanner class is used to accept the user input 11 | * during execution of a java program 12 | */ 13 | 14 | Scanner s1 = new Scanner(System.in); 15 | 16 | System.out.println("Please enter a string:"); 17 | 18 | String str1 = s1.nextLine(); 19 | 20 | String temp = ""; 21 | 22 | for (int i = 0; i <= str1.length()-1; i++) { 23 | temp = str1.charAt(i) + temp; 24 | } 25 | 26 | System.out.println("Reversed String is: " + temp); 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /Section 4/StringBuilderClass1.txt: -------------------------------------------------------------------------------- 1 | package special_classes; 2 | 3 | public class StringBuilderClass1 { 4 | 5 | public static void main(String[] args) { 6 | 7 | /* 8 | * StringBuilder class is used to create mutable (modifiable) string 9 | * Some useful methods: 10 | * append, insert, replace, delete, reverse 11 | */ 12 | 13 | String str1 = "I"; 14 | 15 | str1 = str1 + " Like"; 16 | 17 | str1 = str1 + " Java"; 18 | 19 | System.out.println(str1); 20 | 21 | //I / Like / I like / Java / I like Java 22 | 23 | StringBuilder sb1 = new StringBuilder("I"); 24 | 25 | sb1.append(" Like"); 26 | sb1.append(" Java"); 27 | 28 | System.out.println(sb1); 29 | 30 | 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /Section 4/StringBuilderClass2.txt: -------------------------------------------------------------------------------- 1 | package special_classes; 2 | 3 | public class StringBuilderClass2 { 4 | 5 | public static void main(String[] args) { 6 | 7 | /* 8 | * Some useful methods from StringBuilder 9 | * insert, replace, delete, reverse 10 | */ 11 | StringBuilder sb1 = new StringBuilder("Learning is fun"); 12 | 13 | sb1.insert(9, "Java "); 14 | 15 | System.out.println(sb1); 16 | 17 | sb1.replace(9, 13, "Everything"); 18 | 19 | System.out.println(sb1); 20 | 21 | sb1.deleteCharAt(0); 22 | 23 | System.out.println(sb1); 24 | 25 | sb1.delete(2, 10); 26 | 27 | System.out.println(sb1); 28 | 29 | sb1.reverse(); 30 | 31 | System.out.println(sb1); 32 | 33 | 34 | 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /Section 4/StringReverseProgram.txt: -------------------------------------------------------------------------------- 1 | package special_classes; 2 | 3 | public class StringReverseProgram { 4 | 5 | public static void main(String[] args) { 6 | 7 | //Program to reverse a string 8 | 9 | String str1 = "ABCDE"; 10 | String temp = ""; 11 | 12 | for (int i = 0; i <= str1.length()-1; i++) { 13 | temp = str1.charAt(i) + temp; 14 | } 15 | 16 | System.out.println("Reversed String: " + temp); 17 | } 18 | 19 | } 20 | -------------------------------------------------------------------------------- /Section 4/UUIDClass.txt: -------------------------------------------------------------------------------- 1 | package special_classes; 2 | 3 | import java.util.UUID; 4 | 5 | public class UUIDClass { 6 | 7 | public static void main(String[] args) { 8 | 9 | 10 | for(int i = 1; i <= 10; i++) { 11 | System.out.println(UUID.randomUUID()); 12 | } 13 | 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /Section 5/DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Learn-How-to-Code-The-Complete-Core-Java-Programming-Course/eb54411c83978b2252257adc9d2be7f2a973188c/Section 5/DS_Store -------------------------------------------------------------------------------- /Section 6/Access Specifiers in Java.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Learn-How-to-Code-The-Complete-Core-Java-Programming-Course/eb54411c83978b2252257adc9d2be7f2a973188c/Section 6/Access Specifiers in Java.pdf -------------------------------------------------------------------------------- /Section 6/Android.txt: -------------------------------------------------------------------------------- 1 | package abstraction; 2 | 3 | public class Android extends Mobile{ 4 | 5 | @Override 6 | public void doubleTap() { 7 | System.out.println("Android Double Tap"); 8 | } 9 | 10 | } 11 | -------------------------------------------------------------------------------- /Section 6/Animal.txt: -------------------------------------------------------------------------------- 1 | package inheritance; 2 | 3 | public class Animal { 4 | 5 | public void whoAmI() { 6 | System.out.println("I am an Animal"); 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /Section 6/Animal_Main.txt: -------------------------------------------------------------------------------- 1 | package inheritance; 2 | 3 | public class Animal_Main { 4 | 5 | public static void main(String[] args) { 6 | 7 | Animal a; 8 | 9 | a = new Animal(); 10 | a.whoAmI(); 11 | 12 | a = new Dog(); 13 | a.whoAmI(); 14 | 15 | a = new Cat(); 16 | a.whoAmI(); 17 | 18 | } 19 | 20 | } 21 | -------------------------------------------------------------------------------- /Section 6/Cars.txt: -------------------------------------------------------------------------------- 1 | package inheritance; 2 | 3 | public class Cars { 4 | 5 | protected String make; 6 | String model; 7 | private int year; 8 | } 9 | -------------------------------------------------------------------------------- /Section 6/Cat.txt: -------------------------------------------------------------------------------- 1 | package inheritance; 2 | 3 | public class Cat extends Animal{ 4 | 5 | public void whoAmI() { 6 | System.out.println("I am an Cat"); 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /Section 6/Class1.txt: -------------------------------------------------------------------------------- 1 | package inheritance; 2 | 3 | public class Class1 { 4 | 5 | int num1; 6 | int num2; 7 | 8 | public void doAddition() { 9 | System.out.println("Addition is " + (num1 + num2)); 10 | } 11 | 12 | } 13 | -------------------------------------------------------------------------------- /Section 6/Class2.txt: -------------------------------------------------------------------------------- 1 | package inheritance; 2 | 3 | public class Class2 extends Class1 { 4 | 5 | 6 | public void doSubtraction() { 7 | System.out.println("Subtraction is " + (num1 - num2)); 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /Section 6/Class2_Final.txt: -------------------------------------------------------------------------------- 1 | package final_keyword; 2 | 3 | public class Class2 extends Final_Keyword{ 4 | 5 | 6 | 7 | } 8 | -------------------------------------------------------------------------------- /Section 6/Dog.txt: -------------------------------------------------------------------------------- 1 | package inheritance; 2 | 3 | public class Dog extends Animal{ 4 | 5 | public void whoAmI() { 6 | System.out.println("I am an Dog"); 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /Section 6/Final_Keyword.txt: -------------------------------------------------------------------------------- 1 | package final_keyword; 2 | 3 | public class Final_Keyword { 4 | 5 | /** 6 | * Final Field is used to create a Constant 7 | * Final Method is used to avoid Method Overriding 8 | * Final Class is used to prevent Inheritance 9 | */ 10 | 11 | final int A = 100; 12 | 13 | final void abc() { 14 | System.out.println("Final method abc"); 15 | } 16 | 17 | } 18 | -------------------------------------------------------------------------------- /Section 6/German_Cars.txt: -------------------------------------------------------------------------------- 1 | package inheritance; 2 | 3 | public class German_Cars extends Cars{ 4 | 5 | public void setCarDetails() { 6 | make = "BMW"; 7 | model = "X6"; 8 | //year = 2018; 9 | } 10 | 11 | } 12 | -------------------------------------------------------------------------------- /Section 6/Hotel_Booking.txt: -------------------------------------------------------------------------------- 1 | package inheritance; 2 | 3 | public class Hotel_Booking extends Travel_Booking { 4 | String hotel_Rating; 5 | 6 | public Hotel_Booking(String beginDate, String endDate, String destination, String hotel_Rating) { 7 | super(beginDate, endDate, destination); 8 | this.hotel_Rating = hotel_Rating; 9 | } 10 | 11 | public void bookHotel() { 12 | System.out.println("Hotel booked at " + destination + " from " + beginDate + " to " + endDate); 13 | super.doThis(); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Section 6/IOS.txt: -------------------------------------------------------------------------------- 1 | package abstraction; 2 | 3 | public class IOS extends Mobile{ 4 | 5 | @Override 6 | public void doubleTap() { 7 | System.out.println("IOS Double Tap"); 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /Section 6/Interfaces/Class1.txt: -------------------------------------------------------------------------------- 1 | package interfaces; 2 | 3 | public class Class1 implements Int1{ 4 | 5 | @Override 6 | public void doThis() { 7 | 8 | 9 | } 10 | 11 | } 12 | -------------------------------------------------------------------------------- /Section 6/Interfaces/Class2.txt: -------------------------------------------------------------------------------- 1 | package interfaces; 2 | 3 | public abstract class Class2 implements Int2{ 4 | 5 | public abstract void abc(); 6 | 7 | } 8 | -------------------------------------------------------------------------------- /Section 6/Interfaces/Class3.txt: -------------------------------------------------------------------------------- 1 | package interfaces; 2 | 3 | public class Class3 implements Int1, Int2 { 4 | 5 | @Override 6 | public void doThat() { 7 | // TODO Auto-generated method stub 8 | 9 | } 10 | 11 | @Override 12 | public void doThis() { 13 | // TODO Auto-generated method stub 14 | 15 | } 16 | 17 | } 18 | -------------------------------------------------------------------------------- /Section 6/Interfaces/Class4.txt: -------------------------------------------------------------------------------- 1 | package interfaces; 2 | 3 | public class Class4 extends Class2{ 4 | 5 | @Override 6 | public void doThat() { 7 | // TODO Auto-generated method stub 8 | 9 | } 10 | 11 | @Override 12 | public void doThis() { 13 | // TODO Auto-generated method stub 14 | 15 | } 16 | 17 | @Override 18 | public void abc() { 19 | // TODO Auto-generated method stub 20 | 21 | } 22 | 23 | } 24 | -------------------------------------------------------------------------------- /Section 6/Interfaces/Int1.txt: -------------------------------------------------------------------------------- 1 | package interfaces; 2 | 3 | public interface Int1 { 4 | 5 | static final int a = 100; 6 | 7 | void doThis(); 8 | 9 | static void xyz() { 10 | System.out.println("Static xyz from Int1"); 11 | } 12 | 13 | default void uvw() { 14 | System.out.println("Default uvw from Int1"); 15 | } 16 | 17 | } 18 | -------------------------------------------------------------------------------- /Section 6/Interfaces/Int2.txt: -------------------------------------------------------------------------------- 1 | package interfaces; 2 | 3 | public interface Int2 extends Int1{ 4 | 5 | void doThat(); 6 | 7 | } 8 | -------------------------------------------------------------------------------- /Section 6/Interfaces/Interface_Main.txt: -------------------------------------------------------------------------------- 1 | package interfaces; 2 | 3 | public class Interface_Main { 4 | 5 | public static void main(String[] args) { 6 | 7 | /** 8 | **** Interface in Java **** 9 | * 1. Interface is a collection of abstract methods 10 | * 2. Class can implement an Interface 11 | * 3. Interface can extend from another Interface 12 | * 4. Non abstract class extending from an abstract class needs to implement unimplemented methods 13 | * 5. Non abstract class implementing an interface needs to implement unimplemented methods 14 | * 6. Interface can not be instantiated 15 | * 7. Interface does not have a constructor 16 | * 8. In addition to abstract methods interface can contain static and default methods 17 | * 9. Interface cannot have data members. All variables by default considered as Static and Final 18 | * 10.Everything is public by default 19 | * 20 | */ 21 | 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /Section 6/Japanese_Cars.txt: -------------------------------------------------------------------------------- 1 | package temp; 2 | 3 | import inheritance.Cars; 4 | 5 | public class Japanese_Cars extends Cars{ 6 | 7 | public void setCarDetails() { 8 | make = "BMW"; 9 | //model = "X6"; 10 | //year = 2018; 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /Section 6/Main.txt: -------------------------------------------------------------------------------- 1 | package inheritance; 2 | 3 | public class Main { 4 | 5 | public static void main(String[] args) { 6 | 7 | Class2 c2 = new Class2(); 8 | 9 | c2.num1 = 100; 10 | c2.num2 = 50; 11 | 12 | c2.doAddition(); 13 | c2.doSubtraction(); 14 | 15 | } 16 | 17 | } 18 | -------------------------------------------------------------------------------- /Section 6/Mobile.txt: -------------------------------------------------------------------------------- 1 | package abstraction; 2 | 3 | public abstract class Mobile { 4 | 5 | /** 6 | * 4 Pillars of OOPS 7 | * 1.Encapsulation 8 | * 2.Inheritance 9 | * 3.Polymorphism 10 | * 4.Abstraction 11 | */ 12 | 13 | public abstract void doubleTap(); 14 | 15 | public void abc() { 16 | System.out.println("I am abc"); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Section 6/Mobile_Main.txt: -------------------------------------------------------------------------------- 1 | package abstraction; 2 | 3 | public class Mobile_Main { 4 | 5 | public static void main(String[] args) { 6 | 7 | Mobile m; 8 | 9 | m = new IOS(); 10 | m.doubleTap(); 11 | 12 | m = new Android(); 13 | m.doubleTap(); 14 | 15 | } 16 | 17 | } 18 | -------------------------------------------------------------------------------- /Section 6/PolyMain.txt: -------------------------------------------------------------------------------- 1 | package inheritance; 2 | 3 | public class PolyMain { 4 | 5 | public static void main(String[] args) { 6 | 7 | 8 | Triangle t1 = new Triangle(); 9 | t1.setBaseAndHeight(10.0, 20.98); 10 | t1.calcArea(); 11 | 12 | Rectangle r1 = new Rectangle(); 13 | r1.setBaseAndHeight(20.98, 34.987); 14 | r1.calcArea(); 15 | 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /Section 6/Polygon.txt: -------------------------------------------------------------------------------- 1 | package inheritance; 2 | 3 | public class Polygon { 4 | 5 | double base; 6 | double height; 7 | 8 | public void setBaseAndHeight(double base, double height) { 9 | this.base = base; 10 | this.height = height; 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /Section 6/Rectangle.txt: -------------------------------------------------------------------------------- 1 | package inheritance; 2 | 3 | public class Rectangle extends Polygon{ 4 | 5 | public void calcArea() { 6 | System.out.println("Area of Rectangle is " + (base*height)); 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /Section 6/Super Keyword/A.txt: -------------------------------------------------------------------------------- 1 | package super_keyword; 2 | 3 | public class A { 4 | 5 | int num1 = 100; 6 | 7 | public void doThis() { 8 | System.out.println("Do This From A"); 9 | } 10 | 11 | } 12 | -------------------------------------------------------------------------------- /Section 6/Super Keyword/B.txt: -------------------------------------------------------------------------------- 1 | package super_keyword; 2 | 3 | public class B extends A{ 4 | 5 | int num1 = 200; 6 | 7 | public void doThis() { 8 | System.out.println("Do This From B"); 9 | } 10 | 11 | public void xyz() { 12 | System.out.println(num1); 13 | super.doThis(); 14 | System.out.println("XYZ Executed"); 15 | } 16 | 17 | } 18 | -------------------------------------------------------------------------------- /Section 6/Super Keyword/Class1.txt: -------------------------------------------------------------------------------- 1 | package super_keyword; 2 | 3 | public class Class1 { 4 | 5 | int num1; 6 | 7 | public Class1(int a) { 8 | num1 = a; 9 | } 10 | 11 | 12 | } 13 | -------------------------------------------------------------------------------- /Section 6/Super Keyword/Class2.txt: -------------------------------------------------------------------------------- 1 | package super_keyword; 2 | 3 | public class Class2 extends Class1{ 4 | 5 | int num2; 6 | 7 | public Class2(int a, int b) { 8 | super(a); 9 | num2 = b; 10 | } 11 | 12 | 13 | 14 | } 15 | -------------------------------------------------------------------------------- /Section 6/Super Keyword/Main_Class.txt: -------------------------------------------------------------------------------- 1 | package super_keyword; 2 | 3 | public class Main_Class { 4 | 5 | public static void main(String[] args) { 6 | 7 | B b1 = new B(); 8 | 9 | b1.xyz(); 10 | 11 | 12 | 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /Section 6/Travel_Booking.txt: -------------------------------------------------------------------------------- 1 | package inheritance; 2 | 3 | public class Travel_Booking { 4 | 5 | String beginDate; 6 | String endDate; 7 | String destination; 8 | 9 | public Travel_Booking(String beginDate,String endDate,String destination) { 10 | this.beginDate = beginDate; 11 | this.endDate = endDate; 12 | this.destination = destination; 13 | } 14 | 15 | public void doThis() { 16 | System.out.println("I am doing this"); 17 | } 18 | 19 | } 20 | -------------------------------------------------------------------------------- /Section 6/Travel_Main.txt: -------------------------------------------------------------------------------- 1 | package inheritance; 2 | 3 | public class Travel_Main { 4 | 5 | public static void main(String[] args) { 6 | 7 | Hotel_Booking h1 = new Hotel_Booking("12-12-2020", "12-31-2020", "Las Vegas", "5 Star"); 8 | 9 | h1.bookHotel(); 10 | } 11 | 12 | } 13 | -------------------------------------------------------------------------------- /Section 6/Triangle.txt: -------------------------------------------------------------------------------- 1 | package inheritance; 2 | 3 | public class Triangle extends Polygon{ 4 | 5 | public void calcArea() { 6 | System.out.println("Area of Triangle is " + (0.5*base*height)); 7 | } 8 | 9 | 10 | } 11 | -------------------------------------------------------------------------------- /Section 7/2-Dimensional Array.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Learn-How-to-Code-The-Complete-Core-Java-Programming-Course/eb54411c83978b2252257adc9d2be7f2a973188c/Section 7/2-Dimensional Array.pdf -------------------------------------------------------------------------------- /Section 7/Array Exercise.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Learn-How-to-Code-The-Complete-Core-Java-Programming-Course/eb54411c83978b2252257adc9d2be7f2a973188c/Section 7/Array Exercise.docx -------------------------------------------------------------------------------- /Section 7/Array Structure.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Learn-How-to-Code-The-Complete-Core-Java-Programming-Course/eb54411c83978b2252257adc9d2be7f2a973188c/Section 7/Array Structure.png -------------------------------------------------------------------------------- /Section 7/Array_2D.txt: -------------------------------------------------------------------------------- 1 | package arrays; 2 | 3 | public class Array_2D { 4 | 5 | public static void main(String[] args) { 6 | 7 | /* 8 | * What is 2-D Array? 9 | * How to get length of 2-D Array? 10 | * How to add elements to 2-D Array? 11 | * How to retrieve elements from 2-D Array? 12 | * How to update elements of 2-D Array? 13 | * How to iterate over 2-D Array using modified 'for loop'? 14 | */ 15 | 16 | String [][] arr = 17 | { 18 | {"A","B","C"}, 19 | {"E","F"}, 20 | {"SDF","FG","FG","JH"} 21 | }; 22 | 23 | System.out.println(arr.length); 24 | System.out.println(arr[2].length); 25 | 26 | System.out.println(arr[2][1]); 27 | arr[2][1] = "AAAA"; 28 | System.out.println(arr[2][1]); 29 | 30 | for(String[] x : arr) { 31 | for(String y : x) { 32 | System.out.println(y); 33 | } 34 | System.out.println("----------------------"); 35 | } 36 | 37 | } 38 | 39 | } 40 | -------------------------------------------------------------------------------- /Section 7/Array_2D_Exercise.txt: -------------------------------------------------------------------------------- 1 | package arrays; 2 | 3 | public class Array_2D_Exercise { 4 | 5 | public static void main(String[] args) { 6 | 7 | /* 8 | * Write a program to add table to 2 to 6 in the rows of a 2-D array 9 | * { 10 | * {2,4,6,8...20}, 11 | * {3,6,9,12...30}, 12 | * {4,8,12,16...40}, 13 | * {5,10,15,20...50}, 14 | * {6,12,18,24...60} 15 | * } 16 | */ 17 | 18 | int [][] arr = new int [5][10]; 19 | 20 | for(int i = 2; i <= 6; i++) { 21 | for(int j = 1; j <= 10; j++) { 22 | arr[i-2][j-1] = i * j; 23 | } 24 | } 25 | 26 | for(int [] x : arr) { 27 | for(int y : x) { 28 | System.out.print(y + " "); 29 | } 30 | System.out.print("\n"); 31 | } 32 | 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /Section 7/Array_Exercise.txt: -------------------------------------------------------------------------------- 1 | package arrays; 2 | 3 | public class Array_Exercise { 4 | 5 | public static void main(String[] args) { 6 | 7 | /* 8 | * Write a program to reverse the contents of an array 9 | */ 10 | 11 | int [] arr = {10,20,30,35,40,50,60}; 12 | 13 | int j = arr.length-1; 14 | int temp = 0; 15 | 16 | for(int i = 0; i <= (arr.length-1)/2; i++) { 17 | temp = arr[i]; 18 | arr[i] = arr[j]; 19 | arr[j] = temp; 20 | j--; 21 | } 22 | 23 | for(int x : arr) { 24 | System.out.println(x); 25 | } 26 | 27 | 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /Section 7/Array_Object.txt: -------------------------------------------------------------------------------- 1 | package arrays; 2 | 3 | public class Array_Object { 4 | 5 | public static void main(String[] args) { 6 | 7 | int [] arr1 = new int [10]; 8 | 9 | arr1[0] = 20; 10 | arr1[1] = 40; 11 | arr1[3] = 60; 12 | arr1[2] = 80; 13 | arr1[6] = 100; 14 | 15 | for(int i = 0; i <= arr1.length-1; i++) { 16 | System.out.println(arr1[i]); 17 | } 18 | 19 | } 20 | 21 | } 22 | -------------------------------------------------------------------------------- /Section 7/Array_Of_Object.txt: -------------------------------------------------------------------------------- 1 | package arrays; 2 | 3 | public class Array_Of_Object { 4 | 5 | public static void main(String[] args) { 6 | 7 | Object [][] arr = 8 | { 9 | {"Mayur", 33, 5.11, 'M'}, 10 | {"Shruti", 30, 5.7, 'F'}, 11 | {"Gaurav", 31, 5.10, 'M'}, 12 | {"John", 45, 6.1, 'M'} 13 | }; 14 | 15 | 16 | for (Object [] x : arr) { 17 | for (Object y : x) { 18 | System.out.print(y + " "); 19 | } 20 | System.out.print("\n"); 21 | } 22 | 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /Section 7/Arrays.txt: -------------------------------------------------------------------------------- 1 | package arrays; 2 | 3 | public class Arrays { 4 | 5 | public static void main(String[] args) { 6 | 7 | /* 8 | * What is an array? 9 | * How to declare an array? 10 | * What is length of array? 11 | * How to update array elements? 12 | * Iterating on array elements using For Loop. 13 | */ 14 | 15 | String [] DaysOfWeek = {"Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"}; 16 | 17 | System.out.println(DaysOfWeek.length); 18 | 19 | System.out.println(DaysOfWeek[2]); 20 | 21 | DaysOfWeek[2] = "RRR"; 22 | 23 | System.out.println(DaysOfWeek[2]); 24 | 25 | for (int i = 0; i <= DaysOfWeek.length - 1; i++) { 26 | System.out.println(DaysOfWeek[i]); 27 | } 28 | 29 | int [] arr1 = {12,3,34,65,765,678,87654,456}; 30 | 31 | char [] arr2 = {'a','e','i'}; 32 | 33 | 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /Section 7/Enhanced_For_Loop.txt: -------------------------------------------------------------------------------- 1 | package arrays; 2 | 3 | import java.util.Scanner; 4 | 5 | public class Enhanced_For_Loop { 6 | 7 | public static void main(String[] args) { 8 | 9 | /* 10 | * Create a program to add table of any given number to an array. 11 | * Create an enhanced for loop to display all the contents of the array 12 | */ 13 | 14 | Scanner s1 = new Scanner(System.in); 15 | 16 | System.out.println("Please enter a number:"); 17 | 18 | int num1 = s1.nextInt(); 19 | 20 | int [] arr = new int [10]; 21 | 22 | for (int i = 1; i <= 10; i++) { 23 | arr[i-1] = num1 * i; 24 | } 25 | 26 | System.out.println("-------------------"); 27 | 28 | for(int n : arr) { 29 | System.out.println(n); 30 | } 31 | 32 | 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /Section 7/Frequently Asked Interview Programs on Arrays.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Learn-How-to-Code-The-Complete-Core-Java-Programming-Course/eb54411c83978b2252257adc9d2be7f2a973188c/Section 7/Frequently Asked Interview Programs on Arrays.pdf -------------------------------------------------------------------------------- /Section 8/Array List Structure.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Learn-How-to-Code-The-Complete-Core-Java-Programming-Course/eb54411c83978b2252257adc9d2be7f2a973188c/Section 8/Array List Structure.pdf -------------------------------------------------------------------------------- /Section 8/ArrayList Vs LinkedList.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Learn-How-to-Code-The-Complete-Core-Java-Programming-Course/eb54411c83978b2252257adc9d2be7f2a973188c/Section 8/ArrayList Vs LinkedList.pdf -------------------------------------------------------------------------------- /Section 8/Array_List.txt: -------------------------------------------------------------------------------- 1 | package lists; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | 6 | public class Array_List { 7 | 8 | public static void main(String[] args) { 9 | 10 | /* 11 | * ArrayList implements List Interface. 12 | * ArrayList supports creation of dynamic arrays. 13 | * Supported Methods: 14 | * 1. Accessing Elements - Add, Get, Update, Remove, Clear 15 | * 2. Searching Elements - Index Of, Contains, 16 | * 3. Viewing portion of list - SubList 17 | * 4. Iterating over list 18 | * 5. Size, toArray, isEmpty 19 | */ 20 | 21 | ArrayList arr = new ArrayList(); 22 | 23 | //List arr1 = new ArrayList(); 24 | 25 | arr.add("Red"); 26 | arr.add("Blue"); 27 | arr.add("Green"); 28 | arr.add("Yellow"); 29 | arr.add("Pink"); 30 | arr.add("Black"); 31 | arr.add("White"); 32 | arr.add("Purple"); 33 | arr.add("Brown"); 34 | 35 | System.out.println(arr.get(0)); 36 | System.out.println(arr.get(3)); 37 | arr.set(3, "Pink"); 38 | System.out.println(arr.get(3)); 39 | //arr.remove(0); 40 | //arr.remove("Green"); 41 | //arr.clear(); 42 | System.out.println(arr.indexOf("Pink")); 43 | System.out.println(arr.lastIndexOf("Pink")); 44 | System.out.println(arr.contains("White")); 45 | 46 | List arr2 = arr.subList(2, 5); 47 | System.out.println(arr2); 48 | System.out.println("--------------------"); 49 | System.out.println(arr.isEmpty()); 50 | System.out.println(arr.size()); 51 | 52 | System.out.println("List Elements:" + arr); 53 | 54 | System.out.println("--------------------"); 55 | 56 | for(String x : arr) { 57 | System.out.println(x); 58 | } 59 | 60 | } 61 | 62 | } 63 | -------------------------------------------------------------------------------- /Section 8/Linked List Structure.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Learn-How-to-Code-The-Complete-Core-Java-Programming-Course/eb54411c83978b2252257adc9d2be7f2a973188c/Section 8/Linked List Structure.pdf -------------------------------------------------------------------------------- /Section 8/Linked_List.txt: -------------------------------------------------------------------------------- 1 | package lists; 2 | 3 | import java.util.LinkedList; 4 | 5 | public class Linked_List { 6 | 7 | public static void main(String[] args) { 8 | 9 | /* 10 | * LinkdList implements List Interface. 11 | * LinkedList elements are linked together using pointers. 12 | * Supported Methods: 13 | * 1. Accessing Elements - Add, Get, Update, Remove, Clear 14 | * 2. Searching Elements - Index Of, Contains, 15 | * 3. Viewing portion of list - SubList 16 | * 4. Iterating over list 17 | * 5. Size, toArray, isEmpty 18 | * 6. Peek and Poll Methods 19 | */ 20 | 21 | var list = new LinkedList(); 22 | 23 | list.add(1.1); 24 | list.add(1.2); 25 | list.add(1.2); 26 | list.add(1.4); 27 | list.add(1.5); 28 | list.add(1.6); 29 | 30 | //System.out.println(list.get(2)); 31 | //list.set(2, 3.3); 32 | //System.out.println(list.get(2)); 33 | //list.add(3, 9.8); 34 | //list.clear(); 35 | //list.remove(0); 36 | //list.remove(1.6); 37 | 38 | //System.out.println(list.indexOf(1.99)); 39 | //System.out.println(list.lastIndexOf(1.2)); 40 | //System.out.println(list.contains(90.0)); 41 | 42 | //System.out.println(list.peekFirst()); 43 | //System.out.println(list.peekLast()); 44 | 45 | System.out.println(list.pollFirst()); 46 | System.out.println(list.pollLast()); 47 | 48 | System.out.println(list); 49 | //System.out.println(list.subList(2, 4)); 50 | 51 | 52 | 53 | } 54 | 55 | } 56 | -------------------------------------------------------------------------------- /Section 8/List_Iterator.txt: -------------------------------------------------------------------------------- 1 | package lists; 2 | import java.util.ArrayList; 3 | import java.util.ListIterator; 4 | 5 | public class List_Iterator { 6 | 7 | public static void main(String[] args) { 8 | 9 | /* 10 | * List Iterator is used when we want to enumerate elements of List 11 | * It can be used both on ArrayList and LinkedList 12 | * Methods: 13 | * next, hasNext, previous, hasPrevious, 14 | * nextIndex, previousIndex, add, set, remove 15 | */ 16 | 17 | var list = new ArrayList(); 18 | 19 | list.add(1.1); 20 | list.add(1.2); 21 | list.add(1.3); 22 | list.add(1.4); 23 | list.add(1.5); 24 | 25 | ListIterator itr = list.listIterator(list.size()); 26 | 27 | while(itr.hasPrevious()) { 28 | System.out.println(itr.previous()); 29 | } 30 | 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /Section 8/List_Iterator_Program1.txt: -------------------------------------------------------------------------------- 1 | package lists; 2 | 3 | import java.util.ArrayList; 4 | import java.util.ListIterator; 5 | 6 | public class List_Iterator_Program1 { 7 | 8 | public static void main(String[] args) { 9 | 10 | /* 11 | * Remove all null values from an ArrayList 12 | */ 13 | 14 | var list = new ArrayList(); 15 | 16 | list.add(100); 17 | list.add(200); 18 | list.add(300); 19 | list.add(null); 20 | list.add(400); 21 | list.add(500); 22 | list.add(null); 23 | list.add(null); 24 | list.add(600); 25 | 26 | ListIterator itr = list.listIterator(); 27 | 28 | while(itr.hasNext()) { 29 | if (itr.next() == null) { 30 | //itr.remove(); 31 | itr.set(0); 32 | } 33 | } 34 | 35 | System.out.println(list); 36 | } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /Section 8/List_Iterator_Program2.txt: -------------------------------------------------------------------------------- 1 | package lists; 2 | 3 | import java.util.LinkedList; 4 | import java.util.ListIterator; 5 | 6 | public class List_Iterator_Program2 { 7 | 8 | public static void main(String[] args) { 9 | 10 | /* 11 | * Update all ODD numbers from a LinkedList to EVEN Numbers 12 | */ 13 | 14 | var list = new LinkedList(); 15 | 16 | list.add(10); 17 | list.add(20); 18 | list.add(11); 19 | list.add(23); 20 | list.add(100); 21 | list.add(30); 22 | list.add(111); 23 | list.add(119); 24 | 25 | ListIterator itr = list.listIterator(); 26 | 27 | while(itr.hasNext()) { 28 | 29 | int i = (int) itr.next(); 30 | if (i % 2 == 1) { 31 | i++; 32 | itr.set(i); 33 | } 34 | 35 | } 36 | 37 | System.out.println(list); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /Section 9/Hash_Map.txt: -------------------------------------------------------------------------------- 1 | package maps; 2 | 3 | import java.util.HashMap; 4 | 5 | public class Hash_Map { 6 | 7 | public static void main(String[] args) { 8 | 9 | /* 10 | * HashMap provides the basic implementation of Map interface 11 | * It stores data in Key and Value pairs 12 | * We can access a value using the corresponding key 13 | * Methods: put, get, containsKey, remove, clear, keySet, values, entrySet 14 | */ 15 | 16 | var map = new HashMap(); 17 | 18 | map.put(1, "Jan"); 19 | map.put(0, "Feb"); 20 | map.put(3, "Mar"); 21 | map.put(4, "Apr"); 22 | map.put(5, "May"); 23 | 24 | System.out.println(map.get(2)); 25 | 26 | System.out.println(map.containsKey(3)); 27 | 28 | map.put(4, "Dec"); 29 | 30 | //map.remove(4); 31 | 32 | //map.remove(5, "May1"); 33 | 34 | //map.clear(); 35 | 36 | var set1 = map.keySet(); 37 | 38 | var set2 = map.values(); 39 | 40 | var set3 = map.entrySet(); 41 | 42 | System.out.println(set1); 43 | System.out.println(set2); 44 | System.out.println(set3); 45 | 46 | System.out.println(map); 47 | 48 | 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /Section 9/Hash_Set.txt: -------------------------------------------------------------------------------- 1 | package sets; 2 | 3 | import java.util.ArrayList; 4 | import java.util.HashSet; 5 | 6 | public class Hash_Set { 7 | 8 | public static void main(String[] args) { 9 | 10 | /* 11 | * Set is a Collection that cannot contain duplicate elements. 12 | * HashSet does not maintain insertion order 13 | * No positional access of elements 14 | * Basic Methods: add, remove, clear, contains, size, 15 | * IMP: Union and Intersection of Sets 16 | * IMP: Convert set to list 17 | */ 18 | 19 | var set1 = new HashSet(); 20 | 21 | set1.add(10); 22 | set1.add(20); 23 | set1.add(30); 24 | set1.add(40); 25 | set1.add(50); 26 | set1.add(10); 27 | set1.add(20); 28 | 29 | var set2 = new HashSet(); 30 | 31 | set2.add(10); 32 | set2.add(40); 33 | set2.add(50); 34 | set2.add(70); 35 | set2.add(80); 36 | 37 | //set1.addAll(set2); 38 | 39 | //set1.retainAll(set2); 40 | 41 | //System.out.println(set1); 42 | 43 | //set1.remove(20); 44 | 45 | var list1 = new ArrayList(); 46 | 47 | list1.addAll(set1); 48 | 49 | System.out.println(list1); 50 | } 51 | 52 | } 53 | -------------------------------------------------------------------------------- /Section 9/Iterating_Over_Set.txt: -------------------------------------------------------------------------------- 1 | package sets; 2 | 3 | import java.util.HashSet; 4 | import java.util.Iterator; 5 | import java.util.TreeSet; 6 | 7 | public class Iterating_Over_Set { 8 | 9 | public static void main(String[] args) { 10 | 11 | /* 12 | * Special For Loop 13 | * Iterator 14 | */ 15 | 16 | HashSet set1 = new HashSet(); 17 | 18 | set1.add(100); 19 | set1.add(200); 20 | set1.add(300); 21 | set1.add(400); 22 | set1.add(500); 23 | 24 | for(int x : set1) { 25 | System.out.println(x); 26 | } 27 | 28 | var set2 = new TreeSet(); 29 | 30 | set2.add("Sun"); 31 | set2.add("Mon"); 32 | set2.add("Tue"); 33 | set2.add("Wed"); 34 | set2.add("Thu"); 35 | 36 | System.out.println("---------------"); 37 | 38 | Iterator it1 = set2.iterator(); 39 | 40 | while(it1.hasNext()) { 41 | System.out.println(it1.next()); 42 | } 43 | } 44 | 45 | } 46 | -------------------------------------------------------------------------------- /Section 9/Linked_Hash_Set.txt: -------------------------------------------------------------------------------- 1 | package sets; 2 | 3 | import java.util.LinkedHashSet; 4 | 5 | public class Linked_Hash_Set { 6 | 7 | public static void main(String[] args) { 8 | 9 | /* 10 | * A LinkedHashSet is an ordered version of HashSet 11 | * LinkedHashSet maintains a doubly-linked List across all elements 12 | * No positional access of elements 13 | * Basic Methods: add, remove, clear, contains, size, 14 | * IMP: Union and Intersection of Sets 15 | * IMP: Convert set to list 16 | */ 17 | 18 | LinkedHashSet set1 = new LinkedHashSet(); 19 | 20 | set1.add('a'); 21 | set1.add('e'); 22 | set1.add('i'); 23 | set1.add('o'); 24 | set1.add('u'); 25 | 26 | System.out.println(set1); 27 | 28 | 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /Section 9/Map_Iterating.txt: -------------------------------------------------------------------------------- 1 | package maps; 2 | 3 | import java.util.Iterator; 4 | import java.util.Map.Entry; 5 | import java.util.TreeMap; 6 | 7 | public class Map_Iterating { 8 | 9 | public static void main(String[] args) { 10 | 11 | var map = new TreeMap(); 12 | 13 | map.put(10, Math.sqrt(10)); 14 | map.put(30, Math.sqrt(30)); 15 | map.put(50, Math.sqrt(50)); 16 | map.put(40, Math.sqrt(40)); 17 | map.put(20, Math.sqrt(20)); 18 | /* 19 | for(Entry e : map.entrySet()) { 20 | System.out.println(e); 21 | } 22 | */ 23 | 24 | Iterator it = map.entrySet().iterator(); 25 | 26 | while(it.hasNext()) { 27 | System.out.println(it.next()); 28 | } 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /Section 9/Tree_Map.txt: -------------------------------------------------------------------------------- 1 | package maps; 2 | 3 | import java.util.TreeMap; 4 | 5 | public class Tree_Map { 6 | 7 | public static void main(String[] args) { 8 | 9 | /* 10 | * TreeMap is implemented based on red-black tree structure 11 | * It is sorted by keys 12 | * Methods: put, get, containsKey, containsValue, replace, remove, clear, keySet, values, entrySet 13 | * firstEntry,lastEntry,firstKey,lastKey,pollFirstEntry,pollLastEntry 14 | */ 15 | 16 | var map = new TreeMap(); 17 | 18 | map.put('d', 1000); 19 | map.put('a', 2000); 20 | map.put('c', 3000); 21 | map.put('b', 4000); 22 | 23 | //System.out.println(map.containsValue(30000)); 24 | //map.put('a', 6000); 25 | 26 | //map.replace('a', 6000); 27 | 28 | //System.out.println(map.firstEntry()); 29 | //System.out.println(map.lastEntry()); 30 | //System.out.println(map.firstKey()); 31 | //System.out.println(map.lastKey()); 32 | 33 | //System.out.println(map.pollFirstEntry()); 34 | //System.out.println(map.pollLastEntry()); 35 | 36 | System.out.println(map); 37 | 38 | 39 | 40 | 41 | } 42 | 43 | } 44 | -------------------------------------------------------------------------------- /Section 9/Tree_Set.txt: -------------------------------------------------------------------------------- 1 | package sets; 2 | 3 | import java.util.Set; 4 | import java.util.TreeSet; 5 | 6 | public class Tree_Set { 7 | 8 | public static void main(String[] args) { 9 | 10 | /* 11 | * TreeSet is an important implementation of the SortedSet interface 12 | * Elements are sorted in ascending order by default 13 | * No positional access of elements 14 | * Basic Methods: add, remove, clear, contains, size, 15 | * IMP: Union and Intersection of Sets 16 | * IMP: Convert set to list 17 | */ 18 | 19 | Set set1 = new TreeSet(); 20 | 21 | set1.add("Rob"); 22 | set1.add("Bob"); 23 | set1.add("Andy"); 24 | set1.add("Charls"); 25 | 26 | System.out.println(set1); 27 | 28 | var set2 = new TreeSet(); 29 | 30 | set2.add(100); 31 | set2.add(10); 32 | set2.add(50); 33 | set2.add(2); 34 | set2.add(0); 35 | 36 | System.out.println(set2); 37 | } 38 | 39 | } 40 | --------------------------------------------------------------------------------