Java Full Reference Guide
Comprehensive notes from basics to advanced topics.
1. Introduction to Java
Java is a high-level, class-based, object-oriented programming language designed to have
as few implementation dependencies as possible. It is platform-independent due to the
Java Virtual Machine (JVM).
2. Java Basics
Java programs start execution from the 'main' method: public static void main(String[]
args). Data types include int, float, double, char, boolean. Variables can be declared as
local, instance, or static. Control statements include if-else, switch, loops (for, while,
do-while).
3. Object-Oriented Programming
Java supports four pillars of OOP: Encapsulation, Inheritance, Polymorphism, and
Abstraction. Classes define objects, and objects are instances of classes. Interfaces
define contracts for classes. Access modifiers: public, private, protected, and default
determine visibility.
4. Exception Handling
Java uses try-catch-finally blocks to handle exceptions. Checked exceptions (IOException,
SQLException) must be declared; unchecked (NullPointerException, ArithmeticException)
do not. Custom exceptions can be created by extending Exception.
5. Collections Framework
The Java Collections Framework includes interfaces like List, Set, Map, and their
implementations (ArrayList, HashSet, HashMap). Collections utility methods
(Collections.sort, reverse) simplify data manipulation.
6. Streams and Lambda Expressions
Java 8 introduced Streams and Lambda expressions for functional-style programming.
Example: list.stream().filter(x -> x > 10).collect(Collectors.toList());
7. File Handling
Files can be managed using java.io and java.nio packages. Classes like FileReader,
FileWriter, BufferedReader, and FileInputStream are used for I/O operations.
8. Multithreading
Threads allow concurrent execution. Threads can be created by extending Thread or
implementing Runnable. Synchronization ensures thread safety. The Executor framework
manages thread pools efficiently.
9. Java Memory Model & Garbage Collection
The JVM manages memory with heap and stack areas. Garbage Collection automatically
removes unused objects. Reference types: strong, weak, soft, and phantom references.
10. Java Database Connectivity (JDBC)
JDBC allows communication with databases using DriverManager and Connection
classes. Steps: Load driver → Establish connection → Create statement → Execute query
→ Close connection.
11. Java 8+ Features
Includes Streams, Optional, Method references, LocalDate/Time API, and
CompletableFuture for async programming.
12. Spring Framework Overview
Spring provides Inversion of Control (IoC) and Dependency Injection (DI) to manage
beans. Spring Boot simplifies development with embedded servers and auto-configuration.
13. Best Practices
Follow naming conventions, handle exceptions properly, close resources, use generics,
and write unit tests. Use modern build tools like Maven or Gradle for dependency
management.