Java basics series: 1. JVM and JDK · 2. Hello World and the three kinds of errors · 3. Variables and types · 4. Operators and branching · 5. Loops and methods · 6. Arrays and strings · 7. Console and text files · 8. Byte streams and serialization
Many “weird” production bugs (integer overflow, comparing Integers with ==, money off by a cent) start in Java’s foundations, so this series starts there. This first post needs no prior reading: afterwards you can explain how Java runs, how the JDK, JRE and JVM differ, and which Java version to pick for a new project. Next up: Hello World and the three kinds of errors, with the first set of exercises.
1. Programming languages and where Java fits
Key idea: Java is a high-level language, but it runs anywhere because of the JVM, not because it’s high-level. C code still has to be recompiled for every OS and CPU.
Software is a sequence of instructions telling a computer what to do. Languages come in three layers:
| Layer | What it looks like | Example |
|---|---|---|
| Machine code | Raw bits the CPU executes directly; every CPU family has its own instruction set | 10110000 01100001 |
| Assembly | Readable names for machine instructions, but you still think in registers and memory. An assembler translates it into machine code | mov eax, 2 / add eax, 3 |
| High-level languages | Close to natural language; no thinking about registers | Java, Go, Python, C |
Slide correction: the slides call the tool that translates assembly a “compiler”. The right name is assembler; a compiler translates high-level languages.
How Java runs
Key idea: javac compiles source to bytecode; the JVM loads, verifies and interprets it, and the JIT compiles frequently run code to native code.
flowchart LR
A[Hello.java] -->|javac| B[Hello.class<br/>bytecode]
B --> C[JVM]
C --> D[Class loader<br/>+ verifier]
D --> E[Interpreter]
E -->|hot code| F[JIT compiler<br/>C1/C2]
F --> G[Native machine code]
E --> G
- Bytecode: an intermediate instruction set that doesn’t depend on any CPU. Each platform (Windows, macOS, Linux, ARM…) has its own JVM to run it.
- JIT (just-in-time compilation, compiling while the program runs): code that runs often (“hot spots”) is compiled to native code and optimized for how the program actually behaves. That’s why benchmarks must account for warm-up.
- Since Java 11 you can run
java Hello.javadirectly, without callingjavacfirst (single-file programs).
JDK, JRE, JVM
Key idea: three nested layers: the JVM runs bytecode, the JRE adds the standard library to run apps, the JDK adds the tools to build them.
| Component | Contents | Who needs it |
|---|---|---|
| JVM | The virtual machine: class loader, garbage collector (GC), JIT | Bundled in the JRE/JDK |
| JRE | JVM + the standard library (java.lang, java.util…) |
Anyone running an app |
| JDK | JRE + development tools: javac, jar, jshell, jdb, jcmd, jfr… |
Developers |
Since Java 11, Oracle no longer ships a separate JRE. For a slim deployment runtime, build one with jlink or use a JRE image such as Eclipse Temurin’s.
Java versions and the LTS releases
Key idea: since Java 10 (March 2018), a new release ships every six months (March and September). Companies move from one LTS to the next, because regular releases are only patched until the next one ships.
- LTS (long-term support): a release vendors keep patching for years. LTS releases used to come every three years (8, 11, 17); since Java 17 it’s every two.
- Features worth remembering: 8 lambdas, streams,
java.time· 11HttpClient,varin lambda parameters · 17 records, sealed classes, switch expressions · 21 virtual threads, pattern matching forswitch· 25 compact source files, non-staticmain. - As of this writing (November 2026), Java 26 and 27 are out but are non-LTS; the next LTS is expected to be Java 29 (September 2027).
Slide correction: the slides say “the latest JDK is 22”. There is already an LTS 25 (2025), and new projects should pick the latest LTS (21 or 25).
Version numbering and the full feature table for each LTS
Java’s numbering has changed a few times, which makes older material confusing:
- Java 1.0 to 1.4: versions were literally
1.x. - Java 5 to 8: the marketing name dropped the
1., but the internal version stayed1.5…1.8. That’s whyjava -versionon Java 8 prints1.8.0_xxx. - Java 9 onwards: a single number (
9,17.0.12,21.0.5). Java 9 was the last “ship when the features are ready” release, so material claiming the six-month cadence started with Java 9 is slightly off.
The number in brackets is the release where a feature became final, if it differs from the LTS.
| LTS | Released | Features worth remembering |
|---|---|---|
| Java 8 | Mar 2014 | Lambdas, the Stream API, java.time replacing Date/Calendar, Optional, default methods in interfaces |
| Java 11 | Sep 2018 | var (10) plus var in lambda parameters, the standard HttpClient, running java Hello.java directly, String.isBlank/strip/lines/repeat, Files.readString/writeString. The Java EE and CORBA modules were removed from the JDK, and Oracle stopped shipping a separate JRE |
| Java 17 | Sep 2021 | Switch expressions (14), helpful NullPointerException messages (14), text blocks (15), records and pattern matching for instanceof (16), sealed classes. JDK internals are strongly encapsulated. Spring Boot 3 / Spring Framework 6 require Java 17 as a minimum |
| Java 21 | Sep 2023 | Virtual threads, pattern matching for switch, record patterns, sequenced collections (getFirst(), reversed()), Generational ZGC |
| Java 25 | Sep 2025 | Compact source files and non-static main (void main() { IO.println("Hi"); }), statements allowed before super(...) in constructors, import module, scoped values, compact object headers (smaller objects). Rolled up from 22–24: unnamed variables _ (22), the Foreign Function & Memory API (22), stream gatherers (24), and virtual threads no longer getting pinned by synchronized (24) |
Why Java for the backend
Key idea: a huge ecosystem, almost 30 years of JVM engineering, static typing that makes refactoring safe, and backward compatibility that enterprises trust.
- Ecosystem: Spring, Hibernate, Kafka clients, testing libraries…; the standard library already ships collections, I/O, an HTTP client, date/time and concurrency.
- The JVM: modern GCs (G1, ZGC), the JIT, observability tools (JFR, JMC).
- Memory safety: the GC reclaims objects nobody references; the JVM always checks array bounds and throws on a bad access. You can still leak memory by holding references you don’t need, e.g. a
static Mapused as an unbounded cache. - Static typing and backward compatibility: excellent IDE support, ten-year-old code still runs, plenty of jobs.
- Java was created in 1995 at Sun Microsystems; Oracle acquired Sun in 2010. The open-source OpenJDK is rebuilt by many vendors: Temurin, Corretto, Zulu…
Slide correction: the slides call Java “purely object-oriented”. It isn’t: its 8 primitive types are not objects.
Java runs banking and payments, big data (Hadoop, Spark, Kafka), cloud services, Android and build tools (Maven, Gradle). The full list is in the block below.
Where Java is used, the features usually listed, and popularity numbers
Beyond enterprise backends, web servers (Tomcat, Jetty) and Spring microservices:
- Finance, banking and payments: core banking, stock-exchange matching engines, payment gateways. This is where stability and backward compatibility are valued most.
- Big data and distributed systems: Hadoop, Spark, Kafka, Flink, Elasticsearch and Cassandra are written in Java or Scala and run on the JVM.
- Cloud: every major cloud provider ships a Java SDK; many internal services at Google, Amazon, Netflix, Uber and LinkedIn run on the JVM.
- Android: Google prefers Kotlin, but both run on the same platform and share libraries.
- Developer tools: Maven, Gradle, Jenkins, IntelliJ IDEA, Eclipse.
- Elsewhere: desktop apps (Swing, JavaFX, increasingly rare), games (Minecraft: Java Edition), point-of-sale terminals, embedded and IoT devices, SIM cards and chip bank cards (Java Card).
The features usually listed when Java is introduced:
- Platform independence: the same
.classfile runs on any OS with a JVM. - Robustness and safety: static typing catches many errors at compile time; the bytecode verifier checks
.classfiles before they run; the JVM checks array bounds and casts, so a bad access throws instead of silently reading the wrong memory as in C; no pointer arithmetic. - Automatic memory management: no
free/delete, so no double-free or use-after-free bugs. - A huge standard library: collections, I/O, networking, an HTTP client, date/time, concurrency and security, before you even touch Maven Central.
- Easy to learn, a good base for other languages: C-family syntax (like C, C++, C#, JavaScript and Kotlin) without raw pointers. Moving from Java to C# or Kotlin is quick.
- Built-in multithreading in the language and standard library, plus a JIT that makes long-running code fast.
Popularity: in the 2023 Stack Overflow survey, about 30% of developers used Java, 7th behind JavaScript, HTML/CSS, SQL, Python, TypeScript and Bash; the TIOBE index has kept Java near the top for years. The slides’ “most googled languages of 2023” chart has an unclear source and method. When you quote numbers (in an interview, say), name a concrete source and year.
Tooling
Key idea: install a JDK (not just an IDE), set JAVA_HOME, check with java -version and javac -version, then pin versions so every machine behaves the same.
- IDE: IntelliJ IDEA. JetBrains merged Community and Ultimate into a single distribution: the core is free, advanced features are paid. IntelliJ can download a JDK for you (File → Project Structure → SDK), but the IDE doesn’t replace a JDK.
JAVA_HOMEpoints to the JDK directory; Maven, Gradle and many other tools read it to decide which JDK to use.- If you juggle several JDKs, use SDKMAN!, jenv or asdf.
Setting JAVA_HOME per OS, and other IDEs
- macOS:
export JAVA_HOME=$(/usr/libexec/java_home -v 21). Windows: System Properties → Environment Variables. - Eclipse and Spring Tool Suite (Eclipse prepackaged for Spring) are both free; VS Code needs the Extension Pack for Java.
- Any IDE works as long as it gives you code completion, errors as you type and a debugger.
Remember
- Explain why Java is “write once, run anywhere” and C isn’t.
- Trace the path from
Hello.javato machine code, and say why a Java service needs warm-up. - Tell the JDK, JRE and JVM apart, and know what a production server needs.
- List the LTS releases and pick a Java version for a new project, with reasons.
- Know why “Java is purely OOP” and “Java is secure thanks to its sandbox” are wrong.
Interview questions
Junior
What is the difference between the JDK, the JRE and the JVM?
The JVM runs bytecode; the JRE is the JVM plus the standard library, enough to run apps; the JDK is the JRE plus development tools.
The JDK tools include javac, jar, jshell, jcmd… Developers install the JDK; production servers only need a runtime, which you can build with jlink.
Why is Java called “write once, run anywhere”?
Because javac produces platform-independent bytecode, and every OS/CPU combination has its own JVM that runs it.
You package your app once (as a JAR) and it runs on any machine with a compatible JVM.
Besides backends, where is Java used, and what makes it popular with enterprises?
Banking and payments, big data, Android, build tools and embedded devices; enterprises pick it for stability, memory safety, a huge ecosystem and backward compatibility.
Concretely: big data tools (Hadoop, Spark, Kafka), build tools (Maven, Gradle), chip cards (Java Card). The JVM runs everywhere, the GC manages memory and arrays are always bounds-checked (so buffer-overflow-style bugs are rare), ten-year-old code still runs, and hiring is easy.
Mid
What is an LTS release? Which Java version would you pick for a new project?
An LTS release gets security patches for years (a regular one for six months). For a new project I pick the latest LTS our key dependencies support: usually 25, or 21.
The LTS releases are 8, 11, 17, 21 and 25; since 17 there’s a new one every two years. “Key dependencies” means Spring Boot, monitoring agents and build plugins. I also pin the version in Maven/Gradle and in the Docker image.
Name a few changes between Java 8 and 21 that you use every day.
Records, switch expressions, text blocks, var, pattern matching and virtual threads, each backed by a real example.
var (10); HttpClient, String.isBlank/strip/lines and Files.readString (11); switch expressions and helpful NPE messages (14); text blocks (15); records and pattern matching for instanceof (16); sealed classes (17); virtual threads, pattern matching for switch, record patterns and sequenced collections (21). Examples: records instead of hand-written DTOs, a switch over a sealed interface so the compiler catches missing cases, virtual threads for services that mostly wait on I/O.
How do OpenJDK, Oracle JDK, Temurin and Corretto differ?
They’re all builds of the same OpenJDK code and behave practically the same; they differ in licence, patch support period and bundled tooling.
Others include Azul Zulu and the Microsoft Build of OpenJDK. They all pass the compatibility test kit (TCK). Companies usually pick Temurin or Corretto to avoid licensing questions, often matching their platform (Corretto on AWS, for example).
Senior
What is the JIT, and how does it affect benchmarks and service startup?
The JIT compiles hot methods to native code at runtime, so a service is noticeably slower for its first few seconds; benchmarks need warm-up, deployments need readiness probes or warm-up traffic.
The JVM interprets first, counts how often each method runs, then compiles hot methods (C1 for quick compilation, C2 for deeper optimization, with inlining and escape analysis). Use JMH for benchmarks. For faster startup, look at CDS/AppCDS, GraalVM native images or CRaC.
What do you watch out for when upgrading a service from Java 8 or 11 to 21?
Three risk groups: removed APIs, encapsulated JDK internals and changed runtime behaviour; upgrade in steps and re-measure in a production-like environment.
- Removed APIs: JAXB, JAX-WS and CORBA left the JDK in 11, so they need explicit dependencies. Moving to Spring Boot 3 also means renaming
javax.*tojakarta.*. - Strong encapsulation (16, 17): libraries that reflect into JDK internals break; upgrade Lombok, Mockito, ByteBuddy and APM agents, or use
--add-opensas a stopgap. - Tooling:
jdeps --jdk-internalsfinds uses of internal APIs, andjdeprscanfinds APIs slated for removal. - Runtime changes: G1 is the default GC, the JVM respects container CPU and memory limits, and UTF-8 is the default charset since 18. Re-measure memory and latency.
- Approach: build on the new JDK first, adopt new features later, run the full test suite, canary the deployment, and watch GC logs and p99 latency.
Useful phrases for interviews
- “Java compiles to bytecode, and the JVM’s JIT turns hot paths into native code at runtime, which is why we warm services up before taking traffic.”
- “The JVM starts in the interpreter and only compiles hot methods once it has profiling data.”
- “We standardized on the Temurin distribution of OpenJDK 21 and pin it in Gradle and in our base image.”
- “We stay on LTS releases and plan an upgrade window each time a new one ships.”
- “The main upgrade blockers from 8 to 17 were the removed Java EE modules and libraries that relied on JDK internals.”
- “The Security Manager is gone, so we rely on container isolation rather than an in-JVM sandbox.”
- “An assembler turns assembly into machine code, whereas a compiler handles high-level languages like Java.”
- “The garbage collector frees unreachable objects, but you can still leak memory by holding on to references you no longer need.”
Notes based on the Fundamentals of Backend course (Ronin Engineer) and the Hỏi Dân IT Java Core material, plus my own research, rewritten in my own words.