Primitive Data Types
Intrinsic data type that directly stores the value in memory
Examples: int, byte, short, long, float, double, char, boolean
Non-primitive Data Types
Reference data type that stores the memory address of an object
Examples: String, Array, objects of user-defined classes
Custom-defined Data Types
Data types that are created by users to store specific types of data
Defined as class or interface
class MyClass {
// class definition
}
interface MyInterface {
// interface definition
}
Operators and Type Casting
Operators
Arithmetic: +, -, *, /, %, ++, --
Relational: <, >, <=, >=, ==, !=
Logical: &&, ||, !
Assignment: =, +=, -=, *=, /=, %=
Bitwise: &, |, ^, ~, <<, >>
Ternary: (expression) ? value\_if\_true : value\_if\_false
Type Casting
Implicit Casting: Automatically done by Java when smaller data type is assigned to
a larger data type
Explicit Casting: Manually done by Java programmer using a cast operator
(targetType)
User Input and Scanner Class
Scanner Class
Built-in Java class to get user input
Located in java.util package
Uses import java.util.Scanner; to access
Example code snippet:
Scanner myObj = new Scanner(System.in); // Create a Scanner object
int userInput = myObj.nextInt(); // Read user input
Conditionals and Decision Making
Conditional Statements
If-else: Executes block of statements if provided condition is true, else executes
else block
Switch-case: Executes block of statements based on the value of an expression
Note: Loops, loops with breaks and continues, loops within loops, nested loops will
not be covered here
Arrays and Multidimensional Arrays
Arrays
Collection of elements of the same data type
Defined using dataType[] arrayName; or dataType arrayName[];
Declaration and initialization example:
int[] myIntArray = {1, 2, 3, 4, 5};
int myIntArray[];
myIntArray = new int[5]; // initializing the array with 5 elements
Multidimensional Arrays
Array of arrays
Defined as: dataType[][] arrayName;
Declaration, initialization, and assigning values example:
int[][] myIntArray = new int[2][3];