Table of contents
1.
Introduction
2.
Types of Operators
3.
Assignment Operator in Java
3.1.
Syntax
4.
Types of Assignment Operators in Java
4.1.
= Operator
4.2.
+= Operator
4.3.
-= Operator
4.4.
*= Operator
4.5.
/= Operator
4.6.
%= Operator
5.
Example of Java Assignment Operators
6.
Frequently Asked Questions
6.1.
What does += operator do?
6.2.
What is the use of the modulus operator?
6.3.
What are compound statement operators?
7.
Conclusion
Last Updated: Jul 28, 2025

Java Assignment Operators

Author Rhythm Jain
0 upvote
Career growth poll
Do you think IIT Guwahati certified course can help you in your career?

Introduction

Operators are the fundamental building blocks of every programming language. Java, too, includes a variety of operators that may be used to accomplish different calculations and operations, such as logical, arithmetic, relational, and so on. They are categorized according to the functionality they offer.

Also see, Duck Number in Java and Hashcode Method in Java.

Types of Operators

There are many types of operators such as:

  • Assignment Operator
  • Unary Operators
  • Bitwise Operators
  • Relational Operators
  • Arithmetic Operators
  • Logical Operators
  • Ternary Operator
  • Shift Operators

Also see, Swap Function in Java

Assignment Operator in Java

Variables are assigned values using these operators. The assignment operator's left operand is a variable, while the assignment operator's right operand is a value assigned to the variable. The right-side value must be of the same data type as the operand on the left. Right to left associativity exists for assignment operators, which means that the value supplied on the operator's right-hand side gets assigned to the variable on the left.

Syntax

var_name <operator> value;

Types of Assignment Operators in Java

We have the following types of assignment operators in java:

= Operator

This is the simple assignment operator. Values from the operand on the right side of the operator are assigned to the operand on the left side of the operator.

Syntax

var1 = var2;

+= Operator

This is a compound assignment operator. This operator comprises the '+' and '=' operators. Values from the operand on the right side of the operator are added to the value on the left side of the operand, and the result is assigned to the operand on the left side of the operator.

Syntax

var1 += var2; 

Above statement is same as var1=var1+var2.

-= Operator

This is a compound assignment operator. This operator comprises the '-' and '=' operators. Values from the operand on the right side of the operator are subtracted from the value on the left side of the operand and the result is assigned to the operand on the left side of the operator.

Syntax

var1 -= var2;
You can also try this code with Online Java Compiler
Run Code

Above statement is same as var1=var1-var2.

*= Operator

This is a compound assignment operator. This operator combines the '*' and '=' operators. Values from the operand on the right side of the operator are multiplied by the value on the left side of the operand, and the result is assigned to the operand on the left side of the operator.

Syntax

var1 *= var2;
You can also try this code with Online Java Compiler
Run Code

Above statement is same as var1=var1*var2.

/= Operator

This is a compound assignment operator. This operator combines the '/' and the '=' operators. Values from the operand on the left side of the operator are divided by the value on the right side of the operand, and the result is assigned to the operand on the left side of the operator.

Syntax

var1 /= var2;
You can also try this code with Online Java Compiler
Run Code

Above statement is same as var1=var1/var2.

%= Operator

This is a compound assignment operator. This operator combines the '%' and '=' operators. Values from the operand on the left side of the operator are divided by the value on the right side of the operand, and the remainder is assigned to the operand on the left side of the operator.

Syntax

var1 %= var2;
You can also try this code with Online Java Compiler
Run Code

The above statement is the same as var1=var1%var2.

Example of Java Assignment Operators

import java.io.*;
public class Main
{
	public static void main(String[] args) {
		int num1=10,num2=5;

		//= operator
		num1=7;
		System.out.println(num1);

		//+= operator
		num1=10;num2=5;
		num1+=num2;
		System.out.println(num1);

		//-= operator
		num1=10;num2=5;
		num1-=num2;
		System.out.println(num1);

		//+= operator
		num1=10;num2=5;
		num1+=num2;
		System.out.println(num1);

		//*= operator
		num1=10;num2=5;
		num1*=num2;
		System.out.println(num1);

		///= operator
		num1=10;num2=5;
		num1/=num2;
		System.out.println(num1);

		//%= operator
		num1=10;num2=5;
		num1%=num2;
		System.out.println(num1);


	}
}
You can also try this code with Online Java Compiler
Run Code

Output

7
15
5
15
50
2
0

 

Practice by yourself on online java compiler.

Frequently Asked Questions

 

What does += operator do?


This operator comprises the '+' and '=' operators. Values from the operand on the right side of the operator are added to the value on the left side of the operand, and the result is assigned to the operand on the left side of the operator.
Example var1 += var2; 
 

What is the use of the modulus operator?


 Modulus operator returns the remainder of division of two numbers. For example, 5%2 will return 1 since the remainder is 1 when 5 is divided by 2.
 

What are compound statement operators?


 The compound Assignment operator is the operator that combines Arithmetic operator and assignment.

Conclusion

In this article, we have extensively discussed Assignment Operators and their implementation in Java. We tried to cover it with some examples.

Live masterclass