Java Notes
Java Notes
## **Table of Contents**
1. [Introduction to Java](#1-introduction-to-java)
2. [Java Syntax & Structure](#2-java-syntax--structure)
3. [Data Types & Variables](#3-data-types--variables)
4. [Operators](#4-operators)
5. [Control Flow Statements](#5-control-flow-statements)
6. [Methods (Functions)](#6-methods-functions)
7. [Arrays](#7-arrays)
8. [Object-Oriented Programming (OOP)](#8-object-oriented-programming-oop)
9. [Exception Handling](#9-exception-handling)
10. [File Handling](#10-file-handling)
11. [Collections Framework](#11-collections-framework)
12. [Multithreading](#12-multithreading)
---
---
---
## **4. Operators**
| Category | Operators |
|----------|-----------|
| Arithmetic | `+`, `-`, `*`, `/`, `%`, `++`, `--` |
| Relational | `==`, `!=`, `>`, `<`, `>=`, `<=` |
| Logical | `&&`, `||`, `!` |
| Assignment | `=`, `+=`, `-=`, `*=`, `/=`, `%=` |
| Bitwise | `&`, `|`, `^`, `~`, `<<`, `>>`, `>>>` |
---
// While Loop
while (i < 5) {
System.out.println(i);
i++;
}
// Do-While Loop
do {
System.out.println(i);
i++;
} while (i < 5);
```
---
---
## **7. Arrays**
### **1D Array**
```java
int[] numbers = {1, 2, 3, 4, 5};
for (int num : numbers) {
System.out.println(num);
}
```
### **2D Array**
```java
int[][] matrix = {{1, 2}, {3, 4}};
System.out.println(matrix[0][1]); // Output: 2
```
---
---
---
// Writing to a file
FileWriter writer = new FileWriter("file.txt");
writer.write("Hello Java!");
writer.close();
---
## **12. Multithreading**
### **Thread Creation (Extending Thread Class)**
```java
class MyThread extends Thread {
public void run() {
System.out.println("Thread is running");
}
}