Prep
Prep
Java is a high-level, object-oriented programming language developed by Sun Microsystems (now owned by Oracle).
It is designed to be platform-independent, secure, and robust.
Main features of Java:
Platform-independent (Write Once, Run Anywhere - WORA)
Object-Oriented (supports OOP concepts like inheritance, polymorphism, encapsulation)
Multi-threaded (supports concurrent execution of multiple tasks)
Secure (provides a secure runtime environment with bytecode verification)
Robust (has strong memory management and exception handling)
Garbage Collected (automatic memory management)
Distributed (supports networking & remote method invocation)
Component Description
JDK (Java Development Kit) Includes JRE + development tools (compiler, debugger) for Java application development.
JRE (Java Runtime Environment) Provides libraries and JVM to run Java applications but does not include development tools.
JVM (Java Virtual Machine) Abstract machine that executes Java bytecode, making Java platform-independent.
Example of static
Declared inside a method or block Declared inside a class but outside methods
Local Variable Instance Variable
8. What is a constructor?
A constructor is a special method used to initialize an object when it is created. It has the same name as the class and no
return type.
Keyword Description
finally A block that executes after try-catch, used for cleanup code.
Stack Heap
Stores method calls & local variables Stores objects and instance variables
Copies only references, not actual data Creates a new independent copy of data
Memory Allocation No memory until an object is created Memory is allocated in the heap
🔟 What is Encapsulation?
➡ Wrapping data (variables) and code (methods) into a single unit (class) & restricting access.
class Person {
private String name; // Private variable
public void setName(String name) { this.name = name; }
public String getName() { return name; }
}
✅ The name variable cannot be accessed directly outside the class.
Multiple
Not supported Supported
Inheritance
Definition General connection between two objects Weak "has-a" relationship Strong "has-a" relationship
Lifespan Objects are independent Child can exist without parent Child cannot exist without parent
Pattern Purpose
Can access Only static members Both static & instance members