• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Knute Snortum
  • Paul Clapham
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Frits Walraven
Bartenders:
  • Ganesh Patekar
  • Tim Holloway
  • salvin francis

main method  RSS feed

 
Ranch Hand
Posts: 238
  • 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.
 
Marshal
Posts: 64494
225
  • 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
  • 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
 
Java Cowboy
Posts: 16084
88
Android IntelliJ IDE Java Scala Spring
  • 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".
 
  • 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.....
 
Rancher
Posts: 3742
16
  • 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
Posts: 16084
88
Android IntelliJ IDE Java Scala Spring
  • 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
  • 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......
 
The glass is neither half full or half empty. It is too big. But this tiny ad is just right:
how do I do my own kindle-like thing - without amazon
https://coderanch.com/t/711421/engineering/kindle-amazon
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!