sudo apt install default-jdk
— default-JDK includes JRE. If you only want JRE, then you only need to install default-jre
instead
Javac compiler converts .java
files into Java bytecode which is run by a Java virtual machine.
javac myfile.java
compiles the given file and outputs myfile.class
which contains the Java bytecodejava 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
}