Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 3

OPERATORS In java

-----------------

Arithematic operators [+,-,*, /, %]: These are used for performing arithematic
operations.
--------------------------------------

1)/--->Quotient

2)%--->Reminder

Relational operators [<,>,<=,>=,==,=,!=]: These are used for comparing the values.
---------------------------------------

Logical operators [&&(AND),||(OR)]: a=5, b=3, c=6--->if(a>c && a>b)--->false&&--


>false
-----------------------------------

These are used for checking multiple conditions at a time.

These are applicable for boolean but not for integral values. if(5&&3)--
>CompileError

Bitwise operators[&(AND),|(OR)]:
-------------------------------

These are used for checking multiple conditions at a time.

These are applicable for both boolean,integral values.

5&3

5->0101
3->0011
--------
0001 -->1

Unary operators[++,--]:
-----------------------

These are used for increment or decrement single value.

Ternary operator[?:]: It is simplified version of if and else.


---------------------
-----------------------------------------------------------------------------------
----------------------------------------

conditional statements
----------------------
if statement is used to test the condition.
-------------------------------------------
It checks boolean condition: true or false.
-------------------------------------------
There are various types of if statement in Java
------------------------------------------------

simple if
---------
if(condition)
{

code to be executed
}

if-else
-------
if-else statement also tests the condition. It executes the if block if condition
is true otherwise else block is executed

if(condition)
{
code
}
else
{
code
}

if-else-if
-----------
if-else-if statement executes one condition from multiple statements

if(condition1)
{

else if(condition2)
{

}
else if(condition3)
{

else
{

}
switch case : switch statement executes one statement from multiple conditions.
------------

There can be one or n number of case values for a switch expression.

The case value must be of switch expression type only.

The case value must be literal or constant. It doesn't allow variables.

The case values must be unique. In case of duplicate value, it renders compile-time
error.

switch(expression){
case value1:

code

case value2:

code

default:

code to be executed if any case not matched;


}

-----------------------------------------------------------------------------------
-------------------------------------------------------------------

You might also like