Java Learning Notes
Java Learning Notes
Java Learning Notes
1. Basics of Programming
- Syntax: Java programs start with a class definition and contain a main method to run the code.
Example:
```java
System.out.println("Hello, World!");
```
Example:
```java
```
- Data Types: Java has primitive data types like int, float, char, etc., and reference types like String.
- Comments: Use `//` for single-line comments, and `/* ... */` for multi-line comments.
Example:
```java
import java.util.Scanner;
```
3. Operators
Example:
```java
int a = 5, b = 3;
```
4. Conditional Statements
Example:
```java
} else {
```
5. Looping Structures
Example:
```java
System.out.println("Hello, World!");
```
Example:
```java
int i = 0;
while (i < 5) {
System.out.println("Hello, World!");
i++;
```
- Defining Functions: Functions in Java are created with `public`, `static`, and `void` keywords (in simple cases).
Example:
```java
System.out.println("Hello, World!");
```
- Calling Functions:
Example:
```java
greet();
```
7. Data Structures
Example:
```java
System.out.println(numbers[0]);
```
Example:
```java
import java.util.ArrayList;
list.add("Hello");
System.out.println(list.get(0));
```