Java basics: what the language is and where it is used
What Java is
Java is a strictly typed object-oriented
programming language. Sun Microsystems released the first version on
23 May 1995, and the language and the main implementation are now
developed in the open through the Java Community Process, with Oracle
holding the trademark.
Source code is compiled to bytecode, a set of instructions for a virtual
machine rather than for one processor. Any computer with a Java virtual
machine runs the same .class file, which is where the
old promise of write once, run anywhere comes from.
The language has classes, interfaces, inheritance, generics, exceptions
and a garbage collector that frees memory the program no longer uses.
A new JDK appears every six months, in March and September, and every
fourth release is a long-term support version that most projects stay on.
Where Java runs
Java is the language of large server systems: banks, shops and
databases run their back ends on it, and frameworks
such as Spring build on it. Android applications
were written in Java long before Kotlin, and the data tools Hadoop and
Spark run on the JVM as well.
On this site Java appears in two places: the language itself and
Selenium with Java for browser tests.
The JVM also runs Groovy, Kotlin and Scala, so
the same runtime covers several languages.
Install the JDK
Compiling needs a JDK, not the smaller runtime, because
javac ships with the JDK. The
install guide covers
Linux,
macOS,
FreeBSD and
OpenBSD.
On Ubuntu the distribution package is the
shortest route:
sudo apt install -y openjdk-21-jdk
java -version
openjdk version "21.0.5" 2024-10-15 OpenJDK Runtime Environment (build 21.0.5+11) OpenJDK 64-Bit Server VM (build 21.0.5+11, mixed mode, sharing)
Hello, Java
Save this as Hello.java. The file name must match the name of the public class, or the compiler refuses the file:
public class Hello {
public static void main(String[] args) {
System.out.println("Hello, Java");
}
}
Compile it with javac, then run the class with the virtual machine. The command takes the class name, not the file name:
javac Hello.java
java Hello
Hello, Java
The compiler writes Hello.class next to the source. From JDK 11 a single source file runs without a separate compile step: java Hello.java compiles it in memory and starts it, which is handy for a first program and for small tools.
Where to go next
The compiling and running article takes
the same two commands further, and the
switch statement and
final pages walk through single
language features.
In IntelliJ IDEA the same project needs no command line: the run button
compiles the file and starts the class. The IDE setup is in the
IntelliJ IDEA article.
Version numbers move with every release: a newer JDK prints its own, and the Hello, Java line is the same on all of them.
Article author: Arthur Isaev