ITM 152

Object Oriented Programming in Java

TU BITM · Semester 2 · BITM curriculum and programme regulation

Requirement
required
Credits
3
Study Guide
9 units available

Chapter notes

Authoritative study guide across 9 syllabus units

Open a unit to read its study notes.

Unit 1: Lab: Write and execute basic Java programs· 5 LHs· ~6 marks

Part 1: Core Concepts (2 Marks)

  • Write Once, Run Anywhere (WORA): Java’s foundational philosophy where source code compiles into platform-independent intermediate Bytecode (.class), executed on any operating system hosting an architecture-specific JVM.
  • JVM vs. JRE vs. JDK: JDK (Java Development Kit) contains compiler (javac) and tools; JRE (Java Runtime Environment) provides class libraries and JVM; JVM (Java Virtual Machine) is the abstract execution engine executing Bytecode.
  • Just-In-Time (JIT) Compiler: A runtime JVM subsystem that translates frequently executed Bytecode sequences (hotspots) directly into native CPU machine instructions, dramatically boosting execution performance.
  • Garbage Collection (GC): An autonomous background daemon thread in the JVM that reclaims heap memory occupied by unreferenced objects, eliminating manual memory deallocation bugs.

Part 2: Structural Frameworks (10 Marks)

Complete Java Architecture Pipeline (Source to Native Execution)

  1. Developer Source: Program.java
    • (javac compiler)
  2. Platform-Independent Bytecode: Program.class
    • ================ JVM BOUNDARY ================
  3. ClassLoader Subsystem: Loading, Linking, Initialization
  4. JVM Runtime Memory Areas
    • Method Area | Heap (Objects) | JVM Stack (Frames) | PC Registers | Native Stack
  5. Execution Engine
    • | Bytecode Interpreter <---> JIT Compiler (HotSpot) |
    • | (C1 / C2 Compilers) |
  6. Native Machine Code Executed by Host OS (Windows/Linux/macOS)

Part 3: Distinction Tables

Basis of Comparison Java Development Kit (JDK) Java Runtime Environment (JRE)
Primary Audience Software developers and engineers End-users executing pre-compiled applications
Tooling Included Compiler (javac), debugger (jdb), archiver (jar) JVM, core standard class libraries, runtime loaders
Development Role Required to compile and build .java files Capable only of executing existing .class files
Physical Scope Superset of JRE (JDK=JRE+Dev Tools\text{JDK} = \text{JRE} + \text{Dev Tools}) Subset of JDK (JRE=JVM+Class Libraries\text{JRE} = \text{JVM} + \text{Class Libraries})

Part 4: Worked Problems & Exam Traps

Canonical Java Program Archetype

public class WelcomeBITM {
    // Execution entry point
    public static void main(String[] args) {
        System.out.println("Welcome to BITM Tribhuvan University!");
        for (int i = 0; i < args.length; i++) {
            System.out.printf("Arg[%d] = %s\n", i, args[i]);
        }
    }
}

Execution workflow:

  1. javac WelcomeBITM.java   ⟹  \implies Generates WelcomeBITM.class.
  2. java WelcomeBITM Nepal IT   ⟹  \implies Executes JVM, outputs arguments.

TU Exam Trap: If a public class is declared public class WelcomeBITM, the source filename MUST exactly match: WelcomeBITM.java (including strict case sensitivity). A filename mismatch triggers an immediate compilation failure.