Java Revision

java dev.to

Java Interview Revision Pack

1. One-Page Cheat Sheet

Core Java Basics

Topic Must Know
JDK Used to develop Java apps. Contains compiler, tools, JRE
JRE Used to run Java apps. Contains JVM + libraries
JVM Executes bytecode, manages memory, GC, JIT
Stack Method calls, local variables, references
Heap Objects, arrays, instance variables
main() JVM entry point: public static void main(String[] args)

OOP + Keywords

Concept Key Rule
static Belongs to class, one copy
final variable Cannot reassign
final method Cannot override
final class Cannot extend
abstract class Cannot instantiate, can have abstract + concrete methods
Upcasting Safe: Parent p = new Child()
Downcasting Risky: use instanceof
Dynamic Dispatch Object type decides overridden method execution

String Concepts

Topic Rule
String immutable Safe, secure, pool-friendly
String literal Stored in String Pool
new String() Creates new heap object
Compile-time concat Goes to pool
Runtime concat Creates new object
final String concat Can be compile-time optimized

Memory Tricks

JDK = Develop
JRE = Run
JVM = Execute

Stack = Methods
Heap = Objects

Reference Type = What you can access
Object Type = What executes
Enter fullscreen mode Exit fullscreen mode

2. Interview Revision Notes

What It Is

Core Java is the foundation of Java development. It includes JVM, memory management, OOP, strings, type casting, access control, and basic runtime behavior.

Why It Exists

Java is designed to be platform-independent, object-oriented, secure, and memory-managed.

How It Works Internally

.java file
 ↓ javac
.class bytecode
 ↓ JVM
Class Loading
 ↓
Bytecode Verification
 ↓
JIT Compilation
 ↓
Execution
 ↓
Garbage Collection
Enter fullscreen mode Exit fullscreen mode

Real Production Usage

In backend systems, these concepts matter for:

  • Debugging memory issues
  • Writing thread-safe code
  • Avoiding string/object comparison bugs
  • Understanding Spring Boot startup
  • Handling performance issues
  • Explaining object lifecycle in interviews

3. Last-Minute Interview Revision

Must Remember

  1. Java is always pass-by-value.
  2. Stack stores method frames; Heap stores objects.
  3. Object type decides overridden method execution.

Interview Buzzwords

JVM
Bytecode
JIT
Garbage Collection
Stack Frame
Heap Memory
String Pool
Immutability
Dynamic Dispatch
Upcasting
Downcasting
Covariant Return
Pass-by-Value
Enter fullscreen mode Exit fullscreen mode

Red Flags

Avoid saying:

Java is pass-by-reference ❌
StringBuilder is thread-safe ❌
final object cannot be modified ❌
static belongs to object ❌
Heap is per thread ❌
Enter fullscreen mode Exit fullscreen mode

4. Active Recall Questions

Beginner

  1. What is the difference between JDK, JRE, and JVM?
  2. What is stored in Stack memory?
  3. What is stored in Heap memory?
  4. Why is main() static?
  5. Why is String immutable?
  6. What is the String Pool?
  7. What is the use of static?
  8. What does final mean for a variable?
  9. What is an enum?
  10. What is widening type casting?

Intermediate

  1. Difference between == and .equals() for String?
  2. Why does new String("Java") create a new object?
  3. What happens in runtime string concatenation?
  4. Why is downcasting dangerous?
  5. What is dynamic method dispatch?
  6. Can a final ArrayList be modified?
  7. Abstract class vs interface?
  8. JAR vs WAR?
  9. StringBuilder vs StringBuffer?
  10. What is covariant return type?

Advanced

  1. Explain Java pass-by-value with object references.
  2. Explain initialization order in inheritance.
  3. Why does (byte)130 become -126?
  4. How does compile-time string optimization work?
  5. How does JVM call main()?
  6. What is the relation between reference type and object type?
  7. Why are enums singleton constants?
  8. Can static methods be overridden?
  9. What happens when a child constructor is called?
  10. How does immutability help thread safety?

5. Flash Cards

Q: What is JVM?
A: It executes Java bytecode and manages memory.

Q: What is Stack memory?
A: It stores method calls, local variables, and references.

Q: What is Heap memory?
A: It stores objects and arrays.

Q: Why is String immutable?
A: For security, thread safety, and String Pool optimization.

Q: What is upcasting?
A: Assigning child object to parent reference.

Q: What is downcasting?
A: Converting parent reference back to child type.

Q: Is Java pass-by-value?
A: Yes, always.

Q: Can final ArrayList be modified?
A: Yes, but the reference cannot be reassigned.

Q: What is dynamic dispatch?
A: Runtime decides overridden method based on object type.

Q: What is byte range?
A: -128 to 127.


6. Interview Story Preparation

What I Did

In my Java/backend work, I used core Java concepts while building APIs, handling object models, debugging issues, and writing maintainable backend logic.

Challenges Faced

I had to understand memory behavior, object references, string handling, and runtime behavior to avoid bugs.

How I Solved Them

I focused on JVM basics, object lifecycle, immutability, type casting, and clean OOP principles.

Business Impact

This helped me write more reliable, maintainable, and production-safe code.

STAR Answer

“In my previous development experience, I worked on backend and API-related features where Java fundamentals were important. I used OOP principles, understood object references, handled strings carefully, and debugged runtime issues. This helped me avoid common bugs like wrong object comparison, unsafe casting, and misunderstanding reference behavior. As a result, the code became cleaner, easier to maintain, and more reliable.”


7. Common Interview Traps

