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: The meaning behind it

  1. #1
    Junior Member
    Join Date
    Jul 2012
    Posts
    10
    Thanks
    3
    Thanked 2 Times in 2 Posts

    Default The meaning behind it

    What is the meaning of test in this example? Does the test equal to June123?

    String actualPassword = "June123", test;


  2. #2
    Member
    Join Date
    Jul 2012
    Posts
    83
    My Mood
    Cynical
    Thanks
    3
    Thanked 9 Times in 9 Posts

    Default Re: The meaning behind it

    The meaning to me is test is that actualPassword holds "June123" and the test variable is null.

  3. #3
    Super Moderator pbrockway2's Avatar
    Join Date
    Jan 2012
    Posts
    939
    Thanks
    6
    Thanked 202 Times in 178 Posts

    Default Re: The meaning behind it

    It's exactly equivalent to the clearer, more intelligible, better

    String actualPassword = "June123";
    String test;

  4. #4
    Junior Member
    Join Date
    Jul 2012
    Posts
    10
    Thanks
    3
    Thanked 2 Times in 2 Posts

    Default Re: The meaning behind it

    What do you mean by It's exactly equivalent to the clearer, more intelligible, better?

  5. #5
    Super Moderator pbrockway2's Avatar
    Join Date
    Jan 2012
    Posts
    939
    Thanks
    6
    Thanked 202 Times in 178 Posts

    Default Re: The meaning behind it

    I mean

    (1) that in any Java code where you see the line you posted you can replace it with the two lines I posted and see no change in behaviour - either in compiling or at runtime,

    and (2) that the two line form better expresses the fact that you end up with two String variables one initialised to a reference to "June123" and the other, uninitialised, as Fubarable described.

    -----

    It is the fact that the more elaborate form is better that motivated my response. The two forms are equivalent, but the two line version makes it crystal clear that two things are being declared and what their types are. The ", test" is liable to be missed, or strike the eye as part of the string literal that precedes it. Where arrays are involved, having two variables declared on the same line may also mislead the unwary reader as to the type of the variables.

Similar Threads

  1. Newbie: needs meaning of terms (dictionary)
    By boyscout in forum Member Introductions
    Replies: 1
    Last Post: March 29th, 2011, 05:34 AM
  2. Meaning of Java Packages
    By Effrego in forum Java Theory & Questions
    Replies: 1
    Last Post: February 5th, 2011, 04:18 PM
  3. the meaning of 'instanceof'
    By Abednego Setyawan in forum Object Oriented Programming
    Replies: 1
    Last Post: March 12th, 2010, 12:45 AM