What is the meaning of test in this example? Does the test equal to June123?
String actualPassword = "June123", test;
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.
What is the meaning of test in this example? Does the test equal to June123?
String actualPassword = "June123", test;
The meaning to me is test is that actualPassword holds "June123" and the test variable is null.
It's exactly equivalent to the clearer, more intelligible, better
String actualPassword = "June123"; String test;
What do you mean by It's exactly equivalent to the clearer, more intelligible, better?
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.