Java Master Study Guide
Complete Exam & Final Prep — Modules 1–7
How the Modules Connect
Each module is a layer on top of the last — skipping one makes the next feel harder than it needs to be.
Module What it gives you Why the next module needs it
1. Core Architecture How Java runs at all You need a running program
(JDK/JRE/JVM, main()) before you can put anything
inside it
2. Variables & Data Types Boxes to store values in Operators need values to
operate on
3. Operators & I/O Doing things with values, talking Control structures need
to the user conditions built from operators
4. Control Structures Decisions and repetition Methods are just named,
reusable blocks of this logic
5. Procedural Programming Reusable methods, scope, Classes are collections of
overloading methods + the data they act on
6. OOP Fundamentals Classes, objects, access control Inheritance is classes building on
other classes
7. Advanced OOP Inheritance, polymorphism, This is the foundation for every
abstraction larger Java project you write
next
Arrays don't get their own numbered module, but they show up starting in Module 1 (String[] args)
and are essential by Module 7 (Shape[] shapes) — so the primer below locks them in early, before
they show up unexplained in someone else's code.
Quick Primer: Arrays
Used everywhere from Module 1 onward, so it earns a spot before you hit code that assumes you already
know it.
Think of an array as a strip of numbered lockers, all the same size, all holding the same type of thing.
Each item gets a locker number (its index), and indexes always start at 0.
int[] scores = {90, 85, 77}; // array literal: 3 lockers, holds ints
String[] names = new String[3]; // 3 empty lockers, holds Strings (all start as null)
[Link](scores[0]); // 90 -> FIRST locker is index 0, not 1
[Link]([Link]); // 3 -> length is a property, no parentheses
scores[1] = 100; // overwrite locker 1 (was 85, now 100)
for (int i = 0; i < [Link]; i++) { // classic index loop
[Link](scores[i]);
}
for (int s : scores) { // "enhanced for" / for-each — cleaner, read-only
[Link](s);
}
● Fixed size: once created, an array's length never changes. Need it to grow? That's what
ArrayList is for (outside the scope of Modules 1–7).
● Common exam trap: scores[3] on a 3-element array throws
ArrayIndexOutOfBoundsException at runtime — valid indexes run 0 to length - 1, not
1 to length.
● Arrays are non-primitive: int[] scores is a reference type, just like String — it can be
null, and passing it to a method passes the reference, so the method can change the contents
of the original array.
MODULE 1: CORE ARCHITECTURE
JDK, JRE, JVM • Bytecode & Compilation • The main() Entry Point
1. The Core Concept
Think of Java like shipping a recipe to kitchens all over the world, where every kitchen has different
stove brands (Windows, Mac, Linux).
● JDK (Java Development Kit) = the entire chef's toolkit — knives, cookbooks, the oven itself. It's
what you install to write and build Java programs. It contains the JRE + compiler + dev tools.
● JRE (Java Runtime Environment) = just the oven and pantry — what you need to run an already-
written recipe (program), but not to write one.
● JVM (Java Virtual Machine) = the actual "universal stove" that takes your standardized recipe
card (bytecode) and cooks it correctly no matter which kitchen (OS) it's in. This is what gives Java
its "Write Once, Run Anywhere" superpower.
● Bytecode = your recipe translated into a universal language (.class file) that any JVM can
read, regardless of the underlying computer.
● `main()` = the "start cooking here" sticky note. It's the front door of every standalone Java
application — the JVM looks specifically for this method to begin execution.
2. Exam-Ready Cheat Sheet
Term Contains Purpose
JDK JRE + Compiler (javac) + Develop & compile code
Debugger + Tools
JRE JVM + Core Libraries Run compiled code
JVM Class loader + Execution engine Executes bytecode, gives
platform independence
● Compilation flow: `.java` (source) → javac compiler → `.class` (bytecode) → JVM
interprets/JITs → machine code.
● JIT (Just-In-Time compiler) inside the JVM speeds up execution by compiling hot bytecode to
native machine code at runtime.
● Exact required signature: public static void main(String[] args)
● public → JVM (outside the class) must be able to call it.
● static → JVM calls it without creating an object first.
● void → returns nothing.
● String[] args → holds command-line arguments.
● File name must match the public class name exactly (case-sensitive): [Link] →
class HelloWorld.
3. Visual Code Breakdown
// File MUST be named [Link] to match the public class
public class HelloWorld {
// JVM searches for this EXACT signature to start the program
public static void main(String[] args) {
// Prints text to console, then moves to a new line
[Link]("Hello, JVM!");
}
// javac [Link] -> creates [Link] (bytecode)
// java HelloWorld -> JVM runs the bytecode
}
4. Common Exam Traps
● Confusing JDK/JRE/JVM order — remember JDK ⊃ JRE ⊃ JVM (each contains the next).
● Forgetting static on main() — the program compiles but throws a runtime error since the
JVM can't call it without an object.
● Thinking Java is "interpreted only" — it's actually compiled to bytecode first, then
interpreted/JIT-compiled by the JVM (a hybrid model).
5. Mini Practice Quiz
Q1. Which component is responsible for making Java "platform independent"? A) JDK B) javac C) JVM
D) IDE
Q2. What will happen if you write public void main(String[] args) (missing static)? A)
Compiles and runs normally B) Compile-time error C) Compiles, but throws a runtime error when
launched D) Program runs but prints nothing
Q3 (Short Code). Write the minimal valid Java program (class + main method) that prints
"Compiling..." to the console.
MODULE 2: VARIABLES & DATA TYPES
Primitives (int, double) • Non-Primitives (String) • Implicit/Explicit Casting
1. The Core Concept
Imagine labeled storage boxes. A box labeled int can only hold whole numbers, one labeled double
holds numbers with decimals — these are primitives, simple fixed-size boxes storing the raw value
directly.
A String is different — it's not a raw value box, it's a reference — like a locker number pointing to
where the actual text is stored elsewhere in memory. That's why Strings are called non-primitive (or
reference) types.
Casting is converting between box types. Implicit casting is like pouring a small cup into a bigger bucket
— safe and automatic (int → double). Explicit casting is like squeezing a bucket into a small cup — you
might lose stuff (double → int loses decimals), so Java forces you to manually confirm it.
2. Exam-Ready Cheat Sheet
Primitives (8 total): byte, short, int, long, float, double, char, boolean
Type Size Example
int 4 bytes int age = 21;
double 8 bytes double gpa = 3.9;
char 2 bytes char grade = 'A'; (single
quotes!)
boolean 1 bit (conceptually) boolean pass = true;
Non-Primitive: String, arrays, classes, interfaces — store a reference/address, can be null.
String name = "Alex"; // double quotes!
String empty = null; // valid for non-primitives, NOT for primitives
Casting Rules:
● Implicit (Widening) — small → big, automatic, no data loss: int → long → float →
double
● Explicit (Narrowing) — big → small, manual, possible data loss: (int) 9.7 → 9 (truncates,
doesn't round!)
double d = 10; // implicit: int -> double, automatic
int i = (int) 10.9; // explicit: must cast, result = 10 (truncated, NOT rounded)
3. Visual Code Breakdown
public class DataTypes {
public static void main(String[] args) {
int wholeNumber = 42; // primitive: stores value directly
double decimalNumber = 3.14; // primitive: 8-byte floating point
char letter = 'J'; // primitive: single character, single quotes
boolean isTrue = true; // primitive: only true/false
String text = "Java"; // non-primitive: reference to text data
double implicitCast = wholeNumber; // int -> double: automatic, safe
int explicitCast = (int) decimalNumber; // double -> int: MUST cast, truncates to 3
[Link](implicitCast); // prints 42.0
[Link](explicitCast); // prints 3 (not 3.14, decimal is chopped off)
}
}
4. Common Exam Traps
● Using double quotes for char ("A") instead of single quotes ('A') — this is a compile error.
● Assuming explicit casting rounds — it actually truncates ((int) 9.9 = 9, not 10).
● Forgetting String uses == for reference comparison (do two variables point to the same
object?) vs .equals() for actual content comparison — a huge trap on exams.
5. Mini Practice Quiz
Q1. What is the output of [Link]((int) 7.8);? A) 8 B) 7 C) 7.8 D) Compile error
Q2. Which of these is a non-primitive data type? A) int B) boolean C) String D) double
Q3 (Short Code). Declare a double variable price with value 19, then explicitly cast it into an int
variable roundedPrice and print the result.
MODULE 3: BASIC OPERATORS & I/O
Arithmetic • Concatenation • Escape Sequences • println() & Scanner
1. The Core Concept
Arithmetic operators are your basic calculator buttons (+ - * /). But when + is used with a String,
Java switches modes: instead of adding numbers, it glues text together (concatenation) — like taping
two labels into one long label.
Escape sequences are special keyboard shortcuts inside text (like \n for "press Enter here") that let you
format printed output without literally hitting Enter in your code.
`[Link]()` is your program's mouth — talks to the user. `Scanner` is your program's ears —
listens for what the user types in.
2. Exam-Ready Cheat Sheet
Operator Meaning Note
+ Add (numbers) or Concatenate 1 + 2 = 3, but "1" + 2 = "12"
(if either side is String)
-*/ Subtract, Multiply, Divide / between two ints = integer
division (drops remainder!)
% Modulus (remainder) 7 % 2=1
Escape Sequences: \n newline · \t tab · \" quote · \\ backslash
Scanner Setup:
import [Link]; // required import
Scanner input = new Scanner([Link]); // create the object
int x = [Link](); // read an int
String s = [Link](); // read a full line of text
double d = [Link](); // read a double
⚠️ Classic gotcha: calling nextInt() then nextLine() immediately after — the leftover newline
character gets consumed by the empty nextLine(), skipping input.
3. Visual Code Breakdown
import [Link]; // needed to use Scanner class
public class OperatorsDemo {
public static void main(String[] args) {
Scanner input = new Scanner([Link]); // sets up keyboard listener
[Link]("Enter your age: "); // print() = no new line after
int age = [Link](); // reads an integer from user
int result = 7 / 2; // integer division -> 3 (remainder dropped)
double preciseResult = 7.0 / 2; // 3.5, since one operand is a double
String message = "You are " + age + " years old.\n"; // concatenation + escape
sequence
[Link](message); // prints text, then moves cursor to new line
[Link]("Col1\tCol2"); // \t inserts a tab space between words
}
}
4. Common Exam Traps
● Integer division surprise: 5 / 2 gives 2, not 2.5, because both operands are int. Need 5.0 /
2 or cast one to double.
● Operator precedence in concatenation: "Total: " + 1 + 2 prints "Total: 12" (left-to-
right string concat), but "Total: " + (1 + 2) prints "Total: 3".
● Mixing nextInt()/nextDouble() with nextLine() causes the classic "skipped input" bug
from a leftover newline.
5. Mini Practice Quiz
Q1. What does [Link]("Total: " + 3 + 4); output? A) Total: 7 B) Total: 34 C)
Compile error D) Total: 3 4
Q2. What is the result of 9 / 4 in Java (both operands are int)? A) 2.25 B) 2 C) 3 D) 2.0
Q3 (Short Code). Using Scanner, prompt the user for their name (a String) and print "Hello,
[name]!" on its own line using an escape sequence.
MODULE 4: CONTROL STRUCTURES
if / else • switch • for / while / do-while
1. The Core Concept
Control structures are the "decision forks" and "repeat buttons" of your program.
● `if / else` = a fork in the road: "IF it's raining, take an umbrella; ELSE, wear sunglasses."
● `switch` = a vending machine: you press one specific button (a value) and it jumps directly to
that specific slot, rather than checking conditions one by one.
● Loops = a treadmill on repeat. for is best when you know exactly how many times to repeat
(like "run 10 laps"). while repeats as long as a condition holds true (like "run until you're tired"
— checked before each lap). do-while is the same, but guarantees at least one lap happens
before checking if you're tired.
2. Exam-Ready Cheat Sheet
if (condition) { }
else if (condition2) { }
else { }
switch (variable) {
case value1:
// code
break; // without break, execution "falls through" to next case!
default:
// code if no case matches
}
for (int i = 0; i < 5; i++) { } // init; condition; update
while (condition) { } // checks BEFORE running — may run 0 times
do { } while (condition); // checks AFTER running — always runs at least once
● switch works with: int, char, String, enum (not double/boolean).
● Loop keywords: break exits the loop entirely; continue skips to the next iteration.
3. Visual Code Breakdown
public class ControlFlow {
public static void main(String[] args) {
int score = 85;
if (score >= 90) { // checked first
[Link]("A");
} else if (score >= 80) { // checked only if above was false
[Link]("B"); // this line runs
} else {
[Link]("C");
}
char grade = 'B';
switch (grade) { // jumps directly to matching case
case 'A':
[Link]("Excellent");
break; // stops here, prevents fall-through
case 'B':
[Link]("Good"); // this runs
break;
default:
[Link]("Keep trying");
}
for (int i = 0; i < 3; i++) { // runs exactly 3 times: i=0,1,2
[Link]("For loop: " + i);
}
int count = 0;
do {
[Link]("Runs at least once: " + count);
count++;
} while (count < 0); // condition is false, but already ran once
}
}
4. Common Exam Traps
● Forgetting break; in switch cases — causes fall-through, where execution keeps running into
the next case's code.
● Using = (assignment) instead of == (comparison) inside an if condition — if (x = 5) is a
compile error for int (not boolean), but a dangerous silent bug pattern in general.
● Off-by-one errors in for loops: for (int i = 0; i <= 5; i++) runs 6 times (0 through
5), not 5 — easy exam trick question.
5. Mini Practice Quiz
Q1. How many times does this loop execute? for (int i = 1; i <= 4; i++) { } A) 3 B) 4 C) 5
D) Infinite
Q2. What happens if you omit break; in a switch case that matches? A) Nothing extra happens B)
Compile error C) Execution falls through to the next case(s) until a break or the end D) Only the default
case runs
Q3 (Short Code). Write a while loop that prints the numbers 1 through 5 (inclusive).
MODULE 5: PROCEDURAL
PROGRAMMING
Methods & Parameters • Pass-by-Value • Local vs Global Scope • Overloading
1. The Core Concept
A method is a reusable mini-recipe card you can call by name instead of rewriting the same steps
repeatedly. Parameters are the ingredients you hand it when calling it.
Pass-by-value is crucial: Java doesn't hand the method your actual ingredient — it hands it a photocopy.
If the method scribbles on the photocopy (changes the parameter), your original ingredient outside the
method is untouched.
Scope is about "which room can see which whiteboard." A local variable is written on a whiteboard
inside one specific room (method) — only visible there. A field (sometimes loosely called "global" in
Java, though Java has no true globals) is written on the whiteboard in the main hallway (the class) —
visible to every room (method) in that class.
Method overloading = having multiple recipe cards with the same name but different ingredient lists
(parameter types/counts), so the "chef" (compiler) picks the correct one based on what you hand over.
2. Exam-Ready Cheat Sheet
returnType methodName(paramType param1, paramType param2) {
// body
return value; // only if returnType isn't void
}
● Pass-by-value: primitives copy the value; objects/arrays copy the reference (so the method can
still mutate the object's internal state, but reassigning the reference itself doesn't affect the
caller's variable).
● Local variable: declared inside a method — exists only during that method's execution, invisible
elsewhere.
● Instance/field variable: declared inside the class, outside any method — accessible by all
methods in that class.
● Overloading rules: must differ in parameter list (type, number, or order) — return type ALONE is
not enough to overload.
3. Visual Code Breakdown
public class MethodsDemo {
static int globalCounter = 0; // FIELD: visible to every method in this class
public static void main(String[] args) {
int localVar = 10; // LOCAL: only visible inside main()
modifyValue(localVar); // passes a COPY of localVar's value
[Link](localVar); // still 10! Original is untouched (pass-by-value)
[Link](add(2, 3)); // calls int version -> 5
[Link](add(2.5, 3.5)); // calls double version -> 6.0 (OVERLOADING)
}
static void modifyValue(int num) {
num = 999; // only changes the LOCAL COPY inside this method
}
static int add(int a, int b) { // version 1: two ints
return a + b;
}
static double add(double a, double b) { // version 2: two doubles (overloaded)
return a + b;
}
}
4. Common Exam Traps
● Believing a method can permanently change a primitive argument's value in the caller — it
cannot, due to pass-by-value.
● Trying to overload methods by return type only (e.g., int add() vs double add() with
identical parameters) — this is a compile error, not valid overloading.
● Confusing scope: trying to access a method's local variable from another method, or forgetting a
local variable "shadows" (temporarily hides) a field of the same name inside that method.
5. Mini Practice Quiz
Q1. After calling a method that reassigns an int parameter inside its body, what happens to the original
variable in main()? A) It changes to the new value B) It remains unchanged C) It becomes 0 D) Compile
error
Q2. Which is a valid way to overload a method? A) Same name, same parameters, different return type
B) Same name, different number of parameters C) Different name, same parameters D) Same name,
same parameters, different access modifier
Q3 (Short Code). Write two overloaded methods named multiply — one that takes two ints and
returns their product, and one that takes two doubles and returns their product.
MODULE 6: OOP FUNDAMENTALS
Packages & Access Modifiers • Classes, Attributes & Objects • 'new' • Class Relations
1. The Core Concept
A class is a blueprint (e.g., "Car Blueprint"), and an object is an actual physical car built from that
blueprint. You can build many cars (objects) from one blueprint (class) — each with its own color,
mileage, etc. (attributes).
The `new` keyword is the construction command — it tells Java "actually build one of these now" and
hands you back a reference to the freshly built object.
Packages are like folders that organize related blueprints (classes) together, preventing name clashes
(two different Car classes in different packages don't conflict).
Access modifiers are locks on your blueprint's rooms, controlling who's allowed to see or use them:
public (anyone), private (only this class), protected (this class + subclasses + same package), and
default/package-private (only same package).
Class relations describe how blueprints connect: "has-a" (composition — a Car has an Engine object) vs
"is-a" (inheritance — covered in Module 7).
2. Exam-Ready Cheat Sheet
package [Link]; // must be the first line in the file
public class Car { // the blueprint
private String color; // attribute (private = locked, only Car can touch it)
public int mileage; // attribute (public = anyone can access)
public Car(String color) { // constructor: runs when 'new' builds an object
[Link] = color; // 'this' refers to the current object's own field
}
}
// Elsewhere:
Car myCar = new Car("Red"); // 'new' builds the object in memory, myCar holds the reference
Modifier Same Class Same Package Subclass (diff Everywhere
package)
private ✅ ❌ ❌ ❌
default (none) ✅ ✅ ❌ ❌
protected ✅ ✅ ✅ ❌
public ✅ ✅ ✅ ✅
● Class relations: "has-a" = composition (one class contains another as a field). "is-a" = inheritance
(Module 7).
3. Visual Code Breakdown
package vehicles; // organizes this class into the "vehicles" folder/namespace
public class Engine { // a separate small class
public int horsepower = 300;
}
public class Car {
private String color; // private: hidden from outside classes
private Engine engine; // "HAS-A" relationship: Car contains an Engine object
public Car(String color) { // constructor
[Link] = color; // assigns the parameter to this object's field
[Link] = new Engine(); // 'new' builds a fresh Engine object, stored in Car
}
public String getColor() { // public "getter" method exposes the private field safely
return color;
}
}
// In another class:
Car myCar = new Car("Blue"); // 'new' allocates memory, constructor runs, reference returned
[Link]([Link]()); // can't touch 'color' directly (private) - must use
getter
4. Common Exam Traps
● Confusing a class (the blueprint/template, compile-time concept) with an object (the actual
instance in memory, created via new).
● Forgetting that private fields need public "getter/setter" methods to be accessed from
outside the class — directly typing [Link] from another class causes a compile error.
● Mixing up default (package-private) access with protected — default has no subclass privilege
outside the package, but protected does.
5. Mini Practice Quiz
Q1. What keyword actually allocates memory and creates an object from a class? A) class B) new C)
public D) import
Q2. Which access modifier allows access from the same class AND same package, but NOT from a
subclass in a different package? A) private B) default (no modifier) C) protected D) public
Q3 (Short Code). Write a class Book with a private String title field, a constructor that sets it, and a
public getter method getTitle().
MODULE 7: ADVANCED OOP STRATEGIES
Inheritance • Overriding • Polymorphism • Abstract Classes & Interfaces • final
1. The Core Concept
Inheritance ("is-a" relationship) is like a child inheriting traits from a parent: a Dog is an Animal, so it
automatically gets the Animal's general traits (like eat()), but can also have its own special traits
(bark()).
Method overriding is when the child provides its own specific version of a parent's method — e.g., every
Animal can makeSound(), but Dog overrides it to specifically bark instead of the generic sound.
Polymorphism ("many forms") means you can treat different objects through a common parent type,
and each will automatically perform its own specific behavior — like a universal remote control button
"Play" that works differently on a TV vs. a stereo, but you press the same button either way.
Abstract classes are incomplete blueprints — they say "every subclass MUST have a makeSound()
method" without deciding what it does. Interfaces are pure contracts — 100% "must-do lists" with no
implementation, allowing unrelated classes to share behavior across different family trees.
`final` is the "no more changes allowed" stamp: final variable = the value can't be reassigned; final
method = can't be overridden; final class = can't be extended/inherited at all.
2. Exam-Ready Cheat Sheet
class Animal { // parent / superclass
void makeSound() { [Link]("Some sound"); }
}
class Dog extends Animal { // "extends" = inheritance ("is-a")
@Override // annotation confirms this overrides parent
void makeSound() { [Link]("Bark"); } // OVERRIDING: same signature, new
behavior
}
abstract class Shape { // cannot be instantiated directly (no 'new
Shape()')
abstract double getArea(); // no body - subclasses MUST implement this
void describe() { [Link]("A shape"); } // CAN have regular implemented methods
too
}
interface Movable { // pure contract, no bodies (Java 8+ allows
default methods)
void move(); // implicitly public abstract
}
class Car2 implements Movable { // "implements" for interfaces
public void move() { [Link]("Driving"); }
}
final int MAX = 100; // cannot be reassigned
final class Utility { } // cannot be extended/subclassed
Feature Abstract Class Interface
Instantiable? No No
Methods w/ body allowed? Yes Only default/static (Java 8+)
Multiple inheritance? extends only ONE implements MANY
Fields Any type public static final only
(constants)
Polymorphism in action:
Animal a = new Dog(); // parent reference TYPE, child OBJECT
[Link](); // calls Dog's version at RUNTIME -> prints "Bark" (dynamic binding)
3. Visual Code Breakdown
abstract class Shape { // abstract = incomplete blueprint, cannot do 'new
Shape()'
abstract double getArea(); // subclasses are FORCED to implement this
}
class Circle extends Shape { // "extends" = inheritance, Circle IS-A Shape
double radius;
Circle(double radius) { [Link] = radius; }
@Override // OVERRIDING the abstract method with real logic
double getArea() {
return [Link] * radius * radius;
}
}
class Square extends Shape {
double side;
Square(double side) { [Link] = side; }
@Override
double getArea() { // different implementation, same method name
return side * side;
}
}
public class ShapeTest {
public static void main(String[] args) {
Shape[] shapes = { new Circle(2), new Square(3) }; // POLYMORPHISM: array of parent
type
for (Shape s : shapes) {
// Same method call, but different behavior runs depending on actual object type
[Link]("Area: " + [Link]());
}
}
}
4. Common Exam Traps
● Trying to do new Shape() on an abstract class — this is always a compile error; abstract
classes can never be directly instantiated.
● Confusing overriding (same signature, redefined behavior in a subclass, runtime polymorphism)
with overloading (same name, different parameter list, resolved at compile time) — these are
commonly tested against each other.
● Forgetting a class can only extends one class (single inheritance) but can implements
multiple interfaces — a very common multiple-choice trick.
5. Mini Practice Quiz
Q1. What is the output of:
Animal a = new Dog();
[Link]();
(assuming Dog extends Animal and overrides makeSound() to print "Bark") A) Some sound B) Bark
C) Compile error D) Nothing prints
Q2. Which statement is TRUE about interfaces in Java? A) A class can implement only one interface B)
Interface fields are automatically public static final C) Interfaces can have private constructors
D) You can create objects directly from an interface using new
Q3 (Short Code). Write an interface Flyable with one method fly(), then a class Bird that
implements it and prints "Flying high" inside fly().
MASTER GLOSSARY
Alphabetical, one-line-per-term recall for the night before the exam.
Term One-line meaning
Abstract class Incomplete blueprint; can hold both unfinished
(abstract) and finished methods; can't be
instantiated
Access modifier Lock controlling who can see a field/method:
private, default, protected, public
Array Fixed-size, numbered collection of same-type
values, indexed from 0
Bytecode The .class output of javac; universal
instructions any JVM can run
Casting (explicit) Manually forcing a big type into a small one; may
lose data (truncates, doesn't round)
Casting (implicit) Automatic, safe conversion from a small type to a
bigger one
Class The blueprint that defines what an object looks
like and can do
Constructor Special method that runs when new builds an
object; sets up initial state
Field A variable declared inside a class but outside any
method; visible to all methods in that class
Fall-through When a switch case without break keeps
executing into the next case
final Locks a variable (can't reassign), method (can't
override), or class (can't extend)
Term One-line meaning
Interface Pure contract of method signatures with no
bodies; a class can implement many
JDK Java Development Kit — everything needed to
write and compile Java (includes the JRE)
JIT Just-In-Time compiler inside the JVM; compiles
hot bytecode to native machine code at runtime
JRE Java Runtime Environment — everything needed
to run already-compiled Java
JVM Java Virtual Machine — executes bytecode, gives
Java its platform independence
Local variable Declared inside a method; exists and is visible
only during that method's execution
Method overloading Same method name, different parameter list;
resolved at compile time
Method overriding Child class replaces a parent's method with its
own version; resolved at runtime
new Keyword that actually allocates memory for an
object and returns a reference to it
Object An actual instance built from a class blueprint, via
new
Package Folder-like namespace that groups related classes
and prevents name clashes
Pass-by-value Java always copies the value (or the reference)
into a method — reassigning a parameter never
changes the caller's original variable
Polymorphism Treating different objects through a common
parent type; each runs its own behavior
automatically
Primitive type Simple fixed-size box storing a raw value directly:
byte, short, int, long, float,
double, char, boolean
Reference type Non-primitive type (String, arrays, objects)
storing an address pointing to the real data; can
be null
Scope Which part of the code can "see" a given variable
this Refers to the current object's own field, used to
disambiguate from a parameter of the same
name
ANSWER KEY
Module 1 — Q1: C (JVM) | Q2: C (compiles, but runtime error since JVM can't invoke a non-static main)
| Q3:
public class Main {
public static void main(String[] args) {
[Link]("Compiling...");
}
}
Module 2 — Q1: B (7) | Q2: C (String) | Q3:
double price = 19;
int roundedPrice = (int) price;
[Link](roundedPrice);
Module 3 — Q1: B ("Total: 34" — left-to-right string concatenation) | Q2: B (2, integer division) | Q3:
Scanner input = new Scanner([Link]);
[Link]("Enter your name: ");
String name = [Link]();
[Link]("Hello, " + name + "!\n");
Module 4 — Q1: B (4 times: i=1,2,3,4) | Q2: C (falls through) | Q3:
int i = 1;
while (i <= 5) {
[Link](i);
i++;
}
Module 5 — Q1: B (remains unchanged, pass-by-value) | Q2: B (different number of parameters) | Q3:
static int multiply(int a, int b) { return a * b; }
static double multiply(double a, double b) { return a * b; }
Module 6 — Q1: B (new) | Q2: B (default/package-private) | Q3:
public class Book {
private String title;
public Book(String title) { [Link] = title; }
public String getTitle() { return title; }
}
Module 7 — Q1: B (Bark — dynamic method dispatch at runtime) | Q2: B (interface fields are public
static final automatically) | Q3:
interface Flyable {
void fly();
}
class Bird implements Flyable {
public void fly() { [Link]("Flying high"); }
}