Day 1
Day 1
o Includes components like the class loader, memory management, and garbage
collector.
o A subset of the JDK that includes the JVM and standard libraries.
o A superset of JRE that includes tools for development like the compiler (javac),
debugger, and libraries.
System.out.println("Hello, JVM!");
o Rules:
Local variables
Instance variables
Static variables
Example:
boolean (true/false)
Example:
double pi = 3.14159;
Example:
double pi = 3.14;
Example:
Conditional Statements: Use if, else if, and else for decision-making.
Example:
// if-else
System.out.println("Underage");
} else {
System.out.println("Adult");
// Switch-case
int day = 3;
switch (day) {
}
}
7. Iteration Statements
Example:
// While loop
int count = 1;
count++;
// Do-while loop
do {
num--;
// For loop
Example:
// For loop
// For-each loop
// Break example
if (i == 3) break;
// Continue example
if (i == 3) continue;
// Return example
Summary Table
JVM runs bytecode, JRE includes JVM, JDK includes JRE and
JVM, JRE, JDK
development tools.
Identifiers, Variables, Identifiers name elements, variables store data, literals are constant values.
Topic Key Points
Literals
Primitive Data Types Eight types: byte, short, int, long, float, double, char, boolean.
For and For-Each Loop for for known iterations, for-each for collections/arrays.
Jump, Break, Continue break exits loops, continue skips an iteration, return exits methods.
Arrays
An array in Java is a collection of elements of the same data type stored in contiguous memory
locations. Arrays are useful for storing and manipulating a fixed-size sequential collection of data.
Key Features:
Fixed size: The size of an array is defined when it is created and cannot be changed.
Syntax:
Example:
2. Types of Arrays
a. One-Dimensional Array
Example:
int[] numbers = {10, 20, 30, 40, 50}; // Declaration and initialization
b. Two-Dimensional Array
A table-like structure where elements are accessed using two indices.
Example:
int[][] matrix = {
{1, 2, 3},
{4, 5, 6},
{7, 8, 9}
};
System.out.println();
c. Multi-Dimensional Array
Example:
int[][][] cube = {
};
// Access elements
a. Declaration
b. Memory Allocation
c. Initialization
int[] numbers = {10, 20, 30, 40, 50}; // Combined declaration and initialization
d. Accessing Elements
4. Array Properties
Length Property:
o Example:
Default Values:
o boolean: false
b. Copying Arrays
c. Sorting Arrays
import java.util.Arrays;
Arrays.sort(arr);
You can pass arrays to methods and return arrays from methods.
Example:
System.out.println();
}
static int[] doubleArray(int[] arr) {
doubled[i] = arr[i] * 2;
return doubled;
printArray(numbers);
printArray(doubled);
8. Array of Objects
Example:
class Student {
String name;
int age;
this.name = name;
this.age = age;
}
}
Student[] students = {
};
9. Limitations of Arrays
2. No methods for common operations like insertion or deletion (use collections like ArrayList
for dynamic arrays).
Concept Description