Java Reviewer (Markor)
Java Reviewer (Markor)
1. Strings in Java
Definition: Strings are objects of the String class in Java, used to store text. Strings are immutable (cannot be changed once created).
Creating Strings
Useful Methods
System.out.println(s1.length()); // Output: 7
2. Loops in Java
a. While Loop
Syntax:
while (condition) {
// Code block
}
Example:
int i = 0;
while (i < 5) {
System.out.println(i);
i++;
}
b. Do-While Loop
Syntax:
do {
// Code block
} while (condition);
Example:
int i = 0;
do {
System.out.println(i);
i++;
} while (i < 5);
c. For Loop
Syntax:
Example:
d. For-Each Loop
Syntax:
Example:
3. Arrays
Definition: Arrays are fixed-size, ordered collections of the same data type.
Syntax:
Ragged Arrays
Common Operations
1. Access:
System.out.println(numbers[0]);
2. Length:
System.out.println(numbers.length);
Multi-Dimensional Arrays
Syntax:
int[][] matrix = new int[3][3];
Accessing Elements:
System.out.println(matrix[0][1]);
4. Methods
Syntax:
returnType methodName(parameters) {
// Code block
}
Main Method
Common Methods
System.out.println("Programming".indexOf("gram")); // Output: 3
System.out.println("Java".charAt(1)); // Output: a
5. Key Terms