Back to TechDepth
TechDepth / JavaFREE COURSE

CODESTUDIO / GO BEYOND SYNTAX

JavaUnderstand the concepts. Build real technical depth.

Go beyond tutorials with Java. A dedicated path for technical understanding and interview preparation.

19 learning modules50 interview questionsSelf-paced · Free
Java / learning workspace

Your technical depth starts here.

MODULE 1

Java Fundamentals, JVM Architecture, and First Program

1.1 Module Overview

This module provides the foundation of Java programming. You will learn what Java is, how Java applications compile and execute across the JDK, JRE, and JVM, how to configure your development environment, and how to write and run your first Java program.

By the end of this module, you should be able to:

  • Explain what Java is and why it remains a dominant backend language.
  • Differentiate between the JDK, JRE, and JVM.
  • Describe the Java compilation and bytecode execution pipeline.
  • Write, compile, and run your first Java program from the command line.
  • Understand the anatomy of the main method.
  • Describe core Java design principles: platform independence, security, and automated memory management.

1.2 What is Java?

Definition

Java is a high-level, statically typed, class-based, object-oriented programming language designed for portability, security, scalability, and large-scale distributed application development.

Java programs are compiled into intermediate bytecode rather than platform-specific machine code. This bytecode runs on the Java Virtual Machine (JVM), enabling the principle of "Write Once, Run Anywhere" (WORA).

Where Java is Used

  • Enterprise & Backend Services: High-throughput microservices using Spring Boot, Quarkus, and Micronaut.
  • Fintech & Banking Systems: Core transaction ledgers, trading platforms, and payment gateways.
  • Cloud-Native & Distributed Systems: Apache Kafka, Apache Spark, Hadoop, Elasticsearch, and Cassandra.
  • Android App Development: Native Android runtime (ART) builds on Java APIs.
  • Embedded & Desktop Systems: Enterprise desktop tooling and IoT gateways.

1.3 Your First Java Program

Source Code (Main.java)

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

Step-by-Step Explanation

  • public class Main: Defines a class named Main. In Java, every line of executable code must reside inside a class. When a class is declared public, the enclosing file name must exactly match the class name (Main.java).
  • public static void main(String[] args): The standard entry point of every standalone Java application recognized by the JVM.
    • public: Access modifier allowing the JVM to invoke the method from outside the package.
    • static: Indicates the method belongs to the class itself, allowing the JVM to invoke it without instantiating an object first.
    • void: The method returns no value upon completion.
    • main: The designated method name required by the runtime launcher.
    • String[] args: Array of command-line arguments passed into the program.
  • System.out.println(...): Standard output method. System is a built-in final class in java.lang, out is a static PrintStream member, and println prints the string followed by a newline.

1.4 Compilation and Execution Pipeline

A .java file does not run directly on host CPU architecture. It goes through compilation and interpretation/JIT compilation.

text
Source Code (Main.java)
       ↓
 javac Compiler
       ↓
Bytecode (Main.class)
       ↓
Class Loader (JVM)
       ↓
Bytecode Verifier
       ↓
Execution Engine (Interpreter + JIT Compiler)
       ↓
Host Machine Hardware (x86_64, ARM64)

Compilation and Run Commands

bash
# 1. Compile source into bytecode
javac Main.java

# 2. Inspect generated bytecode class file
ls -la Main.class

# 3. Launch the JVM and execute the main method
java Main

Output

text
Hello, CodeStudio!

1.5 JDK vs JRE vs JVM

Understanding the runtime stack is fundamental for developers and deployment engineers.

ComponentFull FormPurposeIncludes
JDKJava Development KitFull toolkit to write, compile, and debug Java programsCompiler (javac), debugger (jdb), archiver (jar), diagnostic tools (jcmd), plus JRE
JREJava Runtime EnvironmentMinimum environment required to run compiled Java applicationsJVM, core class libraries (rt.jar / modules), runtime configuration
JVMJava Virtual MachineAbstract computing machine that executes bytecode instructionsClass loader, memory areas (Heap, Stack, Metaspace), Execution Engine (JIT)

Relationship Hierarchy

text
+-------------------------------------------------------+
| JDK (Development Kit)                                 |
|  [javac, javadoc, jar, jlink, jcmd, debugger]        |
|  +-------------------------------------------------+  |
|  | JRE (Runtime Environment)                       |  |
|  |   [Core Java Class Libraries (java.base, etc.)] |  |
|  |   +------------------------------------------+  |  |
|  |   | JVM (Virtual Machine)                    |  |  |
|  |   |   [Class Loader, Memory, JIT Engine]     |  |  |
|  |   +------------------------------------------+  |  |
|  +-------------------------------------------------+  |
+-------------------------------------------------------+

1.6 Core Features of Java

FeatureTechnical Meaning
Platform IndependentBytecode executes uniformly on any JVM implementation conforming to the JVM Specification.
Object-OrientedPure focus on modular classes, encapsulation, inheritance, abstraction, and polymorphism.
Strongly TypedStrict compile-time type verification prevents unexpected memory type mismatches.
Automatic Memory ManagementGarbage Collector (GC) runs concurrently to reclaim unreferenced heap objects, eliminating manual free().
Robust & SecurePointer arithmetic is disallowed; runtime array bounds and type checks eliminate memory corruptions.
High PerformanceJust-In-Time (JIT) HotSpot compiler dynamically translates frequently executed bytecode loops into native assembly.
Built-in MultithreadingNative OS thread abstraction, locks, concurrency utilities, and modern Virtual Threads (Project Loom).

1.7 Best Practices

  • Always name your file identically to your public class (case-sensitive).
  • Maintain standard package conventions (com.company.project.module).
  • Write meaningful Javadoc comments (/** ... */) for public APIs.
  • Keep main method minimal—use it only to bootstrap application objects.
  • Prefer explicit command-line compilation checks during local testing before relying on IDE automation.

1.8 Practice Exercises

  1. Write, compile, and execute a program that prints your name and career target.
  2. Inspect the bytecode of Main.class using javap -c Main.
  3. Pass two numbers as command-line arguments (args[0] and args[1]), parse them with Integer.parseInt(), and print their sum.
  4. Modify the class name in Main.java to App without renaming the file, and observe the compilation error.
  5. Write a program that displays the active Java version using System.getProperty("java.version").

1.9 Module Recap

In this module, you learned:

  • What Java is and why it excels in enterprise and distributed systems.
  • How source code is compiled by javac into bytecode and executed by the JVM.
  • The architectural distinction between the JDK, JRE, and JVM.
  • How to structure the public static void main(String[] args) method.
  • Why WORA (Write Once, Run Anywhere) and JIT compilation deliver high performance with safety.