main() method in java
posted 19 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
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...........
cheers
vigneswar.

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...........
cheers
vigneswar.

posted 19 years ago
Is an entry point to your java application.The excecution of the program starts from main.
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
public static void main(String[]args)
Is an entry point to your java application.The excecution of the program starts from main.
posted 19 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Read The main Method and The main() Method in Java.
[ March 13, 2006: Message edited by: Chetan Parekh ]
[ March 13, 2006: Message edited by: Chetan Parekh ]
My blood is tested +ve for Java.
posted 19 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
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:
printSomething("Hello");
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]);
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:
printSomething("Hello");
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]);
posted 19 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
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
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
| Let me tell you a story about a man named Jed. He made this tiny ad: Paul Wheaton's 16th Kickstarter: Gardening playing cards for gardeners and homesteaders https://coderanch.com/t/889615/Paul-Wheaton-Kickstarter-Gardening-playing |









