File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Importance of main Method

 
Ragupathirajan Venkatesan
Ranch Hand
Posts: 62
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64171
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's because servlets are not standalone programs. They are executed as part of a larger program -- the servlet container.
 
Ragupathirajan Venkatesan
Ranch Hand
Posts: 62
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 6109
6
Android IntelliJ IDE Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64171
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Of course the container runs in the JVM.
 
Ragupathirajan Venkatesan
Ranch Hand
Posts: 62
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13044
6
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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


 
Don't get me started about those stupid light bulbs.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic