Java Cheat Sheet Expanded
Java Cheat Sheet Expanded
1. Basic Syntax
2. Data Types
3. Operators
+ Addition
- Subtraction
* Multiplication
/ Division
% Modulus
== Equal to
!= Not equal to
>= Greater than or equal to
<= Less than or equal to
4. Control Statements
if (condition) {
// code block
} else {
// another code block
}
Java Cheat Sheet
switch(expression) {
case value1:
// code
break;
default:
// code
}
5. Loops
while (condition) {
// loop body
}
6. Functions
class Animal {
String name;
void makeSound() {
System.out.println("Sound");
}
}
}
}
8. Exception Handling
try {
int x = 10 / 0;
} catch (ArithmeticException e) {
System.out.println("Error: " + e.getMessage());
}
9. File Handling
import java.io.*;
try {
FileWriter writer = new FileWriter("file.txt");
writer.write("Hello, Java");
writer.close();
} catch (IOException e) {
System.out.println("An error occurred.");
}