• Post Reply Bookmark Topic Watch Topic
  • New Topic

Command Line  RSS feed

 
Vinod Sinha
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
guess what's the output of the following code snippet and tell me why the output is so ?
Code:
class test{
public static void main(String args[]){
for (int i = 0;i < args.length; i++) {
System.out.println("File " + i + ":" + args[i]);
}
if (args.length<=0) {
System.out.println("No files!");
}
}
}

To run the program give command line argument as *
java test * // Do not forget to type * symbol after words "java test" !!!
 
Amit KumarS
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi vinod..

this will display all the directories and files of the current directory.. and this is not because it is what java does... actually u run this program from the command line and * is treated as special character by the OS. * symbolises as wild card character and thus it send the name of all the directories and files to the java program as command line argument which is stored in args[]
I hope i have answered your question.. please revert back if still in doubt
Thanks
Amit
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!