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

  • Private Policy
  • Contact
  • Java
  • Java Core
  • Java Lambda Expression
  • Java Fundamentals
  • Java Stream
  • Java Tools
  • Java XML
  • Jakarta EE
  • CDI
  • JSON Binding
  • JSON Processing
  • MVC

This view

  • Original page
  • New address

GeezerVison is showing huongdanjava.com — Assignment operator in Java - Huong Dan Java

Khanh Nguyen

I love Java and everything related to Java.

Follow

Share this post

Views: 1,183

In Java, we have the following assignment operators:

  • =
  • +=
  • -=
  • *=
  • /=

– The assignment operator “=” is used most often, which is used to initialize the variable and assign a new value to it.

Example:

Assignment operator in Java

You cannot use this assignment operator to assign a boolean value to a variable of type char, byte, short, int, long or float, or double and vice versa. If you try to do that then the compile error will occur.

Assignment operator in Java

You cannot assign a variable whose data type has a larger range value to a variable whose value type has a smaller range value.

For example, we cannot assign a variable of type long to a variable of type int:

Assignment operator in Java

That’s because the range value of the long type is greater than int.

The remaining operators include “+ =”, “- =”, “* =”, “/ =” are abbreviations for summation, subtraction, multiplication and division with the assignment operator.

  • “+=”: first plus then assign.
  • “-=”: the first is the subtraction followed by the assignment.
  • “*=”: first multiply then assign.
  • “/=”: first divide then assign.

For example, we have the following calculation:

Java
1
a += b;

which means that

Java
1
a = a + b;

Or

Java
1
a -= b;

which means that

Java
1
a = a - b

Similarly to divide and multiply.

You might also like...

  • What is a Database Transaction? ACID, JDBC & Isolation Levels

    What is a Database Transaction? ACID, JDBC & Isolation Levels

  • What is JDBC? JDBC Architecture, Driver, Connection, Statement & PreparedStatement | Java

    What is JDBC? JDBC Architecture, Driver, Connection, Statement & PreparedStatement | Java

  • Java Primitive Data Types Part 2 | float, double, boolean

    Java Primitive Data Types Part 2 | float, double, boolean

  • Java Primitive Data Types Part 1 | byte, short, int, long, char & Type Conversion

    Java Primitive Data Types Part 1 | byte, short, int, long, char & Type Conversion

Previous Post: Questions Management – Frontend – Apply routing using RouterModule of Angular
Next Post: Code coverage with JaCoCo Maven Plugin

Add Comment Cancel reply

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.