Home » Core Java » Basic Operators – Java += Operator

About Yatin

Yatin
The author is graduated in Electronics & Telecommunication. During his studies, he has been involved with a significant number of projects ranging from programming and software engineering to telecommunications analysis. He works as a technical lead in the information technology sector where he is primarily involved with projects based on Java/J2EE technologies platform and novel UI technologies.

Basic Operators – Java += Operator

Hello readers, in this tutorial, we will learn the Java += operator.

1. Introduction

Java programming offers Operators that are used to perform various operations in Java. In this tutorial, we’ll only cover the += operator that falls under the Compound Assignment operators’ category.

1.1 Compound assignment operators in Java

Following table list the different compound assignment operators.

OperatorDescriptionSyntaxIs equivalent to?
+=Compound addition assignment operatorele2 += ele1ele2 = ele2+ele1
-=Compound subtraction assignment operatorele2 -= ele1ele2 = ele2-ele1
*=Compound multiplication assignment operatorele2 *= ele1ele2 = ele2*ele1
/=Compound division assignment operatorele2 /= ele1ele2 = ele2/ele1
%=Compound modulo assignment operatorele2 %= ele1ele2 = ele2%ele1

To start with the captioned tutorial, we are hoping that users at present have their preferred Ide installed on their machines. For easy usage, I am using Eclipse Ide on a Windows operating system.

2. Basic Operators – Java += Operator

In this example, we’ll demonstrate the += operator in java. For a better understanding, developers can execute the below code in Eclipse Ide.

Example.java

01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
20
package com.example;
public class Example {
    // Basic operators - Java += Operator.
    public static void main(String[] args) {
        int ele1 = 5;
        int ele2 = 5;
        ele2 += ele1;   // ele2 += ele1 is equal to ele2 = ele2+ele1;
        System.out.println("+= Output is: "+ ele2);
String str1 = "Java";
        String str2 = "Geek";
        str2 += str1;   // str2 += str1 is equal to str2 = str2+str1;
        System.out.println("+= Output is: "+ str2);
    }
}

If everything goes well, the following output will be printed in the Ide console.

Output

1
2
3
+= Output: 10
+= Output: GeekJava

That is all for this tutorial and I hope the article served you whatever you were looking for. Happy Learning and do not forget to share!

3. Java += Operator – Summary

In this tutorial, we learned the += operator in Java. Developers can download the sample application as an Eclipse project in the Downloads section.

4. Download the Source Code

This was an example of += operator in Java programming language.

Download
You can download the full source code of this example here: Basic Operators – Java += Operator
(No Ratings Yet)
Start the discussion Views Tweet it!

Do you want to know how to develop your skillset to become a Java Rockstar?

Subscribe to our newsletter to start Rocking right now!

To get you started we give you our best selling eBooks for FREE!

 

1. JPA Mini Book

2. JVM Troubleshooting Guide

3. JUnit Tutorial for Unit Testing

4. Java Annotations Tutorial

5. Java Interview Questions

6. Spring Interview Questions

7. Android UI Design

 

and many more ....

 

Receive Java & Developer job alerts in your Area

 

Leave a Reply

avatar

This site uses Akismet to reduce spam. Learn how your comment data is processed.

  Subscribe  
Notify of