Friday, March 1, 2024

OPERATORS IN JAVA

Operators  in Java

  • TYPES OF OPERATORS
  • JAVA OPERATOR AND ITS PRECEDENCE 

There are many types of operators in Java such as: -

  • Unary Operator,
  • Arithmetic Operator,
  • Shift Operator,
  • Relational Operator,
  • Bitwise Operator,
  • Logical Operator,
  • Ternary Operator and
  • Assignment Operator.

 Java operator and its precedence 

Java unary operator

Unary means single or one therefore unary operators in Java require only one operand. With the help of Unary operators, we can perform various operations.

  • incrementing/decrementing a value by one
  • negating an expression
  • inverting the value of a Boolean

let us better understand this by a program



Java arithmetic operator

It consists of basic 4 calculations add, subtract, multiply, divide: -

Let us understand this through a program

 

Java left shift operator

To move all the bits of a value to the left by a defined number of times, the Java left shift operator << is used.










Right shift operator

In Java, you may use the left shift operator >> to shift all of a value's bits to the left by a specified amount.


Java Shift Operator Example:







 






Java AND operator example

Logical AND & bitwise AND

The logical provider won't check the second condition if the first condition is false. The second requirement is only verified if the first condition is met. The bitwise operator always assesses both conditions to decide if the first condition is true or not.

Let us try with an example: -









 




Java (OR) operator example

Logical (or) and bitwise (or)

The logical || operator does not examine the second condition when the first condition is met. We will only consider the second condition if the first proves to be false.

The bitwise | operator continuously verifies both conditions to see if the first condition is true.














Java ternary operator

 The Java Ternary operator is frequently used in Java programming to replace if-then-else statements with single lines of code. It is distinct from all other conditional operators in that it needs three operands.

Let us try it with an example 













Another Example:







 





Java assignment operator

One of the most used operators is the one for installing Java. Its goal is to change the operand from left to right.

 

Let us try with some examples:
















For adding sort




No comments:

Post a Comment

Featured Post

ASSOCIATION RULE IN MACHINE LEARNING/PYTHON/ARTIFICIAL INTELLIGENCE

Association rule   Rule Evaluation Metrics Applications of Association Rule Learning Advantages of Association Rule Mining Disadvantages of ...

Popular