0% found this document useful (0 votes)
9 views10 pages

Java Interview Prep: Core Concepts & Collections

The document outlines key topics for a Java interview preparation, focusing on Core Java, Object-Oriented Programming (OOP), and the Collections Framework. It includes a daily revision checklist, fundamental concepts, and important features of Java, such as data types, wrapper classes, OOP principles, and collection types. Additionally, it emphasizes the need for daily coding practice and provides a summary of concepts to focus on for effective learning.

Uploaded by

dreamers.nerd
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views10 pages

Java Interview Prep: Core Concepts & Collections

The document outlines key topics for a Java interview preparation, focusing on Core Java, Object-Oriented Programming (OOP), and the Collections Framework. It includes a daily revision checklist, fundamental concepts, and important features of Java, such as data types, wrapper classes, OOP principles, and collection types. Additionally, it emphasizes the need for daily coding practice and provides a summary of concepts to focus on for effective learning.

Uploaded by

dreamers.nerd
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Java Interview Notes – Day 1: Core Java,

OOP, and Collections Framework

🧠 Daily Revision Checklist


Review Core Java Fundamentals (data types, memory model, strings, exceptions)
Revise Wrapper Classes & Autoboxing
Brush up OOP Concepts with examples
Practice Collections Framework and know when to use each type
Solve 2–3 small coding problems daily (string manipulation, list operations, map counting, etc.)

☕ Core Java Fundamentals


1. Java Architecture Overview
Java is both compiled and interpreted.
Source code ( .java ) → Compiled by javac → Bytecode ( .class ) → Interpreted by JVM.
JDK: Development kit (compiler, libraries, JVM).
JRE: Runtime environment (libraries + JVM only).
JVM: Converts bytecode to machine code at runtime using JIT compiler.

2. Data Types and Sizes

Data Type Size (bits) Default Value Range

boolean 1 false true / false

byte 8 0 -128 to 127

short 16 0 -32,768 to 32,767


Data Type Size (bits) Default Value Range

int 32 0 -2³¹ to 2³¹-1

long 64 0L -2⁶³ to 2⁶³-1

float 32 0.0f ~ ±3.4×10³⁸

double 64 0.0d ~ ±1.7×10³⁰⁸

char 16 '�' 0 to 65,535 (Unicode)

🔹 Important Points:
char in Java is unsigned (unlike C/C++).
float literals need f or F, e.g., 3.14f .
Default floating type is double.

3. Wrapper Classes (Detailed)


Primitive Wrapper Class Example

boolean Boolean Boolean bool = [Link];

byte Byte Byte b = [Link]("10");

short Short Short s = 100;

int Integer Integer i = [Link](5);

long Long Long l = [Link](100L);

float Float Float f = 10.5f;

double Double Double d = [Link](99.99);

char Character Character c = 'A';

🔸 Key Concepts:
Autoboxing: Automatic conversion from primitive → wrapper.
int x = 10;
Integer y = x; // autoboxing

Unboxing: Wrapper → primitive.

Integer i = 10;
int j = i; // unboxing

Comparing Wrappers:
Use .equals() to compare values.
== checks reference equality (except for cached values in range -128 to 127).

🔹 Common Wrapper Methods:


[Link]("123"); // String → int
[Link]("12.5"); // String → Double
[Link]('5'); // true
[Link]('A'); // 'a'

🧩 Object-Oriented Programming (OOP)


1. Core Principles
1. Encapsulation – Binding data & methods in a single unit (class).
2. Abstraction – Hiding implementation details and exposing only behavior.
3. Inheritance – Reusing behavior by deriving new classes.
4. Polymorphism – One interface, many implementations (method overriding & overloading).

2. Encapsulation
Achieved using private fields and public getters/setters.
public class Account {
private double balance;
public double getBalance() { return balance; }
public void deposit(double amount) { [Link] += amount; }
}

3. Abstraction
Achieved using abstract classes and interfaces.

abstract class Shape {


abstract void draw();
}
class Circle extends Shape {
void draw() { [Link]("Drawing Circle"); }
}

4. Inheritance
Enables code reuse.
Supports single inheritance in classes, multiple inheritance via interfaces.

class A { void show() { [Link]("A"); } }


