Skip to main content

Operators in Java

MY PROGRAMMING PARADISE


Operators in java:

Operators are the symbols that tell the computer to execute certain mathematical or logical operations. A mathematical or logical expression is generally formed with the help of an operator.

There are many types of operators in java which are given below:

1. Arithmetic operator

2. Increment and Decrement operator

3. Assignment Operator

4. Relational Operator

5. Logical Operator

6. Bitwise Operator

7. Ternary Operator

 

Assume variable A holds 20 and variable B holds 30 then:

 

Operator type

Operator

Description

Example

Arithmetic operator

 

+

Adds two operands

A+B= 50

-

Subtracts second operand from the first

A-B=- 10

*

Multiply both operands

A*B= 600

/

Divide numerator by denominator

B/A= 3

%

Modulus Operator and remainder of after an integer division

B%A= 10

Unary or Increment and Decrement operator

++

Increment operator, increases integer value by one

A++ will give 21

--

Decrement operator, decreases integer value by one

A-- will give 19

Assignment Operator

 

=

Simple assignment operator, Assigns values from right

side operands to left side operand

C = A + B will assign value of

A + B into C

+=

Add AND assignment operator, It adds right operand to

the left operand and assign the result to left operand

C += A is equivalent to

C = C + A

-=

Subtract AND assignment operator, It subtracts right

operand from the left operand and assign the result to

left operand

C -= A is equivalent to

C = C - A

*=

Multiply AND assignment operator, It multiplies right

operand with the left operand and assign the result to left operand

C *= A is equivalent to

C = C * A

/=

Divide AND assignment operator, It divides left operand

with the right operand and assign the result to left

operand

C /= A is equivalent to

C = C / A

%=

Modulus AND assignment operator, It takes modulus

using two operands and assign the result to left operand

C %= A is equivalent to C = C % A

Relational Operator

 

>

Checks if the value of left operand is greater than the value of

Right operand, if yes then condition becomes true.

(A > B) is not true.

<

Checks if the value of left operand is less than the value of right

Operand, if yes then condition becomes true.

(A < B) is true.

>=

Checks if the value of left operand is greater than or equal to the

Value of right operand, if yes then condition becomes true.

(A >= B) is not

true.

<=

Checks if the value of left operand is less than or equal to the

Value of right operand, if yes then condition becomes true.

(A <= B) is true.

==

Checks if the value of two operands is equal or not, if yes then

Condition becomes true.

(A == B) is not

true.

!=

Checks if the value of two operands is equal or not, if values are

not equal then condition becomes true

(A != B) is true.

 

Operator type

Operator

Description

Example

Logical Operator

&&

 Returns true when both conditions are true.

 

 


||

 Returns true if at least one condition is true.

Bitwise Operator

&

 It returns 1 if and only if both bits are 1, else returns 0.

^

It returns 0 if both bits are the same, else returns 1.

|

It returns 1 if either of the bit is 1, else returns 0.

Ternary Operator

?:

Conditional Expression

 


Video Link:) Click here

Comments

Popular posts from this blog

Data Types In SQL

  Data Types In SQL W hat is Data Type? A data type as the name suggests it is the type or category to which the data belongs to. A data type specifies a particular type of data, such as integer, floating-point, Boolean, etc. In SQL, the data type defines the type of data to be stored in each column of a table. SQL data types can be broadly divided into three categories 1.       Numeric Data Types 2.       String Data Types 3.       Data & Time Data Types Numeric Data Types String Data Types Data&Time DataTypes BIT CHAR(SIZE) DATE TINYINT VARCHAR(SIZE) TIME SMALLINT TEXT(SIZE) DATETIME MEDIUMINT TINYTEXT(SIZE) TIMESTAMP INT MEDIUMTEXT(SIZE) YEAR BIGINT LONGTEXT   ...

Switch Statement In Java

Switch Statement:  The switch statement is just like if-else-if ladder statement. It executes one statement from multiple conditions. It works with a byte, short, int, long, and String. In other words, we can say the Switch case statement is a substitute for a long if statement that compares to several integral values. Syntax of Switch statement in java Enhance Switch or Switch With Arrow: The new syntax uses the -> operator instead of the colon we're used to with switch statements. Also, there's no break keyword. Another addition is the fact that we can now have comma-delimited criteria. Syntax of Enhance Switch in java  

Conditional Statements In Java

  Conditionals Statement   A conditional statement  is a set of rules performed if a certain condition is met. A conditional statement begins with the keyword if followed by parentheses. The result of the evaluation is true or false. ·       ‘ if ‘ statement ·       ‘ if-else ‘ statement ·         Nested ‘ if ‘ statement ·       ‘ if-else - if ‘ statement IF statement: ‘IF’ statement is the most basic and simple statement among all the statements. For example- if a value is less than 0, return “Negative value”. Let’s see an example- IF-ELSE statement: The if-else is statement is an extended version of If. Let’s see an example- Nested IF-ELSE statement : In Java, when there is an if statement inside another if statement then it is known as nested if-else. Let’s see an example- IF-ELSE-IF: ‘ if-else-if ’ statement is used when we need to check mul...