Trap Correct Understanding
Java pass-by-reference Java is always pass-by-value
final object cannot change Reference fixed, object can change
== compares String content == compares reference
Runtime concat goes to pool Usually creates heap object
Static method override Static methods are hidden, not overridden
Downcasting always safe Only safe if actual object type matches
Parent reference executes parent method Overridden method uses object type

8. Memory Tricks

JDK → Develop
JRE → Run
JVM → Execute
Enter fullscreen mode Exit fullscreen mode
Stack = Story of method calls
Heap = Home of objects
Enter fullscreen mode Exit fullscreen mode
Reference type = Remote control buttons
Object type = Actual machine behavior
Enter fullscreen mode Exit fullscreen mode
final reference = fixed address
object = house can still change inside
Enter fullscreen mode Exit fullscreen mode
Upcasting = Child goes up safely
Downcasting = Coming down carefully
Enter fullscreen mode Exit fullscreen mode

9. 30-Second Interview Answer

“Core Java concepts are important because they explain how Java code actually runs. JDK is used for development, JRE runs the application, and JVM executes bytecode. Stack stores method calls and local variables, while Heap stores objects. Java is always pass-by-value, Strings are immutable and stored in the String Pool, and runtime polymorphism is handled through dynamic dispatch where the actual object type decides the overridden method execution.”


10. Ultimate Revision Table

Topic Definition Important Points Interview Focus
JDK/JRE/JVM Java development/runtime/execution layers JDK contains JRE, JRE contains JVM Java execution flow
Stack vs Heap Memory areas Stack per thread, Heap shared Memory debugging
String Immutable text object Pool, security, thread safety == vs .equals()
static Class-level member One copy per class Loading and shared data
final Restriction keyword Variable/method/class rules Final reference trap
abstract Incomplete class design Cannot instantiate Abstract class vs interface
Upcasting Parent ref to child object Safe Polymorphism
Downcasting Parent ref to child type Use instanceof Runtime exception
Dynamic Dispatch Runtime method binding Object type decides method OOP internals
Type Casting Convert data types Widening safe, narrowing risky Overflow traps
Byte Overflow Range wraparound 128 → -128, 130 → -126 Coding output questions
JAR/WAR/EAR Java packaging Boot uses executable JAR Deployment

Interview Readiness Score

8/10

You are strong on fundamentals. Main revision needed is on tricky output-based questions.

Top 5 Things To Revise Before Interview

  1. String compile-time vs runtime concatenation
  2. Java pass-by-value with object references
  3. Dynamic dispatch and casting
  4. Initialization order in inheritance
  5. Byte overflow and narrowing casting

Java Type System & Variables – Interview Revision Pack


1. One-Page Cheat Sheet

Java Type System

Statically Typed

int age = 25;
Enter fullscreen mode Exit fullscreen mode
  • Type checked at compile time
  • Compiler knows variable types before execution
  • Prevents invalid assignments

Strongly Typed

int x = true; // Error
Enter fullscreen mode Exit fullscreen mode
  • No implicit conversion between unrelated types
  • Type safety enforced by compiler

var Keyword

var name = "Bhupesh";
Enter fullscreen mode Exit fullscreen mode

Compiler infers:

String name = "Bhupesh";
Enter fullscreen mode Exit fullscreen mode

Important:

var = Type Inference
NOT Dynamic Typing
Enter fullscreen mode Exit fullscreen mode

Primitive Data Types

byte
short
int
long
float
double
char
boolean
Enter fullscreen mode Exit fullscreen mode

Sizes

Type Size
byte 1 byte
short 2 bytes
int 4 bytes
long 8 bytes
float 4 bytes
double 8 bytes
char 2 bytes
boolean JVM dependent

float vs double

float f = 10.5f;
double d = 10.5;
Enter fullscreen mode Exit fullscreen mode

Interview Trap

float f = 10.5;
Enter fullscreen mode Exit fullscreen mode

❌ Compile Error

Reason:

Decimal literals are double by default
Enter fullscreen mode Exit fullscreen mode

Type Conversion

Widening

int  long
int  double
Enter fullscreen mode Exit fullscreen mode

Automatic

Narrowing

double  int
int  byte
Enter fullscreen mode Exit fullscreen mode

Requires cast

int x = (int)10.5;
Enter fullscreen mode Exit fullscreen mode

Arithmetic Promotion

byte + byte
Enter fullscreen mode Exit fullscreen mode

Result:

int
Enter fullscreen mode Exit fullscreen mode

Interview favorite.


Wrapper Classes

int  Integer
char  Character
boolean  Boolean
Enter fullscreen mode Exit fullscreen mode

Needed for Collections.

ArrayList<Integer>
Enter fullscreen mode Exit fullscreen mode

Autoboxing

Integer num = 10;
Enter fullscreen mode Exit fullscreen mode

Compiler:

Integer.valueOf(10)
Enter fullscreen mode Exit fullscreen mode

Unboxing

Integer num = 10;
int x = num;
Enter fullscreen mode Exit fullscreen mode

Compiler:

num.intValue()
Enter fullscreen mode Exit fullscreen mode

Dangerous

Integer num = null;
int x = num;
Enter fullscreen mode Exit fullscreen mode

❌ NullPointerException


Variables

Local

void test() {
    int x = 10;
}
Enter fullscreen mode Exit fullscreen mode
  • Stack
  • Must initialize

Instance

class User {
    int age;
}
Enter fullscreen mode Exit fullscreen mode
  • Heap
  • One per object

Static

static int count;
Enter fullscreen mode Exit fullscreen mode
  • Shared
  • One per class

static vs final vs static final

static
Enter fullscreen mode Exit fullscreen mode

Shared