class B extends A { void show() { [Link]("B"); } }

5. Polymorphism
Compile-time: Method overloading.
Runtime: Method overriding.

class Parent { void speak() { [Link]("Parent"); } }


class Child extends Parent { void speak() { [Link]("Child"); } }
Parent obj = new Child(); [Link](); // Child
2. Important Keywords

static vs instance
static belongs to class, not objects
shared across all instances

final
variable → constant
method → cannot override
class → cannot extend

transient
Skipped in serialization.

volatile
Guarantees visibility across threads.

3. equals() & hashCode()


Equal objects must have identical hashCodes.

@Override public boolean equals(Object o){}


@Override public int hashCode(){ return [Link](id); }
4. Immutable Classes

final class User {


private final String name;
User(String n){ [Link] = n; }
public String getName(){ return name; }
}

5. Builder Pattern

User u = new UserBuilder().setName("A").setAge(20).build();

6. Java 8–21 Features (In-depth)

Lambdas

Runnable r = () -> [Link]("Hi");

Streams

List<String> filtered = [Link]()


.filter(s -> [Link]("A"))
.map(String::toUpperCase)
.toList();

Method References
[Link]::println
Optional

[Link]("Hi").orElse("Default");

Default & Static Methods in Interface

default void log(){}


static void help(){}

Records (Java 14+)

public record Person(String name, int age){}

Switch Expressions (Java 14+)

int result = switch(x){


case 1 -> 10;
case 2 -> 20;
default -> 0;
};

Sealed Classes (Java 17)

public sealed class Shape permits Circle, Square{}

Virtual Threads (Java 21)

[Link](() -> runTask());


🧰 Java Collections Framework
1. Overview
Provides ready-to-use data structures and algorithms.
All reside in [Link] package.

2. Interfaces Hierarchy

Collection
├── List (Ordered, duplicates allowed)
│ ├── ArrayList
│ ├── LinkedList
│ └── Vector / Stack
├── Set (No duplicates)
│ ├── HashSet
│ ├── LinkedHashSet
│ └── TreeSet (sorted)
└── Queue
├── PriorityQueue
└── Deque (ArrayDeque, LinkedList)
Map (Key-Value pairs, not under Collection)
├── HashMap
├── LinkedHashMap
└── TreeMap

3. Key Implementations
🔸 List
Ordered, allows duplicates.
Best for indexed access.

Type Features

ArrayList Fast random access, slow inserts/removes


Type Features

LinkedList Fast insertion/removal, slow access

Vector Synchronized version of ArrayList

Stack Legacy class (extends Vector)

🔸 Set
No duplicates.
| Type | Features |
|-------|-----------|
| HashSet | Unordered, fastest lookup |
| LinkedHashSet | Maintains insertion order |
| TreeSet | Sorted order, slower due to red-black tree |

🔸 Map
Key-value pairs.

Type Features

HashMap Fastest (O(1)), allows nulls

LinkedHashMap Ordered version of HashMap

TreeMap Sorted by keys (natural/comparator)

4. Important Concepts
✅ Fail-Fast vs Fail-Safe
Fail-Fast: Throws ConcurrentModificationException (e.g., ArrayList, HashMap).
Fail-Safe: Works on a cloned copy (e.g., ConcurrentHashMap, CopyOnWriteArrayList).

✅ Comparable vs Comparator
Comparable: Natural ordering ( compareTo() inside class).
Comparator: Custom ordering ( compare() external).
[Link](list, (a, b) -> [Link]() - [Link]());

✅ HashCode & Equals Contract


If two objects are equal → must have same hashCode().
Unequal objects → may have same hashCode() (collision).

5. Common Interview Snippets

Map<String, Integer> map = new HashMap<>();


[Link]("a", 1);
[Link]("b", 2);
for (var entry : [Link]()) {
[Link]([Link]() + "=" + [Link]());
}

🏁 Summary
Concept What to Focus

Primitives Size, default, conversion rules

Wrappers Autoboxing, equals vs ==

OOP Real-world examples for each concept

Collections When to use which collection, Big-O behavior

Coding Daily practice 15–20 mins

Next Day: Multithreading, Concurrency, and Executors Framework

You might also like