Oop Reviewer
Oop Reviewer
Identifiers
• Identifier: The name assigned to a variable for reading and writing.
Rules of Identifiers
• No special characters except underscore
• No whitespaces
• Cannot use numbers alone
• Can use numbers alongside letters
Declaring Variables
Without value:
datatype identifier;
Example: int num;
With value:
datatype identifier = value;
Example: int num = 5;
Arithmetic Operators
Symbol | Operation | Result
+ | Addition | Sum
- | Subtraction | Difference
* | Multiplication | Product
/ | Division | Quotient
% | Modulus | Remainder
++ | Increment | Add 1
-- | Decrement | Subtract 1
Relational Operators
Symbol | Label | Syntax
== | Equals | x == y
!= | Not Equals | x != y
< | Less Than | x < y
<= | Less Than or Equal | x <= y
> | Greater Than | x > y
>= | Greater Than or Equal | x >= y
Logical Operators
Symbol | Label | Description
&& | AND | Both conditions must be true
|| | OR | Either condition must be true
! | NOT | Inverts the current condition
Control Flows
Control flows manage the execution of code in programs. Java provides several structures to
make decisions, repeat tasks, and control program flow.
Loops
1. For loop - Repeats a code block a specified number of times
2. While loop - Repeats a code block while condition is true
3. Do-while loop - Executes at least once before checking condition
Branching Statements
• break - Exits loop or switch early
• continue - Skips current loop iteration
• return - Exits a method, optionally returning a value
Functions or Methods
Methods are code blocks that perform specific actions when called, organizing and sorting
code within a class.
Creating Methods
modifiers returnType methodName(){
//code
}
Calling Methods
public static void main(String[] args){
methodName();
}
Introduction to OOP
Java Constructors
• Constructors are special methods for initializing objects, called upon object creation to set
initial values for attributes.
Java Packages
• Definition: Used to group related classes and avoid name conflicts.
• Types:
- Built-in Packages: Java API, included in the Java Development Environment.
- User-defined Packages: Created by developers to organize classes and improve
maintainability.
Importing Packages