Understanding
Java
Language
Lesson Overview:
Understanding Java Class, Method,
Modifiers, Datatypes, Basic
Operators, Comparison Operators,
Logical Operators, If Statement.
Java Class & Method
Class − A class can be defined as a
template/blueprint that describes the
behavior/state that the object of its type supports.
Methods − A method is basically a behavior. A
class can contain many methods. It is in methods
where the logics are written, data is manipulated
and all the actions are executed.
Java Modifier
Public - The code is accessible for all
classes.
Private - The code is only accessible within
the declared class.
Protected - The code is accessible in the
same package and subclasses.
Java Datatypes/Variable
Types
String - Stores text, such as "Hello". String values are
surrounded by double quotes.
Int - stores integers (whole numbers), without
decimals.
Float - stores numbers, with decimals.
Char - stores single characters, such as 'a' or 'B'. Char
values are surrounded by single quotes.
Boolean - stores values with two states: true or false.
Java Basic Operators
+ (Addition) - Adds values on either side of the operator.
- (Subtraction) - Subtracts right-hand operand from left-
hand operand.
*(Multiplication) - Multiplies values on either side of the
operator.
/ (Division) - Divides left-hand operand by right-hand
operand.
% (Modulus) - Divides left-hand operand by right-hand
operand and returns remainder.
++ (Increment) - Increases the value of operand by 1.
-- (Decrement) - Decreases the value of operand by 1.
Java Comparison Operators
Equal to ( == )
Not equal ( != )
Greater than ( > )
Less than ( < )
Greater than or equal to ( >= )
Less than or equal to ( <= )
Java Logical Operators
Logical and ( && )
Logical or ( || )
Logical not ( ! )
Java If Statement
if (condition) {
}
-----------------------------------------------
if (condition) {
// block of code to be executed if the condition is true
} else {
// block of code to be executed if the condition is false
}
-----------------------------------------------
if (condition1) {
// block of code to be executed if condition1 is true
} else if (condition2) {
// block of code to be executed if the condition1 is false and condition2 is true
} else {
// block of code to be executed if the condition1 is false and condition2 is false
}