Java Notes
while loops: are entry-controlled loops that repeatedly execute a block of code as long as a specified boolean condition evaluates to true. The condition is checked before each iteration, meaning the loop body may not execute at all if the initial condition is false.
Boolean: is a primitive data type that can hold only one of two values: true or false. It is primarily used to represent logical conditions and control the flow of programs in statements like if, while, and for loops.
Core OOP and Structure Keywords class and interface: The fundamental building blocks for defining objects and contracts.
Extends and implements: Used for inheritance and implementing interface methods.
This and super: Refer to the current object and its immediate superclass, respectively.
new: Creates instances of classes. enum: Defines a fixed set of constants.
Access and Modifier Keywords public, private, protected: Control the visibility of classes, methods, and variables.
static: Associates members with the class rather than specific instances.
final: Prevents inheritance, overriding, or reassignment
abstract: Indicates that a class or method must be implemented by a subclass.
Conditional Statements (if, else,if,else)
if, else, switch, case, default: Manage conditional execution.
for, while, do: Handle looping structures.
try, catch, finally, throw, throws: Manage runtime errors and exceptions.
Data Types and Modern Features
int, boolean, double, char, void: Primitive types and method return types. instanceof: Checks if an object is an instance of a specific class.
var: Allows local variable type inference.
record: Declares an immutable data class .
sealed and permits: Restricts which classes can extend a class.
Section 2: Variables & Data Types
Section 3: Operators
Section 4: Strings
Section 5: Conditional Statements (if, else if, else)
Quiz 1
The char data type in Java can be used to store a negative number.
A double variable in Java, when declared but not initialized, automatically takes the value of 0.0.
In Java, the default value for an int variable, when not explicitly initialized, is 0.
Quiz 2
Which operator is used to find the remainder in Java?
What will be the result of the following Java code?
System.out.println(5 * 2.0);
When performing division between an int and a double, what is the type of the result?
System.out.println(5 / 2.0);
What is the output of the following Java statement?
System.out.println(5 + 5);
Quiz 3
What you know
What does the following Java line output?
System.out.println( '5' == 5 );
What is the result of comparing an integer with a double in Java?
System.out.println( 5 == 5.0 );
What is the output of the following Java statement?
System.out.println( 5 != 4 );
What is the output of the following Java statement?
System.out.println( 5 == 5 );
Quiz 4
What you know
Evaluate the output for the negation of a true condition:
System.out.println( !(5 == 5) );
What does the following Java line output?
System.out.println( 5 < 4 || 4 > 5 );
What is the result of this logical operation?
System.out.println( 5 5 || 4 4 );
What is the output of the following Java statement?
System.out.println( 5 == 5 && 4 > 5 );
What is the output of the following Java statement?
System.out.println( 5 5 && 4 4 );
Quiz 5
What will the following Java line output?
System.out.println( "Hello World!".startsWith("He") );
What is the result of the following Java expression?
"Hello World!".substring(3, 8)
What does the following Java code output?
System.out.println( "Hello World!".charAt(6) );
What is the output of the following Java statement?
System.out.println( "Hello World!".length() );
Operators: are special symbols used to perform operations on variables and values,
While loops: are control structures that repeat a block of code as long as a specified boolean condition remains true. They are primarily used when the number of iterations is unknown beforehand, such as when waiting for specific user input or processing data until a certain state is reached
The loop operates by testing the condition before executing the body (an "entry-controlled" loop). If the condition is initially false, the loop body never executes. The standard structure involves three key steps to ensure the loop terminates: Initialization: Set a tracker variable to an initial value outside the loop. Condition: Define the boolean expression that determines if the loop should continue. Update: Modify the tracker variable inside the loop body to eventually make the condition false.