1. University MCA (AI/ML) Semester 2
  2. CAP477
  3. Unit 1

CAP477 · Unit 1: Java fundamentals

Java platform: JDK, JRE, JVM and bytecode

8 practice questions

Key points

  • javac turns .java into bytecode .class; JVM runs it
  • JDK includes JRE which includes JVM
  • main is public static void
  • Bytecode is platform independent, JVM is not

Java is a compiled and interpreted, object-oriented language designed for "write once, run anywhere".

Flow: source .java -> javac compiler -> bytecode .class -> run by the JVM on any OS. Bytecode is platform independent; the JVM is platform specific.

TermMeaning
JVMVirtual machine that loads, verifies and executes bytecode; includes the JIT compiler and garbage collector
JREJVM + core class libraries needed to run programs
JDKJRE + development tools (javac, jar, javadoc, debugger) to build programs

Entry point: public static void main(String[] args). It is public so the JVM can call it, static so no object is needed, and void because it returns nothing to the JVM.

Rules: a public class must live in a file with the same name (Main in Main.java). Java is case sensitive. Execution stops at the end of main; the process exit code is 0 unless System.exit(n) or an uncaught exception intervenes.

Features: automatic garbage collection, no pointer arithmetic, strong typing, built-in multithreading, and security through the bytecode verifier.

Exam pitfall: JDK contains JRE contains JVM; the JVM alone cannot compile.

Try two questions

Question 1 · Tier 2, Understand

Java achieves 'write once, run anywhere' because:

  1. Java has no standard library
  2. Source code is compiled separately for each OS
  3. Bytecode runs on any platform that has a JVM
  4. The JVM is identical on all platforms internally
Show the answer

C. The same .class files run on any JVM; each platform supplies its own JVM.

Question 2 · Tier 3, Apply

Which tool is part of the JDK but not of the JRE?

  1. javac
  2. The garbage collector
  3. The JVM
  4. The class libraries
Show the answer

A. Only the JDK ships the compiler and development tools.