Java Mastery: From Basics to Advanced OOP

Mac Java Installation Steps Download and Install Java Check installed JDKs /usr/libexec/java_home -V [for Mac] java -version [for Windows] Open .zshrc and set JAVA_HOME vi ~/.zshrc [using terminal] export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk-17.jdk/Contents/Home [add this] esc → :wq [Save and exit] Save and reload shell config in terminal source ~/.zshrc Check Java HOME is setup properly from terminal echo $JAVA_HOME Windows Java Installation Steps Download and Install Java Check installed JDKs java -version [for Windows] Set JAVA_HOME Environment Variable Open System Properties → Advanced → Environment Variables Under System variables, click New and add: Variable name: JAVA_HOME Variable value: C:\Program Files\Java\jdk-17 [or your JDK path] Click OK to save Update PATH Variable In the same Environment Variables window, select Path → Edit → New, then add: %JAVA_HOME%\bin Click OK to save and close Verify Configuration in Command Prompt java -version echo %JAVA_HOME% Class-level/Instance variables/field + Local Variable 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 public class Car { String brand; // Class-level/Instance variables/field (each Car object has its own copy) int year; static int wheels = 4; //Static variable (shared by ALL Car objects) public Car(String brand, int year) { // Constructor (sets instance variables) this.brand = brand; this.year = year; } public void displayInfo() { // Method with a local variable String info = "Car Brand: " + brand + ", Year: " + year + ", Wheels: " + wheels; // Local variable (exists only while this method runs) System.out.println(info); } public static void main(String[] args) { Car myCar = new Car("Toyota", 2022); // Local variable in main() myCar.displayInfo(); // Calling instance method using the object System.out.println("All cars have " + Car.wheels + " wheels."); // Accessing static variable Car anotherCar = new Car("Honda", 2020); // Creating another car to show that static variable is shared anotherCar.displayInfo(); } } When to use static You’d only make it static if the method doesn’t depend on any specific object’s data. For example: public static void showWheelsInfo() { System.out.println(“All cars have " + wheels + " wheels.”); } This one is static because it only uses the wheels variable — which is also static — and doesn’t need to know about a specific Car object. Perfect! Here’s your fully formatted version with bold definitions and added emojis for each concept to make it visually pop: ...

November 6, 2025 ·  (Updated: February 18, 2026) · 11 min · 2183 words · FewSteps
Read More

Complete Java Interview Prep Sheet

Complete Java Interview Prep Sheet (Final Version) 1. Core OOP Concepts 4 Fundamental Principles: Abstraction: Hide implementation details, show only essential features (abstract classes/interfaces). (what to implement). Encapsulation: Bundle data + methods, hide internals using private fields + public getters/setters (data hiding). Inheritance: Child class acquires parent class properties (is-a relationship, single inheritance only). Polymorphism: Same interface, multiple forms (compile-time: method overloading; runtime: method overriding). Key Points: Java not pure OOP (uses primitives, no multiple class inheritance). Object class is root of all classes: equals(), hashCode(), toString(), wait()/notify(). Multiple inheritance via interfaces only (no diamond problem). 2. Java Basics Class/Object/Method: ...

February 11, 2026 ·  (Updated: February 18, 2026) · 3 min · 618 words · FewSteps
Read More