final
Enter fullscreen mode Exit fullscreen mode

Fixed

static final
Enter fullscreen mode Exit fullscreen mode

Constant


2. Interview Revision Notes

What It Is

Java's type system defines how data is stored, validated, converted, and accessed during program execution.


Why It Exists

Goals:

  • Type safety
  • Prevent runtime errors
  • Efficient memory usage
  • Platform-independent execution

How It Works Internally

Compilation

var name = "Java";
Enter fullscreen mode Exit fullscreen mode

Compiler converts:

String name = "Java";
Enter fullscreen mode Exit fullscreen mode

No runtime magic.


Arithmetic Promotion

byte a = 10;
byte b = 20;

a + b
Enter fullscreen mode Exit fullscreen mode

Internally:

(int)a + (int)b
Enter fullscreen mode Exit fullscreen mode

Result becomes:

int
Enter fullscreen mode Exit fullscreen mode

Autoboxing

Integer x = 10;
Enter fullscreen mode Exit fullscreen mode

Compiler:

Integer x = Integer.valueOf(10);
Enter fullscreen mode Exit fullscreen mode

Unboxing

int x = wrapper;
Enter fullscreen mode Exit fullscreen mode

Compiler:

wrapper.intValue();
Enter fullscreen mode Exit fullscreen mode

Real Production Usage

Wrapper Classes

Used heavily in:

Collections
Streams
Generics
Hibernate
Spring Data
REST APIs
Enter fullscreen mode Exit fullscreen mode

static final

Used for:

public static final String API_URL
Enter fullscreen mode Exit fullscreen mode

Configuration constants.


byte

Used in:

Network packets
Images
Binary protocols
Embedded systems
Enter fullscreen mode Exit fullscreen mode

Very relevant to your Jio experience.


Common Interview Questions

Is Java statically typed?

Yes. Types are checked at compile time.


Is Java strongly typed?

Yes. Type safety is enforced.


Does var make Java dynamic?

No.

Only type inference.


Why is char 2 bytes?

Java uses Unicode.


Why can't byte + byte return byte?

Arithmetic promotion converts operands to int.


Why do Collections use Integer instead of int?

Generics only work with objects.


Can unboxing throw an exception?

Yes.

Integer num = null;
int x = num;
Enter fullscreen mode Exit fullscreen mode

Throws NPE.


Senior-Level Discussion Points

Performance

Excessive boxing/unboxing:

Integer
Long
Double
Enter fullscreen mode Exit fullscreen mode

creates extra objects and GC pressure.


Memory Optimization

Use primitives when possible in performance-sensitive systems.


Embedded Systems

Understanding:

byte
short
overflow
casting
memory layout
Enter fullscreen mode Exit fullscreen mode

is valuable in firmware/backend integration environments.


3. Last-Minute Interview Revision

Must Remember

1

Java is Statically Typed
Enter fullscreen mode Exit fullscreen mode

2

var != Dynamic Typing
Enter fullscreen mode Exit fullscreen mode

3

byte + byte = int
Enter fullscreen mode Exit fullscreen mode

Most asked trap.


Interview Buzzwords

Type Safety
Compile-Time Checking
Type Inference
Primitive
Wrapper
Autoboxing
Unboxing
Widening
Narrowing
Arithmetic Promotion
Unicode
Enter fullscreen mode Exit fullscreen mode

Red Flags

Never say:

var makes Java dynamic ❌

byte + byte = byte ❌

Collections support int ❌

char is 1 byte ❌

Unboxing is always safe ❌
Enter fullscreen mode Exit fullscreen mode

4. Active Recall Questions

Beginner

  1. What does statically typed mean?
  2. What does strongly typed mean?
  3. Does Java support dynamic typing?
  4. How many primitive types exist?
  5. Why is char 2 bytes?
  6. What is type inference?
  7. What is widening?
  8. What is narrowing?
  9. What is autoboxing?
  10. What is unboxing?

Intermediate

  1. Why are decimal literals double by default?
  2. Why does byte + byte return int?
  3. Why do Collections need wrappers?
  4. Difference between int and Integer?
  5. Local vs instance variable?
  6. Static vs instance variable?
  7. How does compiler implement autoboxing?
  8. How does compiler implement unboxing?
  9. What is arithmetic promotion?
  10. Why can unboxing throw NPE?

Advanced

  1. How does type inference work internally?
  2. Why did Java choose strong typing?
  3. Explain boxing overhead.
  4. Explain Integer caching.
  5. Explain memory impact of wrappers.
  6. Why isn't boolean size defined by Java specification?
  7. Why are generics incompatible with primitives?
  8. How does JVM represent primitive types?
  9. Explain primitive promotion rules.
  10. How would you optimize a high-performance system to reduce boxing?

5. Flash Cards

Q: Is Java statically typed?
A: Yes.

Q: Is Java strongly typed?
A: Yes.

Q: Does var make Java dynamic?
A: No.

Q: How many primitive types exist?
A: 8.

Q: Why is char 2 bytes?
A: Unicode support.

Q: Default decimal type?
A: double.

Q: byte + byte returns?
A: int.

Q: Primitive → Wrapper?
A: Autoboxing.

Q: Wrapper → Primitive?
A: Unboxing.

Q: Unboxing risk?
A: NullPointerException.


6. Common Interview Traps

Trap Correct Answer
var makes Java dynamic False
byte + byte = byte False
Collections support primitives False
char = 1 byte False
Integer and int are same False
Unboxing never fails False
Local variables get default values False

7. Memory Tricks

Primitive Types

4 Integers
2 Decimals
1 Character
1 Boolean
Enter fullscreen mode Exit fullscreen mode

