Java Cheatsheet

Background:

Installation:

sudo apt install default-jdk — default-JDK includes JRE. If you only want JRE, then you only need to install default-jre instead

Compilation and Execution:

Javac compiler converts .java files into Java bytecode which is run by a Java virtual machine.

  1. javac myfile.java compiles the given file and outputs myfile.class which contains the Java bytecode
  2. java myfile starts the Java virtual machine and runs the bytecode from myfile.class. The portability of Java across different platforms comes from the virtual machine being able to translate the bytecode into platform-specific code.

When the JVM runs myfile.class, it looks for the designated main function inside the class definition. There should be exactly one main function per application, since it serves as the entry point.

public static void main (String[] args) {
		// The entry point of the program
}

Syntax Basics: