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 4 of 4

Thread: little questions

  1. #1
    Junior Member
    Join Date
    Sep 2013
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default little questions

    I'll be posting here all the little questions i'll have just not to open a new thread every time.
    1. Neither Eclipse nor Netbeans don't compile the addition of one in this way.

    public class MainClass {

    public static void main(String[] args) {

    int intValue = 10;
    int newValue = intValue ++;
    System.out.println(newValue);

    }

    }
    The result is still 10.

    2. I know that if i declare a primitive without assinging a number to it, it will have automatically assigned 0. in my case it doesn't work.


    public class MainClass {

    public static void main(String[] args) {

    double intValue;

    System.out.println(intValue);

    }

    }


  2. #2
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,534
    My Mood
    Hungover
    Thanks
    145
    Thanked 647 Times in 552 Posts

    Default Re: little questions

    First off, there is no difference between compiling in netbeans or eclipse. You should be using the command line until you understand what's going on under the hood.

    Do a google search of the difference between a postfix and a prefix operator.

    Only variables at the class level (fields) are given default values. Variables inside methods are not.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    Junior Member Robertgif's Avatar
    Join Date
    Feb 2013
    Posts
    19
    My Mood
    Amazed
    Thanks
    6
    Thanked 1 Time in 1 Post

    Default Re: little questions

    class PrePostDemo {
         public static void main(String[] args){
              int i = 3;
          i++;
          System.out.println(i);    // "4"
          ++i;             
          System.out.println(i);    // "5"
          System.out.println(++i);  // "6"
          System.out.println(i++);  // "6"
          System.out.println(i);    // "7"
         }
    }

    Take a look at this code, what does it show you? If it still is confusing then go back to google searching postfix and a prefix like Kevin suggested.
    "You should not let technology (or method) drive your design, but make your design drive the technology".

    Always learning!

  4. #4
    Member
    Join Date
    May 2013
    Posts
    107
    My Mood
    Amused
    Thanks
    16
    Thanked 10 Times in 10 Posts

    Default Re: little questions

    Prefix and postfix notation is one of those things I can never quite keep straight. I always use those statements completely within their own isolated statement and can't figure out why anyone would do otherwise. It seems like you're just asking for trouble introducing extra confusion for no reason.

Similar Threads

  1. questions
    By fahid in forum Java Theory & Questions
    Replies: 1
    Last Post: December 5th, 2012, 04:42 AM
  2. List of my Java3D Questions, and Proguard questions
    By Zachary1234 in forum Java SE APIs
    Replies: 0
    Last Post: November 16th, 2012, 09:40 PM
  3. Few questions
    By CSUTD in forum What's Wrong With My Code?
    Replies: 1
    Last Post: October 11th, 2011, 10:23 PM
  4. Many questions
    By SharpT in forum What's Wrong With My Code?
    Replies: 11
    Last Post: January 18th, 2011, 09:56 PM
  5. A few questions
    By adenverd in forum Java Theory & Questions
    Replies: 3
    Last Post: May 26th, 2010, 04:34 AM