Last 30 Days
No notifications
Java is a statically typed, object-oriented, compiled-to-bytecode language created by James Gosling at Sun Microsystems in 1995. The slogan "Write Once, Run Anywhere" still holds: your code compiles to bytecode, which runs on the JVM (Java Virtual Machine) on Windows, macOS, Linux, Android — anywhere.
| Domain | Why Java |
| Android apps | Native first language (alongside Kotlin) |
| Big enterprise / banks | Stable, mature, vast ecosystem (Spring, Jakarta EE) |
| Backend services | High throughput, mature tooling, strong typing |
| Big data | Hadoop, Spark, Kafka — all JVM |
| Embedded | Smart cards, IoT (Java SE Embedded) |
public class Hello {
public static void main(String[] args) {
System.out.println("Hello, Java!");
}
}Save as Hello.java (filename must match the public class). Then:
javac Hello.java # compile to Hello.class (bytecode)
java Hello # run on the JVM> Java 11+ also lets you run a single file directly: java Hello.java (no compile step).
| Term | What it is |
| JVM | The runtime that executes .class bytecode |
| JRE | JVM + standard library (just runs Java apps) |
| JDK | JRE + compiler (javac) + tools (jshell, jdeps, javadoc) |
You install the JDK to develop. Get OpenJDK 21 LTS from [adoptium.net](https://adoptium.net/).
Java was designed to fix C++'s biggest pains — manual memory management, header files, fragile cross-platform builds — while keeping a familiar C-style syntax. Trade-off: a fatter runtime and slower startup. Worth it for most server/Android workloads.
| Year | Release | Highlight |
| 1995 | Java 1.0 | Released by Sun |
| 2004 | Java 5 | Generics, autoboxing, enhanced for, annotations |
| 2014 | Java 8 | Lambdas + Streams — biggest shift since 1.0 |
| 2017 | Java 9 | Modules (JPMS), JShell |
| 2018 | Java 11 | LTS; var (Java 10), HTTP client |
| 2021 | Java 17 | LTS; sealed classes, records, pattern matching |
| 2023 | Java 21 | LTS; virtual threads, pattern matching for switch |
Use Java 21 (LTS) for new projects. Java 17 is also widely deployed.
.java → javac → .class → JVM (interprets / JIT-compiles) → CPU instructionsThe JVM uses a JIT (Just-In-Time) compiler to convert hot bytecode into native code at runtime — so long-running Java apps approach C++ speed.
package com.example.demo; // optional but recommendedimport java.util.List; // standard library import
public class Hello { // class name == filename
public static void main(String[] args) {
System.out.println("Hello, Java!");
}
}
public class name: Hello.java → public class Hello.public static void main(String[] args).;.{ }.". Single quotes ' are only for char.# Windows (winget)
winget install EclipseAdoptium.Temurin.21.JDK# macOS (Homebrew)
brew install --cask temurin@21
# Linux (Debian/Ubuntu)
sudo apt install openjdk-21-jdk
Verify:
java --version
javac --versionBoth should report 21.x.
javac Hello.java
java Hellojava Hello.java$ jshell
jshell> int x = 5;
jshell> System.out.println(x * x);
25
jshell> /exitGreat for trying snippets without writing a full class.
public class Greet {
public static void main(String[] args) {
String name = args.length > 0 ? args[0] : "world";
System.out.println("Hello, " + name + "!");
}
}$ java Greet.java Asha
Hello, Asha!String[] args is the array of command-line arguments — note it's a real String array, not argc/argv.
For real projects you'll use a build tool, not raw javac:
| Tool | Notes |
| Maven | XML config (pom.xml); industry default for libraries |
| Gradle | Groovy/Kotlin DSL; preferred by Android & many startups |
For learning, plain javac/java or an IDE is enough.
| Java | C++ | Python | ||||
| Memory | GC | Manual / RAII | GC | |||
| Speed | Fast (JIT) | Fastest | Slowest | |||
| Startup | Slow JVM warmup | Instant | Fast | |||
| Types | Static | Static | Dynamic | |||
| Use cases | Backend, Android | Systems, games | Scripts, ML | Common Beginner Trip-Ups | Mistake | Fix |
| Filename ≠ public class name | Rename file to match | |||||
| Forgot semicolon | Java is C-family — every statement ends with ; | |||||
Used ' for a string | Strings are "..."; 'x' is one char | |||||
Missing public static void main exactly | Even String args[] works, but order matters | |||||
== to compare strings | Use .equals() for String content equality |
You now know how to write, compile and run a Java program. Next: variables and the type system that catches most errors before the program even starts.