Abstract


Entry point method

The class that kickstarts the Java program must have a function with the function signature public static void main(String[] args). This is the standardised entry point, so the JVM knows where to start executing the program.

Adding final to the function signature also works.

The Mother of All Classes


  • java.lang.Object is the root of all classes in Java. Whether they are part of the Java libraries or custom classes you create yourself, all classes implicitly inherit from java.lang.Object

2 useful methods

boolean equals(Object obj): Checks if two objects are the same.

String toString(): Returns a text representation of an object. Java automatically uses toString to convert objects to text when you combine them with strings (using +) or print them.

Java Iterator


  • An OOP Object of the java.util.Iterator OOP Class that can be used to loop through collections like ArrayList and HashSet

Obtaining a Java Iterator

Iterator<T> it = cars.iterator();, where cars is an instance of Java collections.

Get the first element of a collection using Java iterator

it.next(); returns the first element of a collection, where it is a Java iterator.

Loop through a collection using Java iterator

while(it.hasNext()) {System.out.println(it.next());}, where it is a Java iterator.

Remove an element from a collection using Java iterator

it.remove();, where it is a Java iterator.