Java Operators

Java Operators

Operator is a symbol that says the compiler to perform explicit mathematical or logical manipulations.

Types of Operators

  • Unary Operators
  • Binary Operators
  • Teranary Operators

Unary operators

Unary operations have only one operand.

Example:

!      &        ~          *          ++        —        +          –

Binary operators

The binary operators are operate on two operands. These operators can be arithmetic operators, relational, logical operators, bitwise, assignment operators.

Arithmetic Operators

Example:

+      –       *      /        %

These operators are used in arithmetic expressions.

Example:

Arithmetic Operators

Output:

Arithmetic Output

Relational Operators:

==       !=     >     <     >=       <=

These operators are used in relational operations. The relational operations always give 0 (or False) or 1 (or True).

Example:

Java program in Test.java file and compile and run this program. :

Relational Operator

Output:

Relational Operator Output

Logical Operators

The logical operators supported by Java

||   and  !

Logical operators are used in logical expressions. Such expressions always give 0 (or False) or 1 (or True).

Example:

Logical Operator

Output:

Logical Operator Output

Bitwise Operators

Bitwise operator works on bits.

&         |       ^         ~          <<             >>

The Bitwise operators supported by C++ are listed in the following below table.

Example:

Bitwise Operator

Output:

Bitwise Operator Output

Shorthand operators

We combine the assignment operators with arithmetic operators and bitwise operators. Such operators are called as shorthand operators.

Example:

+    =   -=  * = /=  %=  &=  |=  ^=

Assignment Operator

It is an operator used to assign a value to a variable.

Syntax:

variable = value or expression;
int  a=5;

Special Operators

Some special operators are there in C++.

Example:

sizeof()     comma(,)      dot(.)    pointer(*)

Ternary operators or conditional operators

The ternary operators are those operators that operate on three or more operands. Ternary operator is also called as conditional operator. This operator can be used as an alternative to if-else statement.

Precedence of operators or Hierarchy of operators

If an expression contains multiple operators, the order in which operations are to be carried out is called hierarchy.

Example:

x = 3 + 1 * 5;

Here x is assigned 08, not 20 because operator * has higher precedence than +. First multiply 1 and 5 and then adds into 3 and assign it to the variable x.

InstanceOf Operator

The instanceOf operator is wriiten as:

( Object reference variable )    instanceOf         (class/interface type)

Precedence of Java Operators:

CategoryOperatorAssociativity
Postfix() [] . (dot operator)Left to right
Unary++ – – ! ~Right to left
Multiplicative* / %Left to right
Additive+ –Left to right
Shift>> >>> <<Left to right
Relational> >= < <=Left to right
Equality== !=Left to right
Bitwise AND&Left to right

Besant Technologies – Chennai & Bangalore Branch Locations

Besant Technologies - Velachery Branch
Plot No. 119, No.8, 11th Main road, Vijaya nagar,
Velachery, Chennai - 600 042
Tamil Nadu, India
Landmark - Reliance Digital Opposite Street
+91-996 252 8294 / 996 252 8293

Besant Technologies - Tambaram Branch
No.2A, 1st Floor, Duraisami Reddy Street,
West Tambaram, Chennai - 600 045
Tamil Nadu, India
Landmark - Near By Passport Seva
+91-970 725 0260

Besant Technologies - OMR Branch
No. 5/318, 2nd Floor, Sri Sowdeswari Nagar,
OMR, Okkiyam Thoraipakkam, Chennai - 600 097
Tamil Nadu, India
Landmark - Behind Okkiyampet Bus Stop,
+91-887 038 4333

Besant Technologies - Porur Branch
No. 180/84, 1st Floor, Karnataka Bank Building
Trunk Road, Porur,
Chennai - 600 116
Tamilnadu, India
Land Mark: Opposite to Gopalakrishna Theatre
+91-755 022 6990

Besant Technologies - Anna Nagar Branch
Plot No:1371, 28th street kambar colony,
I Block, Anna Nagar ,
Chennai - 600 040
Tamil Nadu, India
Landmark - Behind Reliance Fresh
+91-938 404 0493

Besant Technologies - T.Nagar Branch
Old No:146/2- New No: 48,
Habibullah Road,T.Nagar,
Chennai - 600 017
Tamil Nadu, India
Landmark - Opposite to SGS Sabha
+91-984 025 8377

Besant Technologies - Thiruvanmiyur Branch
22/67, 1st Floor,
North mada street, Kamaraj Nagar
Thiruvanmiyur, Chennai 600041
Tamil Nadu, India
Landmark - Above Thiruvanmiyur ICICI Bank
+91-938 404 0493

Besant Technologies - Siruseri Branch
No. 4/76, Ambedkar Street,
OMR Road, Egatoor, Navallur,
Siruseri, Chennai 600130
Tamil Nadu, India
Landmark - Near Navallur Toll Gate, Next to Yamaha Showroom
+91-7338 810 550

Besant Technologies - Maraimalai Nagar Branch
No.37, Ground Floor,
Thiruvalluvar Salai,
Maraimalai Nagar,Chennai 603209
Tamil Nadu, India
Landmark - Near to Maraimalai Nagar Arch
+91-979 123 7373

Besant Technologies - BTM Layout Branch
No 2, Ground floor,
29th Main Road, Kuvempu Nagar,BTM Layout 2nd Coming from Silkboard, take left at AXA company signal,
Stage, Bangalore - 560 076
Karnataka, India
Landmark - Next to OI Play School
+91-762 494 1772 / 74

Besant Technologies - Marathahalli Branch
No. 43/2, 2nd Floor, VMR Arcade,
Varthur Main Road, Silver Springs Layout,
Munnekollal, Marathahalli, Bengaluru - 560037
Karnataka, India
Landmark - Near Kundalahalli Gate Signal
+91-910 812 6341

Besant Technologies - Rajaji Nagar Branch
No. 309/43, JRS Ecstasy, First Floor,
59th Cross, 3rd Block, Bashyam Circle,
Rajaji Nagar, Bangalore - 560 010
Karnataka, India
Landmark - Near Bashyam Circle
+91- 734 916 0004

Besant Technologies - Jaya Nagar Branch
No. 2nd Floor,1575,11th Main Road,
4th T-Block, Pattabhirama Nagar, Jaya Nagar,
Bangalore-560041
karnataka, India
Land Mark: Opposite to Shanthi Nursing Home
+91-733 783 7626

Besant Technologies - Kalyan Nagar Branch
No.513, 4th Cross Rd
2nd Block, HRBR Layout, Kalyan Nagar,
Bangalore-560043
karnataka, India
Land Mark: Opposite to kalayan nagar Axis Bank
+91-938 404 0495

Besant Technologies - Electronic City Branch
No. 7, 3rd Floor, Ganga Enclave,
Neeladri Road, Karuna Nagar, Doddathoguru Village,
Electronics City Phase 1, Electronic City,
Bangalore - 560100, karnataka, India
Land Mark: Adjacent to HDFC Bank and State Bank Of India
+91-782 392 2180

Besant Technologies - Indira Nagar Branch
No.54, 1st Floor,
5th Main kodihalli,
Bengaluru, Karnataka 560008, India
Landmark: Behind Leela Palace Hotel,
+91-910 812 6339

Besant Technologies - HSR Layout Branch
Plot No. 2799 & 2800, 27th Main,
1st Sector, HSR Layout,
Bengaluru, Karnataka 560102, India
+91-733 783 7626

Besant Technologies - Hebbal Branch
No.29, 2nd Floor, SN Complex,
14th Main Road, E-Block Extention, Sahakara Nagar,
Bengaluru, Karnataka -560092, India
+91-938 404 0496