aspose file tools*
The moose likes Beginning Java and the fly likes main method Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "main method" Watch "main method" New topic
Author

main method

Mathew Lee
Ranch Hand

Joined: Jun 08, 2009
Posts: 238
>>>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

Joined: Oct 13, 2005
Posts: 36478
    
  16
What don't you understand? The quote looks very clear to me.
Mathew Lee
Ranch Hand

Joined: Jun 08, 2009
Posts: 238
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

Joined: Aug 16, 2005
Posts: 13869
    
  10

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".

Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
palanivelrajan subramanian
Greenhorn

Joined: Oct 01, 2009
Posts: 11

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.....


With Regards,
S.Palanivelrajan, Software Engineer
Joanne Neal
Rancher

Joined: Aug 05, 2005
Posts: 3168
    
  10
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.


Joanne
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 13869
    
  10

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

Joined: Oct 01, 2009
Posts: 11

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
 
subject: main method
 
Similar Threads
Simple q on Static and non static
Finished my program but have a big problem
Stupid Confusion about referencing method from main()
Sharpen your pencil, chapter numbers and statics