Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

why public static void main(String args[])

 
John Chong
Greenhorn
Posts: 16
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
May I know why the word static? And is args[] used to capture command line input like javac myfile.java kkk?
 
Sean Casey
Ranch Hand
Posts: 625
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
static is a keyword in the java language, and it is also a modifier. When a method or variable is declared static, it means that it can be used throughout the whole class without instantiating an object. If it isn't static, then you must create an object to invoke the non-static method or non-static variable. You are correct about args[]. For instance say I had a program called Go. When I use the command java Go one two
arg[0]= one , arg[1]= two.
 
Val Dra
Ranch Hand
Posts: 439
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
static is not used to catch anything its an access modifier which tells that inside this method you don't need to create any instance of an object to execute it. As for a parameter it takes an array of strings because you might pass certain arguments to your program to let it know what to do. Special conditions that you might think of.
 
Randall Twede
Ranch Hand
Posts: 4353
2
Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Static is a modifier but not an access modifier. When a member is static it means that no matter how many instances of the class you have, there is only instance of the static member which they all share.
 
Val Dra
Ranch Hand
Posts: 439
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ok
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic