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

Core Java Theory Notes

The document provides core Java theory notes tailored for Java developers with four years of experience, focusing on key concepts such as OOP, exception handling, collections, and Java 8 features. It includes definitions, important points, and distinctions between various Java components like JDK, JRE, and JVM, as well as practical tips for interview preparation. The final section outlines a revision strategy to master each topic effectively.

Uploaded by

aakifahmed313
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)
2 views10 pages

Core Java Theory Notes

The document provides core Java theory notes tailored for Java developers with four years of experience, focusing on key concepts such as OOP, exception handling, collections, and Java 8 features. It includes definitions, important points, and distinctions between various Java components like JDK, JRE, and JVM, as well as practical tips for interview preparation. The final section outlines a revision strategy to master each topic effectively.

Uploaded by

aakifahmed313
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

Core Java Theory Notes

Interview-oriented notes for Java Developers (4 Years Experience)

Quick revision: Focus especially on OOP, String, equals/hashCode, Collections, HashMap, Exceptions, Java 8
Streams, Multithreading, JVM/JDK/JRE, and Garbage Collection.

Page 1
1. Java Introduction
What is Java?
Java is a high-level, object-oriented, class-based programming language designed to be platform independent through
bytecode and the JVM.

Main Features
Simple, object-oriented, platform independent, secure, robust, multithreaded, portable, dynamic, distributed, and high
performance through JIT compilation.

2. JDK, JRE and JVM


JVM
Java Virtual Machine executes Java bytecode and converts it into machine-level instructions.

JRE
Java Runtime Environment = JVM + libraries required to run Java applications.

JDK
Java Development Kit = JRE + development tools such as javac.

Memory trick
JDK → Develop | JRE → Run | JVM → Execute

3. Class and Object


Class
A class is a blueprint or template that defines data and behavior.

Object
An object is an instance of a class. In Student s = new Student();, Student is the class, s is a reference variable, new
creates the object, and Student() is the constructor.

4. Constructor
Definition
A constructor initializes an object. Its name is the same as the class name and it has no return type.

Important points
Constructors are called during object creation, can be overloaded, are not inherited, and cannot be overridden.

5. OOP Concepts
Encapsulation
Wrapping data and methods inside a class and controlling access, commonly using private fields and public methods.

Inheritance
A child class acquires properties and behavior from a parent class using extends.

Polymorphism

Page 2
One interface/reference can represent different forms. Overloading is compile-time polymorphism; overriding is runtime
polymorphism.

Abstraction
Hiding implementation details and exposing required behavior using abstract classes and interfaces.

6. this Keyword
Definition
this refers to the current object's reference.

Common use
It is commonly used when an instance variable and constructor/method parameter have the same name: [Link] = id;

7. super Keyword
Definition
super refers to the immediate parent-class part of the current object.

Uses
Access parent variables, call parent methods, and call the parent constructor.

8. static Keyword
Definition
static means the member belongs to the class rather than to individual objects.

Uses
Can be applied to variables, methods, blocks, and nested classes. Static members are shared at class level.

9. final, finally and finalize()


final
A final variable cannot be reassigned; a final method cannot be overridden; a final class cannot be inherited.

finally
A block used with exception handling, normally executed after try/catch for cleanup.

finalize()
An old Object method associated with cleanup before garbage collection. It is deprecated and should not be used in
modern Java.

Memory trick
final → restriction | finally → exception block | finalize() → old cleanup mechanism

10. Exception Handling


Exception
An exception is an event that disrupts normal program execution.

Page 3
Checked exceptions
Checked by the compiler. Examples: IOException, SQLException, ClassNotFoundException.

Unchecked exceptions
Runtime exceptions. Examples: NullPointerException, ArithmeticException, ArrayIndexOutOfBoundsException.

Keywords
try, catch, finally, throw, throws

11. throw vs throws


throw
Explicitly throws an exception from code, for example: throw new IllegalArgumentException("Invalid value");

throws
Declares in a method signature that the method may pass an exception to its caller, for example: void read() throws
IOException.

Memory trick
throw → actually throws | throws → declares possibility

12. String
Definition
String is an immutable class. Once a String object is created, its content cannot be changed.

Important topics
String Pool, immutability, equals(), ==, StringBuilder, and StringBuffer.

13. StringBuilder vs StringBuffer


StringBuilder
Mutable, generally faster, not synchronized, not thread-safe.

StringBuffer
Mutable, synchronized, thread-safe, generally slower than StringBuilder.

14. Arrays
Definition
An array stores multiple values of the same type and has fixed size.

Example
int[] numbers = {10, 20, 30};

15. Wrapper Classes


Definition
Wrapper classes represent primitive values as objects.

Page 4
Mapping
int → Integer | long → Long | double → Double | char → Character | boolean → Boolean

Autoboxing
Primitive → wrapper object.

Unboxing
Wrapper object → primitive.

16. Collections Framework


List
Allows duplicates and generally preserves insertion order. Examples: ArrayList, LinkedList, Vector, Stack.

Set
Does not allow duplicate elements. Examples: HashSet, LinkedHashSet, TreeSet.

Queue
Designed for queue-based processing. Examples: PriorityQueue, ArrayDeque.

Map
Stores key-value pairs. Examples: HashMap, LinkedHashMap, TreeMap, Hashtable, ConcurrentHashMap.

17. ArrayList vs LinkedList


