Java is a statically typed, object-oriented language that runs on the Java Virtual Machine. That last part is the important bit: your code compiles to bytecode rather than machine code, and the JVM runs that bytecode on any platform it supports. Nearly thirty years on, Java remains one of the most widely deployed languages in business software.
The JVM#
Compiling a C program produces a binary for one operating system and processor. Compiling Java produces bytecode — instructions for an imaginary machine — and the JVM for each platform executes that.
Two consequences follow. The same compiled file runs on Windows, macOS and Linux without recompiling. And the JVM watches your code as it runs and compiles the frequently used parts to machine code, using information a static compiler never has. That is why Java is far faster than people expect, and why the first few requests to a server are slower than later ones.
Where it is used#
| Area | Typical technology |
|---|---|
| Business back ends | Spring Boot |
| Android applications | the Android SDK, alongside Kotlin |
| Big data | Hadoop, Spark, Kafka |
| Financial systems | custom, for the predictable performance |
| Desktop tools | JavaFX, Swing |
| Build and test tooling | Maven, Gradle, Jenkins |
It is particularly entrenched in large organisations, which is worth knowing if employability is part of your reasoning.
Installing#
java --version
javac --version
If those are missing, install a JDK — Temurin, Amazon Corretto and Microsoft’s build are all free and interchangeable. Choose a long-term support release unless you have a reason not to.
Note the distinction: a JRE only runs Java; a JDK also compiles it. You want the JDK.
Your first program#
public class Hello {
public static void main(String[] args) {
System.out.println("Hello");
}
}
javac Hello.java # produces Hello.class
java Hello
Recent JDK versions let you skip the compile step for a single file, and even the class wrapper:
java Hello.java
That boilerplate is the main thing beginners complain about. It exists because Java requires every method to live in a class and every program to have a named entry point — consistency that pays off in large codebases and costs you in a five-line script.
What the language looks like#
// Types are declared and checked at compile time
int count = 42;
double price = 12.99;
String name = "Ana";
boolean ready = true;
var inferred = count * 2; // still an int, just inferred
// Conditions
if (score >= 80) {
grade = "A";
} else if (score >= 70) {
grade = "B";
} else {
grade = "F";
}
// A switch that returns a value
String label = switch (day) {
case SATURDAY, SUNDAY -> "weekend";
default -> "weekday";
};
// Loops
for (String fruit : fruits) System.out.println(fruit);
for (int i = 0; i < 5; i++) System.out.println(i);
// Collections
List<String> names = new ArrayList<>();
Map<String, Integer> ages = new HashMap<>();
// Streams
List<String> adults = people.stream()
.filter(p -> p.age() >= 18)
.map(Person::name)
.sorted()
.toList();
Classes and records#
public class Person {
private final String name;
private int age;
public Person(String name, int age) {
this.name = name;
this.age = age;
}
public String getName() { return name; }
public boolean isAdult() { return age >= 18; }
public void haveBirthday() { age++; }
}
// A record - for data defined by its values
public record Point(double x, double y) { }
var a = new Point(1, 2);
var b = new Point(1, 2);
System.out.println(a.equals(b)); // true
System.out.println(a); // Point[x=1.0, y=2.0]
That one line replaces a constructor, two accessors, equals, hashCode and toString. Records are one of several additions that have made modern Java noticeably less verbose than its reputation suggests.
Exceptions#
try {
String text = Files.readString(Path.of("notes.txt"));
} catch (NoSuchFileException e) {
System.out.println("That file does not exist");
} catch (IOException e) {
System.out.println("Could not read it: " + e.getMessage());
}
Java has checked exceptions: the compiler forces you to either handle certain failures or declare that your method throws them. It is a genuinely divided topic — it makes failure paths explicit, and it also produces a lot of ceremony. Most modern languages chose not to have them.
How it compares#
| Java | C# | Python | JavaScript | |
|---|---|---|---|---|
| Typing | static | static | dynamic | dynamic |
| Verbosity | higher | moderate | low | low |
| Speed | fast | fast | moderate | fast |
| Learning curve | moderate | moderate | gentle | moderate |
| Strongest in | enterprise, Android | business apps, games | data, scripting | web front ends |
Java and C# are close relatives — learning one makes the other largely readable. Java’s advantages are the enormous ecosystem, deployment maturity and job availability. Its disadvantage is that simple things take more lines than in Python.
What to learn, in order#
- Types, variables and strings
- Conditions and loops
- Methods — parameters, returns, overloading
- Classes and objects — fields, constructors, encapsulation
- Collections — List, Map, Set
- Interfaces and inheritance
- Exceptions
- Streams and lambdas
Then pick a direction: Spring Boot for back ends, Android for mobile, or the concurrency APIs for systems work.
Modern Java is not the Java you have read about#
Much of Java’s reputation for verbosity comes from versions that are now well over a decade old. Recent releases added var, records, switch expressions, text blocks, pattern matching and virtual threads. If a tutorial is full of StringBuffer and anonymous inner classes, it is describing an older language.
// A text block, for multi-line strings
String query = """
SELECT id, name
FROM products
WHERE price < ?
""";
// Pattern matching
if (shape instanceof Circle c && c.radius() > 10) {
System.out.println(c.radius());
}
Questions people ask#
Which Java version should I use?
The most recent long-term support release. Anything older is missing years of language improvements, and versions past end of life receive no security fixes.
Is Java free?
Yes. OpenJDK and its many builds are free for any use. Oracle’s own distribution has had varying licence terms, which is why most people use Temurin or Corretto.
Java or Kotlin for Android?
Kotlin is Google’s preferred language for Android now and is more concise. Java still works, and a great deal of existing Android code is Java, so being able to read it is useful either way.
Is Java dying?
No. It is not fashionable, which is different. It runs an enormous amount of production software, receives regular releases with real improvements, and has consistent demand for developers.
Where to go next#
- Java basics — the syntax in more depth.
- Object-oriented programming in Java — classes and interfaces.
- Java collections framework — lists, sets and maps.