Java Operators and Data Types –
Definitions and Examples
1. Java Operators – With Definitions
Operator Type Operator Definition
Arithmetic + Adds two numbers
- Subtracts the right
operand from the left
operand
* Multiplies two numbers
/ Divides the left operand
by the right operand
% Returns the remainder
after division
Relational == Checks if two values are
equal
!= Checks if two values are
not equal
> Checks if the left value is
greater than the right
< Checks if the left value is
less than the right
>= Checks if the left value is
greater than or equal to
the right
<= Checks if the left value is
less than or equal to the
right
Logical && Returns true if both
conditions are true
|| Returns true if at least
one condition is true
! Reverses the result of a
condition
Assignment = Assigns the right value to
the left variable
+= Adds right operand to left
and assigns the result
-= Subtracts right operand
from left and assigns the
result
*= Multiplies and assigns the
result
/= Divides and assigns the
result
%= Finds remainder and
assigns to the variable
Unary + Unary plus – represents a
positive value
- Unary minus – changes
the sign of the value
++ Increments value by 1
(prefix or postfix)
-- Decrements value by 1
(prefix or postfix)
! Logical NOT – reverses
the Boolean value
Bitwise & Bitwise AND – compares
each bit
| Bitwise OR – compares
each bit
^ Bitwise XOR – returns 1 if
bits are different
~ Bitwise NOT – inverts all
the bits
Ternary ?: Short-hand if-else:
condition ? true : false
Shift << Left shift – shifts bits left
>> Right shift – shifts bits
right with sign
>>> Unsigned right shift –
shifts bits right and fills
with 0
2. Java Data Types – With Definitions and Examples
Primitive Data Types
Data Type Category Definition Example
byte Primitive 8-bit integer, used byte a = 100;
to save memory in
large arrays
short Primitive 16-bit integer, short s = 30000;
larger than byte
int Primitive 32-bit integer, int x = 100000;
default type for
integers
long Primitive 64-bit integer, long l =
used for large 123456789L;
values
float Primitive 32-bit decimal float f = 10.5f;
number with single
precision
double Primitive 64-bit decimal double d = 99.99;
number with
double precision
char Primitive 16-bit Unicode char ch = 'A';
character
boolean Primitive Stores only true or boolean flag =
false true;
Non-Primitive (Reference) Data Types
Data Type Definition Example
String A sequence of characters String name = "Vaibhav";
(object of String class)
Array A collection of elements int[] marks = {90, 80, 85};
of the same type
Class A blueprint for objects class Student { ... }
Object An instance of a class Student s1 = new
Student();
Interface A reference type with interface Animal { void
abstract methods sound(); }