| Author |
Abnormal behaviour
|
Uma Kanth
Greenhorn
Joined: Sep 16, 2002
Posts: 20
|
|
Can some body expalin me why the output of the program is different When I send the command line argument as *.Say cmd>javac test.java cmd>java test * class test{ public static void main(String args[]){ for (int i = 0;i < args.length; i++) { System.out.println(i + " " + args[i]); } } } Thanx in advance
|
 |
Valentin Crettaz
Gold Digger
Sheriff
Joined: Aug 26, 2001
Posts: 7610
|
|
I'm not sure I understand your question. Could you please detail a little bit more your problem. Thanks It's possible that I move this discussion to the Java in General (Beginner) forum after answering your question since this does not really belong to the certification exam objectives.
|
SCJP 5, SCJD, SCBCD, SCWCD, SCDJWS, IBM XML
[Blog] [Blogroll] [My Reviews] My Linked In
|
 |
Uma Kanth
Greenhorn
Joined: Sep 16, 2002
Posts: 20
|
|
The output of the program is The list of count and the file names in the current directory
|
 |
Jamal Hasanov
Ranch Hand
Joined: Jan 08, 2002
Posts: 411
|
|
Hi, Uma I think it's a bug (but couldn't find it in java Bug Database). There're a few topics in Javarach regarfding this. One of them:-) Regards, Jamal Hasanov www.j-think.com
|
 |
Jamal Hasanov
Ranch Hand
Joined: Jan 08, 2002
Posts: 411
|
|
Uma, I found it !!! http://www.coderanch.com/t/237887/java-programmer-SCJP/certification/as-parameter-main This is a bug - You had to use java test "*" Regards, Jamal Hasanov www.j-think.com
|
 |
Valentin Crettaz
Gold Digger
Sheriff
Joined: Aug 26, 2001
Posts: 7610
|
|
Jim's answer in the linked discussion kind of solves the problem. I'm moving this to Java in General (Beginner) forum.
|
 |
Dirk Schreckmann
Sheriff
Joined: Dec 10, 2001
Posts: 7023
|
|
|
It's not a bug, it's a feature.
|
[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
|
 |
Layne Lund
Ranch Hand
Joined: Dec 06, 2001
Posts: 3061
|
|
It's not even a bug with java. When you type something on the command line, the system deals with it before anything is sent to the JVM. In DOS and all flavors of Unix, the * is expanded into a list of all the files in the current directory. This is list is what the JVM then forwards on to your program as the command line arguments. So to get a literal "*" character, you have to use the quotes as stated earlier in order to tell the system it is actually a "*" and not an operator. HTH Layne
|
Java API Documentation
The Java Tutorial
|
 |
 |
I agree. Here's the link: jrebel
|
|
subject: Abnormal behaviour
|
|
|