Total:

8
Enter fullscreen mode Exit fullscreen mode

Conversion

Small → Big
=
Widening

Big → Small
=
Narrowing
Enter fullscreen mode Exit fullscreen mode

Variables

Local
 ↓
Method

Instance
 ↓
Object

Static
 ↓
Class
Enter fullscreen mode Exit fullscreen mode

Boxing

Primitive → Wrapper
          ↓
Autoboxing

Wrapper → Primitive
          ↓
Unboxing
Enter fullscreen mode Exit fullscreen mode

8. 30-Second Interview Answer

"Java is a statically and strongly typed language. The compiler knows variable types at compile time and enforces type safety. Java provides 8 primitive data types and corresponding wrapper classes for use with collections and generics. Type conversions are categorized into widening and narrowing. One common interview trap is that arithmetic on byte, short, and char is promoted to int. Java also supports autoboxing and unboxing, though unboxing a null wrapper can result in a NullPointerException."


9. Ultimate Revision Table

Topic Definition Important Points Interview Focus
Statically Typed Types known at compile time Compile-time checking Java fundamentals
Strongly Typed Type safety enforced No unsafe conversions Type system
var Type inference Not dynamic typing Java 10+
Primitive Types Basic data types 8 types Frequently asked
char Unicode character 2 bytes Output questions
float vs double Decimal types double default Traps
Widening Small → Big Automatic Casting
Narrowing Big → Small Explicit cast Output questions
Wrapper Classes Object form of primitives Collections Generics
Autoboxing Primitive → Wrapper Compiler generated Internals
Unboxing Wrapper → Primitive NPE risk Interview favorite
Local Variables Method scope Must initialize Common mistake
Static Variables Class-level Shared OOP basics
static final Constant Shared + fixed Best practices

Interview Readiness Score

8.5/10

Top 5 Things To Revise Before Interview

  1. byte + byte = int
  2. var vs dynamic typing
  3. Autoboxing and unboxing internals
  4. char and Unicode
  5. Local variable initialization vs default values

These five are exactly the kinds of quick Java questions interviewers use to separate candidates who know syntax from candidates who understand the language.

Java OOP – Interview Revision Pack

This pack is optimized for Java Backend, Spring Boot, Full Stack, and Software Developer interviews.


1. One-Page Cheat Sheet

OOP (Object-Oriented Programming)

Definition:
A programming paradigm that organizes software around objects, which encapsulate state (data) and behavior (methods).

Object
   ↓
State (Variables)
+
Behavior (Methods)
Enter fullscreen mode Exit fullscreen mode

Class vs Object

Class Object
Blueprint Real instance
Logical entity Physical entity
No memory until object creation Occupies memory in Heap
class Employee {}      // Class

Employee emp = new Employee();   // Object
Enter fullscreen mode Exit fullscreen mode

Four Pillars of OOP

Pillar Purpose Interview Keyword
Encapsulation Protect Data Data Hiding
Inheritance Reuse Code IS-A
Polymorphism One Interface, Many Forms Dynamic Dispatch
Abstraction Hide Implementation Contract

Encapsulation

private int salary;

public int getSalary(){}

public void setSalary(int salary){}
Enter fullscreen mode Exit fullscreen mode

✔ Hide Data

✔ Validation

✔ Controlled Access


Inheritance

class Dog extends Animal{}
Enter fullscreen mode Exit fullscreen mode

Relationship

Dog IS-A Animal
Enter fullscreen mode Exit fullscreen mode

Purpose

  • Code reuse
  • Extend functionality

Polymorphism

Compile Time

add(int a,int b)

add(int a,int b,int c)
Enter fullscreen mode Exit fullscreen mode

Method Overloading

Compiler decides.


Runtime

Animal a = new Dog();

a.sound();
Enter fullscreen mode Exit fullscreen mode

Method Overriding

JVM decides.


Abstraction

abstract class Payment{

abstract void pay();

}
Enter fullscreen mode Exit fullscreen mode

Shows WHAT to do.

Hides HOW it is done.


Types of Inheritance

Single

Animal
  ↑
 Dog

----------------

Multilevel

Animal
  ↑
Mammal
  ↑
 Dog

----------------

Hierarchical

      Animal
      / | \
   Dog Cat Lion

----------------

Multiple

Not Supported
(Classes)

Supported
(Interfaces)
Enter fullscreen mode Exit fullscreen mode

Interface vs Abstract Class

Interface Abstract Class
Contract Shared Code
Multiple implementation Single inheritance
Constants Instance variables
No constructor Constructor allowed

Constructors

Type Purpose
Default Initialize default object
Parameterized Initialize values
Copy Copy another object (manual)

Execution Flow

new Object()

↓

Heap Allocation

↓

Default Initialization

↓

Constructor Execution

↓

Reference Returned
Enter fullscreen mode Exit fullscreen mode

Java Destructor

❌ No Destructor

✔ Garbage Collector cleans memory

finalize() is deprecated


2. Interview Revision Notes

What is OOP?

OOP is a programming paradigm where software is modeled using objects that combine data and behavior.


Why OOP Exists

Without OOP:

  • Duplicate code
  • Poor maintainability
  • Tight coupling
  • Difficult scaling

OOP solves these by promoting modular, reusable, and maintainable code.


How It Works Internally

Object Creation

Employee e = new Employee();
Enter fullscreen mode Exit fullscreen mode

Internally

new

↓

Heap Memory Allocated

↓

Instance Variables Default Initialized

↓

Constructor Executes

↓

Reference Stored in Stack
Enter fullscreen mode Exit fullscreen mode

