Java Fundamentals Tutorial 0/33 lessons ~6 min read Lesson 2

    Java Introduction

    Java was born in 1995 when James Gosling's team at Sun Microsystems needed a language for interactive TV set-top boxes — devices with unreliable hardware and strict memory limits.

    Course progress0%
    Focus
    21 guided sections
    Practice signal
    Examples included
    Career prep
    Interview Q&A included

    Introduction

    Java was born in 1995 when James Gosling's team at Sun Microsystems needed a language for interactive TV set-top boxes — devices with unreliable hardware and strict memory limits. The project was codenamed Green; the language was first called Oak, then renamed Java. The original pitch was "Write Once, Run Anywhere": compile source to portable bytecode, ship a .class file, and let any device with a Java Virtual Machine (JVM) execute it.

    Thirty years later, Java is not a set-top-box language. It is the default choice for enterprise backends, Android (via Kotlin/JVM bytecode), big-data infrastructure (Kafka, Hadoop, Cassandra, Elasticsearch), and financial trading systems where uptime and auditability matter more than hype cycles. Oracle owns the Java trademark; the reference implementation is OpenJDK, governed openly with contributions from Red Hat, Amazon, Microsoft, and Azul.

    Business problem

    Why enterprises still standardize on Java in 2026:

    • Regulated industries (banking, insurance, healthcare) need languages with 20+ years of audit trail, backward compatibility, and predictable LTS support — not framework churn every 18 months.
    • Scale economics: A JVM service running for months amortizes JIT compilation cost; throughput on long-lived servers often beats interpreted or cold-start-heavy alternatives.
    • Talent & tooling: IntelliJ IDEA, Maven/Gradle, Spring, Micrometer, and millions of Stack Overflow answers reduce time-to-production versus niche stacks.
    • Multi-vendor JVM: Amazon Corretto, Eclipse Temurin, Azul Zulu, GraalVM — no single vendor lock-in on the runtime.

    Why this topic exists

    The problem Java solved in 1995 still exists: heterogeneous hardware, long-lived deployments, and teams that cannot recompile the entire world every time an OS updates.

    • C/C++ pain: Platform-specific binaries, manual memory management, pointer bugs in production.
    • Java's bet: Managed memory (GC), bytecode portability, strict typing at compile time.
    • Rejected alternative: Pure interpreted scripts — too slow for enterprise throughput; native-only — too brittle across deploy targets.
    • Modern evolution: Virtual threads (Project Loom), records, sealed classes — Java absorbs modern ergonomics without breaking the compatibility contract.

    Core concepts

    Core concepts every Java engineer must internalize:

    • JDK vs JRE vs JVM: JDK = develop (javac, javadoc, jfr); JRE = run (deprecated as standalone); JVM = executes bytecode.
    • Bytecode: Not machine code — platform-independent instructions verified before execution.
    • Garbage collection: Automatic reclamation; tune G1/ZGC for latency-sensitive services.
    • Static typing: Types checked at compile time — catches entire classes of bugs before deploy.
    • Release cadence: Feature release every 6 months; LTS every 2 years (8 → 11 → 17 → 21 → 25).
    • Java 21 (LTS): Virtual threads, sequenced collections, pattern matching for switch, record patterns, generational ZGC — the 2026 enterprise baseline.

    Internal architecture

    From source code to running service — the internal path every .java file follows:

    text
    Main.java ──javac──▶ Main.class (bytecode)
    Class Loader (loads .class into Metaspace)
    Bytecode Verifier (safety checks)
    Interpreter (cold path) ──hot──▶ JIT (C1/C2) ──▶ native code
    Garbage Collector (G1 / ZGC / Shenandoah)
    OS threads + hardware

    Three architecture views — platform stack, release train, and enterprise adoption:

    JVM ecosystem — runtime vendors
    OpenJDK
    Reference implementation
    Temurin
    Eclipse Adoptium LTS builds
    Corretto
    Amazon production JDK
    GraalVM
    Native image + polyglot
    Enterprises pick a vendor JDK — all run the same bytecode.
    Java release train
    Feature 6mo
    22, 23, 24…
    LTS 2yr
    8 · 11 · 17 · 21 · 25
    Preview
    Incubator features
    Production
    LTS + vendor support
    Ship features on 6-month cadence; standardize production on LTS.
    Enterprise adoption domains
    Banking
    Core ledgers, payments
    Streaming
    Netflix, Spotify backends
    Big Data
    Kafka, Spark, ES
    Android
    ART runs DEX/JVM bytecode
    Java dominates where reliability, scale, and hiring pool intersect.

    Code walkthrough

    Minimal Java program — every line maps to JVM concepts above:

    • public class Main — top-level class; one public class per file.
    • static void main — JVM contract; no main → no standalone execution.
    • System.out — PrintStream wired to stdout; production uses SLF4J + Logback.
    java
    // Main.java — public class name MUST match filename
    public class Main {
    // JVM entry point — called by runtime via reflection
    public static void main(String[] args) {
    System.out.println("Java " + Runtime.version());
    // Runtime.version() → e.g. 21.0.2+13-LTS on Temurin 21
    }
    }
    // Compile: javac Main.java → Main.class (bytecode)
    // Run: java Main → JVM loads, verifies, executes

    Production example

    Production service skeleton — how Java Introduction concepts appear in a real Spring Boot deployable:

    • Java 21 LTS in toolchain — virtual threads enabled in Spring Boot 3.2+.
    • Temurin JRE — slim container image; no JDK in production.
    • ZGC — low-latency GC flag common on payment and trading services.
    java
    // build.gradle.kts
    plugins { id("org.springframework.boot") version "3.4.0" }
    java { toolchain { languageVersion.set(JavaLanguageVersion.of(21)) } }
    // Application.java
    @SpringBootApplication
    public class PaymentApplication {
    public static void main(String[] args) {
    SpringApplication.run(PaymentApplication.class, args);
    }
    }
    // Dockerfile — production baseline
    FROM eclipse-temurin:21-jre-alpine
    COPY build/libs/app.jar /app.jar
    ENTRYPOINT ["java", "-XX:+UseZGC", "-jar", "/app.jar"]

    Enterprise case study

    Netflix — Java at streaming scale: Netflix runs thousands of Java microservices behind Zuul/ Spring Cloud. Their engineering culture publishes JVM tuning guides, chaos engineering (Chaos Monkey), and migrated critical paths to Java 17+ for virtual-thread-ready stacks. Key lesson: Java wins not because it is fashionable — because decade-long services, massive hiring pool, and predictable LTS upgrades beat rewrite risk.

    • Before: Per-service language fragmentation; inconsistent observability.
    • Decision: Standardize on JVM + Spring ecosystem with paved-road templates.
    • After: Shared libraries, consistent metrics (Atlas), faster incident response.

    Performance considerations

    Performance is a JVM discipline — not something you bolt on after launch:

    • JIT warm-up: First requests after deploy are slower — use readiness probes, not liveness-only.
    • GC choice: G1 default; ZGC/Shenandoah for sub-10ms pause targets on Java 21.
    • Virtual threads: Java 21 — millions of lightweight threads for I/O-bound work without reactive complexity.
    • Profiling: JFR (Java Flight Recorder) + async-profiler in production — not guesswork.

    Security considerations

    Java platform security — architectural, not optional:

    • LTS patching: Oracle/Adoptium ship CVE fixes — running EOL Java 8 is a compliance failure.
    • Security Manager (deprecated): Modern apps use container boundaries + OS sandboxing instead.
    • Deserialization: Never deserialize untrusted bytes — RCE vector in legacy Java apps.
    • Dependency scanning: OWASP Dependency-Check, Snyk on Maven/Gradle lockfiles.

    Scalability considerations

    Why Java scales horizontally in enterprise:

    • Stateless services: Spring Boot pods scale behind K8s HPA — JVM heap sized per container limit.
    • Thread models: Platform threads for CPU-bound; virtual threads for I/O-bound at 10× lower memory.
    • Data tier separation: Java service layer scales independently of PostgreSQL/Kafka.
    • Multi-region: Same bytecode runs in us-east-1 and eu-west-1 — no recompile per region.

    Production challenges

    Real production failures teams hit when they treat Java as "just another language":

    • Metaspace OOM: Dynamic class generation (Hibernate, Groovy, bad frameworks) exhausts Metaspace — not heap.
    • GC pause storms: Heap too small for traffic spike — tune or scale horizontally before blaming "Java is slow."
    • Classpath hell: Duplicate SLF4J bindings, conflicting Jackson versions — enforce BOM in Gradle/Maven.
    • Java 8 lock-in: Teams fear migration; miss virtual threads, records, text blocks — accumulate tech debt.

    Common mistakes

    • Learning Java 8 tutorials in 2026 — you miss 13 years of language and JVM improvements.
    • Using System.out.println in production instead of structured logging (SLF4J + JSON appenders).
    • Assuming "Java is slow" from cold-start micro-benchmarks — JVM wins on sustained throughput.
    • Ignoring LTS calendar — running non-LTS (e.g. Java 22) in production without vendor support plan.
    • Conflating Java the language with Spring — learn JVM fundamentals first, frameworks second.

    Debugging guide

    When Java misbehaves in production — staff engineer playbook:

    • Read the stack trace bottom-up — root cause is often the deepest "Caused by".
    • jcmd <pid> VM.flags — verify GC, heap, and container-aware settings.
    • jfr start / jfr dump — capture 60s flight recording during incident.
    • Heap dump: jcmd GC.heap_dump + Eclipse MAT for leak analysis.
    • Version check: java -version on prod pod — mismatched local vs deploy is common.
    bash
    # Quick production health check
    java -version
    jcmd 1 VM.uptime
    jcmd 1 GC.heap_info
    jcmd 1 Thread.print | head -50

    Best practices

    • Target Java 21 LTS for new services (2026 baseline); plan 25 LTS migration path.
    • Use Eclipse Temurin or Amazon Corretto — free, patched, production-grade.
    • Pin JDK in CI and Docker with same major version as production.
    • Adopt records and sealed classes for DTOs and domain models — less boilerplate.
    • Enable -XX:+HeapDumpOnOutOfMemoryError in all production JVM flags.

    Anti-patterns

    • Deploying fat JARs without layer caching — 200MB images rebuild from scratch every CI run.
    • Sharing mutable static state across requests in Spring singletons — thread-safety bugs.
    • Using new Integer() or boxing in hot loops — allocation pressure (use primitives).
    • Big-bang Java 8 → 21 migration without dependency audit — breaks on removed APIs (javax → jakarta).

    Staff engineer notes

    • Staff engineers choose Java when the organization optimizes for predictability over novelty — hiring, LTS, bytecode portability, and 30 years of battle-tested libraries.
    • Your job in architecture review is not "Java vs Go" religion — articulate workload fit: throughput, latency SLO, team skill, and migration cost.
    • Java 21 virtual threads change the concurrency default — recommend platform threads only for CPU-bound work; document the decision in an ADR.
    • At Amazon/Netflix scale, the JVM is treated as a managed runtime platform — GC, JFR, and container limits are first-class design inputs, not ops afterthoughts.

    Interview questions

    Interview preparation

    15 questions grouped by difficulty — expand any card for a model answer and follow-up probe.

    Beginner

    5
    1. 1What is the difference between JDK, JRE, and JVM?
      Beginner

      Model answer

      JVM executes bytecode.

      JRE was JVM + standard libraries (deprecated as standalone product).

      JDK is JRE + development tools (javac, jar, javadoc, jfr).

      Production containers typically ship JRE-only images; developers use full JDK.

      Follow-up probe

      What do you ship in a Docker production image?

    2. 2Explain 'Write Once, Run Anywhere' in practical terms.
      Beginner

      Model answer

      • Java source compiles to platform-independent bytecode (.class). Any JVM on Linux, Windows, or macOS interprets/JITs that bytecode to native code. You don't ship OS-specific binaries
      • you ship JARs.

      Follow-up probe

      What breaks WORA assumptions?

    3. 3What is bytecode?
      Beginner

      Model answer

      • Intermediate instruction set for the JVM
      • not source code, not native machine code. Verified for safety before execution. Enables JIT optimization on hot paths.

      Follow-up probe

      Can you decompile .class files?

    4. 4Why does Java use garbage collection?
      Beginner

      Model answer

      • Automatic memory management removes manual free() errors (use-after-free, double-free). GC trades some CPU and pause latency for developer productivity and safety
      • tunable for low-latency with ZGC.

      Follow-up probe

      When would you prefer manual memory (Rust/C++)?

    5. 5What is the main method and why is it special?
      Beginner

      Model answer

      public static void main(String[] args) is the JVM entry contract.

      The runtime loads the class and invokes main via reflection.

      Without it, the class is a library, not an executable.

      Follow-up probe

      How does Spring Boot start without you writing much in main?

    Intermediate

    5
    1. 6What is the difference between Java 8, 11, 17, and 21?
      Intermediate

      Model answer

      • All are LTS releases with extended vendor support. 8: lambdas, streams. 11: HTTP client, var. 17: sealed classes, records. 21: virtual threads, sequenced collections, pattern matching
      • current enterprise baseline.

      Follow-up probe

      Would you deploy Java 23 to production?

    2. 7Explain the Java release cadence (6-month vs LTS).
      Intermediate

      Model answer

      Feature releases every 6 months (22, 23, 24…) for early adopters.

      LTS every 2 years (8, 11, 17, 21, 25) with multi-year security patches.

      Enterprises standardize on LTS; evaluate features in non-LTS before next LTS absorbs them.

      Follow-up probe

      How do you plan an LTS upgrade across 200 microservices?

    3. 8What are virtual threads (Project Loom) in Java 21?
      Intermediate

      Model answer

      • Lightweight threads managed by the JVM, not OS
      • ideal for I/O-bound concurrency at millions of threads with low memory. Platform threads still preferred for CPU-bound work. Spring Boot 3.2+ integrates with Tomcat/Jetty virtual thread executors.

      Follow-up probe

      Virtual threads vs reactive (WebFlux)?

    4. 9Compare HotSpot, GraalVM, and OpenJ9.
      Intermediate

      Model answer

      • HotSpot (OpenJDK default): mature JIT, G1/ZGC. GraalVM: native-image AOT, polyglot, faster startup for serverless. OpenJ9 (Eclipse): lower memory footprint, IBM heritage. All run same bytecode
      • choice is operational trade-off.

      Follow-up probe

      When would you pick GraalVM native-image?

    5. 10Why do banks and fintech still use Java?
      Intermediate

      Model answer

      Backward compatibility (code from 2005 runs on 21), mature ecosystem (Spring, JPA, Kafka), strong typing, audit-friendly tooling, massive hiring pool, and LTS security patching for compliance (SOC2, PCI-DSS).

      Follow-up probe

      What would make you recommend Kotlin on JVM instead?

    Advanced

    5
    1. 11Walk through class loading when you run java Main.
      Advanced

      Model answer

      class → bytecode verifier checks safety → interpreter executes cold → JIT (C1/C2) compiles hot methods to native → GC manages heap.

      * classes from rt modules.

      Follow-up probe

      What is a classloader leak?

    2. 12How does JIT compilation affect performance?
      Advanced

      Model answer

      Interpreter runs bytecode initially.

      HotSpot profiles hot methods and compiles to native via C1 (fast compile) then C2 (aggressive optimize).

      g.

      monomorphic → megamorphic IC).

      Warm-up matters for latency-sensitive first requests.

      Follow-up probe

      What triggers deoptimization?

    3. 13Design a Java LTS migration strategy for 400 microservices.
      Advanced

      Model answer

      Inventory JDK versions and dependencies (javax/jakarta).

      Central BOM on Java 21.

      Pilot 5 services with full regression + canary.

      Automate CI matrix on 17+21.

      Shadow traffic.

      Roll per team with rollback.

      Track GC pause and startup metrics.

      ADR per breaking change.

      Follow-up probe

      How do you handle libraries stuck on Java 8?

    4. 14Java vs Go for a new payments API — how do you decide?
      Advanced

      Model answer

      Payments need strong typing, mature crypto libraries, audit trail, and team skill.

      Java/Spring wins on ecosystem and hiring if latency SLO allows JVM warm-up.

      Go wins on small static binaries and simple deployment if team is small and throughput moderate.

      Document workload: I/O vs CPU, p99 target, team size.

      Follow-up probe

      What metrics would change your decision after 6 months?

    5. 15Explain how Netflix uses Java at scale.
      Advanced

      Model answer

      • Thousands of Spring Cloud microservices, standardized observability (Atlas), chaos engineering, JVM tuning culture. Java chosen for service longevity, developer velocity, and cross-team library sharing
      • not because it is the fastest language on paper.

      Follow-up probe

      What problems does polyglot microservices create that Java standardization avoids?

    Hands-on exercise

    Lab: Java platform discovery — run in the playground below, then answer:

    • Print Runtime.version() and identify your JDK vendor.
    • Print available processors and max memory — relate to container limits.
    • Modify the program to print "Enterprise-ready" only if major version ≥ 21.
    • Write one sentence: which LTS would you recommend for a new payment service and why.

    JavaJava Introduction

    Starter Templates
    OutputRemote JVM (Piston · Java 15)
    Press Run to execute. Real javac + JVM via remote API. Falls back to simulator on network failure.

    Architecture trade-offs

    • Java vs native (Go/Rust): Java wins throughput + ecosystem on long-lived services; native wins cold start and memory for tiny binaries.
    • LTS vs latest feature release: LTS wins support and compliance; feature releases win early access to preview APIs.
    • HotSpot vs GraalVM native-image: HotSpot wins peak throughput; native-image wins startup time and RSS for serverless.

    Summary

    Java Introduction is not history trivia — it is the foundation for every architecture decision that follows. You now understand why Java dominates enterprise software, how the JVM executes your code, why LTS matters, what Java 21 delivers, and how companies like Netflix standardize on the platform. Next: set up JDK 21 and write production-grade Java.

    Key takeaways

    • Java was built for portability and longevity — WORA via bytecode + JVM still defines enterprise adoption.
    • Standardize on Java 21 LTS for new work; understand the release train (6-month feature vs 2-year LTS).
    • The JVM ecosystem (Temurin, Corretto, GraalVM) is multi-vendor — bytecode is the portability contract.
    • Netflix, Amazon, and banking run Java for predictability, hiring, and decades of library investment — not hype.
    • Staff engineers evaluate Java on workload fit, GC/JFR operability, and migration cost — not slogans.
    Ready to mark this lesson complete?Track your journey across the entire course.