What Is Java

Learning goals

By the end of this chapter you should be able to explain what Java is, how the JVM fits in, why Java is still widely used, and what you will build as you progress through this course.


What is Java?

Java is a general-purpose, object-oriented programming language created at Sun Microsystems (now Oracle). Programs are written as human-readable source code (.java files), compiled to bytecode (.class files), and executed on the Java Virtual Machine (JVM).

That three-step pipeline is the defining trait:

Source (.java)  →  Compiler (javac)  →  Bytecode (.class)  →  JVM runs it

Because bytecode runs on the JVM—not directly on the CPU—Java is platform-independent: the same compiled .class file can run on macOS, Linux, or Windows as long as a compatible JVM is installed.

public class Hello {
    public static void main(String[] args) {
        System.out.println("Hello, Java!");
    }
}

Every standalone Java program starts in a main method. You will write your first complete program in the next chapter.


Why learn Java in 2026?

Strength What it means in practice
Huge ecosystem Libraries and tools for almost every domain
Strong typing Many bugs caught at compile time
Mature JVM Decades of performance tuning, profiling, monitoring
Enterprise adoption Banks, e-commerce, Android (via Kotlin), backend services
Job market Still one of the most requested backend skills

Java is not the newest language, but it evolves steadily. JDK 21 (our baseline) brought virtual threads, improved pattern matching, and long-term support—making it a practical choice for new projects as well as legacy systems.


Key vocabulary

  • JDK (Java Development Kit) — compiler, tools, and runtime needed to develop Java programs.
  • JRE / JVM — the runtime that executes bytecode. Modern JDKs bundle the JVM.
  • API — the standard library (java.lang, java.util, java.io, …).
  • Bytecode — portable intermediate representation, not machine code.
  • Garbage collector (GC) — automatically reclaims memory from unused objects.

You do not manage memory manually with free() as in C. The GC tracks object reachability and frees unreachable objects.


Write once, run anywhere — nuance

“Write once, run anywhere” (WORA) is mostly true for pure Java code. Caveats:

  • Native libraries (JNI) tie you to an OS or CPU architecture.
  • JDK version on the deployment machine must be the version you compiled with (unless you use --release).
  • File paths and locale differ across platforms; portable code avoids hard-coded OS assumptions.

Java vs other languages (high level)

Java Python JavaScript C++
Typing Static, strong Dynamic Dynamic Static
Execution JVM bytecode Interpreted / VM JIT in browser/Node Native binary
Memory GC GC GC Manual
Primary use Backend, Android Scripting, ML Web front/back Systems, games

Java sits in the “compiled + managed runtime” camp—similar trade-offs to C# on .NET or Kotlin on the JVM.


Common mistakes (beginners)

  1. Confusing JDK with “Java the language.” You need the JDK installed to compile; the language itself is just the syntax and semantics.
  2. Expecting instant results like a scripting language. Java requires a class, a main method, and compilation before the first run—this friction pays off on larger projects.
  3. Assuming Java is only for old enterprise apps. Modern Java (records, sealed classes, virtual threads) is competitive for greenfield services.
  4. Skipping understanding of the JVM. When things go wrong (memory, performance, class loading), the JVM is where you look.

Practice checkpoint

  1. Explain in one sentence what the JVM does.

    • Answer: The JVM loads bytecode and executes it, providing memory management, security, and platform abstraction.
  2. Name the three artifacts in the compile-run pipeline (file types and tool).

    • Answer: .java source → javac.class bytecode → JVM execution.
  3. True or false: Java source code runs directly on the CPU without compilation.

    • Answer: False. Source is compiled to bytecode first; the JVM interprets/JIT-compiles bytecode.
  4. Why might the same .class file fail on two machines?

    • Answer: Missing or older JVM, missing dependencies, or use of platform-specific native code.

Interview angles

  • “What is the difference between JDK, JRE, and JVM?” — JDK = dev kit (compiler + tools + runtime). JRE = runtime only (largely merged into JDK today). JVM = executes bytecode.
  • “Is Java compiled or interpreted?” — Both: javac compiles to bytecode; the JVM interprets and JIT-compiles hot paths to native code.
  • “Why garbage collection?” — Eliminates manual free/delete, reduces memory leaks and use-after-free bugs; cost is pause times and less predictable latency (tunable).

Next: /java/learn/getting-started/install-and-first-program/