1. An operator is a command that interprets given values or variables and produces a
result. They are used to perform calculations on given data.
Operator What It Does
• (+) addition
• (-) subtraction
• (*) multiplication
• (/) division
• (%) modulus (returns the remainder of a division)
Each of these is a binary operator; that is, they combine two operands to produce a
result—2 + 3 for example will result in 5. An operand is just the term for a value to
which an operator is applied.
Java's logical operators are split into two subtypes, relational and conditional.
Relational Operators
Conditional symbols and their meanings
Symbol Condition
== is equal to
!= is not equal to
> is greater than
< is less than
>= is greater than or equal to
<= is less than or equal to
Relational operators are used primarily in if statements, while loops, and on occasion for
loops.
Conditional Operators
Conditional symbols and their meanings
Symbol Condition
&& AND
|| OR
! NOT
2. AND is when you need everything to be true
OR is when you need only one thing to be true
Summary:
• Operators serve to bring values and/or variables together and yield new results.
• Arithmetic operators are used for basic math calculations, as well as
incrementing and decrementing numeric variables.
• Logical operators evaluate comparisons against AND, OR, and NOT conditions
to determine whether a series of conditions are true or false.
• Remember Java always executes code inside parenthesis first!
Sample:
package conditionaloperator;
/**
*
* @author Paul
*/
public class ConditionalOperator {
public static void main( String[] args ) {
String status = "";
int grade = 85;
//get status of the student
status = (grade >= 60)?"Passed":"Fail";
//print status
System.out.println( status );
}
}