This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

main method

 
Mathew Lee
Ranch Hand
Posts: 238
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
>>>Also not that because it is static you cannot manipulate non static methods or data. Because of this the main method often contains very little code, typically it contains code to create an instance of the enclosing class and then a call to a non static method that really gets the program to do its work.






I was reading above lines from link
http://www.jchq.net/certkey/0401certkey.htm

did not understand it clearly.


Any ideas, resources,sample code,links, highly appreciated. thanks in advance.
 
Campbell Ritchie
Sheriff
Pie
Posts: 47293
52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What don't you understand? The quote looks very clear to me.
 
Mathew Lee
Ranch Hand
Posts: 238
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I did not understand

>>>not that because it is static you cannot manipulate non static methods or dat

Please advise
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Pie
Posts: 15150
31
Android IntelliJ IDE Java Scala Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do you know what static means?

It means that something belongs to the whole class, rather than to specific objects of the class. If you have a static member variable, then there is only one copy of that variable, which is shared by all instances of the class - rather than every object having its own copy of the variable. See Understanding Instance and Class Members in Oracle's Java Tutorials for a more detailed explanation.

Note that the main method is static. That means that it is called on the class and not on any particular object of the class. You cannot access non-static member variables from inside a static method, because when the static method is running there is no "current object".
 
palanivelrajan subramanian
Greenhorn
Posts: 11
Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also not that because it is static you cannot manipulate non static methods or data. Because of this the main method often contains very little code, typically it contains code to create an instance of the enclosing class and then a call to a non static method that really gets the program to do its work.



In the above quote... they mentioned that we can call a non-static method from main method..but literally we can't able to do that... if we want to call a method from the main method then that method should be static.....
 
Joanne Neal
Rancher
Pie
Posts: 3742
16
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
palanivelrajan subramanian wrote:In the above quote... they mentioned that we can call a non-static method from main method..but literally we can't able to do that... if we want to call a method from the main method then that method should be static.....

It could have been phrased better but I think you'll find they meant you could call a non-static method using the instance of the enclosing class that had just been created.
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Pie
Posts: 15150
31
Android IntelliJ IDE Java Scala Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
palanivelrajan subramanian wrote:
Also not that because it is static you cannot manipulate non static methods or data. Because of this the main method often contains very little code, typically it contains code to create an instance of the enclosing class and then a call to a non static method that really gets the program to do its work.



In the above quote... they mentioned that we can call a non-static method from main method..but literally we can't able to do that... if we want to call a method from the main method then that method should be static.....

To express it in code:

 
palanivelrajan subramanian
Greenhorn
Posts: 11
Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi jesper its fine......but they didn't mentioned clearly.. that's what only i got confused......
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic