Java has a variety of operators that can be used to perform different operations on variables or values. Some of the commonly used operators in online javascript compiler are:

 

Arithmetic operators 

Arithmetic operators are used to perform basic mathematical operations in Java. These operators work on numerical data types such as integer, float, double, and long. The following are the arithmetic operators in Java:

  1. Addition (+): The addition operator is used to add two values or variables. For example, int sum = a + b; will add the values of variables a and b and store the result in the variable sum.
  2. Subtraction (-): The subtraction operator is used to subtract two values or variables. For example, int difference = a - b; will subtract the value of variable b from variable a and store the result in the variable difference.
  3. Multiplication (*): The multiplication operator is used to multiply two values or variables. For example, int product = a * b; will multiply the values of variables a and b and store the result in the variable product.
  4. Division (/): The division operator is used to divide two values or variables. For example, int quotient = a / b; will divide the value of variable a by variable b and store the result in the variable quotient.
  5. Modulus (%): The modulus operator is used to find the remainder of a division operation. For example, int remainder = a % b; will find the remainder when variable a is divided by variable b and store the result in the variable remainder like JavaScript Ternary Operator.

It is important to note that when using arithmetic operators, the data types of the operands should be compatible. For example, if one operand is an integer and the other is a double, the integer operand will be promoted to a double before the operation is performed.

 

Comparison operators

Comparison operators are used to compare two values or variables in Java and return a boolean value (true or false) based on the comparison. The following are the comparison operators in Java:

  1. Equal to (==): The equal to operator is used to check if two values or variables are equal. For example, a == b will return true if variable a is equal to variable b.
  2. Not equal to (!=): The not equal to operator is used to check if two values or variables are not equal. For example, a != b will return true if variable a is not equal to variable b.
  3. Greater than (>): The greater than operator is used to check if one value or variable is greater than another value or variable. For example, a > b will return true if variable a is greater than variable b.
  4. Greater than or equal to (>=): The greater than or equal to operator is used to check if one value or variable is greater than or equal to another value or variable. For example, a >= b will return true if variable a is greater than or equal to variable b.
  5. Less than (<): The less than operator is used to check if one value or variable is less than another value or variable. For example, a < b will return true if variable a is less than variable b.
  6. Less than or equal to (<=): The less than or equal to operator is used to check if one value or variable is less than or equal to another value or variable. For example, a <= b will return true if variable a is less than or equal to variable b.

When using comparison operators, the data types of the operands should be compatible. For example, if one operand is an integer and the other is a double, the integer operand will be promoted to a double before the comparison is performed in online javascript compiler.

 

Logical operators

Logical operators are used to combine two or more boolean expressions in Java and return a boolean value (true or false) based on the logical operation. The following are the logical operators in Java:

  1. AND (&&): The AND operator returns true if both the expressions on the left and the right side of the operator are true. For example, if(a > 0 && a < 10) will return true if variable a is greater than 0 AND less than 10.
  2. OR (||): The OR operator returns true if at least one of the expressions on the left and the right side of the operator is true. For example, if(a > 0 || b > 0) will return true if either variable a is greater than 0 OR variable b is greater than 0.
  3. NOT (!): The NOT operator is a unary operator that returns the opposite of the boolean expression. For example, if(!a > 0) will return true if variable a is NOT greater than 0.

When using logical operators, the operands must be boolean expressions or expressions that can be evaluated as boolean JavaScript Ternary Operator

 

Bitwise operators

Bitwise operators are used to perform operations on individual bits of binary numbers in Java. The following are the bitwise operators in Java:

  1. AND (&): The AND operator compares two bits and returns 1 if both bits are 1. For example, 110 & 101 = 100.
  2. OR (|): The OR operator compares two bits and returns 1 if at least one of the bits is 1. For example, 110 | 101 = 111.
  3. XOR (^): The XOR operator compares two bits and returns 1 if only one of the bits is 1. For example, 110 ^ 101 = 011.
  4. Complement (~): The complement operator is a unary operator that flips all the bits of a number. For example, ~110 = 001.
  5. Left shift (<<): The left shift operator shifts the bits of a number to the left by a specified number of positions. For example, 110 << 2 = 11000.
  6. Right shift (>>): The right shift operator shifts the bits of a number to the right by a specified number of positions. For example, 110 >> 1 = 011.
  7. Unsigned right shift (>>>): The unsigned right shift operator shifts the bits of a number to the right by a specified number of positions, but fills in the new positions with zeros instead of copying the sign bit. For example, -1 >>> 1 = 01111111111111111111111111111111.

When using bitwise operators, the operands must be integers or types that can be promoted to integers, such as char and byte.