DEV Community

Cover image for #5 Known is a Drop! Operators in Java
Deepikandas
Deepikandas

Posted on

#5 Known is a Drop! Operators in Java

Operators in Java

Operators are special symbols that perform specific operations on one, two, or three operands, and then return a result.

Simple Assignment Operator
=
eg: int id=2;

Arithmetic Operators:
Additive operator + (also used
for String concatenation)
eg: int sum=29+18;
String Concatenation:
System.out.println("java" + 2 + 3);//java23-after string ,everything is string
System.out.println(2+3+"java");//5java-addition operation
Subtraction operator -
eg: int minus=89-35;

Multiplication operator *
eg:int product=78*11;

Division operator - /
eg: float quotient=78/10;

Remainder operator - %
eg: int modulo =56/8

compound assignments
You can also combine the arithmetic operators with the simple assignment operator to create compound assignments.
eg: x+=1; ->which means x=x+1

Unary Operators
'+' Unary plus operator --> positive value (numbers are positive without this, however)

'-' Unary minus operator --> negates an expression

++ Increment operator --> increments a value by 1

-- Decrement operator -->decrements a value by 1

! Logical complement operator - inverts the value of a boolean
example for increment/Decrement :

Equality and Relational Operators

Greater than >
Less than <
Greater than or equal to  >=
Less than or equal to    <=
Enter fullscreen mode Exit fullscreen mode

Conditional Operators
&& Conditional-AND
|| Conditional-OR
?: Ternary (shorthand for
if-then-else statement)

Type Comparison Operator
instanceof Compares an object to
a specified type

Bitwise and Bit Shift Operators
These operators are less commonly used
(&,`,^,~,<<,>>,<<<)

Top comments (0)