Runtime Polymorphism

Animal a = new Dog();

a.sound();
Enter fullscreen mode Exit fullscreen mode

Internally

Reference Type
↓

Animal

Object Type
↓

Dog

↓

JVM uses Dynamic Method Dispatch

↓

Dog.sound()
Enter fullscreen mode Exit fullscreen mode

Constructor Chaining

Child()
Enter fullscreen mode Exit fullscreen mode

Internally

Child()

↓

super()

↓

Parent Constructor

↓

Child Constructor
Enter fullscreen mode Exit fullscreen mode

Real Production Usage

Encapsulation

Used in:

  • DTOs
  • Entities
  • POJOs
  • Spring Beans

Inheritance

Used for:

RuntimeException



CustomException
Enter fullscreen mode Exit fullscreen mode

Polymorphism

Spring uses it everywhere.

Example

UserService service;

service = new UserServiceImpl();
Enter fullscreen mode Exit fullscreen mode

Loose coupling.


Abstraction

Repositories

Services

Payment gateways

Notification systems

Authentication

Logging


Common Interview Questions

What is OOP?

Programming using objects containing state and behavior.


Why is Encapsulation important?

Protects data and enforces validation.


Difference between Encapsulation and Abstraction?

Encapsulation hides data.

Abstraction hides implementation.


Why doesn't Java support Multiple Inheritance?

Diamond Problem.


Why can abstract classes have constructors?

To initialize inherited state when a subclass object is created.


Difference between Interface and Abstract Class?

Interface defines a contract.

Abstract class provides partial implementation and shared state.


Difference between Overloading and Overriding?

Overloading

  • Same class
  • Compile time

Overriding

  • Inheritance
  • Runtime

Does Java support Copy Constructors?

Not automatically.

Developers create them manually.


Does Java have Destructors?

No.

Garbage Collector manages memory.


Senior-Level Discussion Points

Favor Composition Over Inheritance

Instead of:

IS-A
Enter fullscreen mode Exit fullscreen mode

Prefer:

HAS-A
Enter fullscreen mode Exit fullscreen mode

More flexible.


Program to Interfaces

Instead of

UserServiceImpl service;
Enter fullscreen mode Exit fullscreen mode

Use

UserService service;
Enter fullscreen mode Exit fullscreen mode

This enables dependency injection and loose coupling.


SOLID Principles

OOP is the foundation of:

  • Dependency Injection
  • Spring Framework
  • Design Patterns
  • Microservices

3. Last-Minute Interview Revision

Must Remember

1

Encapsulation = Hide Data
Enter fullscreen mode Exit fullscreen mode

2

Abstraction = Hide Implementation
Enter fullscreen mode Exit fullscreen mode

3

Reference Type
↓

Accessible Methods

Object Type
↓

Executed Method
Enter fullscreen mode Exit fullscreen mode

Interview Buzzwords

Object

Class

Inheritance

IS-A

HAS-A

Encapsulation

Abstraction

Loose Coupling

Dynamic Dispatch

Method Overloading

Method Overriding

Constructor Chaining

Diamond Problem

Garbage Collection

Composition
Enter fullscreen mode Exit fullscreen mode

Red Flags

Never say:

Interface stores state ❌

Java supports multiple class inheritance ❌

Overloading is runtime polymorphism ❌

Overriding is compile-time polymorphism ❌

Java has destructors ❌

finalize() is destructor ❌
Enter fullscreen mode Exit fullscreen mode

4. Active Recall Questions

Beginner

  1. What is OOP?
  2. Difference between Class and Object?
  3. What is Encapsulation?
  4. What is Inheritance?
  5. What is Polymorphism?
  6. What is Abstraction?
  7. What is a Constructor?
  8. Why do we use Constructors?
  9. What is a Default Constructor?
  10. Does Java have Destructors?

Intermediate

  1. Encapsulation vs Abstraction?
  2. Interface vs Abstract Class?
  3. Overloading vs Overriding?
  4. Why doesn't Java support multiple inheritance?
  5. What is the Diamond Problem?
  6. Constructor execution flow?
  7. What is constructor chaining?
  8. Why can abstract classes have constructors?
  9. Types of inheritance?
  10. What is runtime polymorphism?

Advanced

  1. How does JVM perform dynamic dispatch?
  2. Explain constructor chaining internally.
  3. Why is composition preferred over inheritance?
  4. How does Spring use interfaces for dependency injection?
  5. Explain loose coupling with interfaces.
  6. What happens in memory when an object is created?
  7. Why can't constructors be overridden?
  8. Why can't constructors be abstract or static?
  9. Explain Liskov Substitution Principle using inheritance.
  10. How do design patterns leverage OOP?

5. Flash Cards

Q: What is OOP?
A: Programming using objects containing state and behavior.

Q: Encapsulation?
A: Hiding data using private members and controlled access.

Q: Inheritance?
A: Acquiring properties and behavior of another class.

Q: Polymorphism?
A: One interface, many implementations.

Q: Abstraction?
A: Hiding implementation details while exposing essential functionality.

Q: Interface?
A: Defines a contract.

Q: Abstract class?
A: Provides partial implementation and shared state.

Q: Constructor?
A: Initializes an object during creation.

Q: Does Java have destructors?
A: No, memory is managed by the Garbage Collector.

Q: Why no multiple class inheritance?
A: To avoid the Diamond Problem.


6. Interview Story Preparation (Based on Your Experience)

Drawing from your resume and Jio experience :

What I Did

Designed and developed web interfaces for JioFiber Mesh and ONT devices using ReactJS and collaborated with backend APIs. Worked with cross-functional teams, participated in code reviews, testing, automation, and documentation.

