So this line
public static void main(String[] args)
is used only once per class right ? It is to allow me to use strings and anything else ? My basic understanding is that it is used to store the... strings used in that class inside it or something like that (everywhere i red the explanations were a bit too complex for me to understand it fully. But then comes my last question, how do i decide where in my code to write this line, because I have seen some programs have it on the top just below the class name, others have it somewhere in the middle or in the bottom, so how to decide where to use it and can i just always put it first on the top so i don't have to think about it ?
Asked
Active
Viewed 55 times
-4

sem3456
- 9
- 1
-
8I recommend you work through a series of Java tutorials. What you've said above about `main` is not at all correct, which is *fine*, we all start out not knowing things, and then we learn them. But the best way to do that is by studying tutorials. – T.J. Crowder Aug 12 '16 at 18:22
-
google (or bing it if you want to) java command line argument – Steve Aug 12 '16 at 18:23
-
Suggested reading: [the main method](https://docs.oracle.com/javase/tutorial/getStarted/application/#MAIN) – copeg Aug 12 '16 at 18:26
1 Answers
0
public static void main(String[] args)
is supposed to be the method that runs first in your class. String[] args
is so if you export your project as a runnable jar, you can open it using commandline, and it will receive your commands as an array of String objects. See this answer for more information: What is "String args[]"? parameter in main method Java
You can really put it anywhere as long as it is within your class (something like this works)
public class ClassName {
//you can put other methods here if you want
public static void main(String[] args) {
//do stuff
}
//you can put other methods here if you want
}

Community
- 1
- 1

hackergirl808
- 89
- 6
-
Ok, I red what you gave me, only the last question remains, whats the difference where in my program I write it, I am left with the feeling i can write it anywhere and it will be all the same ? – sem3456 Aug 12 '16 at 18:57