├── .gitignore ├── README.md ├── .gitmodules ├── Actions_Py.py ├── K_Final.java ├── Z_Z_A_Thread.java ├── D_Conditionals.java ├── W_equals_to.java ├── .github └── workflows │ └── Java-Test.yml ├── M_Inheritance_And_Encapsulation.java ├── U_Anonymous_Classes.java ├── B_Variables.java ├── V_Inner_Class.java ├── C_UserInput.java ├── I_Referencing.java ├── Z_Z_F_LambdaExpression.java ├── P_Method_Overloading.java ├── O_Method Overriding.java ├── Y_Exception.java ├── Q_Abstract_Class.java ├── X_Enums.java ├── J_Static.java ├── Z_Thread.java ├── S_Interfaces.java ├── E_Switch.java ├── A_Hello_World.java ├── N_Polymorphism.java ├── T_Casting.java ├── Z_Z_E_HashMap.java ├── R_Example_Abstract.java ├── L_Inheritance_And_Encapsulation.java ├── Z_Z_C_DeserializationClass.java ├── G_OOP.java ├── F_Array.java ├── Z_Z_B_SerializationClass.java ├── H_Objects.java └── Z_Z_D_Files.java /.gitignore: -------------------------------------------------------------------------------- 1 | *.txt 2 | *.class 3 | *.bat 4 | *.sh -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Learn_Java 2 | A Simple Repository To Learn Java 3 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "DSA-Java"] 2 | path = DSA-Java 3 | url = https://github.com/garvit-joshi/DSA-Java.git 4 | -------------------------------------------------------------------------------- /Actions_Py.py: -------------------------------------------------------------------------------- 1 | #This File is Used by GitHub Actions to check if Uploded Java Code has no Error 2 | import glob 3 | import os 4 | ifile=open("Input.txt","w") 5 | for file in glob.glob("*.java"): 6 | command="javac \""+file+"\"" 7 | os.system(command) 8 | ifile.write(command) 9 | ifile.write("\n") 10 | -------------------------------------------------------------------------------- /K_Final.java: -------------------------------------------------------------------------------- 1 | class K_Final { 2 | public static final double PI = 3.14; 3 | 4 | /** 5 | * final keyword to mark a variable constant, so that it can be assigned only 6 | * once. 7 | */ 8 | public static void main(String[] args) { 9 | System.out.println(PI); 10 | } 11 | } 12 | /** 13 | * Methods and classes can also be marked final. This serves to restrict methods 14 | * so that they can't be overridden and classes so that they can't be 15 | * subclassed. 16 | */ -------------------------------------------------------------------------------- /Z_Z_A_Thread.java: -------------------------------------------------------------------------------- 1 | class Loader implements Runnable { 2 | public void run() { 3 | System.out.println("Hello"); 4 | } 5 | } 6 | 7 | class Z_Z_A_Thread { 8 | public static void main(String[] args) { 9 | Thread t = new Thread(new Loader()); 10 | t.start(); 11 | } 12 | } 13 | /** 14 | * Second Method:creating Threads is implementing the Runnable interface. 15 | * Implement the run() method. Then, create a new Thread object, pass the 16 | * Runnable class to its constructor, and start the Thread by calling the 17 | * start() method. 18 | */ -------------------------------------------------------------------------------- /D_Conditionals.java: -------------------------------------------------------------------------------- 1 | class D_Conditionals { 2 | public static void main(String[] args) { 3 | int age = 25; 4 | if (age > 0) { 5 | if (age > 16) { 6 | System.out.println("Welcome!"); 7 | } else if (age < 13) { 8 | System.out.println("Too Young"); 9 | } else { 10 | System.out.println("Wait For Few Years"); 11 | } 12 | } else { 13 | System.out.println("Error"); 14 | } 15 | /****************************** 16 | * Logical Statements two=&& , || 17 | ***************************/ 18 | age = 25; 19 | int money = 100; 20 | if (age > 18 || money > 500) { 21 | System.out.println("Welcome!"); 22 | } 23 | } 24 | } -------------------------------------------------------------------------------- /W_equals_to.java: -------------------------------------------------------------------------------- 1 | class Animal { 2 | String name; 3 | 4 | Animal(String n) { 5 | name = n; 6 | } 7 | } 8 | 9 | /** 10 | * (==)compares the references and not the object values. 11 | */ 12 | class W_equals_to { 13 | public static void main(String[] args) { 14 | Animal a1 = new Animal("Robby"); 15 | Animal a2 = new Animal("Robby"); 16 | System.out.println(a1 == a2); // Output:False 17 | /** 18 | * Despite having two objects with the same name, the equality testing returns 19 | * false, because we have two different objects (two different references or 20 | * memory locations). 21 | */ 22 | } 23 | } -------------------------------------------------------------------------------- /.github/workflows/Java-Test.yml: -------------------------------------------------------------------------------- 1 | name: Java-Code-Testing 2 | 3 | on: [push] 4 | 5 | jobs: 6 | build: 7 | runs-on: windows-latest 8 | 9 | steps: 10 | - uses: actions/checkout@v2 11 | - uses: actions/setup-python@v2 12 | with: 13 | python-version: '3.9.7' 14 | architecture: 'x64' 15 | - uses: actions/setup-java@v1 16 | with: 17 | java-version: '1.8' # The JDK version to make available on the path. 18 | java-package: jdk # (jre, jdk, or jdk+fx) - defaults to jdk 19 | architecture: x64 # (x64 or x86) - defaults to x64 20 | - name: build 21 | run: | 22 | python --version 23 | python Actions_Py.py 24 | -------------------------------------------------------------------------------- /M_Inheritance_And_Encapsulation.java: -------------------------------------------------------------------------------- 1 | class A { 2 | public A() { 3 | System.out.println("New A"); 4 | } 5 | } 6 | 7 | class B extends A { 8 | public B() { 9 | System.out.println("New B"); 10 | } 11 | } 12 | 13 | class M_Inheritance_And_Encapsulation { 14 | public static void main(String[] args) { 15 | /** 16 | * Constructors are not member methods, and so are not inherited by subclasses. 17 | * However, the constructor of the superclass is called when the subclass is 18 | * instantiated. 19 | */ 20 | B obj = new B(); 21 | } 22 | } 23 | /** 24 | * Output: "New A" "New B" 25 | */ 26 | /** 27 | * You can access the superclass from the subclass using the super keyword. For 28 | * example, super.var accesses the var member of the superclass. 29 | */ -------------------------------------------------------------------------------- /U_Anonymous_Classes.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Anonymous classes are a way to extend the existing classes on the fly. 3 | */ 4 | class Machine { 5 | public void start() { 6 | System.out.println("Starting..."); 7 | } 8 | } 9 | 10 | class U_Anonymous_Classes { 11 | public static void main(String[] args) { 12 | Machine m = new Machine() { 13 | @Override 14 | public void start() { 15 | /** 16 | * The @Override annotation is used to make your code easier to understand, 17 | * because it makes it more obvious when methods are overridden. 18 | */ 19 | System.out.println("Wooooo"); 20 | } 21 | }; 22 | /** 23 | * After the constructor call, we have opened the curly braces and have 24 | * overridden the start method's implementation on the fly. 25 | */ 26 | m.start(); // Output:Wooooo 27 | Machine c = new Machine(); 28 | c.start(); // Output:Starting... 29 | } 30 | } -------------------------------------------------------------------------------- /B_Variables.java: -------------------------------------------------------------------------------- 1 | class B_Variables { 2 | public static void main(String[] args) { 3 | String name = "David"; // You are allowed to define an empty string. For example, String str = ""; 4 | int age = 42; 5 | int x = ++age; // Prefix: Increments the variable's value and uses the new value in the 6 | // expression. 7 | int y = age++; // Postfix: The variable's value is first used in the expression and is then 8 | // increased. 9 | double score = 15.9; 10 | ++score; 11 | char group = 'Z'; // The char data type represents a single character. 12 | boolean online = true; 13 | String firstName, lastName; 14 | firstName = "David"; 15 | lastName = "Williams"; 16 | System.out.println("My name is " + firstName + " " + lastName); // The + (plus) operator between strings adds 17 | // them together to make a new string. This 18 | // process is called concatenation. 19 | } 20 | } -------------------------------------------------------------------------------- /V_Inner_Class.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Java supports nesting classes; a class can be a member of another class. Just 3 | * write a class within a class. Unlike a class, an inner class can be private. 4 | * Once you declare an inner class private, it cannot be accessed from an object 5 | * outside the class. 6 | */ 7 | class Robot { 8 | int id; 9 | 10 | Robot(int i) { 11 | id = i; 12 | Brain b = new Brain(); 13 | b.think(); 14 | } 15 | 16 | private class Brain { 17 | public void think() { 18 | System.out.println(id + " is thinking"); 19 | } 20 | } 21 | } 22 | 23 | /** 24 | * The class Robot has an inner class Brain. The inner class can access all of 25 | * the member variables and methods of its outer class, but it cannot be 26 | * accessed from any outside class. 27 | */ 28 | public class V_Inner_Class { 29 | public static void main(String[] args) { 30 | Robot r = new Robot(1); 31 | } 32 | } -------------------------------------------------------------------------------- /C_UserInput.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | class C_UserInput { 4 | public static void main(String[] args) { 5 | Scanner cin = new Scanner(System.in); // In order to use the Scanner class, create an instance of the class by 6 | // using the following syntax 7 | System.out.println(cin.nextLine()); 8 | cin.close(); 9 | /* 10 | * cin.close():If you do not close the scanner class it will generate warnings 11 | * like Resource leak. Resource leak is generally an erroneous pattern of 12 | * resource consumption where a program does not release the resource it has 13 | * acquired. This can lead to poor services. 14 | */ 15 | } 16 | } 17 | /*************************** 18 | * Read a byte - nextByte() Read a short - nextShort() Read an int - nextInt() 19 | * Read a long - nextLong() Read a float - nextFloat() Read a double - 20 | * nextDouble() Read a boolean - nextBoolean() Read a complete line - nextLine() 21 | * Read a word - next().charAt(0); 22 | ******************************/ -------------------------------------------------------------------------------- /I_Referencing.java: -------------------------------------------------------------------------------- 1 | class I_Referencing { 2 | public static void main(String[] args) { 3 | Person j; 4 | j = new Person("John"); 5 | j.setAge(20); 6 | celebrateBirthday(j); 7 | System.out.println(j.getAge()); 8 | /** 9 | * Because j is a reference type, the method affects the object itself, and is 10 | * able to change the actual value of its attribute. 11 | */ 12 | } 13 | 14 | static void celebrateBirthday(Person p) { 15 | p.setAge(p.getAge() + 1); 16 | /** 17 | * The method celebrateBirthday takes a Person object as its parameter, and 18 | * increments its attribute. 19 | */ 20 | } 21 | } 22 | 23 | class Person { 24 | private String name; 25 | private int age; 26 | 27 | Person(String n) { 28 | this.name = n; 29 | } 30 | 31 | public int getAge() { 32 | return age; 33 | } 34 | 35 | public void setAge(int a) { 36 | this.age = a; 37 | } 38 | } -------------------------------------------------------------------------------- /Z_Z_F_LambdaExpression.java: -------------------------------------------------------------------------------- 1 | interface A { 2 | boolean isEven(int nos); 3 | } 4 | 5 | interface B { 6 | double product(int a, int b); 7 | } 8 | 9 | interface C { 10 | int sumOfArray(int[] a); 11 | } 12 | 13 | interface D { 14 | void show(int a, double b); 15 | } 16 | 17 | class Z_Z_F_LambdaExpression { 18 | public static void main(String args[]) { 19 | A Even = (nos) -> (nos % 2) == 0; 20 | if (Even.isEven(10)) { 21 | System.out.println("10 is even"); 22 | } 23 | B Pro = (a, b) -> a * b; 24 | System.out.println("Product Is:" + Pro.product(4, 5)); 25 | int arr[] = { 3, 1, 2, 5, 4 }; 26 | C sumOf = (a) -> { 27 | int sum = 0; 28 | for (int i = 0; i < a.length; i++) { 29 | sum = sum + a[i]; 30 | } 31 | return sum; 32 | }; 33 | System.out.println("Sum is:" + sumOf.sumOfArray(arr)); 34 | D sho = (a, b) -> System.out.println("a:" + a + " b:" + b); 35 | sho.show(5, 6); 36 | } 37 | } -------------------------------------------------------------------------------- /P_Method_Overloading.java: -------------------------------------------------------------------------------- 1 | /** 2 | * When methods have the same name, but different parameters, it is known as 3 | * method overloading. This can be very useful when you need the same method 4 | * functionality for different types of parameters. 5 | */ 6 | class P_Method_Overloading { 7 | static double max(double a, double b) { 8 | if (a > b) { 9 | return a; 10 | } else { 11 | return b; 12 | } 13 | } 14 | 15 | static int max(int a, int b) { 16 | if (a > b) { 17 | return a; 18 | } else { 19 | return b; 20 | } 21 | } 22 | 23 | public static void main(String[] args) { 24 | System.out.println(max(8, 17)); // Calls:static int max(int a, int b) { 25 | System.out.println(max(3.14, 7.68)); // Calls:static double max(double a, double b) { 26 | } 27 | } 28 | /** 29 | * Another name for method overloading is compile-time polymorphism. 30 | */ 31 | /** 32 | * An overloaded method must have a different argument list; the parameters 33 | * should differ in their type, number, or both. 34 | */ 35 | -------------------------------------------------------------------------------- /O_Method Overriding.java: -------------------------------------------------------------------------------- 1 | class Animal { 2 | public void makeSound() { 3 | System.out.println("Grr..."); 4 | } 5 | } 6 | 7 | class Cat extends Animal { 8 | public void makeSound() { 9 | System.out.println("Meow"); 10 | } 11 | } 12 | 13 | class O_Method_Overriding { 14 | public static void main(String[] args) { 15 | Cat c = new Cat(); 16 | c.makeSound(); 17 | /** 18 | * Output: Meow 19 | */ 20 | Animal a = new Animal(); 21 | a.makeSound(); 22 | } 23 | } 24 | /** 25 | * Method overriding is also known as runtime polymorphism. 26 | */ 27 | /** 28 | * Rules for Method Overriding: - Should have the same return type and arguments 29 | * - The access level cannot be more restrictive than the overridden method's 30 | * access level (Example: If the superclass method is declared public, the 31 | * overriding method in the sub class can be neither private nor protected) - A 32 | * method declared final or static cannot be overridden - If a method cannot be 33 | * inherited, it cannot be overridden - Constructors cannot be overridden 34 | */ -------------------------------------------------------------------------------- /Y_Exception.java: -------------------------------------------------------------------------------- 1 | /** 2 | Exception handling is a powerful mechanism that handles runtime errors to maintain normal 3 | application flow. 4 | */ 5 | /** 6 | * An exception can occur for many different reasons. Some examples: - A user 7 | * has entered invalid data. - A file that needs to be opened cannot be found. - 8 | * A network connection has been lost in the middle of communications. - 9 | * Insufficient memory and other issues related to physical resources. 10 | */ 11 | public class Y_Exception { 12 | /* 13 | * static int div(int a, int b) throws ArithmeticException { if(b == 0) { throw 14 | * new ArithmeticException("Division by Zero"); } else { return a / b; } } 15 | */ 16 | public static void main(String[] args) { 17 | try { 18 | int a[] = new int[2]; 19 | System.out.println(a[5]); 20 | } catch (Exception e) { 21 | System.out.println("An error occurred"); 22 | } 23 | /** 24 | * (Exception e) statement in the catch block - it is used to catch all possible 25 | * Exceptions. System.out.println(div(42, 0)); 26 | */ 27 | } 28 | } -------------------------------------------------------------------------------- /Q_Abstract_Class.java: -------------------------------------------------------------------------------- 1 | /** 2 | Data abstraction provides the outside world with only essential information, 3 | in a process of representing essential features without including implementation 4 | details. 5 | */ 6 | /** 7 | An abstract class is defined using the abstract keyword. 8 | - If a class is declared abstract it cannot be instantiated (you cannot create objects of 9 | that type). 10 | - To use an abstract class, you have to inherit it from another class. 11 | - Any class that contains an abstract method should be defined as abstract. 12 | */ 13 | /** 14 | * An abstract method is a method that is declared without an implementation 15 | * (without braces, and followed by a semicolon): abstract void walk(); 16 | */ 17 | abstract class Animal { 18 | /** 19 | * A class containing an abstract method is an abstract class. 20 | */ 21 | int legs = 0; 22 | 23 | abstract void makeSound(); 24 | } 25 | 26 | class Cat extends Animal { 27 | public void makeSound() { 28 | System.out.println("Meow"); 29 | } 30 | } 31 | 32 | class Q_Abstract_Class { 33 | public static void main(String[] args) { 34 | Cat c = new Cat(); 35 | c.makeSound(); 36 | } 37 | } -------------------------------------------------------------------------------- /X_Enums.java: -------------------------------------------------------------------------------- 1 | /** 2 | * An Enum is a special type used to define collections of constants. Basically, 3 | * Enums define variables that represent members of a fixed set. 4 | */ 5 | public class X_Enums { 6 | enum Rank { 7 | SOLDIER, SERGEANT, CAPTAIN 8 | } 9 | 10 | public static void main(String[] args) { 11 | Rank a = Rank.SOLDIER; 12 | 13 | switch (a) { 14 | case SOLDIER: 15 | System.out.println("Soldier says hi!"); 16 | break; 17 | case SERGEANT: 18 | System.out.println("Sergeant says Hello!"); 19 | break; 20 | case CAPTAIN: 21 | System.out.println("Captain says Welcome!"); 22 | break; 23 | } 24 | a = Rank.SERGEANT; 25 | switch (a) { 26 | case SOLDIER: 27 | System.out.println("Soldier says hi!"); 28 | break; 29 | case SERGEANT: 30 | System.out.println("Sergeant says Hello!"); 31 | break; 32 | case CAPTAIN: 33 | System.out.println("Captain says Welcome!"); 34 | break; 35 | } 36 | } 37 | } -------------------------------------------------------------------------------- /J_Static.java: -------------------------------------------------------------------------------- 1 | class Counter { 2 | public static int COUNT = 0; 3 | 4 | /** 5 | * When you declare a variable or a method as static, it belongs to the class, 6 | * rather than to a specific instance. This means that only one instance of a 7 | * static member exists, even if you create multiple objects of the class, or if 8 | * you don't create any. It will be shared by all objects. 9 | */ 10 | Counter() { 11 | COUNT++; 12 | /** 13 | * The COUNT variable will be shared by all objects of that class. 14 | */ 15 | } 16 | } 17 | 18 | class Vehicle { 19 | public static void horn() { 20 | System.out.println("Beep"); 21 | } 22 | } 23 | 24 | public class J_Static { 25 | public static int pCount; 26 | 27 | public static void main(String[] args) { 28 | Counter c1 = new Counter(); 29 | Counter c2 = new Counter(); 30 | System.out.println(Counter.COUNT); 31 | Vehicle.horn(); 32 | /** 33 | * the horn method can be called without creating an object: because it is a 34 | * static method. 35 | */ 36 | J_Static.pCount = 1; 37 | J_Static.pCount++; 38 | System.out.println(J_Static.pCount); 39 | } 40 | } 41 | /** 42 | * Another example of static methods are those of the Math class, which is why 43 | * you can call them without creating a Math object. 44 | */ -------------------------------------------------------------------------------- /Z_Thread.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Java is a multi-threaded programming language. This means that our program 3 | * can make optimal use of available resources by running two or more components 4 | * concurrently, with each component handling a different task. 5 | */ 6 | class Loader extends Thread { 7 | public void run() { 8 | System.out.println("Hello"); 9 | } 10 | } 11 | 12 | class Z_Thread { 13 | public static void main(String[] args) { 14 | /** 15 | * First Method:Loader class extends the Thread class and overrides its run() 16 | * method. When we create the obj object and call its start() method, the run() 17 | * method statements execute on a different thread. 18 | */ 19 | Loader obj = new Loader(); 20 | obj.start(); 21 | } 22 | } 23 | /** 24 | * Every Java thread is prioritized to help the operating system determine the 25 | * order in which to schedule threads. The priorities range from 1 to 10, with 26 | * each thread defaulting to priority 5. You can set the thread priority with 27 | * the setPriority() method. 28 | */ 29 | /** 30 | * The Thread.sleep() method pauses a Thread for a specified period of time. For 31 | * example, calling Thread.sleep(1000); pauses the thread for one second. Keep 32 | * in mind that Thread.sleep() throws an InterruptedException, so be sure to 33 | * surround it with a try/catch block. 34 | */ -------------------------------------------------------------------------------- /S_Interfaces.java: -------------------------------------------------------------------------------- 1 | /** 2 | An interface is a completely abstract class that contains only abstract methods. 3 | Some specifications for interfaces: 4 | - Defined using the interface keyword. 5 | - May contain only static final variables. 6 | - Cannot contain a constructor because interfaces cannot be instantiated. 7 | - Interfaces can extend other interfaces. 8 | - A class can implement any number of interfaces. 9 | */ 10 | /* 11 | Interfaces have the following properties: 12 | - An interface is implicitly abstract. You do not need to use the abstract keyword 13 | while declaring an interface. 14 | - Each method in an interface is also implicitly abstract, so the abstract keyword is 15 | not needed. 16 | - Methods in an interface are implicitly public. 17 | */ 18 | /** 19 | * A class can inherit from just one superclass, but can implement multiple 20 | * interfaces! 21 | */ 22 | interface Animal { 23 | public void eat(); 24 | 25 | public void makeSound(); 26 | } 27 | 28 | /** 29 | * When you implement an interface, you need to override all of its methods. 30 | */ 31 | class Cat implements Animal { 32 | public void makeSound() { 33 | System.out.println("Meow"); 34 | } 35 | 36 | public void eat() { 37 | System.out.println("omnomnom"); 38 | } 39 | } 40 | 41 | class S_Interfaces { 42 | public static void main(String[] args) { 43 | Cat c = new Cat(); 44 | c.eat(); 45 | } 46 | } -------------------------------------------------------------------------------- /E_Switch.java: -------------------------------------------------------------------------------- 1 | public class E_Switch { 2 | public static void main(String[] args) { 3 | int day = 3; 4 | switch (day) { 5 | case 1: 6 | System.out.println("Monday"); 7 | break; 8 | /* 9 | * The break and continue statements change the loop's execution flow, also used 10 | * in switch The break statement terminates the loop and transfers execution to 11 | * the statement immediately following the loop. 12 | */ 13 | case 2: 14 | System.out.println("Tuesday"); 15 | break; 16 | case 3: 17 | System.out.println("Wednesday"); 18 | break; 19 | default: 20 | System.out.println("Could Be any Day"); // No break is needed in the default case, as it is always the 21 | // last statement in the switch. 22 | } 23 | } 24 | } 25 | /** 26 | * for (initialization; condition; increment/decrement) { statement(s) } 27 | * Initialization: Expression executes only once during the beginning of loop 28 | * Condition: Is evaluated each time the loop iterates. The loop executes the 29 | * statement repeatedly, until this condition returns false. 30 | * Increment/Decrement: Executes after each iteration of the loop. 31 | */ 32 | /** 33 | * do { System.out.println(x); x++; } while(x < 5); 34 | */ -------------------------------------------------------------------------------- /A_Hello_World.java: -------------------------------------------------------------------------------- 1 | class A_Hello_World { 2 | /******************************************** 3 | * - Every program in Java must have a class. - Every Java program starts from 4 | * the main method. 5 | ******************************************/ 6 | public static void main(String args[]) { 7 | System.out.println("Hello World"); 8 | } 9 | } 10 | /************************************************************************************************ 11 | * - public: anyone can access it - static: method can be run without creating 12 | * an instance of the class containing the main method - void: method doesn't 13 | * return any value - main: the name of the method 14 | **************************************************************************************************/ 15 | /************************************************************ 16 | * -Another name for a Multi-Line comment is a Block comment. 17 | ************************************************************/ 18 | /****************************************** 19 | * This is also a documentation comment 20 | ******************************************/ 21 | /*********************************************************************************************** 22 | * Javadoc is a tool which comes with JDK and it is used for generating Java 23 | * code documentation in HTML format from Java source code which has required 24 | * documentation in a predefined format. 25 | ***********************************************************************************************/ -------------------------------------------------------------------------------- /N_Polymorphism.java: -------------------------------------------------------------------------------- 1 | /** 2 | * A call to a member method will cause a different implementation to be 3 | * executed, depending on the type of the object invoking the method. Here is an 4 | * example: Dog and Cat are classes that inherit from the Animal class. Each 5 | * class has its own implementation of the makeSound() method. 6 | */ 7 | class Animal { 8 | public void makeSound() { 9 | System.out.println("Grr..."); 10 | } 11 | } 12 | 13 | class Cat extends Animal { 14 | public void makeSound() { 15 | System.out.println("Meow"); 16 | } 17 | } 18 | 19 | class Dog extends Animal { 20 | public void makeSound() { 21 | System.out.println("Woof"); 22 | } 23 | } 24 | 25 | class N_Polymorphism { 26 | public static void main(String args[]) { 27 | /** 28 | * As all Cat and Dog objects are Animal objects, 29 | */ 30 | Animal a = new Dog(); 31 | Animal b = new Cat(); 32 | /** 33 | * We've created two reference variables of type Animal, and pointed them to the 34 | * Cat and Dog objects. 35 | */ 36 | a.makeSound(); 37 | b.makeSound(); 38 | /** 39 | * As the reference variable a contains a Dog object, the makeSound() method of 40 | * the Dog class will be called. The same applies to the b variable. 41 | */ 42 | } 43 | } 44 | /** 45 | * Polymorphism, which refers to the idea of "having many forms", occurs when 46 | * there is a hierarchy of classes related to each other through inheritance. 47 | */ 48 | -------------------------------------------------------------------------------- /T_Casting.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Assigning a value of one type to a variable of another type is known as Type 3 | * Casting. 4 | */ 5 | class A { 6 | public void print() { 7 | System.out.println("A"); 8 | } 9 | } 10 | 11 | class T_Casting extends A { 12 | public void print() { 13 | System.out.println("Hello!!"); 14 | } 15 | 16 | public static void main(String[] args) { 17 | A object = new T_Casting(); 18 | T_Casting b = (T_Casting) object; 19 | b.print(); 20 | } 21 | } 22 | /** 23 | * Java supports automatic type casting of integers to floating points, since 24 | * there is no loss of precision. On the other hand, type casting is mandatory 25 | * when assigning floating point values to integer variables. 26 | */ 27 | /** 28 | * Upcasting: You can cast an instance of a subclass to its superclass. Consider 29 | * the following example, assuming that Cat is a subclass of Animal. Animal a = 30 | * new Cat(); Java automatically upcasted the Cat type variable to the Animal 31 | * type. 32 | */ 33 | /** 34 | * Casting an object of a superclass to its subclass is called downcasting. 35 | * Example: Animal a = new Cat(); ((Cat)a).makeSound(); This will try to cast 36 | * the variable a to the Cat type and call its makeSound() method. 37 | */ 38 | /** 39 | * Why is upcasting automatic, downcasting manual? Well, upcasting can never 40 | * fail. But if you have a group of different Animals and want to downcast them 41 | * all to a Cat, then there's a chance that some of these Animals are actually 42 | * Dogs, so the process fails. 43 | */ -------------------------------------------------------------------------------- /Z_Z_E_HashMap.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | 3 | class Student { 4 | private String Name; 5 | private int Age; 6 | 7 | Student(String Nam, int A) { 8 | Name = Nam; 9 | Age = A; 10 | } 11 | 12 | public void Display() { 13 | System.out.println("Name:" + Name); 14 | System.out.println("Age:" + Age); 15 | } 16 | } 17 | 18 | class Z_Z_E_HashMap { 19 | public static void main(String args[]) { 20 | String name, Regno; 21 | int Age; 22 | /* 23 | * Create a HashMap object called Data that will store String keys and 24 | * Student(Object). 25 | */ 26 | HashMap Data = new HashMap(); 27 | Scanner cin = new Scanner(System.in); 28 | for (int i = 0; i < 4; i++) { 29 | System.out.println("Enter Name:"); 30 | name = cin.nextLine(); 31 | System.out.println("Enter Age:"); 32 | Age = cin.nextInt(); 33 | cin.nextLine(); 34 | System.out.println("Enter Registration No.:"); 35 | Regno = cin.nextLine(); 36 | /* 37 | * To add items to HashMap, use the put() method: 38 | */ 39 | Data.put(Regno, new Student(name, Age)); 40 | } 41 | System.out.println("\n\nData Added Now Serching:"); 42 | System.out.println("Enter Registration No You want to search:"); 43 | Regno = cin.nextLine(); 44 | Search(Regno, Data); 45 | } 46 | 47 | public static void Search(String Regno, HashMap Data) { 48 | /* 49 | * To access a value in the HashMap, use the get() method and refer to its key: 50 | */ 51 | Data.get(Regno).Display(); 52 | } 53 | } -------------------------------------------------------------------------------- /R_Example_Abstract.java: -------------------------------------------------------------------------------- 1 | 2 | /** 3 | Example How Abstract Class Works 4 | */ 5 | import java.util.*; 6 | 7 | abstract class Bank2 { 8 | /** 9 | * A class containing an abstract method is an abstract class. 10 | */ 11 | abstract int interest(int amt); 12 | } 13 | 14 | class ICICIBank extends Bank2 { 15 | int interest(int amt) { 16 | int amt1; 17 | if (amt < 50000) { 18 | amt1 = (amt * 7 * 3) / 100; 19 | } else { 20 | amt1 = (amt * 10 * 3) / 100; 21 | } 22 | return amt1; 23 | } 24 | } 25 | 26 | class AxisBank extends Bank2 { 27 | int interest(int amt) { 28 | int amt1; 29 | if (amt < 45000) { 30 | amt1 = (amt * 5 * 3) / 100; 31 | } else { 32 | amt1 = (amt * 10 * 3) / 100; 33 | } 34 | return amt1; 35 | } 36 | } 37 | 38 | class SBIBank extends Bank2 { 39 | int interest(int amt) { 40 | int amt1; 41 | if (amt < 51000) { 42 | amt1 = (amt * 8 * 3) / 100; 43 | } else { 44 | amt1 = (amt * 10 * 3) / 100; 45 | } 46 | return amt1; 47 | } 48 | } 49 | 50 | class R_Example_Abstract { 51 | public static void main(String[] args) { 52 | Scanner cin = new Scanner(System.in); 53 | int amt, amtsbi, amtaxis, amticici; 54 | System.out.println("Enter The Amount You Want to \"Deposit:\""); 55 | System.out.println(""); 56 | amt = cin.nextInt(); 57 | Bank2 i1 = new ICICIBank(); 58 | amticici = i1.interest(amt); 59 | Bank2 i2 = new SBIBank(); 60 | amtsbi = i2.interest(amt); 61 | Bank2 i3 = new AxisBank(); 62 | amtaxis = i3.interest(amt); 63 | if (amtaxis > amtsbi) { 64 | if (amtaxis > amticici) { 65 | System.out.println("Axis Bank:" + amtaxis); 66 | } else { 67 | System.out.println("ICICI Bank:" + amticici); 68 | } 69 | } else { 70 | if (amtsbi > amticici) { 71 | System.out.println("SBI:" + amtsbi); 72 | } else { 73 | System.out.println("ICICI:" + amtsbi); 74 | } 75 | } 76 | } 77 | } -------------------------------------------------------------------------------- /L_Inheritance_And_Encapsulation.java: -------------------------------------------------------------------------------- 1 | /** 2 | Encapsulation: 3 | The idea behind encapsulation is to ensure that implementation details are 4 | not visible to users. The variables of one class will be hidden from the 5 | other classes, accessible only through the methods of the current class. 6 | This is called data hiding. 7 | To achieve encapsulation in Java, declare the class' variables as private 8 | and provide public setter and getter methods to modify and view the variables' 9 | values. 10 | In summary, encapsulation provides the following benefits: 11 | - Control of the way data is accessed or modified 12 | - More flexible and easily changed code 13 | - Ability to change one part of the code without affecting other parts 14 | */ 15 | /** 16 | * Inheritance: Inheritance is the process that enables one class to acquire the 17 | * properties (methods and variables) of another. With inheritance, the 18 | * information is placed in a more manageable, hierarchical order. The class 19 | * inheriting the properties of another is the subclass (also called derived 20 | * class, or child class); the class whose properties are inherited is the 21 | * superclass (base class, or parent class). 22 | */ 23 | class Animal { 24 | protected int legs; 25 | 26 | /** 27 | * protected access modifier, makes the members visible only to the subclasses. 28 | */ 29 | public void eat() { 30 | System.out.println("Animal eats, Legs:" + legs); 31 | } 32 | } 33 | 34 | class Dog extends Animal { 35 | /** 36 | * When one class is inherited from another class, it inherits all of the 37 | * superclass' non-private variables and methods. 38 | */ 39 | Dog() { 40 | legs = 4; 41 | } 42 | } 43 | 44 | class L_Inheritance_And_Encapsulation { 45 | public static void main(String[] args) { 46 | Dog d = new Dog(); 47 | d.eat(); 48 | } 49 | } -------------------------------------------------------------------------------- /Z_Z_C_DeserializationClass.java: -------------------------------------------------------------------------------- 1 | import java.io.*; //Contains Serializable Interface 2 | import java.util.*; //Conatins Scanner 3 | 4 | class Emp implements Serializable { 5 | public String name; 6 | public String address; 7 | } 8 | 9 | public class Z_Z_C_DeserializationClass { 10 | public static void main(String[] args) throws IOException, ClassNotFoundException { 11 | Emp e = null; 12 | /************************************************************************* 13 | * We Will Create an object that is null as we will store data from file into 14 | * the object in try block 15 | *************************************************************************/ 16 | Scanner cin = new Scanner(System.in); 17 | System.out.print("Enter The File Form Where You Want To Retrieve The data:"); 18 | String file_name = cin.nextLine(); 19 | try { 20 | // Reading the object from a file 21 | FileInputStream file = new FileInputStream(file_name); 22 | ObjectInputStream in = new ObjectInputStream(file); 23 | /********************************************************************* 24 | * As The file will have data of object, we will createte an object of 25 | * ObjectInputStream to read the data from the file and store it in an object 26 | * using readObject method 27 | *********************************************************************/ 28 | e = (Emp) in.readObject(); 29 | /******************************************************************** 30 | * We Will Be Read data with readObject() method and will store it in e object 31 | * of Emp class 32 | ********************************************************************/ 33 | in.close(); 34 | file.close(); 35 | /******************************************************************* 36 | * Close Both Input Stream 37 | *******************************************************************/ 38 | System.out.println("Name:" + e.name); 39 | System.out.println("Address:" + e.address); 40 | /****************************************************************** 41 | * We Will Show all the data That has been retrived from the file 42 | *******************************************************************/ 43 | } catch (IOException ex) { 44 | System.out.println("IOException is caught"); 45 | } 46 | cin.close(); 47 | } 48 | } -------------------------------------------------------------------------------- /G_OOP.java: -------------------------------------------------------------------------------- 1 | class G_OOP { 2 | /**************************************************************************************** 3 | * A class describes what the object will be, but is separate from the object 4 | * itself. In other words, classes can be described as blueprints, descriptions, 5 | * or definitions for an object. You can use the same class as a blueprint for 6 | * creating multiple objects. The first step is to define the class, which then 7 | * becomes a blueprint for object creation. In other words, an object is an 8 | * instance of a class. 9 | ******************************************************************************************/ 10 | static void sayHello(String name) { 11 | /************************************************************************************** 12 | * Methods define behavior. A method is a collection of statements that are 13 | * grouped together to perform an operation. System.out.println() is an example 14 | * of a method. 15 | ***************************************************************************************/ 16 | System.out.println("Hello !! " + name); 17 | } 18 | 19 | public static void main(String args[]) { 20 | /*********************************************************************************** 21 | * public static void main(String args[]) - This definition indicates that the 22 | * main method takes an array of Strings as its parameters, and does not return 23 | * a value. 24 | **********************************************************************************/ 25 | sayHello("David"); 26 | /*********************************************************************************** 27 | * The advantages of using methods instead of simple statements include the 28 | * following: - code reuse: You can write a method once, and use it multiple 29 | * times, without having to rewrite the code each time. - parameters: Based on 30 | * the parameters passed in, methods can perform various actions. 31 | **********************************************************************************/ 32 | } 33 | } 34 | /*********************************************************************************** 35 | * There are 4 core concepts in OOP: encapsulation, inheritance, polymorphism, 36 | * and abstraction. 37 | **********************************************************************************/ -------------------------------------------------------------------------------- /F_Array.java: -------------------------------------------------------------------------------- 1 | public class F_Array { 2 | public static void main(String[] args) { 3 | /* 4 | * To declare an array, you need to define the type of the elements with square 5 | * brackets. For example, to declare an array of integers: 6 | */ 7 | int[] arr; 8 | /** 9 | * Now, you need to define the array's capacity, or the number of elements it 10 | * will hold. To accomplish this, use the keyword new. 11 | */ 12 | arr = new int[5]; 13 | /** 14 | * To reference elements in an array, type the name of the array followed by the 15 | * index position within a pair of square brackets. 16 | */ 17 | arr[2] = 42; 18 | String[] myNames = { "A", "B", "C", "D" }; 19 | /** 20 | * Sometimes you might see the square brackets placed after the array name, 21 | * which also works, but the preferred way is to place the brackets after the 22 | * array's data type. 23 | */ 24 | System.out.println(myNames[2]); 25 | int[] intArr = new int[5]; 26 | /** 27 | * You can access the length of an array (the number of elements it stores) via 28 | * its length property. 29 | */ 30 | System.out.println(intArr.length); 31 | int[] myArr1 = { 6, 42, 3, 7 }; 32 | int sum = 0; 33 | for (int z = 0; z < myArr1.length; z++) { 34 | /** 35 | * as the last element's index is myArr.length-1. 36 | */ 37 | sum += myArr1[z]; 38 | } 39 | System.out.println(sum); 40 | int[] primes = { 2, 3, 5, 7 }; 41 | /** 42 | * The enhanced for loop (sometimes called a "for each" loop) is used to 43 | * traverse elements in arrays. 44 | */ 45 | for (int t : primes) { 46 | System.out.println(t); 47 | } 48 | /** 49 | * The enhanced for loop declares a variable of a type compatible with the 50 | * elements of the array being accessed. The variable will be available within 51 | * the for block, and its value will be the same as the current array 52 | * element.So, on each iteration of the loop, the variable t will be equal to 53 | * the corresponding element in the array. 54 | */ 55 | /** 56 | * =====================================MULTIDIMENTIONAL 57 | * ARRAY==================================== 58 | */ 59 | int[][] sample = { { 1, 2, 3 }, { 4, 5, 6 } }; 60 | int x = sample[1][0]; // The array's two indexes are called row index and column index. 61 | System.out.println(x); // Outputs 4 62 | int[][] myArr = { { 1, 2, 3 }, { 4 }, { 5, 6, 7 } }; 63 | myArr[0][2] = 42; 64 | x = myArr[1][0]; // x=4 65 | } 66 | } -------------------------------------------------------------------------------- /Z_Z_B_SerializationClass.java: -------------------------------------------------------------------------------- 1 | import java.io.*; //Contains Serializable Interface 2 | import java.util.*; //Conatins Scanner 3 | 4 | class Emp implements Serializable { 5 | /******************************************************** 6 | * We Are Implementing Serializable Interface with Emp Class Because We want to 7 | * make this class objects into stream of Bytes 8 | **********************************************************/ 9 | public String name; 10 | public String address; 11 | } 12 | 13 | public class Z_Z_B_SerializationClass { 14 | public static void main(String[] args) { 15 | String file_name; 16 | Scanner cin = new Scanner(System.in); // For takin user input 17 | Emp e = new Emp(); // Making An Object of Emp 18 | System.out.print("Enter Name:"); 19 | e.name = cin.nextLine(); 20 | System.out.print("Enter Address:"); 21 | e.address = cin.nextLine(); 22 | try { 23 | System.out.print("Enter The File Name Where You want to store the Data(Add .txt):"); 24 | file_name = cin.nextLine(); 25 | FileOutputStream file1 = new FileOutputStream(file_name); 26 | /***************************************************** 27 | * The Above Line Shows That The ByteStream of Emp's Object Will be stored in a 28 | * perticular file given in parentheseis. 29 | *****************************************************/ 30 | ObjectOutputStream out = new ObjectOutputStream(file1); 31 | /***************************************************** 32 | * We create an object of ObjectOutputStream with the constructor with a 33 | * parameter of Object of FileOutputStream 34 | ******************************************************/ 35 | out.writeObject(e); 36 | /***************************************************** 37 | * The Above Function is Present In ObjectOutputStream writeObject will take a 38 | * parameter of object that we want to write in a file. 39 | *****************************************************/ 40 | out.close(); 41 | file1.close(); 42 | /***************************************************** 43 | * We will close both the objects 44 | *****************************************************/ 45 | System.out.println("Data Has Been Stored in " + file_name); 46 | } catch (IOException l) { 47 | /**************************************************** 48 | * If An Exception Is Caught, this catch part will run 49 | ****************************************************/ 50 | l.printStackTrace(); 51 | } 52 | } 53 | } -------------------------------------------------------------------------------- /H_Objects.java: -------------------------------------------------------------------------------- 1 | class Animal { 2 | void bark() { 3 | System.out.println("Woof-Woof"); 4 | } 5 | } 6 | 7 | class Vehicle { 8 | private String color; 9 | 10 | /********************************************************************** 11 | * Constructor A constructor can be used to provide initial values for object 12 | * attributes. - A constructor name must be same as its class name. - A 13 | * constructor must have no explicit return type. 14 | ************************************************************************/ 15 | Vehicle() { 16 | color = "Red"; 17 | } 18 | 19 | Vehicle(String c) { 20 | this.setColor(c); 21 | } 22 | 23 | /*********************************************************************************** 24 | * Java automatically provides a default constructor, so all classes have a 25 | * constructor, whether one is specifically defined or not. 26 | *************************************************************************************/ 27 | 28 | // Getter 29 | public String getColor() { 30 | return color; 31 | } 32 | 33 | // Setter 34 | public void setColor(String c) { 35 | this.color = c; 36 | } 37 | /********************************************************************* 38 | * Getters and setters are fundamental building blocks for encapsulation, 39 | **********************************************************************/ 40 | } 41 | 42 | class H_Objects { 43 | public static void main(String[] args) { 44 | Animal dog = new Animal(); 45 | dog.bark(); 46 | /*********************************************************************** 47 | * Now, dog is an object of type Animal. Thus we can call its bark() method, 48 | * using the name of the object and a dot. The dot notation is used to access 49 | * the object's attributes and methods. 50 | ************************************************************************/ 51 | Vehicle v1 = new Vehicle(); 52 | v1.setColor("Green"); 53 | System.out.println(v1.getColor()); 54 | Vehicle v2 = new Vehicle("Blue"); 55 | System.out.println(v2.getColor()); 56 | } 57 | } 58 | /********************************************************************************** 59 | * default: A variable or method declared with no access control modifier is 60 | * available to any other class in the same package. public: Accessible from any 61 | * other class. protected: Provides the same access as the default access 62 | * modifier, with the addition that subclasses can access protected methods and 63 | * variables of the superclass private: Accessible only within the declared 64 | * class itself. 65 | ***********************************************************************************/ 66 | -------------------------------------------------------------------------------- /Z_Z_D_Files.java: -------------------------------------------------------------------------------- 1 | import java.io.File; 2 | import java.io.FileNotFoundException; 3 | import java.util.*; 4 | import java.io.IOException; 5 | import java.io.FileWriter; 6 | import java.io.FileReader; 7 | 8 | class Z_Z_D_Files { 9 | static void Create_A_File() { 10 | Scanner cin = new Scanner(System.in); 11 | System.out.println("Enter the File you want to create(With Extention):"); 12 | String file_name = cin.nextLine(); 13 | try { 14 | File myObj = new File(file_name); 15 | if (myObj.createNewFile()) { 16 | System.out.println("File created: " + myObj.getName()); 17 | } else { 18 | System.out.println("File already exists."); 19 | } 20 | } catch (IOException e) { 21 | System.out.println("An error occurred."); 22 | e.printStackTrace(); 23 | } 24 | } 25 | 26 | static void Read_File() { 27 | Scanner cin = new Scanner(System.in); 28 | System.out.println("Enter The File You want to Read:(With Extention)"); 29 | String file_name = cin.nextLine(); 30 | try { 31 | File file1 = new File(file_name); 32 | Scanner fin = new Scanner(file1); 33 | while (fin.hasNextLine()) { 34 | String lines = fin.nextLine(); 35 | System.out.println(lines); 36 | } 37 | fin.close(); 38 | } catch (FileNotFoundException e) { 39 | System.out.println("An Error Occurred."); 40 | e.printStackTrace(); 41 | } 42 | } 43 | 44 | static void Write_A_File() { 45 | String choice; 46 | Scanner cin = new Scanner(System.in); 47 | System.out.println("Enter The File You want to Write:(With Extention)"); 48 | String file_name = cin.nextLine(); 49 | try { 50 | System.out.println("Do you want to Append in the File(y/n):"); 51 | choice = cin.nextLine(); 52 | if (choice.equals("Yes") || choice.equals("yes") || choice.equals("y") || choice.equals("Y")) { 53 | FileWriter file1 = new FileWriter(file_name, true); 54 | System.out.println("Enter the text you want to write in the file."); 55 | String Text_In_File = cin.nextLine(); 56 | file1.write(Text_In_File); 57 | file1.close(); 58 | } else { 59 | FileWriter file1 = new FileWriter(file_name); 60 | System.out.println("Enter the text you want to write in the file."); 61 | String Text_In_File = cin.nextLine(); 62 | file1.write(Text_In_File); 63 | file1.close(); 64 | } 65 | System.out.println("Successfully wrote to the file."); 66 | } catch (IOException e) { 67 | System.out.println("An error occurred."); 68 | e.printStackTrace(); 69 | } 70 | } 71 | 72 | static void Delete_A_File() { 73 | Scanner cin = new Scanner(System.in); 74 | System.out.println("Enter The File You want to Delete:(With Extention)"); 75 | String file_name = cin.nextLine(); 76 | File file1 = new File(file_name); 77 | if (file1.delete()) { 78 | System.out.println("Deleted the file: " + file1.getName()); 79 | } else { 80 | System.out.println("Failed to delete the file."); 81 | } 82 | } 83 | 84 | static void Delete_A_Folder() { 85 | Scanner cin = new Scanner(System.in); 86 | System.out.println("Enter The Folder You want to Delete:"); 87 | String folder = cin.nextLine(); 88 | File myObj = new File(folder); 89 | if (myObj.delete()) { 90 | System.out.println("Deleted the folder:" + myObj.getName()); 91 | } else { 92 | System.out.println("Failed to delete the folder."); 93 | } 94 | } 95 | 96 | static void Know_A_File() { 97 | Scanner cin = new Scanner(System.in); 98 | System.out.println("Enter The File You want to Know About:(With Extention)"); 99 | String file_name = cin.nextLine(); 100 | File file1 = new File(file_name); 101 | if (file1.exists()) { 102 | System.out.println("File name: " + file1.getName()); 103 | System.out.println("File size in bytes " + file1.length()); 104 | System.out.println("Absolute path: " + file1.getAbsolutePath()); 105 | System.out.println("Readable " + file1.canRead()); 106 | System.out.println("Writeable: " + file1.canWrite()); 107 | } else { 108 | System.out.println("Error:The file does not exist."); 109 | } 110 | } 111 | 112 | public static void main(String[] args) { 113 | int ch; 114 | String choice; 115 | boolean looper = true; 116 | Scanner cin = new Scanner(System.in); 117 | while (looper == true) { 118 | System.out.println("1.Create A File"); 119 | System.out.println("2.Read A File"); 120 | System.out.println("3.Write A File"); 121 | System.out.println("4.Delete a file"); 122 | System.out.println("5.Delete a folder(Empty)"); 123 | System.out.println("6.Know A File"); 124 | System.out.print("Enter Your Choice:"); 125 | ch = cin.nextInt(); 126 | switch (ch) { 127 | case 1: 128 | Create_A_File(); 129 | break; 130 | case 2: 131 | Read_File(); 132 | break; 133 | case 3: 134 | Write_A_File(); 135 | break; 136 | case 4: 137 | Delete_A_File(); 138 | break; 139 | case 5: 140 | Delete_A_Folder(); 141 | break; 142 | case 6: 143 | Know_A_File(); 144 | break; 145 | default: 146 | System.out.println("Enter A Valid Choice"); 147 | break; 148 | } 149 | cin.nextLine(); 150 | System.out.println("Do You want To Perform More Operations[Yes/No]"); 151 | choice = cin.nextLine(); 152 | if (choice.equals("Yes") || choice.equals("yes") || choice.equals("y") || choice.equals("Y")) { 153 | looper = true; 154 | } else { 155 | looper = false; 156 | } 157 | } 158 | } 159 | } --------------------------------------------------------------------------------