wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes What is the main usage of Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "What is the main usage of "String[] args" in public static void main(String[] args)?" Watch "What is the main usage of "String[] args" in public static void main(String[] args)?" New topic
Author

What is the main usage of "String[] args" in public static void main(String[] args)?

abalfazl hossein
Ranch Hand

Joined: Sep 06, 2007
Posts: 635
What is the main usage of "String[] args" in public static void main(String[] args)?Why is "String[] args" used in main method?
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19656
    
  18

Because that's the way to get the command line arguments passed to the JVM.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11170
    
  16

you can type "java MyClassName arg1 arg2 arg3".

the strings after the class name go into the args[] array, so you can use them inside your program.


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
abalfazl hossein
Ranch Hand

Joined: Sep 06, 2007
Posts: 635
May you give examples for what you told?
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

abalfazl hossein wrote:May you give examples for what you told?

Can you loop through an array ? If yes, loop through args[] and execute your application with the command fred has posted.


[My Blog]
All roads lead to JavaRanch
abalfazl hossein
Ranch Hand

Joined: Sep 06, 2007
Posts: 635
What about this:

Because that's the way to get the command line arguments passed to the JVM.

Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

Check this tutorial.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: What is the main usage of "String[] args" in public static void main(String[] args)?
 
Similar Threads
First Java Program not working
what is wrong with these two codes?
how to complie/run a java prog with 2 or more classes
Very Basic Question ....
significance of public, static, void and main