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
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 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 usestoString
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 likeArrayList
andHashSet
Obtaining a Java Iterator
Iterator<T> it = cars.iterator();
, wherecars
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, whereit
is a Java iterator.
Loop through a collection using Java iterator
while(it.hasNext()) {System.out.println(it.next());}
, whereit
is a Java iterator.
Remove an element from a collection using Java iterator
it.remove();
, whereit
is a Java iterator.