aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes A question about String[]??? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "A question about String[]???" Watch "A question about String[]???" New topic
Author

A question about String[]???

tanu dua
Ranch Hand

Joined: Apr 05, 2004
Posts: 145
I have read one question in one of the mock of SCJP.

Output: Code will compile correctly and will print "In first main()" (without quotes) when run with argument of 'a'.
Now i am facing the problem how the character value 'a' can be coverted to String type.
Thanx!!!
Edited by Corey McGlone: Added CODE Tags
[ April 13, 2004: Message edited by: Corey McGlone ]
Corey McGlone
Ranch Hand

Joined: Dec 20, 2001
Posts: 3271
Originally posted by tanu dua:
Now i am facing the problem how the character value 'a' can be coverted to String type.

Hmm... Nowehere in that code is a char converted to a String type. Unless, you're referring to the output line which is never executed.
In such a case, the println method is making use of Character.toString().
I hope that helps,
Corey


SCJP Tipline, etc.
Mark Patrick
Ranch Hand

Joined: Feb 22, 2004
Posts: 51
I think you are getting confused on the overloaded main method. When you run this class as follows:
java MyClass a
The JVM will always look for a method in MyClass with the signature "public static void main(String[] args)" and pass the "a" into the first element of the String array.
The overloaded method "public static void main(char args[])" will never be executed when you run MyClass, even if you pass what appears to be the char value 'a' in the command line argument. The only way that this method can be executed is if you call it from inside of your already running program.


Mark Patrick<br />SCJP 1.4
Lionel Orellana
Ranch Hand

Joined: Mar 19, 2004
Posts: 87
Originally posted by Mark Patrick:
The overloaded method "public static void main(char args[])" will never be executed when you run MyClass, even if you pass what appears to be the char value 'a' in the command line argument.

Wich is to say everything you pass to your program in the command line will be a String.
java MyClass 1 2 sss 'a'
1, 2, sss, and 'a' are passed as Strings to your main method ...
 
wood burning stoves
 
subject: A question about String[]???