File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes what will the o/p for this ... Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "what will the o/p for this ..." Watch "what will the o/p for this ..." New topic

what will the o/p for this ...

arun sharma

Joined: Jul 02, 2003
Posts: 19
Hi friends;
Can u explain why the o/p of this program is like this:
class Test{
public static void main(String args[]){
for(int nElement = 0 ; nElement < args.length ; nElement++)
System.out.println("File: "+args [nElement]);
Brian Smith
Ranch Hand

Joined: Oct 26, 2002
Posts: 232
can tell what do you mean by o/p?
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
If you start a Java program from the command line with a few arguments then the JVM invokes the main method you show in your example, with the parameters in the args. So if you type:
java MyClass able baker charlie
then args[0] is able, args[1] is baker, args[2] is charlie. The loop in your program will print the arguments out on one line each.
Your example includes the word "File:" so I'd guess your program is expecting a list of files as arguments. If a filename includes spaces you'll have to type it in quotes so it is read as one argument and not two or three.
java MyClass "c:\program files\my file.txt"
Is that the kind of thing you were asking? Sorry if I backed up over stuff you already knew.

A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
Dirk Schreckmann

Joined: Dec 10, 2001
Posts: 7023
Welcome to JavaRanch, arun!
Can u explain why the o/p of this program is like this:
What is the output? And do you have any ideas on why it might be that way?
can tell what do you mean by o/p?
Namaste, "o/p" likely means "output".
[ July 04, 2003: Message edited by: Dirk Schreckmann ]

[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
I agree. Here's the link:
subject: what will the o/p for this ...
It's not a secret anymore!