JAVA FULL NOTES (Complete Guide for Beginners to Advanced)

 



1. INTRODUCTION TO JAVA

1.1 What is Java?

  • Java is a high-level, object-oriented, platform-independent programming language.

  • Developed by James Gosling at Sun Microsystems (1995).

  • “Write Once, Run Anywhere” – bytecode runs on JVM on any OS.

1.2 Features of Java

  1. Simple

  2. Object-Oriented

  3. Platform Independent

  4. Secure

  5. Robust

  6. Portable

  7. High Performance (JIT compiler)

  8. Multithreaded

  9. Distributed

  10. Dynamic

1.3 JVM, JDK, JRE

JDK (Java Development Kit)

  • Full package: JRE + compiler (javac) + tools.

JRE (Java Runtime Environment)

  • Provides libraries + JVM to run Java programs.

JVM (Java Virtual Machine)

  • Converts bytecode to machine code.

  • Handles: memory, garbage collection, security.


2. BASICS OF JAVA

2.1 Data Types

Primitive

  • byte (1 byte)

  • short (2 bytes)

  • int (4)

  • long (8)

  • float (4)

  • double (8)

  • char (2)

  • boolean (1 bit)

Non-Primitive

  • String

  • Arrays

  • Classes, Objects

2.2 Variables

  • Instance variables – inside class, outside method.

  • Local variables – inside method.

  • Static variables – shared across objects.

2.3 Operators

  • Arithmetic: + - * / %

  • Relational: < > <= >= == !=

  • Logical: && || !

  • Assignment: = += -= *=

  • Unary: ++ --

  • Ternary: ? :

2.4 Control Statements

Decision Making

  • if

  • if-else

  • else-if ladder

  • switch

Loops

  • for

  • while

  • do-while

  • for-each


3. OBJECT-ORIENTED PROGRAMMING (OOP)

3.1 Class & Object

Class → blueprint
Object → instance

class Student { int id; String name; }

3.2 Constructors

  • Called automatically at object creation.

Types:

  • Default

  • Parameterized

  • Copy constructor (via object reference)

3.3 OOP Pillars

1️⃣ Encapsulation

  • Binding data + methods into one unit.

  • Achieved using private variables and public getters/setters.

2️⃣ Inheritance

  • Process of acquiring properties of another class.

Types:

  • Single

  • Multilevel

  • Hierarchical
    (Java does NOT support multiple inheritance using classes — but interfaces allow it.)

3️⃣ Polymorphism

Compile-time → method overloading

Runtime → method overriding

4️⃣ Abstraction

  • Hiding implementation details.

  • Achieved by:

    • abstract class

    • interface


4. ACCESS MODIFIERS

  1. public – accessible everywhere

  2. private – within class only

  3. protected – within package + subclasses

  4. default – package-private


5. KEYWORDS

  • static – shared across objects

  • this – refers to current object

  • super – refers to parent class

  • final – constant / no overriding / no inheritance

  • return – returns value

  • break, continue – control flow


6. EXCEPTION HANDLING

6.1 Why Exception Handling?

To handle runtime errors gracefully.

6.2 Types of Exceptions

Checked exceptions

  • Must be handled at compile time
    Examples: IOException, SQLException

Unchecked exceptions

  • Runtime errors
    Examples: NullPointerException, ArithmeticException

6.3 Keywords

  • try

  • catch

  • finally

  • throw (used inside method)

  • throws (used in method declaration)


7. JAVA COLLECTIONS FRAMEWORK

Used to store and manipulate groups of objects.

7.1 Interfaces

  • List

  • Set

  • Map

  • Queue

7.2 Implementing Classes

List

  • ArrayList (dynamic array)

  • LinkedList (doubly linked list)

  • Vector

  • Stack

Set

  • HashSet

  • LinkedHashSet

  • TreeSet (sorted)

Map

  • HashMap

  • LinkedHashMap

  • TreeMap

  • Hashtable


8. MULTITHREADING

8.1 Thread Creation

  1. Extend Thread class

  2. Implement Runnable interface

8.2 Thread Methods

  • start()

  • run()

  • sleep()

  • join()

  • yield()

  • setPriority()

8.3 Synchronization

Prevents concurrent access of shared resources.

Types:

  • Method synchronization

  • Block synchronization

  • Static synchronization


9. JAVA MEMORY MANAGEMENT

Heap – stores objects

Stack – stores method calls, local variables

Garbage Collector – removes unused objects

GC Algorithms:

  • Mark & Sweep

  • Generational GC


10. STRING HANDLING

String (immutable)

StringBuilder (mutable, fast)

StringBuffer (thread-safe)


11. FILE HANDLING (java.io & java.nio)

Classes:

  • FileInputStream

  • FileOutputStream

  • BufferedReader

  • FileReader

  • PrintWriter


12. JDBC (Database Connectivity)

Steps:

  1. Load driver

  2. Create connection

  3. Create statement

  4. Execute query

  5. Process results

  6. Close connection


13. JAVA 8 FEATURES

  1. Lambda Expressions

  2. Functional Interfaces

  3. Stream API

  4. Default & Static Methods in Interface

  5. Method References

  6. Optional Class


14. SPRING (BRIEF)

If you need full Spring notes, I can prepare separately.

  • Spring Core – IoC, Dependency Injection

  • Spring MVC – Web apps

  • Spring Boot – Auto configuration, easy setup

  • Spring Data JPA – ORM

  • Spring Security – Authentication


15. MOST IMPORTANT INTERVIEW QUESTIONS

  1. Difference between JDK, JRE, JVM

  2. Overloading vs Overriding

  3. Interface vs Abstract Class

  4. HashMap vs Hashtable

  5. String vs StringBuilder

  6. What is garbage collection?

  7. Checked vs Unchecked exceptions

  8. How HashMap works internally?

  9. Why Java is platform independent?

  10. What is multithreading?


Post a Comment

0 Comments