Challenges Faced

Needed a maintainable architecture while supporting multiple device models and features without duplicating code.

How I Solved Them

Applied OOP principles:

  • Encapsulation for protecting object state.
  • Inheritance where common functionality could be shared.
  • Polymorphism through interfaces and overriding to support different implementations.
  • Abstraction to expose only required functionality across modules.

Business Impact

This improved code reuse, reduced duplication, simplified maintenance, and made feature enhancements easier across multiple device types.

STAR Answer

Situation: We were developing and maintaining web interfaces for multiple JioFiber devices.

Task: Ensure the application remained scalable and maintainable as new device models and features were added.

Action: I applied OOP principles by designing reusable classes, using encapsulation to protect object state, abstraction to separate implementation details, and polymorphism to support different device behaviors without changing client code.

Result: The codebase became easier to maintain, new features were integrated faster, and collaboration across the team improved because of the modular design.


7. Common Interview Traps

Interview Trap Correct Answer
Encapsulation = Data hiding only It also provides controlled access and validation
Abstraction = Same as encapsulation Encapsulation hides data; abstraction hides implementation
Overloading is runtime No, compile-time
Overriding is compile-time No, runtime
Java supports multiple inheritance with classes No, only through interfaces
Interfaces can have constructors No
Abstract classes cannot have constructors They can
Constructors are inherited No
Constructors can be static No
finalize() is a destructor No, it's deprecated and not equivalent to a destructor

8. Memory Tricks

Four Pillars

Protect
Reuse
Many Forms
Hide

↓

Encapsulation
Inheritance
Polymorphism
Abstraction
Enter fullscreen mode Exit fullscreen mode

Overloading vs Overriding

Overloading
↓

Compiler

Overriding
↓

JVM
Enter fullscreen mode Exit fullscreen mode

Interface vs Abstract Class

Need Contract?

↓

Interface

Need Shared Code?

↓

Abstract Class
Enter fullscreen mode Exit fullscreen mode

Constructor Flow

Heap

↓

Defaults

↓

Constructor

↓

Reference
Enter fullscreen mode Exit fullscreen mode

9. 30-Second Interview Answer

"Object-Oriented Programming organizes software around objects that combine state and behavior. The four pillars are encapsulation, inheritance, polymorphism, and abstraction. Encapsulation protects data, inheritance enables code reuse, polymorphism allows one interface with multiple implementations, and abstraction hides implementation details. In Java, multiple class inheritance is not supported to avoid the Diamond Problem, so interfaces are used to achieve multiple inheritance of type. These principles form the foundation of enterprise frameworks like Spring Boot."


10. Ultimate Revision Table

Topic Definition Important Points Interview Focus
OOP Programming with objects State + Behavior Java fundamentals
Class vs Object Blueprint vs Instance Heap allocation Memory model
Encapsulation Hide data Getters, setters, validation Data protection
Inheritance IS-A relationship Code reuse OOP design
Polymorphism One interface, many forms Overloading vs overriding Runtime behavior
Abstraction Hide implementation Abstract classes, interfaces API design
Interface Contract Loose coupling, multiple implementation Spring DI
Abstract Class Shared implementation Constructors, state Code reuse
Constructors Object initialization Default, parameterized, copy Object lifecycle
Garbage Collection Automatic memory management No destructors JVM internals

Interview Readiness Score

9.5/10

You have covered the Java OOP fundamentals expected in most Software Developer interviews. To reach an expert level, spend extra time on:

  1. Runtime polymorphism and dynamic dispatch internals.
  2. Interface vs abstract class scenarios.
  3. Constructor chaining and object creation flow.
  4. Composition vs inheritance (a favorite senior-level design topic).
  5. Explaining how Spring Boot uses OOP principles (interfaces, dependency injection, loose coupling) in real-world applications.

Java Control Flow & Exception Handling – Interview Revision Pack

Optimized for Software Developer, Java Backend, Spring Boot, Full Stack, and Production Support interviews.


1. One-Page Cheat Sheet

Loops

Loop When to Use Production Example
for Known iterations Arrays, Lists, counting
while Unknown iterations Reading files, sockets, user input
do-while Must execute at least once Menu-driven applications
Enhanced for Arrays & Collections Iterating over Lists, Sets

Memory Trick

Known Count
     ↓
for

Unknown Count
     ↓
while

Must Run Once
     ↓
do-while

Collections
     ↓
Enhanced for
Enter fullscreen mode Exit fullscreen mode

Loop Control

break

break;
Enter fullscreen mode Exit fullscreen mode
  • Terminates nearest loop
  • Can be labeled

continue

continue;
Enter fullscreen mode Exit fullscreen mode
  • Skips current iteration
  • Continues next iteration

Switch vs If-Else

switch

✔ One variable

✔ Fixed values

✔ Better readability

if-else

✔ Multiple variables

✔ Range checks

✔ Complex Boolean expressions


Exception Handling Flow

Normal

try
 ↓
finally

----------------

Exception

try
 ↓
catch
 ↓
finally
Enter fullscreen mode Exit fullscreen mode

try-with-resources

try(FileInputStream fis = ...)
Enter fullscreen mode Exit fullscreen mode

Automatically closes:

  • Files
  • Database connections
  • Streams
  • Scanners

Must implement:

AutoCloseable
Enter fullscreen mode Exit fullscreen mode

Checked vs Unchecked

Checked Unchecked
Compile-time Runtime
Must handle Optional
IOException NullPointerException
SQLException ArithmeticException
FileNotFoundException IllegalArgumentException

