Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7042815
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T02:12:50+00:00 2026-05-28T02:12:50+00:00

In Java, I really wonder is there a difference between using a += b;

  • 0

In Java, I really wonder is there a difference between using a += b; or a = a + b; . Which one should I use principally? I know that first one is something like shortcut but does the compiler get those two indications differently?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T02:12:50+00:00Added an answer on May 28, 2026 at 2:12 am

    See the Java language specification, 15.26.2 Compound assignment operators

    To quote the relevant parts:

    A compound assignment expression of the form E1 op= E2 is equivalent
    to E1 = (T)((E1) op (E2)), where T is the type of E1, except that E1
    is evaluated only once.

    short x = 3;
    x += 4.6;
    

    and results in x having the value 7 because it is equivalent to:

    short x = 3;
    x = (short)(x + 4.6);
    

    So it is more than syntactic sugar, as

    int x = 1;
    long a = 2l;
    x+= a;
    

    compiles, where

    int x =1;
    long a =2l;
    x = x+a;
    

    gives you a compile error, as was discussed here on StackOverflow quite recently

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know that Java doesn't really use exact pass by reference, but rather pass
I've got one really big .java class file that has a lot of members.
Using the scripting framework (javax.script.*), it's really easy to get basic integration between Java
I have a really simple Java class that effectively decorates a Map with input
i have a really basic java program just one .java/.class file (.java uncompiled .class
I was really discouraged by java's string encoding. There are many auto conversions in
I am really new to Java and I read that synchronized is very expensive
I'm really stuck trying to use java wrapper library for opencv's cvMatchTemplate. See this
I have a class PanelFormes that extends JPanel, which I use as a container.
What does another build tool targeted at Java really get me? If you use

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.