Java examples for Language Basics:Operator
An Example of Using Java Operators
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") + "\""); } }
List of Relational Operators in Java
Operators | Meaning | Type | Usage | Result |
---|---|---|---|---|
== | Equal to | Binary | 3 == 2 | false |
!= | Not equal to | Binary | 3 != 2 | true |
> | Greater than | Binary | 3 > 2 | true |
>= | Greater than or equal to | Binary | 3 >= 2 | true |
< | Less than | Binary | 3 < 2 | false |
<= | Less than or equal to | Binary | 3 <= 2 | false |
List of Boolean Logical Operators in Java
Operators | Meaning | Type | Usage | Result |
---|---|---|---|---|
! | Logical NOT | Unary | !true | false |
&& | Short-circuit AND | Binary | true && true | true |
& | Logical AND | Binary | true & true | true |
|| | Short-circuit OR | Binary | true || false | true |
| | 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 |