throw vs throws

throw throws
Actually throws Declares possible exception
Inside method Method signature
One exception object Multiple exceptions allowed

Error vs Exception

Exception Error
Recoverable JVM problem
Application issue Serious system issue
Can handle Usually cannot recover

StackOverflowError vs OutOfMemoryError

StackOverflowError OutOfMemoryError
Stack full Heap full
Infinite recursion Too many objects
Method calls Object allocation

2. Interview Revision Notes

What It Is

Control Flow determines how a program executes, while Exception Handling allows Java applications to recover gracefully from runtime failures.


Why It Exists

Without exception handling:

Exception

↓

Program Crash
Enter fullscreen mode Exit fullscreen mode

With exception handling:

Exception

↓

Catch

↓

Recover

↓

Continue Execution
Enter fullscreen mode Exit fullscreen mode

How It Works Internally

Loop Execution

for(int i=0;i<5;i++)
Enter fullscreen mode Exit fullscreen mode

Internally

Initialization

↓

Condition Check

↓

Body

↓

Increment

↓

Repeat
Enter fullscreen mode Exit fullscreen mode

Exception Handling Flow

try{

}
catch(){

}
finally{

}
Enter fullscreen mode Exit fullscreen mode

Internally

Execute try

↓

Exception?

↓

No
↓

finally

-----------------

Yes

↓

Find Matching Catch

↓

Execute Catch

↓

finally
Enter fullscreen mode Exit fullscreen mode

try-with-resources

Compiler converts:

try(FileInputStream fis = ...)
Enter fullscreen mode Exit fullscreen mode

Into something similar to:

FileInputStream fis = ...

try{

}
finally{

fis.close();

}
Enter fullscreen mode Exit fullscreen mode

Automatic cleanup.


Stack Trace Generation

When an exception occurs:

Method A

↓

Method B

↓

Method C

↓

Exception

↓

Stack Trace Generated

↓

Stack Unwinding

↓

Matching Catch Found

↓

Execute Catch
Enter fullscreen mode Exit fullscreen mode

Real Production Usage

for Loop

Processing:

  • Arrays
  • Batch jobs
  • Reports

while Loop

Used for:

  • Reading log files
  • Kafka consumers
  • TCP socket communication
  • Streaming APIs

Exception Handling

Spring Boot uses exceptions extensively:

@ControllerAdvice

@ExceptionHandler

ResponseEntity
Enter fullscreen mode Exit fullscreen mode

try-with-resources

Used for:

  • JDBC
  • File IO
  • REST client streams
  • BufferedReader

Custom Exceptions

Business validation

InvalidUserException

InsufficientBalanceException

OrderNotFoundException
Enter fullscreen mode Exit fullscreen mode

Common Interview Questions

Difference between break and continue?

  • break exits the loop.
  • continue skips only the current iteration.

Why use while instead of for?

When the number of iterations is unknown.


Why use try-with-resources?

Automatic resource cleanup.

No resource leaks.


Difference between Checked and Unchecked Exceptions?

Checked

  • Compiler forces handling.

Unchecked

  • Runtime exceptions.

Difference between throw and throws?

throw

  • Actually throws.

throws

  • Declares responsibility.

Why does finally exist?

To guarantee cleanup regardless of whether an exception occurs.


Can finally fail to execute?

Yes.

Examples:

  • System.exit()
  • JVM crash
  • Power failure
  • OS kill

Difference between Error and Exception?

Exception

Recoverable application problem.

Error

Serious JVM problem.


Difference between StackOverflowError and OutOfMemoryError?

StackOverflowError

Infinite recursion.

OutOfMemoryError

Heap exhausted.


Senior-Level Discussion Points

Never Swallow Exceptions

Bad

catch(Exception e){

}
Enter fullscreen mode Exit fullscreen mode

Good

catch(IOException e){

logger.error(...);

throw e;
}
Enter fullscreen mode Exit fullscreen mode

Catch Specific Exceptions

Avoid

catch(Exception e)
Enter fullscreen mode Exit fullscreen mode

Prefer

catch(IOException e)
Enter fullscreen mode Exit fullscreen mode

Use Custom Exceptions

Instead of

Exception
Enter fullscreen mode Exit fullscreen mode

Prefer

UserNotFoundException

OrderException

PaymentException
Enter fullscreen mode Exit fullscreen mode

Prefer try-with-resources

Never manually forget to close:

  • Files
  • Connections
  • Streams

3. Last-Minute Interview Revision

Must Remember

1

break

↓

Exit Loop
Enter fullscreen mode Exit fullscreen mode

2

continue

↓

Skip Iteration
Enter fullscreen mode Exit fullscreen mode

3

Checked

↓

Compiler

Unchecked

↓

Runtime
Enter fullscreen mode Exit fullscreen mode

Interview Buzzwords

Control Flow

Loop

Iteration

Stack Unwinding

Exception Propagation

Checked Exception

Unchecked Exception

RuntimeException

AutoCloseable

try-with-resources

finally

Custom Exception

Stack Trace

Resource Leak
Enter fullscreen mode Exit fullscreen mode

Red Flags

Never say:

finally always executes ❌

Error can always be recovered ❌

throw and throws are same ❌

try needs catch ❌

break exits current iteration ❌

continue exits loop ❌

OutOfMemoryError = Stack Overflow ❌
Enter fullscreen mode Exit fullscreen mode

4. Active Recall Questions

Beginner

  1. Difference between for and while?
  2. When should you use do-while?
  3. What does break do?
  4. What does continue do?
  5. What is a checked exception?
  6. What is an unchecked exception?
  7. What is finally?
  8. What is try-with-resources?
  9. What is throw?
  10. What is throws?

