An Example of Using Java Operators - Java Language Basics

Java examples for Language Basics:Operator

Description

An Example of Using Java Operators

Demo Code

public class Main {
  public static void main ( String[] args ) {
    int num = 1110;
    double realNum = 25.1115F;
    double veryBigNum = 215.8 / 0.0;  
    double garbage = 0.0 / 0.0; 
    boolean test = true;
    /* ww w  . j  a va2s .c  om*/
    System.out.println ("num = " + num);
    System.out.println ("realNum = " + realNum);
    System.out.println ("veryBigNum = " + veryBigNum);
    System.out.println ("garbage = " + garbage);
    System.out.println ("test = " + test);
    System.out.println ("Maximum int = " + Integer.MAX_VALUE);
    System.out.println ("Maximum double = " + Double.MAX_VALUE);
    System.out.println ("12.5 + 100 = " + (12.5 + 100));
    System.out.println ("12.5 - 100 = " + (12.5 - 100));
    System.out.println ("12.5 * 100 = " + (12.5 * 100));
    System.out.println ("12.5 / 100 = " + (12.5 / 100));
    System.out.println ("12.5 % 100 = " + (12.5 % 100));
    System.out.println ("\"abc\" + \"xyz\" = " + "\"" + ("abc" + "xyz") + "\"");
    
  }
}

Result

List of Relational Operators in Java

Operators Meaning Type UsageResult
== Equal to Binary 3 == 2 false
!= Not equal to Binary 3 != 2 true
> Greater than Binary 3 > 2true
>= Greater than or equal to Binary 3 >= 2 true
< Less thanBinary 3 < 2false
<= Less than or equal toBinary 3 <= 2 false

List of Boolean Logical Operators in Java

Operators Meaning Type UsageResult
! Logical NOT Unary!truefalse
&& Short-circuit AND Binary true && true true
& Logical AND Binary true & true true
|| Short-circuit ORBinary true || falsetrue
| Logical OR Binary true | false true
^ Logical XOR(Exclusive OR ) Binary true ^ true false
&= AND assignment Binary test &= true true
|= OR assignment Binary test |= true true
^= XOR assignment Binary test ^= true false

Related Tutorials