JAVA OOP — INTERNAL EXAM NOTES
Modules 1-3: Fundamentals, Class Fundamentals, Array & String Handling
Exam-Focused Reference | Every syllabus sub-topic covered in detail
MODULE 1: Fundamentals of Object-Oriented Programming
1.1 History of Java
● Java was created by James Gosling and his team at Sun Microsystems, starting in 1991.
● The project was originally called 'Oak' (named after an oak tree outside Gosling's office), later renamed 'Java'.
● Originally designed for embedded systems in consumer electronics (set-top boxes, TVs) — needed to be small,
reliable, and platform-independent.
● Publicly released in 1995 by Sun Microsystems.
● Java's rise was fueled by the growth of the internet — its 'write once, run anywhere' capability made it ideal for
web-based applications (applets).
● Sun Microsystems was acquired by Oracle Corporation in 2010, which now owns and maintains Java.
Exam Points:
● Who created Java and when? — James Gosling, Sun Microsystems, 1991 (released 1995).
● What was Java's original name? — Oak.
● Who owns Java now? — Oracle Corporation.
1.2 Basic Overview of Java
● Java is a high-level, object-oriented, platform-independent programming language.
● Programs are compiled into bytecode, which runs on the Java Virtual Machine (JVM) — the basis of 'write once,
run anywhere'.
● Java is a hybrid language: source code is COMPILED to bytecode, then that bytecode is INTERPRETED (with
JIT compilation) by the JVM.
● Core features (detailed under Buzzwords): Simple, Object-Oriented, Platform-independent, Secure, Robust,
Multithreaded, Architecture-neutral, Portable, High-performance, Distributed, Dynamic.
Exam Points:
● Java is both compiled AND interpreted — a hybrid execution model.
1.3 Bytecode
● Bytecode is the intermediate, platform-independent code generated when a .java file is compiled by javac.
● It is NOT machine code — it is a set of instructions understood by the JVM, not directly by the CPU.
● Stored in .class files.
● The JVM (specific to each operating system) reads this same bytecode and executes it — this is the mechanism
behind 'write once, run anywhere'.
Exam Points:
● What is bytecode? — Platform-independent intermediate code, stored in .class files, executed by the JVM.
● Is bytecode the same as machine code? — No. Machine code is CPU-specific; bytecode is JVM-specific and portable.
1.4 JVM (Java Virtual Machine)
● JVM provides the runtime environment needed to execute Java bytecode.
● It is platform-DEPENDENT (a different JVM exists per OS), but the bytecode it runs is platform-
INDEPENDENT — this combination gives Java its portability.
● Main components: Class Loader (loads .class files into memory), Bytecode Verifier (checks bytecode for
security/correctness), Interpreter/JIT Compiler (converts bytecode to native machine code; JIT speeds up
frequently used code), Garbage Collector (frees memory of unused objects).
● JDK = JVM + libraries + development tools (compiler, debugger). JRE = JVM + libraries (runtime only, no dev
tools). JVM = just the execution engine.
.java file --(javac)--> .class file (bytecode)
--(JVM: ClassLoader -> Bytecode Verifier -> Interpreter/JIT)-->
Machine Code --> Program Output
Exam Points:
● What is JVM? — A virtual machine providing the runtime environment to execute Java bytecode.
● Is JVM platform-independent? — No, JVM itself is platform-dependent; the BYTECODE is platform-independent.
● Name JVM's main components. — Class Loader, Bytecode Verifier, Interpreter/JIT Compiler, Garbage Collector.
● Difference between JDK, JRE, JVM — JDK builds + runs (has compiler); JRE only runs; JVM is the engine inside both.
1.5 Buzzwords (Key Features of Java)
● Simple — easy syntax; removed complex C/C++ features like pointers, multiple class inheritance, operator
overloading.
● Object-Oriented — everything is modeled around objects and classes (encapsulation, inheritance, polymorphism,
abstraction).
● Platform-Independent — bytecode runs on any device with a JVM ('Write Once, Run Anywhere').
● Secure — no explicit pointers, bytecode verification, runs in a sandboxed environment, security manager
controls access.
● Robust — strong memory management, automatic garbage collection, exception handling, strict compile-time
type checking.
● Multithreaded — supports concurrent execution of multiple threads for maximum CPU utilization.
● Architecture-Neutral — compiled bytecode is not tied to any specific processor architecture.
● Portable — architecture-neutral plus no implementation-dependent features, so code behaves identically
everywhere.
● Interpreted — bytecode is interpreted by the JVM at runtime (with JIT compilation for speed).
● High Performance — JIT compilation makes Java much faster than purely interpreted languages.
● Distributed — built-in networking support ([Link]) makes distributed applications easy to build.
● Dynamic — can adapt to an evolving environment; supports dynamic loading of classes at runtime.
Exam Points:
● 'List and explain the buzzwords/features of Java' is a very common direct question — memorize all 12 names and be
ready to write 1 line on each.
1.6 Applications and Applets
● Application: a standalone Java program that runs directly on the machine via the JVM, starting from a main()
method. Needs no browser.
● Applet: a small Java program designed to run inside a web browser (or appletviewer), embedded in an HTML
page. Has NO main() method — its lifecycle is controlled by the browser via init(), start(), stop(), destroy().
Historically extended [Link].
● Applets run in a restricted 'sandbox' for security, while applications have full access to the local system.
● Note: Applets are deprecated/removed in modern Java (9+) and unsupported by modern browsers, but are still
commonly taught for conceptual understanding.
Exam Points:
● Difference between application and applet? — Application: standalone, runs via JVM, entry point main(). Applet: runs
inside a browser, entry point init()/start(), restricted sandbox.
● Which method is the entry point for an applet? — init(), followed by start() — NOT main().
1.7 Constants
● A constant is a value that cannot be changed once assigned.
● Declared using the final keyword: final double PI = 3.14159;
● Naming convention: ALL_CAPS_WITH_UNDERSCORES (e.g. MAX_VALUE).
● Reassigning a final variable after initialization causes a compile error.
final double PI = 3.14159;
final int MAX_MARKS = 100;
Exam Points:
● How do you declare a constant in Java? — Using the final keyword.
● What naming convention is used for constants? — ALL_CAPS_WITH_UNDERSCORES.
1.8 Variables
● Named memory locations that store data whose value can change.
● Three types based on scope: Local variables (declared inside a method, exist only during that call), Instance
variables (declared inside a class, one copy per object), Static/class variables (declared with static, one copy
shared by all objects).
● Must be declared with a data type before use.
Exam Points:
● Name the 3 types of variables based on scope. — Local, Instance, Static (class) variables.
1.9 Data Types
● Primitive types (8): byte, short, int, long, float, double, char, boolean.
● Non-primitive/reference types: String, Arrays, Classes, Interfaces.
● Primitives store the actual value; reference types store an address to heap memory.
Exam Points:
● Be ready for a table question: type name, size in bytes, and default value for each of the 8 primitives.
1.10 Comments
● Single-line comment: // comment text
● Multi-line comment: /* comment text spanning multiple lines */
● Documentation comment: /** ... */ — used by the javadoc tool to auto-generate HTML documentation; supports
tags like @param, @return, @author.
// this is a single-line comment
/* this is a
multi-line comment */
/** This is a documentation comment
* @author Mukul
*/
Exam Points:
● What are the 3 types of comments in Java? — Single-line (//), multi-line (/* */), documentation (/** */).
● What is javadoc? — A tool that generates HTML documentation from /** */ comments.
1.11 Operators
● Arithmetic: + - * / %
● Relational: == != > < >= <=
● Logical: && || !
● Assignment: = += -= *= /=
● Unary: ++ -- ! (increment, decrement, logical NOT)
● Bitwise: & | ^ ~ << >> >>> — operate on the binary representation of integers.
● Ternary (conditional): condition ? valueIfTrue : valueIfFalse — a shorthand for a simple if-else that returns a
value.
int max = (a > b) ? a : b; // ternary example
Exam Points:
● Ternary operator is a shorthand for if-else that RETURNS a value — commonly asked to rewrite an if-else as a ternary or
vice versa.
● Bitwise operators work on the binary form of integers, not boolean logic (that's what && / || are for).
1.12 Control Flow
● Selection statements: if, if-else, switch.
● Iteration statements: for, while, do-while.
● Jump statements: break, continue, return.
● Labeled break/continue: a label placed before an outer loop lets break/continue target that specific outer loop
directly from inside a nested loop.
outer:
for (int i = 1; i <= 3; i++) {
for (int j = 1; j <= 3; j++) {
if (j == 2) continue outer;
[Link](i + " " + j);
}
}
Exam Points:
● Labeled break/continue is a step beyond the basic loops covered earlier — know it exists and can target an OUTER loop
from inside a nested one.
Module Quick Revision
● Java: created by James Gosling, Sun Microsystems (1991), originally 'Oak', released 1995, now owned by Oracle.
● Bytecode = platform-independent intermediate code (.class files); JVM executes it (platform-dependent itself).
● JDK = JVM + tools; JRE = JVM + libraries; JVM = execution engine.
● 12 buzzwords: Simple, Object-Oriented, Platform-Independent, Secure, Robust, Multithreaded, Architecture-Neutral,
Portable, Interpreted, High Performance, Distributed, Dynamic.
● Application = standalone, main(); Applet = runs in browser, init()/start(), sandboxed, deprecated in modern Java.
● Constants use final, ALL_CAPS naming.
● 3 variable scopes: local, instance, static.
● 8 primitive types + reference types (String, arrays, classes, interfaces).
● 3 comment types: //, /* */, /** */ (javadoc).
● Operators: arithmetic, relational, logical, assignment, unary, bitwise, ternary.
● Control flow: selection (if/switch), iteration (for/while/do-while), jump (break/continue/return), plus labeled
break/continue.
MODULE 2: Class Fundamentals
2.1 General Form of a Class
● A class groups fields (data) and methods (behavior) into one blueprint.
● General structure: fields, constructors, then methods (order is convention, not a strict rule).
● Only one class per .java file may be public, and its name must exactly match the filename.
class ClassName {
// fields (instance variables)
// constructors
// methods
}
Exam Points:
● Know the general skeleton by heart — it's often asked as a direct 'write the general form of a class' question.
2.2 Creating a Class
● Define the class with its fields and methods, then create objects from it using new.
class Box {
double width, height, depth;
}
Box b1 = new Box();
Exam Points:
● Recap: class = blueprint, new Box() = actual object on the heap.
2.3 Overloading Methods
● Same method name, different parameter list (type, number, or order), within the SAME class.
● Java determines which version to call by matching the arguments at compile time.
● Constructor overloading (multiple constructors with different parameter lists) works on the same principle.
void show(int a) { [Link]("int: " + a); }
void show(double a) { [Link]("double: " + a); }
void show(int a, int b) { [Link]("two ints: " + (a+b)); }
Exam Points:
● Overloading is resolved by parameter TYPE, NUMBER, or ORDER — not by return type alone.
2.4 Constructor
● Special method, same name as the class, no return type, called automatically when an object is created.
● Default constructor: provided automatically by Java if you write none.
● Parameterized constructor: accepts arguments to initialize fields at creation time.
● Constructor overloading: multiple constructors with different parameter lists.
● Copy constructor: not automatic in Java (unlike C++) — commonly hand-written, taking an object of the same
class and copying its field values into the new object.
class Student {
String name;
Student(Student s) { // copy constructor
name = [Link];
}
}
Exam Points:
● Java has NO automatic copy constructor like C++ — you must write it yourself if needed.
2.5 Declaring Object
● Declaring an object is really two steps: declaring a reference variable, and instantiating it with new.
● Before new is called, the reference variable holds null.
Box b1; // declaration only, b1 is null
b1 = new Box(); // instantiation + constructor call
Exam Points:
● Calling a method on a reference before it's assigned with new causes a NullPointerException.
2.6 Returning Objects
● A method's return type can be a class type — the method then returns an object of that class.
class Box {
double width;
Box increaseWidth() {
Box temp = new Box();
[Link] = [Link] + 10;
return temp;
}
}
Exam Points:
● Returning an object returns the REFERENCE to it, not a copy of its data — same reference rules as everywhere else in
Java.
2.7 Using Objects as Parameters
● Objects can be passed into methods just like primitives.
● Since objects are reference types, the method receives a COPY of the reference (address) — so changes made to
the object's FIELDS inside the method are visible back in the caller, because both point to the same object.
void compare(Box b1, Box b2) {
if ([Link] == [Link]) [Link]("Equal width");
}
Exam Points:
● This is the same pass-by-value-of-reference rule from Methods — Java is always pass-by-value, even for objects.
2.8 Assigning Object Reference Variables
● Box b2 = b1; does NOT copy the object — it copies the REFERENCE (address).
● After this, both b1 and b2 point to the SAME object on the heap.
● Changing a field through b2 will also be visible through b1 — they are the same object, not two separate copies.
● This is different from primitive assignment (int b = a;), which truly copies the value.
Box b1 = new Box();
[Link] = 10;
Box b2 = b1; // b2 now points to the SAME object
[Link] = 20;
[Link]([Link]); // prints 20, not 10!
Exam Points:
● Classic 'predict the output' exam trap — tests whether you understand reference aliasing vs true copying.
2.9 Introducing Access Control
● Java has four access levels: private, default (no modifier), protected, public.
● private — accessible only within the same class.
● default (no modifier written) — accessible within the same package only.
● protected — accessible within the same package, AND by subclasses even in a different package.
● public — accessible from anywhere.
Exam Points:
● Memorize the exact visibility table: private < default < protected < public, in terms of increasing accessibility.
● This exact comparison is one of the most frequently asked theory questions in this module.
2.10 Understanding static
● static variable: one single copy shared across all objects of the class.
● static method: belongs to the class, callable without creating an object.
● static block: a block marked static { } that runs exactly ONCE, when the class is first loaded — used for static
initialization.
class Config {
static int version;
static {
version = 1;
[Link]("Static block ran");
}
}
Exam Points:
● static block runs once, at class-loading time, before main() or any object is created — this timing detail is commonly
tested.
2.11 Introducing final
● final has three distinct uses in Java:
● 1. final variable — value cannot be changed once assigned (a constant).
● 2. final method — cannot be overridden by any subclass.
● 3. final class — cannot be extended/subclassed by any other class (e.g. Java's own String class is final).
final int MAX = 100; // final variable
final void display() { } // final method - cannot override
final class Constants { } // final class - cannot extend
Exam Points:
● 'Explain the 3 uses of final with examples' is a very frequently asked direct question — know all three, not just the
variable use.
2.12 The finalize() Method
● A method historically called by the garbage collector just before an object's memory is reclaimed, allowing
cleanup (e.g. releasing resources).
● Its exact timing is NOT guaranteed — you cannot rely on it running at a predictable moment.
● Deprecated since Java 9 in favor of other cleanup mechanisms (like try-with-resources), but still commonly
asked in college syllabi.
protected void finalize() {
// cleanup code
}
Exam Points:
● finalize() is called by the GC before reclaiming an object, but its execution is NOT guaranteed or predictable — a
common exam nuance to mention.
2.13 this Keyword
● Refers to the current object — the one on which the currently running method/constructor was called.
● Used to resolve naming conflicts between a field and a same-named parameter, and to call another constructor of
the same class via this().
Exam Points:
● Fully covered in Part 2 notes (Topic 16) — revise that if this feels shaky.
2.14 Garbage Collection
● Java automatically manages memory — when an object has no more references pointing to it, it becomes
'eligible for garbage collection'.
● The Garbage Collector runs in the background; the JVM decides WHEN, not the programmer.
● [Link]() can be called to REQUEST garbage collection, but the JVM may or may not act on it immediately
— it is only a request, never a guarantee.
● Benefit: prevents memory leaks common in languages like C/C++, where memory must be freed manually.
Exam Points:
● An object becomes eligible for GC when no live references to it remain (e.g. set to null, or goes out of scope).
● [Link]() only REQUESTS garbage collection — it does not force it. This distinction is commonly tested.
Module Quick Revision
● General class form: fields, constructors, methods.
● Overloading = same name, different parameters, same class, resolved at compile time.
● Constructor: same name as class, no return type; default/parameterized/overloaded; Java has NO automatic copy
constructor.
● Declaring an object = reference declaration + new (instantiation) + constructor call.
● A method can return an object type.
● Objects passed to methods: reference is copied, so field changes reflect back in the caller.
● Assigning one object reference to another copies the ADDRESS, not the object — both variables become aliases of the
same object.
● Access control: private < default (package) < protected (package+subclass) < public (everywhere).
● static: shared variable / class-level method / one-time static block at class load.
● final: variable (constant) / method (no override) / class (no extend).
● finalize(): pre-GC cleanup hook, timing not guaranteed, deprecated since Java 9.
● this: refers to the current object.
● Garbage collection: automatic memory reclaim for unreferenced objects; [Link]() only requests it.
MODULE 3: Array & String Handling
3.1 Array Basics
● 1D array: a single row of same-type elements, index starts at 0.
● 2D array: an array of arrays — think of it as a grid/table (rows and columns).
● Arrays are objects in Java, stored on the heap, with a fixed size once created.
int[] arr = new int[5]; // 1D array
int[][] matrix = new int[3][3]; // 2D array
Exam Points:
● Recap from Part 1 (Topic 10) — make sure 2D array indexing (matrix[row][col]) is comfortable too.
3.2 String Array
● An array where every element is a String.
● Very common in real programs — for example, main(String[] args) itself is a String array holding command-line
arguments.
String[] names = {"Amit", "Priya", "Raj"};
for (String n : names) [Link](n);
Exam Points:
● Know that main(String[] args) is itself an example of a String array being used.
3.3 String Class
● String is an immutable sequence of characters — every 'modification' actually creates a new String object.
● Common methods: length(), charAt(), substring(), indexOf(), equals(), equalsIgnoreCase(), compareTo(),
concat(), trim(), replace(), split(), toCharArray().
Exam Points:
● Recap from Part 1 (Topic 11) — for this exam, also make sure you can name and describe at least 6-8 String methods
directly, a common table-style question.
3.4 StringBuffer Class
● Unlike String, StringBuffer is MUTABLE — its content can be changed without creating a new object each
time.
● Used when doing many string modifications (e.g. inside a loop) — far more efficient than repeatedly
concatenating Strings.
● Common methods: append(), insert(), reverse(), delete(), deleteCharAt(), replace(), capacity().
● StringBuffer's methods are synchronized, making it thread-safe (slightly slower than the non-thread-safe
alternative, StringBuilder).
StringBuffer sb = new StringBuffer("Hello");
[Link](" World");
[Link]();
[Link](sb);
Exam Points:
● Difference between String and StringBuffer? — String is immutable; StringBuffer is mutable, modified in place.
● Is StringBuffer thread-safe? — Yes, its methods are synchronized.
3.5 StringTokenizer Class
● Found in the [Link] package.
● Used to break a String into smaller pieces called 'tokens', based on delimiter characters (default: space, tab,
newline).
● Common methods: hasMoreTokens(), nextToken(), countTokens().
StringTokenizer st = new StringTokenizer("I love Java programming");
while ([Link]()) {
[Link]([Link]());
}
Exam Points:
● What is StringTokenizer used for? — Splitting a string into tokens based on delimiters.
● Modern code often prefers [Link]() instead, but StringTokenizer is still commonly asked in this syllabus.
3.6 Object Class
● Object is the ROOT of the entire Java class hierarchy — every class implicitly extends Object (directly or
indirectly), even without writing 'extends Object'.
● Key inherited methods: toString() — returns a String representation of the object (default:
className@hashcode; commonly overridden).
● equals(Object obj) — compares two objects for equality (default behaves like ==, comparing references;
commonly overridden to compare content).
● hashCode() — returns an integer hash code for the object, used in hash-based collections.
● getClass() — returns the runtime class of the object (used for reflection).
● clone() — creates and returns a copy of the object (requires implementing the Cloneable interface).
Exam Points:
● What is the Object class? — The root superclass of all classes in Java.
● Name 3 methods defined in Object. — toString(), equals(), hashCode() (also getClass(), clone()).
● Why override toString() and equals()? — To provide meaningful string output and content-based equality instead of the
default reference-based behavior.
Module Quick Revision
● 1D array = single row; 2D array = array of arrays (grid).
● String array = array where each element is a String; main(String[] args) is one.
● String = immutable; key methods: length(), charAt(), substring(), equals(), split(), etc.
● StringBuffer = mutable, thread-safe (synchronized), efficient for repeated modification: append(), insert(), reverse(),
delete().
● StringTokenizer ([Link]) splits a string into tokens by delimiter: hasMoreTokens(), nextToken().
● Object = root class of all Java classes; key methods: toString(), equals(), hashCode(), getClass(), clone().