ArrayList
Backed by a dynamic array. Fast random access by index; insertion/removal in the middle may require shifting.

LinkedList
Linked-node structure. Better suited to frequent insertions/removals at known linked positions, but slower random
access.

18. HashMap
Definition
HashMap stores data as key-value pairs.

Internal concepts
Hashing, hashCode(), equals(), buckets, collisions, nodes, and treeification.

Important rule
If two objects are equal according to equals(), they must have the same hashCode(). Same hashCode does not
guarantee equality.

19. entrySet()
Definition
[Link]() returns a Set containing the map's key-value entries.

Usage

Page 5
for ([Link] e : [Link]()) { [Link](); [Link](); }

20. LinkedHashMap
Definition
LinkedHashMap maintains insertion order by default while storing key-value pairs.

21. TreeMap
Definition
TreeMap stores entries ordered by key according to natural ordering or a supplied Comparator.

Important point
Basic operations are generally O(log n).

22. Comparable vs Comparator


Comparable
Defines natural ordering inside the class using compareTo().

Comparator
Defines custom/external ordering using compare().

23. Generics
Definition
Generics provide compile-time type safety and reduce explicit casting.

Example
List list = new ArrayList<>();

24. Java 8 Features


Major features
Lambda expressions, functional interfaces, Stream API, method references, default/static interface methods, Optional,
and the new Date/Time API.

25. Functional Interface


Definition
An interface with exactly one abstract method.

Examples
Predicate, Function, Consumer, Supplier, Runnable, Comparator.

26. Stream API


Definition
Stream API provides a declarative way to process data from collections and other sources.

Page 6
Common operations
filter(), map(), sorted(), distinct(), limit(), collect(), reduce(), forEach().

Important concept
Intermediate operations are generally lazy; terminal operations trigger stream processing.

27. Multithreading
Definition
A thread is a lightweight unit of execution.

Ways
Thread, Runnable, Callable, ExecutorService, Future, and CompletableFuture.

Important topics
Thread lifecycle, synchronization, race condition, deadlock, thread pools, and concurrency utilities.

28. Synchronization
Definition
Synchronization controls access to shared resources so multiple threads do not incorrectly modify shared state at the
same time.

Example
A synchronized method or block can protect a critical section.

29. Garbage Collection


Definition
Garbage Collection automatically reclaims memory occupied by objects that are no longer reachable.

Important point
An object becoming unreachable makes it eligible for GC; it does not guarantee exactly when GC will run.

30. Interface
Definition
An interface defines a contract that implementing classes follow.

Modern Java
Interfaces can contain abstract methods, default methods, static methods, and private methods.

31. Abstract Class


Definition
An abstract class cannot be directly instantiated and may contain abstract and concrete methods.

Can contain
Constructors, instance variables, methods, static members, and abstract methods.

Page 7
32. Abstract Class vs Interface
Abstract class
Can have constructors, instance state, concrete methods, and abstract methods. A class can extend only one class.

Interface
No constructors. Fields are public static final by default. A class can implement multiple interfaces.

33. Method Overloading


Definition
Same method name with different parameter lists. It is compile-time polymorphism.

34. Method Overriding


Definition
A child class provides its own implementation of an inherited parent method. It is runtime polymorphism.

Important
Use @Override to make the intention clear and let the compiler validate the method signature.

35. Access Modifiers


Levels
private, default/package-private, protected, public.

Visibility
private → class only; default → same package; protected → same package plus subclasses; public → everywhere
subject to normal access rules.

36. == vs equals()
==
For object references, compares whether two references point to the same object.

equals()
Compares logical equality when the class implements/overrides it appropriately.

String example
new String("Hello") == new String("Hello") is false, while equals() is true.

37. equals() and hashCode()


Contract
If two objects are equal according to equals(), they must return the same hashCode().

Why important
HashMap and HashSet use hashCode and equals to locate and compare keys/elements.

Page 8
38. Immutable Class
Definition
An immutable object cannot be changed after it is created.

Typical design
Make the class final, fields private final, initialize through constructor, provide no setters, and use defensive copies for
mutable fields when needed.

Example
String is a well-known immutable class.

39. Important Java 17 Topics


Interview focus
Records, sealed classes, pattern matching improvements, text blocks, switch expressions, and modern
language/runtime improvements. Know the features relevant to the Java version used in your project.

Page 9
40. 4-Year Java Developer Interview Priority
• 1. OOP concepts and SOLID basics

• 2. String, String Pool, immutability, == vs equals()

• 3. equals() and hashCode() contract

• 4. Collections: List, Set, Map, Queue

• 5. HashMap internal working

• 6. ArrayList vs LinkedList

• 7. HashSet, LinkedHashSet, TreeSet

• 8. HashMap vs LinkedHashMap vs TreeMap

• 9. Comparable vs Comparator

• 10. Exception handling, throw vs throws

• 11. Java 8 Lambda, Functional Interfaces, Stream API, Optional

• 12. Multithreading, synchronization, ExecutorService, CompletableFuture basics

• 13. JVM, JDK, JRE, heap/stack basics

• 14. Garbage Collection

• 15. Abstract class vs interface

• 16. Overloading vs overriding

• 17. final, finally, finalize()

• 18. this vs super

• 19. Generics

• 20. Java 17 features

Final revision strategy: For every topic, learn (1) definition, (2) why it is used, (3) a small Java program, (4) internal
working where relevant, and (5) 2–3 interview questions.

Page 10

You might also like