+ 1

[DUPLICATE] What is public static void main ( string [] args )?

Plz dont give any type of definations ... If u know the answer .... Plz create an example for it .. so i can easily understand your answer ... i need to learn perfectly ...

15th Dec 2016, 1:32 PM
Prashant Malviya
Prashant Malviya - avatar
4 Answers
+ 2
If you dont get definitions how will you understand, in that case you've solved your own question because you've just provided the example which is code you wrote....
15th Dec 2016, 1:52 PM
Ousmane Diaw
+ 2
A Java program needs to start its execution somewhere. A Java program starts by executing theĀ mainĀ method of some class. You can choose the name of the class to execute, but not the name of the method. The method must always be calledĀ main. Here is how theĀ mainĀ method declaration looks when located inside the Java class declaration from earlier: package myjavacode; public class MyClass { public static void main(String[] args) { } } The three keywordsĀ public,Ā staticĀ andĀ voidĀ have a special meaning. In theĀ main()Ā method example earlier I called theĀ StringĀ array parameterĀ args, and in the second example I called itĀ stringArray. You can choose the name freely. Let us insert a single instruction into theĀ mainĀ method body. Here is an example of how that could look: package myjavacode; public class MyClass { public static void main(String[] args) { System.out.println("Hello World, Java Program"); } } Now theĀ mainĀ method contains this single Java instruction: System.out.println("Hello World, Java Program"); This instruction will print out the textĀ Hello World, Java ProgramĀ to theĀ console. If only a single Java class in your Java program contains aĀ main()Ā method, then the class containing theĀ main()Ā method is often referred to as theĀ main class. You can have as many classes as you want in your project with aĀ main()method in. But, the Java Virtual Machine can only be instructed to run one of them at a time. You can still call the otherĀ main()Ā methods from inside theĀ main()method the Java Virtual Machine executes (you haven't seen how yet) and you can also start up multiple virtual machines which each execute a singleĀ main()Ā method. After the method's parameter list comes first a left curly bracket ({), then some empty space, and then a right curly bracket (}). Inside the curly brackets you locate the Java instructions that are to be executed when theĀ mainĀ method is executed. This is also referred to as theĀ method body.Ā 
15th Dec 2016, 2:43 PM
Vipul Walia
Vipul Walia - avatar
+ 1
it's the main method, a Java program can't run without it. it's where you put all of your code, you can write code outside of the main method but you need to call it from the main method for it to run. for example public static void main(string []args) { system.out.println("hello Java"); // calling the method outside example(); } // method outside of the main method public static void example() { system.out.println("this is method"); } I don't know if this helps p.s I'm not an expert.
15th Dec 2016, 2:01 PM
kallzo
kallzo - avatar
0
guys i need examples of those public static void ... i dont undertand it properly ... why do we need this ... public static void ....
15th Dec 2016, 3:01 PM
Prashant Malviya
Prashant Malviya - avatar