![]() |
| Java Language Operators with Examples Complete Guide |
Operators in Java Programming Language
Java Language Operators Definition: Java language operators is a fundamental components of Java programming that allow programmer to perform operations on variables and values. Operators can be used to perform arithmetic calculations, compare values, assign data, logical conditions. Understanding Java language operators with beginners as well as experienced programmers, because operators are used in almost every programming languages. In this complete guide you will learn all types of Java operators including arithmetic, relational, logical, assignment, ternary, bitwise, conditional, and special operators, explained simple examples.
Types of Operators in Java
- Arithmetic Operators in Java
- Relational Operators in Java
- Logical Operators in Java
- Assignment Operators in Java
- Bitwise Operators in Java
- Increment Operators in Java
- Decrement Operators in Java
- Conditional Operators in Java
- Special Operator in Java
Java Arithmetic Operators
Types of Arithmetic Operators in Java
| Symbols | Operation | Example |
|---|---|---|
| (+) | Addition | (a+b)=> (5+6)=>9 |
| (-) | Subtraction | (a-b)=> (8-3)=>5 |
| (*) | Multiplication | (a*b)=> (5*6)=>30 |
| (/) | Division | (a/b)=> (5/2)=>2.5 |
| (%) | Modulus | (a%b)=> (5%2)=>1 |
Arithmetic Operators in Java Program
public static void main(String[] args) { int x,y; Scanner s=new Scanner(System.in); System.out.print("Enter First Number:"); x=s.nextInt(); System.out.print("Enter Second Number:"); y=s.nextInt(); System.out.println("Addition of x+y:"+(x+y)); System.out.println("Substraction of x-y:"+(x-y)); System.out.println("Multiplication of x*y:"+(x*y)); System.out.println("Division of x/y:"+(x/y)); System.out.println("Modulus of x%y:"+(x%y)); } } ============OUTPUT============ Enter First Number: 6 Enter Second Number: 3 Addition of x+y:9 Substraction of x-y:3 Multiplication of x*y:18 Division of x/y:2 Modulus of x%y:0 |
Relational Operators in Java Language
Relational Operator: A relational operators can be used to performed operation two values compression and results provide true and false. Relational operators compare two variables expression and check relationship than provide results.
Types of Relational Operators
| Symbols | Operation | Example |
|---|---|---|
| (==) | Equal To | (a==b) |
| (>) | Greater Than | (a>b) |
| (<) | Less Than | (a<b) |
| (>=) | Greater Than Or Equal To | (a>=b) |
| (<=) | Less Than Or Equal To | (a<=b) |
| (!=) | Not Equal To | (a!=b) |
Relational Operators Program in Java
public static void main(String[] args) { int x,y; Scanner s=new Scanner(System.in); System.out.print("Enter First Number:"); x=s.nextInt(); System.out.print("Enter Second Number:"); y=s.nextInt(); System.out.println("Equal To x==y:"+(x==y)); System.out.println("Greater Than x>y:"+(x>y)); System.out.println("Less Than x<y:"+(x<y)); System.out.println("Greater than or Equal To x>=y:"+(x>=y)); System.out.println("Less Than or Equal To x<=y:"+(x<=y)); System.out.println("Not Equal To x!=y:"+(x!=y)); } } ============OUTPUT============ Enter First Number: 9 Enter Second Number: 4 Equal To x==y: false Greater Than x>y: true Less Than x<y: false Greater than or Equal To x>=y: true Less Than or Equal To x<=y: false Not Equal To x!=y: true |
Logical Operators in Java
Logical Operator: A logical operators can be used compare two variables and perform logical operations. If the logical condition is true than return 1 and logical condition is false than return 0.
Logical AND Operator: A logical AND operator condition is a both condition are true than result are true. If the any one condition are false then return false.
Logical AND Operator in Java
| import java.util.Scanner; public static void main(String[] args) { String password="12345"; char password[100]="12345"; String user; String pwd; Scanner s=new Scanner(System.in); System.out.print("Enter Username:"); user=s.next(); System.out.print("Enter Password:"); pwd=s.next(); if(user.equals(username)&&pwd.equals(password)){ System.out.println("Login Successfully..."); } else{ System.out.println("Username or Password invalid..."); } } } ============OUTPUT============ Enter Username: jiocoding Enter Password: 12345 Login Successfully |
Logical OR Operator: A logical OR operator can be used to anyone condition are true than both condition are true. If one condition are false than return true.
Logical OR Operators in Java Program
public static void main(String[] args) { String password="12345"; char password[100]="12345"; String user; String pwd; Scanner s=new Scanner(System.in); System.out.print("Enter Username:"); user=s.next(); System.out.print("Enter Password:"); pwd=s.next(); if(user.equals(username)||pwd.equals(password)){ System.out.println("Login Successfully..."); } else{ System.out.println("Username or Password invalid..."); } } } ============OUTPUT============ Enter Username: jiocoding Enter Password: 12345654 Login Successfully |
Logical NOT Operator: A logical NOT operator reverses the state means if the condition is true it returns false and if the condition is false it returns true.
How Many Types of Logical Operators
| Symbols | Operation | Example |
|---|---|---|
| (&&) | Logical AND | (a&&b) |
| (||) | Logical OR | (a||b) |
| (!) | Logical NOT | (a!=b) |
Logical Operators in Java Program
public static void main(String[] args) { String password="12345"; char password[100]="12345"; String user; String pwd; Scanner s=new Scanner(System.in); System.out.print("Enter Username:"); user=s.next(); System.out.print("Enter Password:"); pwd=s.next(); if(user.equals(username)||pwd.equals(password)){ System.out.println("Login Successfully..."); } else{ System.out.println("Username or Password invalid..."); } } } ============OUTPUT============ Enter Username: JIOCODING Enter Password: 12345 Username or Password Invalid |
Assignment Operators in Java
Assignment Operator: A Java assignment operator can be used to assign the value of an right side and variable on the left side.
Types of Assignment Operators
| Symbols | Operation | Example |
|---|---|---|
| (=) | (a=b) | (a=b) |
| (+=) | (a+=b) | (a=a+b) |
| (-=) | (a-=b) | (a=a-b) |
| (*=) | (a*=b) | (a=a*b) |
| (/=) | (a/=b) | (a=a/b) |
| (%=) | (a%=b) | (a=a%b) |
Assignment Operator in Java program
public static void main(String[] args) { int x,y; Scanner s=new Scanner(System.in); System.out.print("Enter First Number:"); x=s.nextInt(); System.out.print("Enter Second Number:"); y=s.nextInt(); ============OUTPUT============ Enter First Number: 8 Enter Second Number: 8 Assignment Addition of x+=y: 16 |
Bitwise Operator Definition
Bitwise Operator: A Java bitwise operator can be used to perform individual operation bits on integers data. Bitwise operators are used to binary operations performed.
Types of Bitwise Operators
| Symbols | Operation | Example |
|---|---|---|
| (&) | Bitwise AND | (a&b) |
| (|) | Bitwise OR | (a|b) |
| (<<) | Bitwise Shift Left | (a<<b) |
| (>>) | Bitwise Shift Right | (a>>b) |
Java Bitwise Operators
public static void main(String[] args) { int x,y; Scanner s=new Scanner(System.in); System.out.print("Enter First Number:"); x=s.nextInt(); System.out.print("Enter Second Number:"); y=s.nextInt(); System.out.println("Bitwsie AND Operator:"+(x&y)); System.out.println("Bitwsie OR Operator:"+(x|y)); System.out.println("Bitwise Shift Left Operator:"+(x<<2)); System.out.println("Bitwsie Shift Right Operator:"+(x>>2)); } } ============OUTPUT============ Enter First Number: 5 Enter Second Number: 3 Bitwise AND Operator: 1 Bitwise OR Operator:7 Bitwise Shift Left Operator: 20 Bitwise Shift Right Operator:1 |
Increment and Decrement Operators
Increment Operator: increment or decrement operators can be used to increase 1 value and decrement 1 value. Mostly increment operator commonly used to loops in java.
Types of Increment and Decrement Operators
| Symbols | Name | Function | Example |
|---|---|---|---|
| (++) | Increment | It increment the value 1 | ++a |
| (--) | Decrement | It Decrement the value 1 | --a |
Increment Operators in Java Program
public static void main(String[] args) { int x=8; System.out.println("Increment Operator ++x:"+(++x)); } ============OUTPUT============ Increment Operator of ++x:9 |
Decrement Operators in Java Program
public static void main(String[] args) { int x=8; System.out.println("Decrement Operator --x:"+(--x)); } ============OUTPUT============ Increment Operator of x++:7 |
Ternary Operator Definitions
Ternary Operators: A conditional operators can be used to one line operators or ternary operators because it can be used to three operands values.
Ternary Operators in Java Program
public static void main(String[] args) { System.out.println(10 < 5 ? "Welcome" : "Jiocoding"); } ============OUTPUT============ Jiocoding |
Conclusion of Operators in Java Programming
Conclusion: A Java operators can be used mathematical operations performed on data variables. I can explain everyone operators including with example if your any query or operator related questions than you can contact me by email or comment.

