Java Full Course - Complete Notes (Beginner to Advanced)
1. Introduction to Java
- Java is a high-level, object-oriented programming language.
- Developed by Sun Microsystems (now owned by Oracle).
- Platform-independent due to the Java Virtual Machine (JVM).
- Secure, robust, portable, and multithreaded language.
- Used in web, mobile, desktop applications, and enterprise systems.
2. Java Installation & Setup
- Install JDK (Java Development Kit).
- Set JAVA_HOME environment variable.
- Use IDEs like Eclipse, IntelliJ IDEA, or NetBeans.
- Compile: javac FileName.java
- Run: java ClassName
3. Basic Java Syntax
- Java programs start with class definitions.
- main() method is the entry point:
public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello, World!");
4. Variables & Data Types
- int, float, double, char, boolean, long, short, byte
- Reference types: String, Arrays, Objects
- Example:
int x = 10;
float pi = 3.14f;
5. Operators
- Arithmetic: +, -, *, /, %
- Relational: ==, !=, >, <, >=, <=
- Logical: &&, ||, !
- Assignment: =, +=, -=, *=, /=
- Unary: ++, --
6. Control Flow Statements
- Conditional: if, if-else, else-if, switch
- Looping: for, while, do-while
- Break & Continue statements
- Example:
for (int i = 0; i < 5; i++) {
System.out.println(i);
7. Methods in Java
- Syntax:
returnType methodName(parameters) {
// body
}
- Method overloading: Same method name, different parameters.
- static vs instance methods
8. Arrays
- Fixed-size data structure
- Syntax:
int[] nums = new int[5];
int[] nums = {1, 2, 3, 4, 5};
- Multi-dimensional arrays:
int[][] matrix = new int[3][3];
9. Object-Oriented Programming (OOP)
- 4 Pillars: Encapsulation, Abstraction, Inheritance, Polymorphism
- Class:
class Car {
String model;
void drive() {}
- Object:
Car myCar = new Car();
10. Constructors
- Special method to initialize objects.
- Default and Parameterized constructors.
- this keyword used to differentiate between instance and local variables.
11. Inheritance
- Allows a class to inherit fields and methods from another class.
- Syntax: class Dog extends Animal
- super keyword used to access parent class properties/methods.
12. Polymorphism
- Compile-time: method overloading
- Run-time: method overriding
- Enables a single interface to represent different types.
13. Abstraction
- Hides complexity and shows only essential features.
- Abstract class:
abstract class Animal {
abstract void sound();
- Interface:
interface Vehicle {
void run();
14. Encapsulation
- Wrapping of data and methods into a single unit.
- Achieved using private variables and public getter/setter methods.
15. Exception Handling
- Used to handle runtime errors.
- Keywords: try, catch, finally, throw, throws
- Example:
try {
int result = 10 / 0;
} catch (ArithmeticException e) {
System.out.println("Error: " + e);
16. File Handling
- Classes: File, FileReader, FileWriter, BufferedReader
- Reading and writing text files.
- Example:
FileWriter writer = new FileWriter("file.txt");
writer.write("Hello");
writer.close();
17. Packages
- Grouping related classes and interfaces.
- Use import to access built-in or user-defined packages.
18. Java Collections Framework (Intro)
- Interfaces: List, Set, Map, Queue
- Classes: ArrayList, LinkedList, HashSet, HashMap, PriorityQueue
- Example:
List<String> list = new ArrayList<>();
19. Java 8+ Features (Brief Overview)
- Lambda Expressions
- Streams API
- Functional Interfaces
- Default and static methods in interfaces
20. Summary Tips:
- Java is case-sensitive.
- Memory Management via Garbage Collector.
- Always close resources like files and scanners.
- Practice with real projects or coding platforms (HackerRank, LeetCode).