HomeBytesheetsRoadmapsUI TemplatesUI ToolsStack Discussion
4 Topics
Chapter•55 Minutes

Java Foundations

Understand Java's history, platform model, source-to-bytecode pipeline, JDK/JRE/JVM roles, program structure, and the modern development workflow.

What Is Java?

Java is a statically typed, class-based programming language and runtime platform designed around portability, safety, tooling, and a large standard library. Java source is normally compiled into JVM bytecode rather than directly into one operating system's machine code. A compatible Java Virtual Machine then executes that bytecode.

The important distinction is between the language and the platform. The language defines syntax and semantics such as classes, interfaces, generics, exceptions, and pattern matching. The platform supplies the JVM, standard libraries, command-line tools, garbage collection, monitoring facilities, and a mature ecosystem.

Java is widely used for backend services, enterprise systems, data processing, financial software, developer tools, and high-throughput server applications.

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

Think of Java as a language plus a runtime ecosystem. The JVM is the execution engine; the JDK is the developer toolkit.

Key Takeaways
  • Java source is normally compiled to JVM bytecode.
  • Portability comes from the JVM abstraction and standardized runtime behavior.
  • The language, JVM, and JDK are related but are not the same thing.

JDK, JRE, and JVM

The JVM executes Java bytecode and provides runtime services such as class loading, memory management, garbage collection, synchronization, and JIT compilation. The JDK is the developer distribution: it includes the runtime plus tools such as javac, java, jar, and diagnostic utilities.

The term JRE historically referred to a runtime distribution containing the JVM and runtime libraries. Modern JDK distributions generally provide the complete runtime image themselves, so treating "install a separate JRE" as the normal development workflow is outdated.

A useful hierarchy is:

JDK = development tools + runtime

JVM = engine that executes JVM bytecode

Java source (.java)
     |
     | javac
     v
Bytecode (.class)
     |
     | JVM class loader + verifier
     v
JVM execution engine
     |
     +--> Interpreter
     +--> JIT compiler
     +--> Garbage collector
     +--> Runtime libraries
Interview shortcut

Java source is compiled to bytecode, then the JVM can interpret and JIT-compile that bytecode at runtime.

Key Takeaways
  • javac compiles Java source into bytecode.
  • The JVM executes bytecode and may compile hot code to native instructions.
  • Modern Java development normally starts with a JDK.

Program Structure and the Entry Point

A Java program is organized around types such as classes, interfaces, enums, and records. A conventional executable application has a main method. The usual entry point is public static void main(String[] args).

public makes the method accessible to the launcher, static means the JVM can invoke it without creating an instance, void means it returns no value, and String[] args receives command-line arguments.

Java identifiers are case-sensitive. Package names are conventionally lowercase, classes use PascalCase, methods and variables use camelCase, and constants commonly use UPPER_SNAKE_CASE.

package com.example.app;

public class Application {
    private static final int DEFAULT_PORT = 8080;

    public static void main(String[] args) {
        System.out.println("Starting on port " + DEFAULT_PORT);
    }
}
Key Takeaways
  • Java is case-sensitive.
  • The main method is a static entry point for conventional command-line applications.
  • Packages provide namespace organization and support access control.

Compile, Run, Package, and Inspect

A minimal workflow is: write source, compile it, run it, package it when needed, and inspect artifacts or diagnostics when something fails.

javac Application.java
java Application
jar --create --file app.jar --main-class Application Application.class
java -jar app.jar

For real projects, Maven or Gradle normally handles dependency resolution, compilation, testing, packaging, code quality, and publishing. The command-line tools remain important because they reveal what the build tool is doing underneath.

Compilation errors are caught before execution. Runtime failures such as NullPointerException, ClassNotFoundException, or an out-of-memory condition happen after compilation and require different debugging techniques.

Build-tool principle

Learn the JDK commands even if you use Maven or Gradle; they make build failures easier to reason about.

Key Takeaways
  • javac compiles source; java launches a class; jar packages artifacts.
  • Build tools automate repetitive workflows but do not replace understanding the JDK tools.
  • Compilation success does not guarantee runtime correctness.