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 main() method in java Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "main() method in java" Watch "main() method in java" New topic

main() method in java

vigneswar rao

Joined: Feb 12, 2006
Posts: 14
Hai ,
I hava a small doubt about the main() method .
we are declaring a simple class like

public class Example
public static void main(String args[])
System.out.println("Hello JavaRanch");

In the above code , what is the meaning of main(String args[])
Can any one explain...........
Ashutosh Limaye
Ranch Hand

Joined: Oct 24, 2005
Posts: 58
public static void main(String[]args)

Is an entry point to your java application.The excecution of the program starts from main.
Chetan Parekh
Ranch Hand

Joined: Sep 16, 2004
Posts: 3640
Read The main Method and The main() Method in Java.
[ March 13, 2006: Message edited by: Chetan Parekh ]

My blood is tested +ve for Java.
Guy Shahar

Joined: Dec 23, 2005
Posts: 22
The main method is like any other method, except that it is the one that will run automatically when you call your program.

Each method can take "arguments" which are listed in brackets after the name of the method. These arguments can provide information for the method to use.
For example - public void printSomething(String s){System.out.print(s);}
When you call this method, you may type in:
and the method with print the word "Hello" on the screen.

The main method takes as an argument an array of Strings, which is traditionally given the name args, though it could be called anything (for example, "main(String[] potatoCakes)" would be valid aswell). The array comes from anything that the user types AFTER the name of the class at the commandline. Normally, to start an application, you would type:
java MyApp
And anything you type after that is an item in the String array. So if I type:
java MyApp Potatoes Cakes PotatoCakes Mmmmm
Then the String[] args array would contain 4 elements:
args[0] = "Potatoes"
args[1] = "Cakes"
args[2] = "PotatoCakes"
args[3] = "Mmmmm"
and these can be used within the main method by referring to their reference in the array. e.g. System.out.print(args[1]);
Yu Fei Xu

Joined: Mar 15, 2006
Posts: 8
hi ,
the main() method just the method that the program get to enter,
you can use the parameter like the other methods you support,
the parameter in main() is a string array,when you compiler your
program, you should support the parameter
I agree. Here's the link:
subject: main() method in java
jQuery in Action, 3rd edition