GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • C programming
  • C++ programming
  • Java programming
  • Python programming
  • HTML
  • CSS
  • Codenora IDE (opens in a new tab)
  • About us
  • Pricing
  • Contact us
  • Privacy policy
  • Terms of service
  • Refund and Cancellation

This view

  • Original page
  • New address

GeezerVison is showing www.dremendo.com — Assignment Operators in Java Programming | Dremendo

  • Dremendo
  • C
  • C++
  • Java
  • Python
  • HTML
  • CSS
  • More
    • Home
    • C Tutorial
    • C++ Tutorial
    • Java Tutorial
    • Python Tutorial
    • HTML Tutorial
    • CSS Tutorial
?>
profile image
Announcements
No new announcements.
mentora icon
Java Programming Tutorial
  • Java Basic Concepts
    • Introduction
    • Variable
    • Data Types
    • Naming Conventions
    • Integer Variable
    • Long Variable
    • Short Variable
    • Byte Variable
    • Float and Double Variables
    • Character Variable
    • Boolean Variable
    • Constant Variable
    • Typecasting
  • Operators in Java
    • Operators
    • Assignment Operators
    • Arithmetic Operators
    • Relational Operators
    • Logical Operators
    • Operator Precedence
  • Input and Output in Java
    • Environment Setup
    • Program Basic Structure
    • Output
    • Input
    • Comments
  • Decision Making in Java
    • Decision Making
    • if Statement
    • if else Statement
    • if else if Statement
    • Conditional Operator
    • switch case Statement
  • Mathematical Functions
    • Mathematical Functions
  • Loops in Java
    • Loops
    • for Loop
    • while Loop
    • do while Loop
  • Arrays in Java
    • One Dimensional Array
    • Two Dimensional Array
  • String in Java
    • String
    • StringBuffer
    • StringBuilder
  • Searching in Java
    • Linear Search
    • Binary Search
  • Sorting in Java
    • Bubble Sort
    • Selection Sort
    • Insertion Sort
  • Function in Java
    • Function
    • Recursive Function
    • Function Overloading
  • OOPs in Java
    • Classes and Objects
    • Instance Variables
    • Instance Methods
    • Access Modifiers
    • Constructor
    • Static Variables
    • Static Methods
    • Inheritance
    • Interface
    • Types of Inheritance
    • Polymorphism
    • Final Class and Method
    • Abstract Class and Method
    • Wrapper Classes
  • Data Structures in Java
    • Stack
    • Queue
    • Circular Queue
    • Double Ended Queue
    • Singly Linked List
    • Doubly Linked List
    • Stack using Linked List
    • Queue using Linked List
  • Packages in Java
    • Packages
  • Exception Handling in Java
    • Exception Handling
    • User-Defined Exception
  • Thread in Java
    • Thread
    • Thread Methods
  • File Handling in Java
    • Text File Handling
    • Binary File Handling
    • Random Access File Handling

bookmark
Table of Contents

    Assignment Operators in Java Programming

    In this lesson, we are going to look at what is assignment operator and will learn the different types of assignment operator with the help of examples.

    What is Assignment Operator

    Assignment Operator in Java is used for assigning value to a variable. Using the assignment operator we can assign the value which is on the right side of the operator to the variable on the left side of the operator.

    Video Explanation

    Click the button below to watch the explanation.

    Please wait while the video is loading....
    video image

    Let's discuss about the different types of assignment operators with examples.

    Assign Operator =

    The Assign Operator = is used to assign a value to a variable. It takes the value on its right-hand side and assigns it to the variable on its left-hand side.

    Example
    int a, b;
    a=5;    // value 5 is assigned to variable a
    b=a;    // value of variable a which is 5 is assigned to the variable b

    As you can see the value 5 which is on the right side of the operator = has been assigned to the left in the variable a. In the same way value of the variable a (5) which is on the right side of the operator = has been assigned to the left in the variable b

    Note

    The lines started with // are called comments which are used to provide information about lines of code. We will learn more about comments in our upcoming lessons.

    Add and Assign Operator +=

    The Add and Assign Operator += is a combination of + and = operators. This operator adds the value of the right-hand operand to the left-hand operand and then assigns the result back to the left-hand operand. It is a shorthand way to perform addition and assignment in a single step.

    Example
    int a=2, b=10, c=5;
    a+=2;    // can be written as a=a+2 (a=2+2) result is a=4
    b+=c;    // can be written as b=b+c (b=10+5) result is b=15

    Subtract and Assign Operator -=

    The Subtract and Assign Operator -= is a combination of - and = operators. This operator subtracts the value of the right-hand operand from the left-hand operand and then assigns the result back to the left-hand operand. It is a shorthand way to perform subtraction and assignment in a single step.

    Example
    int a=6, b=10, c=5;
    a-=2;    // can be written as a=a-2 (a=6-2) result is a=4
    b-=c;    // can be written as b=b-c (b=10-5) result is b=5

    Multiply and Assign Operator *=

    The *= operator is a combination of * and = operators. This operator multiplies the value of the left-hand operand by the right-hand operand and then assigns the result back to the left-hand operand. It is a shorthand way to perform multiplication and assignment in a single step.

    Example
    int a=7, b=10, c=5;
    a*=2;    // can be written as a=a*2 (a=7*2) result is a=14
    b*=c;    // can be written as b=b*c (b=10*5) result is b=50

    Divide and Assign Operator /=

    The /= operator is a combination of / and = operators. This operator divides the value of the left-hand operand by the right-hand operand and then assigns the result back to the left-hand operand. It is a shorthand way to perform division and assignment in a single step.

    Example
    int a=18, b=10, c=5;
    a/=2;    // can be written as a=a/2 (a=18/2) result is a=9 (quotient)
    b/=c;    // can be written as b=b/c (b=10/5) result is b=2 (quotient)

    Modulus and Assign Operator %=

    The %= operator is a combination of % and = operators. This operator calculates the remainder of the division of the left-hand operand by the right-hand operand and then assigns the result back to the left-hand operand. It is a shorthand way to perform modulus and assignment in a single step.

    Example
    int a=6, b=10, c=8;
    a%=2;    // can be written as a=a%2 (a=6%2) result is a=0 (remainder)
    b%=c;    // can be written as b=b%c (b=10%8) result is b=2 (remainder)

    Test Your Knowledge

    Attempt the questions in the exercise to check whether you have understood the lesson clearly.

    Exercise
    Test Your Knowledge
    Previous Next

    We care about your privacy

    Dremendo uses cookies and similar technologies that are necessary for the site to work properly, understand how you interact with our website, and measure the effectiveness of our marketing. By clicking Accept All, you consent to the use of non-essential cookies and similar technologies for analytics, advertising, and ad measurement, as described in our Privacy Policy.

    Cookie Preferences

    Choose which types of cookies Dremendo may use.

    Necessary Cookies

    Required for essential website functionality and security.

    Allow
    Analytics Cookies

    Help us understand how visitors use Dremendo.

    Allow
    Marketing Cookies

    Help us measure advertising performance and understand interactions with our advertisements.

    Allow
    Mentora Question Asked: 0 / 20

    Hi, I’m Mentora!

    I’m your personal AI tutor from Dremendo. Ask me anything, and I’ll help you understand it in a simple and easy way.

    You are visitor 01402503 — GeezerVison does not store the pages you look up.
    Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.