Java
Everything is an object yay!!
Most similar to C++
Running
FirstJavaProgram.java (Same filename as class)
import java.util.Date;
public class Hello {
public static void main(String[] args) {
Date now = new Date();
System.out.println("Hello World: " + now);
}
}javac FirstJavaProgram.java
java FirstJavaProgramJava App Structure
App must have one class
Every file can have any # of classes, but must have one public class that is the filename, public class main is the entry point
Must compile all classes used with javac individually, but dont need to import as it will link automatically b/c names
Data Types
byte(8) | short(16) | int(32) | long(64) | float(32) | double(64) | char(16) | Boolean(1)
Type Conversions
Blocks
C++ if, else if, else, while, do while, for, switch
Data Structures
Builtin Array:
[] syntax, fixed size, store obj & primitatives(int),
.length
ArrayList:
only store objects(Integers), access with functions(.get())
dynamic size,
.size(), generics
.add(item)
.get(i)
.size()
.remove(i)
.set(i, val)
Object Methods
Equals
Default will check object reference is equal, can override equal to be different, essential for Java data structures like HashMaps which will use this equals
Comparator & Comparable
Last updated