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

  • Home
  • SEARCH
  • 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 7775203
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T17:34:14+00:00 2026-06-01T17:34:14+00:00

I tried Javas Hotswap today, and its working quite nice. During my testing i

  • 0

I tried Javas Hotswap today, and its working quite nice. During my testing i stumbled upon a rather weird behaviour. This is my Code:

public class Test extends JFrame implements ActionListener{

private JButton c;
private int f =1;
/**
 * @param args
 */
public static void main(String[] args) {
    Test t = new Test();
}

public Test(){
    this.setPreferredSize(new Dimension(800, 600));
    this.setDefaultCloseOperation(EXIT_ON_CLOSE);
    c = new JButton("Click");
    c.addActionListener(this);
    this.add(c);
    this.pack();
    this.setVisible(true);
}

@Override
public void actionPerformed(ActionEvent e) {
    c.setText(String.valueOf(f++));

}

}

Note the line c.setText(String.valueOf(f++)); near the end. If i switch that to f-- while the program is running, i notice that on the first click on the button after the change, the value is still counting up. The Clicks after that however are counting correctly. The same occurs when changing it back.

The next thing i noticed is: if i change the code to this: c.setText(String.valueOf(f+=1));, run the JVM and Hotswap it to c.setText(String.valueOf(f-=1)); the change is directly applied, with no click-delay.

My question is now: What exactly causes this behaviour? And what are the differences between f++ and f+=1 on JVM Code Level?

  • 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-06-01T17:34:15+00:00Added an answer on June 1, 2026 at 5:34 pm

    Using javap on this code:

    public static void main(String[] args) throws Exception {
        int i = 0;
        i++;
        System.out.println(i);
        i+=1;
        System.out.println(i);
    }
    

    returns

      0: iconst_0
      1: istore_1
      2: iinc          1, 1
      5: getstatic     #2                  // Field java/lang/System.out:Ljava/io/PrintStream;
      8: iload_1
      9: invokevirtual #3                  // Method java/io/PrintStream.println:(I)V
     12: iinc          1, 1
     15: getstatic     #2                  // Field java/lang/System.out:Ljava/io/PrintStream;
     18: iload_1
     19: invokevirtual #3                  // Method java/io/PrintStream.println:(I)V
     22: return
    

    ==> no difference

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

Sidebar

Related Questions

I tried to Java pns Package to send notification to Apple Push Notification Service,
Has anyone tried automatic Java to C++ conversion for speed improvements? Is it a
Just for learning's sake, I tried in java doc but I did not find
I've seen some code such as: out.println(print something); I tried import java.lang.System; but it's
I tried decompiling a Java application to which I do not have the source
I'm pretty new to Java and tried the Best Before puzzle from Spotify yesterday.
I encountered a problem when I tried to use java from matlab. I read
I need to set -Dfile.encoding=UTF8 globally on Windows machine. I tried to set JAVA_OPTS
i Tried to get data from excel in java. if i execute it as
I tried the following code: import java.math.BigInteger; import org.apache.commons.codec.binary.Base32; import org.junit.Test; public class Sandbox

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.