Abstract
- A OOP language that is Statically Typed & Strongly Typed. It also provides some features of the functional paradigms but it isn’t very elegant
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
finalto the function signature also works.
The Mother of All Classes
java.lang.Objectis 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 fromjava.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 usestoStringto convert objects to text when you combine them with strings (using+) or print them.
Java Iterator
- An OOP Object of the
java.util.IteratorOOP Class that can be used to loop through collections likeArrayListandHashSet
Obtaining a Java Iterator
Iterator<T> it = cars.iterator();, wherecarsis an instance of Java collections.
Get the first element of a collection using Java iterator
it.next();returns the first element of a collection, whereitis a Java iterator.
Loop through a collection using Java iterator
while(it.hasNext()) {System.out.println(it.next());}, whereitis a Java iterator.
Remove an element from a collection using Java iterator
it.remove();, whereitis a Java iterator.
