{"id":22016254,"url":"https://github.com/uxxhans/rainbow-cats-general-java-programming-notes","last_synced_at":"2025-03-23T09:15:34.450Z","repository":{"id":119242652,"uuid":"501296838","full_name":"UxxHans/Rainbow-Cats-General-Java-Programming-Notes","owner":"UxxHans","description":"General Java Programming Notes","archived":false,"fork":false,"pushed_at":"2022-06-09T13:21:13.000Z","size":61,"stargazers_count":1,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-28T15:49:03.642Z","etag":null,"topics":["java","note","programming"],"latest_commit_sha":null,"homepage":"","language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/UxxHans.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-06-08T14:55:48.000Z","updated_at":"2023-10-09T11:58:35.000Z","dependencies_parsed_at":null,"dependency_job_id":"a0354bde-dbe5-46b2-a287-757dd563f788","html_url":"https://github.com/UxxHans/Rainbow-Cats-General-Java-Programming-Notes","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/UxxHans%2FRainbow-Cats-General-Java-Programming-Notes","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/UxxHans%2FRainbow-Cats-General-Java-Programming-Notes/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/UxxHans%2FRainbow-Cats-General-Java-Programming-Notes/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/UxxHans%2FRainbow-Cats-General-Java-Programming-Notes/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/UxxHans","download_url":"https://codeload.github.com/UxxHans/Rainbow-Cats-General-Java-Programming-Notes/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245078201,"owners_count":20557283,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["java","note","programming"],"created_at":"2024-11-30T04:33:56.550Z","updated_at":"2025-03-23T09:15:34.423Z","avatar_url":"https://github.com/UxxHans.png","language":null,"readme":"# **Rainbow Cats General Java Programming Notes**\r\n\r\n## **JDK \u0026 Gradle Settings**\r\n#### **Install JDL \u0026 Gradle**\r\n- https://www.oracle.com/java/technologies/downloads/#java11\r\n- https://gradle.org/\r\n#### **Check or Add Environment Variables (In Advanced System Settings)**\r\n- `Name: JAVA_TOOL_OPTIONS` | `Value: -Duser.language=en`\r\n- `Name: JAVA_HOME` | `Value: X:\\...\\Java\\jdk-18.0.1.1`\r\n- `Name: Path` | `Value: X:\\...\\Common Files\\Oracle\\Java\\javapath`\r\n- `Name: Path` | `Value: X:\\...\\Java\\jdk-18.0.1.1\\bin`\r\n- `Name: Path` | `Value: X:\\...\\Gradle\\gradle-7.4.2\\bin`\r\n#### **Check Installation in Command Line**\r\n- `javac -version`\r\n- `gradle -version`\r\n#### **Run Java Programs in Command Line**\r\n- Compile the program in terminal: `javac myProgram.java`\r\n- If nothing goes wrong in the code, we can run the program in terminal: `java myProgram`\r\n- To stop the program in terminal, use `Ctrl + D`.\r\n\r\n## **Access Modifier**\r\n- `public` Accessible everywhere. _[Classes, attributes, methods and constructors.]_\r\n- `default` Only within package. _[Classes, attributes, methods and constructors.]_\r\n- `private` Only within the class. _[Attributes, methods and constructors.]_\r\n- `protected` Within the class. Outside the class through inheritance only. _[Attributes, methods and constructors.]_\r\n```java\r\n//Accessible everywhere\r\npublic class someClass{\r\n    public int someVariable;\r\n    public void func(){\r\n        //Do something.\r\n    }\r\n}\r\n```\r\n\r\n## **Non-Access Modifiers**\r\n- `final` The class cannot be inherited by other classes. Attributes and methods cannot be overridden or modified.\r\n- `static` Attributes and methods belongs to the class, rather than an object.\r\n- `abstract` Can only be used on classes and methods (Only be used in an abstract class). The abstract class cannot be used to create objects. The abstract method does not have a body.\r\n- `transient` Attributes and methods are skipped when serializing the object containing them.\r\n- `synchronized` Methods can only be accessed by one thread at a time.\r\n- `volatile` The value of an attribute is not cached thread-locally, and is always read from the \"main memory\".\r\n```java\r\n//The abstract class cannot be used to create objects.\r\npublic abstract class someClass{\r\n    //Accessible anywhere outside the class and it belongs to the class. \r\n    //Call it through class instead of instances.\r\n    //It can not be changed and worked as a constant.\r\n    private static final int someVariable;\r\n    //The abstract method does not have a body.\r\n    public abstract void func();\r\n}\r\n```\r\n\r\n## **Call Stack**\r\n- Java is a stack-based language so when a method is executed it is put onto a **call-stack**. \r\n- The method being executed at the **top of the stack** is the **most recently called method**.\r\n- The method **finishes** executing once it has reached a **return state** or the **end of method scope** for void method.\r\n\r\n## **Array**\r\n- Array is a contiguous block of memory containing multiple values of the same type. \r\n- When the array is initialized, it will be allocated and will return the address of where the array is stored.\r\n- Array can store both primitive types (values) and reference (pointers) types.\r\n#### **General rules with array initialization**\r\n- Primitive integer types (byte, short, int, long) are initialized to `0 by default`.\r\n- Default value of elements of a boolean array are `false`.\r\n- Floating point numbers such as float and double are initialized to `0.0f` and `0.0d` respectively.\r\n- Elements of a char array is initialized to `\\u0000` (`null` character).\r\n- Any `Reference type` is initialized to `null`.\r\n```java\r\n//---------One-dimensional Arrays Initialization---------\r\nint[] numbers01 = new int[16];            //Initialize with length.\r\nint[] numbers02 = {1, 2, 3, 4, 5};        //Static initialization.\r\nint[] numbers03 = new int[]{1, 2, 3, 4};  //Similarly, we can also initialize using this.\r\n\r\n//Traverse through the array.\r\nfor(int i=0; i\u003cnumbers02.length; i++){\r\n    //Do stuff.\r\n}\r\n\r\n//---------Multi-dimensional Arrays Initialization---------\r\nint[][] array = new int[3][3];  //Matrix-like structure.\r\nint[][] jarray = new int[3][];  //Jagged array. (Different column size on fixed rows count)\r\n\r\n//Defining different column size of a Jagged array.\r\njarray[0] = new int[5];         \r\njarray[1] = new int[10];\r\n\r\n//Traverse through an array.\r\nfor(int y=0; y\u003cjarray.length; y++){\r\n    for(int x=0; x\u003cjarray[y].length; x++){\r\n        //Do stuff.\r\n    }\r\n}\r\n```\r\n\r\n## **Strings**\r\n- String is **a reference type** that aggregates characters and Java treats Strings as **immutable** (will not be able to change later).\r\n```java\r\n//Creates a Meow at a new Memory Address.\r\nString cat = \"Meow\";\r\n//Creates another literial \"Meow, says the cat!\" at another address\r\n//Bind the memory address to the cat variable.\r\ncat += \", says the cat!\"\r\n```\r\n### **String Pool**\r\n- To optimise the memory usage, the compiler will use the `same allocation` and provide the same reference to a string variable of refers to the `same literal`.\r\n- This means once a string literial is specified, it will be `added to a string pool`. After that, other string variables that is using the `same literial` will have the `same memory allocation`.\r\n```java\r\n//Case 1: Output is true. As Meow is already in the string pool,\r\n//cat1 and cat2 are using the same memory address.\r\nString cat1 = \"Meow\";   //0x100\r\nString cat2 = \"Meow\";   //0x100\r\nSystem.out.println(cat1 == cat2);\r\n\r\n//Case 2: Output is false. Because of the keyword new,\r\n//it specifically creates a literial using the new memory address.\r\nString cat1 = \"Meow\";               //0x100\r\nString cat2 = new String(\"Meow\");   //0x200\r\nSystem.out.println(cat1 == cat2);\r\n```\r\n### **Comparing Strings**\r\n- Use method to compare strings properly\r\n```java\r\nString cat1 = \"Meow\";\r\nString cat2 = \"Meow\";\r\n//The output is true. To compare strings properly, we need to use methods.\r\nSystem.out.println(cat1.equals(cat2));\r\n```\r\n\r\n## **ArrayList (Dynamic Array)**\r\nArrayList creates a new array that **doubles the size of the previous array** every time the size **exceeds the limit**, it copys the elements in the previous one to the new extended array and point the pointer to it.\r\n\r\n**Syntax:**\r\n```java\r\nList\u003cReferenceType\u003e name = new ListType\u003cReferenceType\u003e(SizeDefault10);\r\n```\r\n**Methods:**\r\n- `.add(T element)` Add the element to the end of the list.\r\n- `.add(int index, T element)` Inserts the element at the index position, shift the element previously at the index to the right.\r\n- `.set(int index, T element)` Replace the element at the index to the element given.\r\n- `.remove(int index)` Remove the element at the specific index and shift all to the left.\r\n- `.remove(Object obj)` Remove the element and shift all to the left.\r\n- `.get(int index)` Get element at specific index.\r\n- `.size()` Get the size of the list.\r\n- `.clear()` Remove every element in the list.\r\n\r\n**For more instructions:**\r\n*https://docs.oracle.com/javase/8/docs/api/java/util/ArrayList.html*\r\n\r\n## **LinkedList**\r\n- A linked list does not have an array containing all the elements stored. **It chains elements** and their values. Each element is located in arbitary memory address.\r\n- Each element in the linked list is known as a `Node`. Each node contains a `value` and a `link to the next element`. To store a linked list, simply store the head of the list so we can access every element.\r\n\r\n**Traverse Through a Linked List:**\r\n```java\r\npublic int traverseGetSum(Node head){\r\n    Node current = head;\r\n    int sum = 0;\r\n    while(current != null){\r\n        sum += current.value;\r\n        current = current.next;\r\n    }\r\n    return sum;\r\n}\r\n\r\npublic int traverseGetSize(Node head){\r\n    Node current = head;\r\n    int sum = 0;\r\n    while(current != null){\r\n        sum += 1;\r\n        current = current.next;\r\n    }\r\n    return sum;\r\n}\r\n\r\npublic void traverseAddNode(Node toBeAdded){\r\n    if(head == null) {\r\n        head = toBeAdded;\r\n    }else{\r\n        Node current = head;\r\n        while(current.next != null){\r\n            current = current.next;\r\n        }\r\n        current.next = toBeAdded;\r\n    }\r\n}\r\n\r\npublic int traverseRecursiveGetSize(Node node){\r\n    if(node!=null){\r\n        return traverseGetSize(node.next) + 1;\r\n    }else{\r\n        return 0;\r\n    }\r\n}\r\n```\r\n\r\n## **HashMap**\r\n- Works as a dictionary in java.\r\n\r\n**Methods:**\r\n- `.put(K,V)` _Add element._\r\n- `.replace(K, V)` _Replaces the entry only if it is mapped to some value._\r\n- `.get(K)` _Get value using key._\r\n- `.remove(K)` _Remove the mapping for the specified key._\r\n- `.clear()` _Remove all mappings from the map._\r\n- `.entrySet()` _Get all elements._\r\n- `.containsKey(K)` _Returns true if this map contains key._\r\n\r\n**For more instructions:** https://docs.oracle.com/javase/8/docs/api/java/util/HashMap.html\r\n``` java\r\n//Initialization\r\nHashMap\u003cK,V\u003e hashMap = new HashMap\u003cK,V\u003e();\r\n\r\n//Iterate Through the HashMap\r\nfor(HashMap.Entry e : hashMap.entrySet()){\r\n    System.out.println(e.getKey()+\" \"+e.getValue());\r\n}\r\n```\r\n\r\n## **Classes**\r\nThere are two main types: **Primitive types** and **Reference types**.\r\n- Reference types are classes. \r\n- Class defines a type of object that can be reused.\r\n- Every class that we created will have a constructor. Even there is no constructor defined in code, java will create a constructor automatically.\r\n```java\r\npublic class myClass{\r\n    public int variableA;\r\n    public int variableB;\r\n\r\n    //Constructor, will be called when object is created.\r\n    public myClass(int variableA, int variableB){\r\n        //this.variableA means we are referring to the variableA in the class,\r\n        //not the local function argument.\r\n        this.variableA = variableA;\r\n        this.variableB = variableB\r\n    }\r\n}\r\n```\r\n\r\n## **UML Diagram**\r\n**Access Modifier:**\r\n- `[ + ]` public\r\n- `[ - ]` private\r\n- `[ # ]` protected\r\n\r\n**Non-Access Modifier:**\r\n- `[ UnderLine ]` static\r\n- `[ ALL_CAPITAL ]` final\r\n- `[ Italic ]` abstract\r\n\r\n**Others:**\r\n- Name at the top\r\n- `[ \u003c\u003cInterface\u003e\u003e \u003c\u003cEnumeration\u003e\u003e ]` Above the name\r\n\r\n**Syntax:**\r\n- `[ Name : Type ]` Variables\r\n- `[ Name(Name: Type, Name: Type) : Return Type ]` Functions\r\n- Subclasses points **solid arrows** to **Superclasses**.\r\n- Classes points **dashed arrows** to **implemented interfaces**.\r\n- Classes with **generic type** will show the type in a **dashed line box** at top right corner.\r\n\r\n## **Scanner \u0026 Binary I/O**\r\nWe can use methods in `Scanner`, `DataOutputStream` and `DataInputStream`.\r\n\r\n**Read Input: (Scanner)**\r\n```java\r\nimport java.util.Scanner;\r\nimport java.util.InputMismatchException;\r\n\r\npublic class ScannerTest {\r\n    /**\r\n     * The main function of the class.\r\n     * @param args String arguments.\r\n     */\r\n    public static void main(String[] args){\r\n        try{\r\n            Scanner scanner = new Scanner(System.in);\r\n            while(scanner.hasNextLine()){\r\n                int line = scanner.nextInt();\r\n                System.out.println(\"You Entered: \" + line);\r\n            }\r\n            scanner.close();\r\n\r\n        }catch(InputMismatchException e){\r\n            System.out.println(\"Must input numbers.\");\r\n            return;\r\n        }\r\n    }\r\n}\r\n```\r\n\r\n**Read File: (Scanner)**\r\n```java\r\nimport java.io.File;\r\nimport java.io.FileNotFoundException;\r\nimport java.util.Scanner;\r\n\r\npublic class ScannerTest {\r\n    /**\r\n     * The main function of the class.\r\n     * @param args String arguments.\r\n     */\r\n    public static void main(String[] args){\r\n        readPrintFile(null);\r\n    }\r\n\r\n    public static void readPrintFile(String fileName){\r\n        try{\r\n            File file = new File(fileName);\r\n            Scanner scanner = new Scanner(file);\r\n            while(scanner.hasNextLine()){\r\n                String line = scanner.nextLine();\r\n                System.out.println(line);\r\n            }\r\n            scanner.close();\r\n\r\n        }catch(FileNotFoundException e){\r\n            System.out.println(\"No such file.\");\r\n            return;\r\n        }catch(NullPointerException e){\r\n            System.out.println(\"Path given is null.\");\r\n        }\r\n    }\r\n}\r\n```\r\n\r\n**Write: (Binary I/O)**\r\n```java\r\nimport java.io.DataOutputStream;\r\nimport java.io.FileOutputStream;\r\nimport java.io.FileNotFoundException;\r\nimport java.io.IOException;\r\n\r\npublic class BinaryWriter{\r\n    public static void main(String[] args){\r\n        try{\r\n            //Creates a binary file .bin\r\n            FileOutputStream file = new FileOutputStream(\"newFile.bin\");\r\n            DataOutputStream writer = new DataOutputStream(file);\r\n            writer.writeInt(5);\r\n            writer.close();\r\n        }catch(FileNotFoundException e){\r\n            e.printStackTrace();\r\n        }catch(IOException e){\r\n            e.printStackTrace();\r\n        }\r\n    }\r\n}\r\n```\r\n\r\n**Read: (Binary I/O)**\r\n```java\r\nimport java.io.DataInputStream;\r\nimport java.io.FileInputStream;\r\nimport java.io.FileNotFoundException;\r\nimport java.io.IOException;\r\n\r\npublic class BinaryWriter{\r\n    public static void main(String[] args){\r\n        try{\r\n            //Loads in a binary file .bin\r\n            FileInputStream file = new FileInputStream(\"newFile.bin\");\r\n            DataInputStream reader = new DataInputStream(file);\r\n            int n = reader.readInt();\r\n            System.out.println(n);\r\n        }catch(FileNotFoundException e){\r\n            e.printStackTrace();\r\n        }catch(IOException e){\r\n            e.printStackTrace();\r\n        }\r\n    }\r\n}\r\n```\r\n\r\n**Read Binary File in Terminal:**\r\n```\r\nxxd -b newFile.bin\r\n```\r\n\r\n## **Stack and Heap**\r\n- The stack memory has **limited size**. In **JVM** by default, the stack memory limit is **1MB**.\r\n- **A stack frame** can be thought of an instance of a method.\r\n- **The heap** is separate memory space for which objects are **dynamically allocated**.\r\n- Similar to malloc(), whenever we use **a `new` keyword**, memory for the object is **allocated on the heap** and an address is returned.\r\n- When there is **no pointer pointing to the memory loaction**, the memory will **become free automatically** handled by `Java Garbage Collector`. There is no manual deallocation anymore. So we don't need to worry about the memory leak.\r\n\r\n## **Inheritance**\r\n- Inheritance is a **significant concept of OOP**. Allowing **reuseability and changes** to inherited methods between different types in a hierarchy.\r\n- If in the parent class we have a method, then in the child class we will have that method too, and we can override the method in the child class.\r\n\r\n**What does inheritance offer?**\r\n- Attribute and method reusability.\r\n- Defining sub-class methods in parent.\r\n- Overriding (Make some change) inherited methods.\r\n- Type information.\r\n\r\n**Note:**\r\n- **Superclass does not know** about its **subclasses**\r\n- Subclasses cannot be constructed using a superclass constructor.\r\n- You **cannot use subclass properties through a superclass** binding.\r\n- Private is not inherited, **only protected and public is inherited**.\r\n- Ensure the relationship between the superclass and subclass satisfy an **is-a relationship**.\r\n- A class can **only inherit from 1 class**.\r\n- In UML inheritance is shown as a **Generalization**.\r\n\r\n**Syntax: (How do we use it?)**\r\n```java\r\n[Access Modifier] class ClassName extends SuperClassName{\r\n    //Content of the class.\r\n}\r\n\r\n//Example of inheritance\r\n\r\n//Animal.java\r\npublic class Animal{\r\n    public String name;\r\n\r\n    public Animal(String name){\r\n        this.name = name;\r\n    }\r\n\r\n    public void eat(){\r\n        System.out.println(name + \" is eating.\");\r\n    }\r\n}\r\n\r\n//Dog.java\r\npublic class Dog extends Animal{\r\n    public Dog(String name){\r\n        //Use super keyword to access the parent constructor. \r\n        super(name);\r\n    }\r\n\r\n    public void makeSound(){\r\n        System.out.println(\"Woof!\");\r\n    }\r\n}\r\n```\r\n\u003e**Note:** In this case, we must access the parent constructor to create the object. Java will not automatically generate a parameterless constructor because we already declared a constructor. If we don't access the parent constructor, java will not know what value to put in the parameter of the only parent constructor. Therefore, it's safe to always explictly access the parent constructor in the child constructor.\r\n\r\n**Encapsulation:**\r\nWhat does `protected` means?\r\n- It is only accessible within the class\r\n- Attributes and methods will be accessible by all subclass\r\n\r\n**Create Inheritance When:**\r\nThere are two types of relationships we will look at when it comes to inheritance.\r\n\r\n- **Is-a relationship (Extension)** - This is a relationship that we should use inheritance.\r\n- **Has-a relationship (Composition)** - We should not use inheritance with this relationship\r\n\r\n\u003e**For Example:**\r\n\u003e- Character - Player, Enemy, Ally\r\n\u003e- Media - DVD, Book, Image\r\n\u003e- Controller - Gamepad, Joystick, Keyboard\r\n\r\n## **Overloading**\r\n- In regard to Java we are able to use the same method name but with different **method signature**.\r\n- Define method with the **same name** but **different parameters**.\r\n```java\r\nint add(int a, int b){}\r\nint add(int a, int b ,int c){}\r\nint add(double a, double b){}\r\n```\r\n- Also, constructor can be overloaded.\r\n```java\r\npublic class Overloading{\r\n    public int variableA;\r\n    public int variableB;\r\n    public int variableC;\r\n\r\n    public Overloading(){\r\n        //This() is used to access the constructors in current class.\r\n        this(1, 2, 3);\r\n    }\r\n\r\n    public Overloading(int variableA){\r\n        this.variableA = variableA;\r\n        this.variableB = 2;\r\n        this.variableC = 3;\r\n    }\r\n\r\n    public Overloading(int variableA, int variableB, int variableC){\r\n        this.variableA = variableA;\r\n        this.variableB = variableB;\r\n        this.variableC = variableC;\r\n    }\r\n}\r\n```\r\n\r\n## **Throw Exceptions \u0026 Try-Catch Block**\r\n`Checked Exceptions` Exception and any subclasses that is not RuntimeException. **Must handle it using a try-catch block if a method can throw the exception.**\r\n```java\r\npublic class Exceptions{\r\n    //The method throws a checked exception.\r\n    public static void imGonnaCrash() throws Exception{\r\n        throw new Exception(\"Definitely crashing!!\");\r\n    }\r\n\r\n    public static void main(String[] args){\r\n        //Must use try-catch block.\r\n        try{\r\n            imGonnaCrash();\r\n        }catch(Exception e){\r\n            e.getMessage();\r\n        }\r\n    }\r\n}\r\n```\r\n`Unchecked Exception` RuntimeException and any subclasses. __Does not need to handle it__ but can use try-catch block if they want to. It should be __a case where the program should crash__. It is a state that **should occur** during runtime and you cannot handle nicely prior. Unless you are expecting the code to raise an exception.\r\n```java\r\npublic class Exceptions{\r\n    //The method throws an unchecked exception. (RuntimeException)\r\n    //\"throws Exception\" is not needed.\r\n    public static void imGonnaCrash(){\r\n        throw new RuntimeException(\"Definitely crashing!!\");\r\n    }\r\n\r\n    public static void main(String[] args){\r\n        //Does not need to use try-catch block.\r\n        //But can catch it if they want.\r\n        imGonnaCrash();\r\n    }\r\n}\r\n```\r\n`Error` Error is a state that **cannot be handled**. It is typically invoked when the state of the program is considered **unrecoverable**. Error in Java can be handled by a try-catch block, but it is considered **bad practice to catch them**.\r\n```java\r\nError: StackOverFlow\r\n```\r\n**Create Custom Exception** - We can create our own exception class by **extending** the Exception or RuntimeException class.\r\n```java\r\nclass InvalidRefreshRateException extends Exception{\r\n    public InvalidRefreshRateException(){\r\n        super(\"Unsupported refresh rate.\")\r\n    }\r\n}\r\n\r\npublic class Monitor{\r\n    private double refreshRate;\r\n    public final double MAX_REFRESH_RATE;\r\n\r\n    public Monitor(double defaultRate, double max){\r\n        refreshRate = defaultRate;\r\n        MAX_REFRESH_RATE = max;\r\n    }\r\n\r\n    public double setRefreshRate(double hz) throws InvalidRefreshRateException {\r\n        if(hz \u003c 0 || hz \u003e MAX_REFRESH_RATE)\r\n            throw new InvalidRefreshRateException();\r\n        else\r\n            refreshRate = hz;\r\n        return refreshRate;\r\n    }\r\n}\r\n```\r\n\r\n## **Enum**\r\n- Enums are a set of **defined instances of the same type**. An enum within java allows a finite set of instances to be constructed.\r\n- We are unable to create new unique instance (cannot use the new keyword) of an enum type.\r\n- We may use enums in situatuins where the number of instances anre finite or manageable within a sequence of instances.\r\n\r\n**For Example:**\r\n- Telephone State: Busy, Offline, Awaiting, Dialing\r\n- Laptop State: On, Off, Sleeping\r\n- Direction: Left, Right, Up, Down\r\n- Month of a Year: Jan, Feb, Mar, ...\r\n\r\n**Syntax: (How do we use it?)**\r\n```java\r\n[public] enum EnumName\r\n\r\n//Basic Example.\r\nenum Suit{\r\n    Hearts,     //0\r\n    Diamonds,   //1\r\n    Spades,     //2\r\n    Clubs;      //3\r\n}\r\n\r\n//Example Variant 1.\r\nenum Rating{\r\n    //We can also get the number using Rating.BAD.ordinal();\r\n    //We can access all enum values using Rating.values();\r\n    BAD,        //0\r\n    AVERAGE,    //1\r\n    EXCELLENT;  //2\r\n}\r\n\r\npublic class MovieRating{\r\n    Rating rating = Rating.AVERAGE;\r\n\r\n    switch(rating){\r\n        case Rating.BAD:\r\n            System.out.println(\"Don't waste time watching this.\");\r\n            break;\r\n        case Rating.AVERAGE:\r\n            System.out.println(\"Not bad.\");\r\n            break;\r\n        case Rating.EXCELLENT:\r\n            System.out.println(\"Great movie!\");\r\n            break;\r\n    }\r\n}\r\n\r\n//Example Variant 2.\r\n//Similar to a class, enum in Java can use attributes, constructors and methods.\r\nenum Color {\r\n    Black   (000,000,000),\r\n    White   (255,255,255),\r\n    Red     (255,000,000),\r\n    Green   (000,255,000),\r\n    Blue    (000,000,255);\r\n\r\n    private int R;\r\n    private int G;\r\n    private int B;\r\n    private static final MAX = 255;\r\n\r\n    Color(int R, int G, int B){\r\n        this.R = R;\r\n        this.G = G;\r\n        this.B = B;\r\n    }\r\n\r\n    public double getBrightness(){\r\n        return (double)(R+G+B)/(double)(MAX*3);\r\n    }\r\n}\r\n```\r\n\r\n## **Testing, Assert Keyword and JUnit**\r\n### **Assert keyword**\r\n\r\nAssert evaluates an expression and will throw an **AssertionError** if the statement is false. Since it throws an **Error** type, it will cause our program to crash.\r\n\r\n- You would utilise this feature in an attempt to ensure that your program is sound. We are able to test **pre-conditions**, **post-conditions** and anything in between.\r\n\r\n- **Post-condition**\r\nA post-condition is where any output from a method is considered to adhere to the requirement of the method.\r\n**Simply:** What the method promises to do.\r\n\r\n- **Pre-condition**\r\nA pre-condition is where any input from a method is considered to adhere to the requirement of the method.\r\n**Simply:** What the method expect to in take.\r\n\r\n**Syntax: (How do we use it?)**\r\n```java\r\nassert expression\r\n\r\n//Example.\r\nassert list.size() \u003e 0;\r\nassert isFileLoaded();\r\n\r\nprivate void preCheck(){\r\n    File file = new File(path);\r\n    assert file.exists();\r\n    assert file.verify();\r\n}\r\n```\r\n### **JUnit**\r\n- A common testing framework in the Java ecosystem. You will need to write your own test classes to check if your code is performing correctly.\r\n\r\n- **Black Box Testing** - User centric testing, **without knowledge of the internals**, input is given and compared to match the output of the program.\r\n\r\n- **White Box Testing** - This is typically where we employ some unit testing software, to help analyse the **internals of the system** and test them independently.\r\n\r\nThe annotation which we can use in JUnit:\r\n```java\r\n@Test           //Annotates a method as a test method.\r\n@Before         //Allows a method to initialize any object before a test case is executed.\r\n@After          //Allows execution after a test case is executed.\r\n@BeforeClass    //We can initalize class objects when the class is loaded.\r\n@AfterClass     //We can check class objects after the class is loaded.\r\n\r\n//Methods that can be used in JUnit.\r\nassertNull(booleanExpression);\r\nassertTrue(booleanExpression);\r\nassertFalse(booleanExpression);\r\nassertEquals(expected, actual);\r\nassertSame(Obj01, Obj02);\r\n```\r\n\r\n**Compile Test File**\r\n```\r\n\u003e javac -cp .:junit-4.12.jar:hamcrest-core-1.3.jar MyTestClass.java\r\n```\r\n**Run Test File**\r\n```\r\n\u003e java -cp .:junit-4.12.jar:hamcrest-core-1.3.jar org.junit.runner.JUnitCore MyTestClass.java\r\n```\r\n\r\n## **Abstract Classes**\r\n- `Abstract` class is similar to the concrete class, but it **cannot be instantiated**. It can also **enforce** a method implementation for subtypes.\r\n\r\n- The only **difference** of an abstract class from a concrete class is that it **cannot be instantiated** and it can **specify methods subtypes must define**.\r\n\r\n**Why would we use abstract?**\r\n\r\n- The main case for abstract is that we have some type that we do not want to instantiate and is a **generalisation** of many other types.\r\n\r\n\u003e**For Example:**\r\n\u003e- Shape is a generalisation of Triangle, Square, Circle but we don't have a concrete instance of Shape.\r\n\u003e- Furniture is a generalisation of Chair, Sofa, Table and Desk.\r\n\u003e- Weapon is a generalisation of Guns, Swords, Missile and Bomb.\r\n\r\n**Syntax: (How do we use it?)**\r\n```java\r\n[AccessModifier] abstract class ClassName{}\r\n\r\n//Example.\r\npublic abstract class Furniture{\r\n    //Class content.\r\n}\r\n```\r\n\r\n### **Abstract Methods**\r\n- We are able to declare an abstract method in **only abstract classes**. When we declare an abstract method we **do not define a method body** (The logic of the method). And the **subclasses must implement** the method body.\r\n\r\n**Syntax: (How do we use it?)**\r\n```java\r\n[AccessModifier] abstract TypeName MethodName(argType1 argName1, argType2 argName2);\r\n\r\n//Example.\r\npublic abstract void stack(Furniture furniture); //Don't define the body.\r\n```\r\n\r\n## **Interfaces**\r\n`Interface` a list of abstract methods and default methods. Similar to abstract methods, interface **can not be instantiated** and it also defines the methods that a class **must implement**.\r\n\r\n- Cannot specify any attributes except static final attributes and only methods can be specified.\r\n- Do not (typically) provide a method definition.\r\n- Cannot be instantiated.\r\n- Whenever a class need to use interface, it uses the keyword `implements`.\r\n- We can implement multiple interfaces in one class.\r\n\r\n**When can we use interface?**\r\n\r\n- We can use interface when two classes are not is-a relationship but share a same characteristic. For example, a dog and a robot don't have parent-child relationship, but they can both move. We could implement an IMoveable interface.\r\n\r\n**For Example:** **There are TONS of objects in the game scene and you want to interact with some of them.**\r\n\r\n\u003e**Without interface, you will have to write:**\r\n\u003e- A lot of `interact` methods in different object classes in the scene.\r\n\u003e- If in the player class, detect area is collided with objectA that you know is interactable and button is pressed, call the `objectA.interact()`.\r\n\u003e- If the player detect area is collided with objectB that you know is interactable and button is pressed, call the `objectB.interact()`.\r\n\u003e- If ObjC, ObjD, ObjE, ...\r\n\r\n\u003e**With interface, you will just need to write:**\r\n\u003e- If the detect area is collided with anything that implements `IInteractable` and button is pressed, call the `interactObj.interact()`.\r\n\r\n**For instance, in `Unity` you can write something like this to interact with objects with `C#`:**\r\n```c#\r\npublic void Update(){\r\n    GameObject nearestGameObject = GetNearestGameObject();\r\n    if(nearestGameObject == null) return;\r\n    if (Input.GetButtonDown(\"Fire1\")){\r\n        if (nearestGameObject.TryGetComponent(out IInteractable interactable)) \r\n            interactable.interact();\r\n    }\r\n}\r\n```\r\n\r\n**Syntax: (How do we use it?)**\r\n```java\r\n[AccessModifier] interface InterfaceName{}\r\n\r\n//Example.\r\npublic interface IDamageable{\r\n    //Interface content.\r\n    public void damage(float amount);\r\n    public void heal(float amount);\r\n    public void destory();\r\n}\r\n\r\n//A class that implements the interface.\r\npublic class Cat implements IDamageable{\r\n    public float health;\r\n    public float defence;\r\n\r\n    public Cat(float health, float defence){\r\n        this.health = health;\r\n        this.defence = defence;\r\n    }\r\n\r\n    public void damage(float amount){\r\n        if(amount \u003e 0){\r\n            health -= amount * (1 - defence);\r\n            System.out.println(\"Meow, it hurts!\");\r\n        }\r\n    }\r\n\r\n    public void heal(float amount){\r\n        if(amount \u003e 0){\r\n            health += amount;\r\n            System.out.println(\"Meow, it feels good!\");\r\n        }\r\n    }\r\n\r\n    public void destory(){\r\n        health = 0;\r\n        System.out.println(\"Meow, I died...\");\r\n    }\r\n}\r\n\r\n//A class that implements the interface.\r\npublic class Crate implements IDamageable{\r\n    public int hitsCouldWithstand;\r\n\r\n    public Crate(int hitsCouldWithstand){\r\n        this.hitsCouldWithstand = hitsCouldWithstand;\r\n    }\r\n\r\n    public void damage(float amount){\r\n        if(amount \u003e 0){\r\n            hitsCouldWithstand -= 1\r\n            System.out.println(\"Crack!\");\r\n        }\r\n    }\r\n\r\n    public void heal(float amount){\r\n        System.out.println(\"Cannot heal crate...\");\r\n    }\r\n\r\n    public void destory(){\r\n        hitsCouldWithstand = 0;\r\n        System.out.println(\"Boom, Crate is Shattered!\");\r\n    }\r\n}\r\n\r\n//So you can write something like:\r\n//If my sword collides with anything that is damageable (With IDamageable), call the damage function.\r\n//You will not need to to know what you hit with sword.\r\n//And you will not need to get the class then call the specific method in that concrete class.\r\n```\r\n\r\n### **Default Methods**\r\n- Simply we are able to define a default method in the interface by using `default` keyword.\r\n\r\n**Syntax: (How do we use it?)**\r\n```java\r\n[Modifier] default \u003creturnType\u003e MethodName(parameters){}\r\n\r\n//Example.\r\npublic default void talk(String content){\r\n    //Method body.\r\n}\r\n```\r\n\r\n## **Generics**\r\n**Why do we need `Generics`?**\r\n\r\n- Without generics, we would need to create duplicating code for every data type. We would need to create:\r\n\u003e- `IntArrayList`\r\n\u003e- `DoubleArrayList`\r\n\u003e- `FloatArrayList`\r\n\u003e- `StringArrayList`\r\n\r\n- This is awful, now we're maintaining duplicate code for a change in data type. However, with generics, we will know what kind of data type we are storing.\r\n\r\n**The advantage of generics:**\r\n- Stronger type checks at complie time\r\n- Elimination of casts\r\n- Enabling programmers to implement generic algorithms\r\n\r\n**Syntax: (How do we use this?)**\r\n```java\r\n//Generic variables.\r\n[public] T variable;\r\n[public] type\u003cT\u003e variable;\r\n//Generic classes.\r\n[public] class ClassName\u003cParam0[,Param1...]\u003e{}\r\n//Generic method in generic classes.\r\n[public][static] T methodName(T param){}\r\n//Static generic method in non-generic classes.\r\n[public] static \u003cParam0[,Param1...]\u003e returnType methodName(Param0[,Param1]){}\r\n\r\n//Example.\r\npublic class Container\u003cT, V\u003e{\r\n    public T variableA;\r\n    public V variableB;\r\n    public ArrayList\u003cT\u003e variableList;\r\n\r\n    public T get(){\r\n        //Content.\r\n    }\r\n\r\n    public void set(V element){\r\n        //Content.\r\n    }\r\n}\r\n\r\npublic class Container{\r\n    //Static generic method in non-generic classes.\r\n    public static \u003cT\u003e T find(T needle, T[] sea){\r\n        //Content.\r\n    }\r\n}\r\n\r\npublic class mainClass{\r\n    class Needle{\r\n        public int value;\r\n        public Needle(int value){\r\n            this.value = value;\r\n        }\r\n    }\r\n\r\n    public static void main(String[] args){\r\n        needle n = new Needle(25);\r\n        needle[] ns = {\r\n            new Needle(10),\r\n            new Needle(25),\r\n            new Needle(80)\r\n        };\r\n        //Call static generic method.\r\n        Container.\u003cNeedle\u003efind(n, ns);\r\n    }\r\n}\r\n```\r\n**Type Parameters** - We also can specify an upper bound type:\r\n```java\r\n[public] class ClassName\u003cParam0 [extends SuperType]\u003e\r\n\r\n//Example.\r\npublic class ShoppingCart\u003cT extends Item\u003e{\r\n    //Class content.\r\n}\r\n```\r\n**Generic Arrays** - Java can not create generic array. Unless we store the data in an object array first and cast the target type.\r\n\r\n```java\r\npublic class JArray\u003cT\u003e{\r\n    private T[] array;\r\n    public JArray(int length){\r\n        array = (T[]) new Object[length];\r\n    }\r\n\r\n    public T[] get(){\r\n        return array;\r\n    }\r\n\r\n    public T get(int index){\r\n        if(index \u003e= array.length){\r\n            throw new ArrayIndexOutOfBoundsException();\r\n        }\r\n        return array[index];\r\n    }\r\n\r\n    public void set(int index, T obj){\r\n        array[index] = obj;\r\n    }\r\n\r\n    public void clear(){\r\n        array = (T[]) new Object[array.length];\r\n    }\r\n\r\n    public int length(){\r\n        return array.length;\r\n    }\r\n}\r\n```\r\n**Iterable \u0026 Iterator** - Implement generic interface to make the foreach loop work in your own class.\r\n```java\r\npublic class MyOwnLinkedList\u003cT\u003e implements Iterable\u003cT\u003e{\r\n    //Some linked list logic...\r\n\r\n    public Iterator\u003cT\u003e iterator(){\r\n        return new Iterator\u003cT\u003e(){\r\n            Node\u003cT\u003e cursor;\r\n\r\n            public boolean hasNext(){\r\n                return cursor != null;\r\n            }\r\n\r\n            public T next(){\r\n                T value = cursor.value;\r\n                cursor = cursor.next;\r\n                return value;\r\n            }\r\n        }\r\n    }\r\n}\r\n```\r\n\r\n## **Recursion \u0026 Memoization**\r\n**What is recursion?**\r\n- Recursion is a technique within computer science that allows calling a function itself.\r\n- Recursive functions are aligned with recursive sequence or series, where the output of a function is dependent on the output from the same function with a change of input.\r\n\r\n**Recursive function is made of:**\r\n- **A base case** (or many base cases), where the function terminates.\r\n- **Recursive case** (or many recursive cases), which will converge to a base case. (Goes towards a base case, otherwise it will never stop)\r\nOnce it reaches the bottom, it will start **Backtracking**.\r\n\r\n_Note: Drawing an execution tree will help understand the complicated recursion._\r\n\r\n**Disadvantages of recursion:**\r\n- The java programming model does not allow for infinite recursion.\r\n- Inefficient with memory.\r\n- Potentially more computationally demanding due to the overhead caused by method calls.\r\n\r\n**Advantages of recursion:**\r\n- Problem can often be represented easily with recursion.\r\n\r\n**What is memorization?**\r\n- Memoization is a technique for storing the results of a computation.\r\n- You may know it as a different term: **Caching**.\r\n- We store the result as we may need to reuse it later.\r\n- Let's say we had a website that computes a simple page, the page doesn't differ between each user access, we could keep the result and send it every time it is asked.\r\n\r\n## **Anonymous Classes**\r\n- **Construct an instance of an interface immediately. (A class that implement the interface.)**\r\n\r\n- **Format:** `interface = new Type() {[Fields] [Functions]};`\r\n\r\n- **Note:** Unlike Lambdas, Anonymous Classes can also create instances of non-functional interfaces. (Interfaces with multiple abstract methods.) But need to implemtent all of the abstract methods.\r\n\r\n```Java\r\n/**\r\n * The output is:\r\n * こんにちは!\r\n * Jatutu.\r\n */\r\n\r\ninterface Greetings{\r\n    public default void sayComplexHello(String name){\r\n        sayHello();\r\n        System.out.println(name + \".\");\r\n    }\r\n    public void sayHello();\r\n}\r\n\r\npublic class TestGreetings{\r\n    //Set language to Japanese.\r\n    public static String lang = \"JPN\";\r\n    public static String name = \"Jatutu\";\r\n\r\n    public static void main(String[] args){\r\n        Greetings greetings;\r\n\r\n        //We can use different operations using the Greetings interface.\r\n        switch(lang){\r\n            case \"ENG\":\r\n                greetings = new Greetings() {\r\n                    @Override\r\n                    public void sayHello(){\r\n                        System.out.println(\"Hello!\");\r\n                    }\r\n                };\r\n                break;\r\n            case \"CHN\":\r\n                greetings = new Greetings() {\r\n                    @Override\r\n                    public void sayHello(){\r\n                        System.out.println(\"你好!\");\r\n                    }\r\n                };\r\n                break;\r\n            case \"JPN\":\r\n                greetings = new Greetings() {\r\n                    @Override\r\n                    public void sayHello(){\r\n                        System.out.println(\"こんにちは!\");\r\n                    }\r\n                };\r\n                break;\r\n            case \"ITY\":\r\n                greetings = new Greetings() {\r\n                    @Override\r\n                    public void sayHello(){\r\n                        System.out.println(\"Ciao!\");\r\n                    }\r\n                };\r\n                break;\r\n            default:\r\n                greetings = new Greetings() {\r\n                    @Override\r\n                    public void sayHello(){\r\n                        System.out.println(\"!\");\r\n                    }\r\n                };\r\n                break;\r\n        }\r\n\r\n        //We just need to call the function without knowing the operation.\r\n        greetings.sayComplexHello(name);\r\n    }\r\n}\r\n```\r\n\r\n## **Lambda Functions**\r\n- **For quick use of interfaces.**\r\n_[If this is not clear, Imaging the use cases of calculator]_\r\n\r\n- **Requirement:** The interface must delare only one abstract method.\r\n\r\n- **Format:** `interface = (argument1, argument2, ...) -\u003e functionBody`\r\n\r\n- **Note:** Prior to Java 8, Lambda does not exist.\r\n\r\n```Java\r\n/**\r\n * The output is also:\r\n * こんにちは!\r\n * Jatutu.\r\n */\r\n\r\ninterface Greetings{\r\n    public default void sayComplexHello(String name){\r\n        sayHello();\r\n        System.out.println(name + \".\");\r\n    }\r\n    public void sayHello();\r\n}\r\n\r\npublic class TestGreetings{\r\n    //Set language to Japanese.\r\n    public static String lang = \"JPN\";\r\n    public static String name = \"Jatutu\";\r\n\r\n    public static void main(String[] args){\r\n        Greetings greetings;\r\n\r\n        //We can use different operations using the Greetings interface.\r\n        switch(lang){\r\n            case \"ENG\":\r\n                greetings = () -\u003e System.out.println(\"Hello!\");\r\n                break;\r\n            case \"CHN\":\r\n                greetings = () -\u003e System.out.println(\"你好!\");\r\n                break;\r\n            case \"JPN\":\r\n                greetings = () -\u003e System.out.println(\"こんにちは!\");\r\n                break;\r\n            case \"ITY\":\r\n                greetings = () -\u003e System.out.println(\"Ciao!\");\r\n                break;\r\n            default:\r\n                greetings = () -\u003e System.out.println(\"!\");\r\n                break;\r\n        }\r\n\r\n        //We just need to call the function without knowing the operation.\r\n        greetings.sayComplexHello(name);\r\n    }\r\n}\r\n```\r\n\r\n## **Wildcards**\r\nUnlike arrays, where we are able to assign types to a variable of an inherited type, Generic types cannot be assigned to a type that specifies a lower bound.\r\n```java\r\n//If you have a parent and a child type.\r\npublic class Animal{}\r\npublic class Cat extends Animal{}\r\npublic class Container\u003cT\u003e{}\r\n\r\n//You can do this.\r\npublic Animal[] animalArrayA = new Cat[5];\r\npublic Animal[] animalArrayB = {\r\n    new Cat(\"Happy Cat\"),\r\n    new Cat(\"Sad Cat\")\r\n};\r\n\r\n//But you cannot do this in Generics.\r\npublic Container\u003cAnimal\u003e animals = new Container\u003cCat\u003e();\r\n```\r\nIn wildcards we can read if we know the super type and we can write if we know the lower bound (Child Type).\r\n\r\n**Syntax: (How can we use it?)**\r\n```java\r\n//We don't know the type of the generics.\r\nType\u003c?\u003e variable;\r\n//We don't know the type of the generics but we know the lower bound.\r\n//Anything that is a parent of the child. (Including the parent)\r\n//We can only write.\r\nType\u003c? super LowerBound\u003e variable;\r\n//We don't know the type of the generics but we know the upper bound.\r\n//Anything that is a child of the parent. (Including the child)\r\n//We can only read.\r\nType\u003c? extends UpperBound\u003e variable;\r\n\r\n//Write employee into any list that is parent of employee.\r\n//No matter how broad the scope is, employee is still in the scope.\r\n//Adding a employee to a upper bound list is always valid. \r\n//Eg. Adding employee into an employee list, a person list,\r\n//an animal list, a living being list and an everything list is still valid.\r\n//However, if use ? extends xx, it will go down infinitely.\r\n//Eg. It will not be possible if you put an employee into a product manager list.\r\n//Because not all employees are product managers, no?\r\npublic void add(List\u003c? super Employee\u003e list, Employee e){\r\n    list.add(e);\r\n}\r\n\r\n//Write customer into any list that is parent of customer.\r\n//No matter how broad the scope is, customer is still in the scope.\r\n//Adding a customer to a upper bound list is always valid.\r\n//Eg. Adding customer to a person list, an animal list,\r\n//a living being list or an everything list is all valid.\r\npublic void add(List\u003c? super Customer\u003e list, Customer c){\r\n    list.add(c);\r\n}\r\n\r\n//Read a list of anything that is a child of employee.\r\n//No matter what they are specifically, read them as an employee is valid.\r\npublic void getEmployees(List\u003c? extends Employee\u003e list){\r\n    for(Employee e : list){\r\n        //Print the employee.\r\n    }\r\n}\r\n\r\n//Read a list of anything that is a child of person.\r\n//No matter what they are specifically, read them as a person is valid.\r\npublic void getPersons(List\u003c? extends Person\u003e list){\r\n    for(Person p : list){\r\n        //Print the person.\r\n    }\r\n}\r\n```\r\n\r\n## **Java Debugger**\r\nYou can use Java Debugger to make life easier.\r\n```\r\n\u003e jdb MyProgram                              //Start debugging.\r\n...\r\n\u003e stop at MyProgram:32                       //Set stopping line number.\r\n...\r\n\u003e run                                        //Run the program.\r\n...\r\nFunctionName \u003e locals                        //Check local variables.\r\n...\r\nFunctionName \u003e step                          //Continue one line.\r\n...\r\nFunctionName \u003e set variableName = value      //Set a variable value.\r\n...\r\nFunctionName \u003e cont                          //Continue the program.\r\n...\r\nFunctionName \u003e dump className[.funcName()]   //Call functions or inspect classes.\r\n...\r\nFunctionName \u003e exit                          //Exit debugger.\r\n```\r\n\r\n## **Create an Java Archive [JAR]**\r\nCreate JAR without manifest:\r\n```\r\njar -cf MyProgram.jar \u003cList of *.class file [Separate with space]\u003e\r\nvim MyProgram.jar\r\nInside MANIFEST.MF add Main-Class: MyMainClass\r\n```\r\nCreate JAR with a manifest:\r\n```\r\nCreate a .txt file in the directory.\r\njar -cfm MyProgram.jar MyTxtFile.txt \u003cList of *.class\u003e\r\n```\r\nRun the JAR File:\r\n```\r\njava -jar MyProgram.jar\r\n```\r\nOr Create JAR with Gradle Build Command:\r\n```\r\ngradle build\r\n```\r\nThen the built files will be available at: `\\build\\distributions\\zipFile.zip`. We will use the .bat file in the zip to execute the program.\r\n\r\n## **Javadoc**\r\n- Documentation is an important aspect to application development. you are producing a technical manual for others to read so they can comprehend your code and utilise it.\r\n\r\n**You should:**\r\n- Write Javadoc Comments\r\n- Write with clear method names and style.\r\n```Java\r\n/**\r\n * A method that finds the cat that is the happiest in scene.\r\n * @param cats All cats in scene.\r\n * @return Return the happiest cat.\r\n */\r\n```\r\n**Identifier:**\r\n- `@return` - Return type description.\r\n- `@param` - Parameter description.\r\n- `@see` - Add a method to `See Also:` in javadoc.\r\n- `@since` - When the method was included in your library.\r\n- `@throws` - Specify what exception it will throw and when to throw.\r\n- `@deprecated` - marks a method/class for removal.\r\n\r\n**Export Javadoc:**\r\n```\r\n\u003e javadoc -d \u003cExport Directory\u003e \u003cPath to .java files\u003e\r\n\u003e javadoc -d \u003cExport Directory\u003e -subpackages packageName\r\n```\r\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fuxxhans%2Frainbow-cats-general-java-programming-notes","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fuxxhans%2Frainbow-cats-general-java-programming-notes","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fuxxhans%2Frainbow-cats-general-java-programming-notes/lists"}