Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 5 of 5

Thread: Got different result from (Eclipse VS NetBean)

  1. #1
    Junior Member
    Join Date
    Apr 2012
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Unhappy Got different result from (Eclipse VS NetBean)

    public class calTest {

    public int i = 1;
    private int j = 1;

    public static void main(String[] args) {

    new calTest().runCal();

    }

    public void runCal() {
    class cal{

    cal(){

    System.out.println("before i = " + i);
    System.out.println("before j = " + j);
    i+=i+=1;
    j+=j+=1;
    System.out.println("i = " + i);
    System.out.println("j = " + j);
    }

    }

    new cal();
    }

    }
    Eclipse result:
    3
    3

    NetBean result:
    3
    4

    Command line result:
    3
    4

    Why is it different?
    Which result should be the correct one?
    Can anyone explain it in detail?
    Thank you very much in advance.


  2. #2
    Member
    Join Date
    Mar 2012
    Location
    United States
    Posts
    118
    My Mood
    Inspired
    Thanks
    1
    Thanked 33 Times in 31 Posts

    Default Re: Got different result from (Eclipse VS NetBean)

    Tried your code and got the same result for Eclipse, NetBeans and command line:
    before i = 1
    before j = 1
    i = 3
    j = 3
    Are you positive the code is the same in Eclipse and NetBeans?

  3. #3
    Junior Member
    Join Date
    Apr 2012
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Got different result from (Eclipse VS NetBean)

    Thank you for your reply:

    Yup, exactly the same code.
    To confirm this, I purposely created the same class again and copy/paste the code from here.
    Both Eclipse and NetBean again gave the same result as I got previously.

    Eclipse: 3, 3 and NetBean: 3, 4 (see below pics).
    Eclipse version 3.7.2 & NetBean version 7.1.1, what version are your using?

    Last edited by SmokyBrain; May 3rd, 2012 at 08:23 PM.

  4. #4
    Super Moderator pbrockway2's Avatar
    Join Date
    Jan 2012
    Posts
    987
    Thanks
    6
    Thanked 206 Times in 182 Posts

    Default Re: Got different result from (Eclipse VS NetBean)

    Indeed. I see the same thing with

    NetBeans IDE 7.1.1 (Build 201203012225)
    1.7.0_03; Java HotSpot(TM) Client VM 22.1-b02
    Windows 7 version 6.1 running on x86; Cp1252; en_US (nb)

    vs

    Eclipse IDE for Java Developers
    Version: Indigo Service Release 1
    Build id: 20110916-0149

    -----

    According to Google this queston has come up (same code) in a few places in the last little while. What is said in this OTN thread by way of explanation seems good to me. Eclipse FTW!

  5. #5
    Junior Member
    Join Date
    Apr 2012
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Got different result from (Eclipse VS NetBean)

    Make the answer the same. 3,3 or 4,4 !!!!!!
    3,4 cause confusion for the DEFINITION of public and private.

    "Sorry Sir, public vs. private, 1M is deducted from your saving account."
    "Good news Sir, the new compiler get you back the 1M that you have lost 1 year ago."
    That's very stupid !

Similar Threads

  1. How to create LoginProgram using NetBean IDE ?
    By anudeep86 in forum Java IDEs
    Replies: 3
    Last Post: January 24th, 2012, 01:08 AM
  2. Error Deploying Applet project in netbean to Tomcat
    By nasajava in forum Web Frameworks
    Replies: 2
    Last Post: October 17th, 2011, 09:12 AM
  3. netbean nextLine
    By Joy123 in forum Java Theory & Questions
    Replies: 2
    Last Post: July 8th, 2011, 08:43 PM
  4. Netbean Desktop Application Help!!
    By flyto9 in forum Java Theory & Questions
    Replies: 2
    Last Post: June 30th, 2011, 05:52 PM
  5. netbean and debuger client
    By 11moshiko11 in forum Java Networking
    Replies: 0
    Last Post: October 8th, 2010, 12:43 PM