Search
  • +44-7459919437 (UK- WhatsApp & Direct Call) | +91-6383544892 (India - WhatsApp Only) | Email Id : vinothrwins@gmail.com
Vinoth Tech Solutions
  • Home
  • Selenium Java Online Training
  • Self Paced Video Course
    • Selenium Course Curriculum
    • Cypress Course Curriculum
    • Playwright Course Curriculum
  • Tutorials
  • Demo Sites
    • Practice Automation
      • Demo Page Healthcare
      • Registration Form
      • Transaction Details
      • DropDown
      • Mouse Event
      • Keyboard Events
      • Alert and Popup
      • Multiple Windows
      • iFrames
      • Wait WebElement
      • WebTable
  • FAQS
  • About Me & Feedback
    • Placed Students Feedback
    • Online Training Feedback
    • LinkedIn Profile
    • TechTalk
  • Free YouTube Courses
    • Python for Automation
    • Free QA Video Courses
      • Manual Testing
      • Java For Automation
      • Selenium Webdriver
      • TestNG
      • Cucumber BDD
      • UFT(QTP) Automation
    • Free Data Science Courses
      • Artificial Intelligence for Beginners
      • Python For A.I
      • Python Pandas
      • Python NumPy
      • Mathematics for A.I
  • Home
  • Selenium Java Online Training
  • Self Paced Video Course
    • Selenium Course Curriculum
    • Cypress Course Curriculum
    • Playwright Course Curriculum
  • Tutorials
  • Demo Sites
    • Practice Automation
      • Demo Page Healthcare
      • Registration Form
      • Transaction Details
      • DropDown
      • Mouse Event
      • Keyboard Events
      • Alert and Popup
      • Multiple Windows
      • iFrames
      • Wait WebElement
      • WebTable
  • FAQS
  • About Me & Feedback
    • Placed Students Feedback
    • Online Training Feedback
    • LinkedIn Profile
    • TechTalk
  • Free YouTube Courses
    • Python for Automation
    • Free QA Video Courses
      • Manual Testing
      • Java For Automation
      • Selenium Webdriver
      • TestNG
      • Cucumber BDD
      • UFT(QTP) Automation
    • Free Data Science Courses
      • Artificial Intelligence for Beginners
      • Python For A.I
      • Python Pandas
      • Python NumPy
      • Mathematics for A.I

Java For Automation

  • What is Java?
  • Why to Learn Java?
  • History of Java
  • Types of Java Applications
  • Naming Conventions
  • Hello World Program
  • Internal Details of Java program
  • What is Java JDK, JRE and JVM ?
  • What is Java Comments ?
  • What is Java Variable?
  • Variable Naming convention
  • Primitive Data Types
  • Non Primitive Data Types
  • Type Casting
  • Java Arithmetic Operators
  • Relational Operators
  • What is logical operators in Java? 
  • What is Assignment Operators in Java? 
  • What is Unary Operators in Java? 
  • What is Ternary Operators in Java?
  • What is Java Control Statements?
  • What are Decision Making statements?
  • What are looping statements?
  • What are Jump statements?
  • What is OOPS concept in Java?
  • Advantages of Java OOPs
  • What is Java Inheritance?
  • What is Java Constructor?
  • What is this keyword?
  • What is Polymorphism?
  • What is super keyword ?
  • What is final keyword? 
  • What are access modifiers?
  • What is Encapsulation? 
  • What is Abstraction? 
View Categories
  • Home
  • Tutorials
  • Java
  • Java For Automation
  • What is Assignment Operators in Java? 

What is Assignment Operators in Java? 

What is Assignment Operators in

Java? 

Assignment operators in Java are used to assign values to variables. The most basic assignment operator is the equal sign =. In addition to the basic assignment, Java provides several compound assignment operators that combine an arithmetic operation with assignment.

1. Basic Assignment Operator (=) #

The = operator assigns the value on the right to the variable on the left.

Example:

public class AssignmentOperatorExample {

    public static void main(String[] args) {

        int a = 10; // Assigns 10 to variable a

        System.out.println("a = " + a);

    }

}

Output:
a = 10

2. Compound Assignment Operators

These operators perform an arithmetic operation on the variable and then assign the result to that variable.

a. Add and Assign (+=) #

This operator adds the right operand to the left operand and assigns the result to the left operand.

Example:

public class AssignmentOperatorExample {

    public static void main(String[] args) {

        int a = 10;

        a += 5; // Equivalent to a = a + 5

        System.out.println("a = " + a); 

    }

}

Output: 
a = 15

b. Subtract and Assign (-=) #

This operator subtracts the right operand from the left operand and assigns the result to the left operand.

Example:

public class AssignmentOperatorExample {

    public static void main(String[] args) {

        int a = 10;

        a -= 3; // Equivalent to a = a - 3

        System.out.println("a = " + a); 
    }

}

Output: 
a = 7

c. Multiply and Assign (*=) #

This operator multiplies the left operand by the right operand and assigns the result to the left operand.

Example:

public class AssignmentOperatorExample {

    public static void main(String[] args) {

        int a = 10;

        a *= 2; // Equivalent to a = a * 2

        System.out.println("a = " + a); // Output: a = 20

    }

}

d. Divide and Assign (/=) #

This operator divides the left operand by the right operand and assigns the result to the left operand.

Example:

public class AssignmentOperatorExample {

    public static void main(String[] args) {

        int a = 10;

        a /= 2; // Equivalent to a = a / 2

        System.out.println("a = " + a); 

    }

}

Output: 
a = 5

e. Modulus and Assign (%=)

This operator takes the modulus of the left operand by the right operand and assigns the result to the left operand.

Example:

public class AssignmentOperatorExample {

    public static void main(String[] args) {

        int a = 10;

        a %= 3; // Equivalent to a = a % 3

        System.out.println("a = " + a); 

    }

}

Output: 
a = 1

Summary

Assignment operators in Java provide a convenient way to update the value of a variable. By using compound assignment operators, you can write more concise and readable code.

Java
What are your Feelings
Share This Article :
  • Facebook
  • X
  • LinkedIn
What is logical operators in Java? What is Unary Operators in Java? 
Table of Contents
  • 1. Basic Assignment Operator (=)
    • a. Add and Assign (+=)
    • b. Subtract and Assign (-=)
    • c. Multiply and Assign (*=)
    • d. Divide and Assign (/=)
© 2018 – 2025 Vinoth Tech Solutions Ltd (UK), Reg. No: 16489105