aspose file tools*
The moose likes Java in General and the fly likes Importance of main Method Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Importance of main Method" Watch "Importance of main Method" New topic
Author

Importance of main Method

Ragupathirajan Venkatesan
Ranch Hand

Joined: Aug 18, 2010
Posts: 62
Hi Friends,

I have one basic doubt. If we want to run any method or enything else from the java class, we need main method to notfy the JVM about our implementation. Execution starts from main method and it goes behind the logic. Now how about the case in servlets or struts actions? Their logic also executed by JVM but with out main method. What is the hidden logic behind that? Whether the framework(struts) takes care of implementing the method or what is happening correctly?

I have some idea about this but not sure whether it is true or not and looking for answer from experties.

Thanks in advance.

Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61434
    
  67

That's because servlets are not standalone programs. They are executed as part of a larger program -- the servlet container.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Ragupathirajan Venkatesan
Ranch Hand

Joined: Aug 18, 2010
Posts: 62
Thanks for your reply. One more info, either stand alone program or servlet at last everything will be considered and java .class file and JVM support is reuired to run the logic in that servlet file as well. Please correct me if I am wrong. Though it is executed by servlet container, at one point of time container needs the JVM support.
Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

The servlet container has its own main() method. That main method might look something like this:


Of course, it's more complex than that, but that's the basic idea.


Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61434
    
  67

Of course the container runs in the JVM.
Ragupathirajan Venkatesan
Ranch Hand

Joined: Aug 18, 2010
Posts: 62
Dear Both,

Thanks for your post. Please correct my understanding here. In Java stand alone program main method will make the class to be loaded into JVM from there on JVM will take care of the execution. In case of servlet or startus action, bootstrap class loader will load the class into JVM, there by execution starts like stand alone program.

Of course, something should be there in class loader, that may be the one you have highlighted in your previous post. expecting your comments on my assumption.

Thanks
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12806
    
    5
there by execution starts like stand alone program.


Nope - execution by the JVM started when the servlet container (Tomcat) is started. Tomcat continues to run various bookkeeping threads and waiting for a request.

Tomcat controls the Threads which will execute the servlet code in response to a request. Servlets do not run like standalone programs, they run in a controlled environment.

Bill


 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Importance of main Method