Intermediate

  1. When should switch be preferred over if-else?
  2. When can finally not execute?
  3. Difference between Error and Exception?
  4. Why is try-with-resources better?
  5. What must a resource implement?
  6. Can try exist without catch?
  7. Can try exist without finally?
  8. What is stack unwinding?
  9. Why create custom exceptions?
  10. Difference between StackOverflowError and OutOfMemoryError?

Advanced

  1. How does JVM search for a matching catch block?
  2. Explain exception propagation.
  3. How does compiler transform try-with-resources?
  4. Why shouldn't you catch Exception everywhere?
  5. Explain suppressed exceptions.
  6. How does Spring Boot handle exceptions globally?
  7. Explain exception translation in Spring Data.
  8. What happens if finally throws another exception?
  9. Why are Errors usually not caught?
  10. Design a custom exception hierarchy for an e-commerce system.

5. Flash Cards

Q: Which loop is best for known iterations?
A: for.

Q: Which loop runs at least once?
A: do-while.

Q: break?
A: Exits the loop.

Q: continue?
A: Skips current iteration.

Q: Checked exception?
A: Compiler-enforced exception.

Q: Unchecked exception?
A: Runtime exception.

Q: throw?
A: Throws an exception object.

Q: throws?
A: Declares exceptions in a method signature.

Q: try-with-resources requires?
A: AutoCloseable.

Q: StackOverflowError?
A: Infinite recursion.


6. Interview Story Preparation (Based on Your Experience)

Based on your Jio Software Developer experience :

What I Did

While developing and supporting JioFiber applications, I handled exceptions during backend development, automation, and testing. I also worked with file operations, logging, and production issue analysis.

Challenges Faced

Production issues could occur due to invalid inputs, file access problems, or unexpected runtime conditions. Proper error handling was essential to avoid application failures.

How I Solved Them

I used structured exception handling, logged errors for troubleshooting, cleaned up resources properly, and created validation logic to prevent invalid operations from reaching production.

Business Impact

This improved application stability, simplified debugging, reduced downtime, and made production support more efficient.

STAR Answer

Situation: During backend development and production support, applications had to handle unexpected runtime failures without crashing.

Task: Ensure the application remained stable and failures could be diagnosed quickly.

Action: I implemented proper exception handling using specific catch blocks, ensured resources were closed correctly, logged meaningful error messages, and validated inputs before processing.

Result: The application became more reliable, production incidents were easier to troubleshoot, and the development team could resolve issues faster.


7. Common Interview Traps

Trap Correct Answer
finally always executes Not if System.exit(), JVM crash, OS kill, or power failure occurs
break skips one iteration No, it exits the loop
continue exits the loop No, it skips only the current iteration
throw and throws are identical throw performs the action; throws declares it
Checked exceptions occur at runtime only They are enforced at compile time
try must always have a catch It can also have only a finally block
Errors should always be caught Most Errors indicate serious JVM issues and are generally not meant to be handled

8. Memory Tricks

Loop Selection

Known Count
↓

for

Unknown Count
↓

while

Must Execute Once
↓

do-while

Collections
↓

Enhanced for
Enter fullscreen mode Exit fullscreen mode

Exception Hierarchy

Throwable

↓

Exception
↓

RuntimeException

↓

Unchecked
Enter fullscreen mode Exit fullscreen mode

Everything else under Exception is generally Checked.

throw vs throws

throw

↓

Action

throws

↓

Declaration
Enter fullscreen mode Exit fullscreen mode

Memory Errors

Stack

↓

Methods

↓

StackOverflowError

----------------

Heap

↓

Objects

↓

OutOfMemoryError
Enter fullscreen mode Exit fullscreen mode

9. 30-Second Interview Answer

"Java control flow uses loops such as for, while, do-while, and enhanced for depending on the iteration requirement. Exception handling allows applications to recover gracefully from runtime failures using try, catch, and finally. Checked exceptions are enforced by the compiler, while unchecked exceptions occur at runtime. Modern Java uses try-with-resources to automatically close resources that implement AutoCloseable, helping prevent resource leaks and making production code safer."


10. Ultimate Revision Table

Topic Definition Important Points Interview Focus
Loops Repeated execution Choose based on iteration pattern Control flow
break Exit loop Can be labeled Nested loops
continue Skip current iteration Loop continues Iteration control
switch vs if-else Choice vs condition Fixed values vs complex logic Code readability
try-catch-finally Exception handling Cleanup with finally Runtime reliability
try-with-resources Automatic cleanup Requires AutoCloseable File I/O, JDBC
Checked Exception Compile-time enforced Must handle or declare API design
Unchecked Exception Runtime exception Optional to handle Input validation
throw vs throws Action vs declaration One object vs method contract Exception flow
Error vs Exception JVM vs application problem Recoverability JVM internals
StackOverflowError Stack exhausted Infinite recursion Recursion bugs
OutOfMemoryError Heap exhausted Excessive object allocation Memory management
Custom Exception Domain-specific error Extends Exception or RuntimeException Clean architecture

Interview Readiness Score

9.5/10

You have a solid grasp of Java control flow and exception handling. To perform well in senior-level interviews, focus on these five areas:

  1. Exception propagation and stack unwinding.
  2. try-with-resources internals and AutoCloseable.
  3. Choosing checked vs unchecked exceptions in API design.
  4. Global exception handling in Spring Boot (@ControllerAdvice, @ExceptionHandler).
  5. Resource management and logging best practices in production systems.

Source: dev.to

arrow_back Back to Tutorials