Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how does JVM run a applet

 
Suman Mummaneni
Ranch Hand
Posts: 96
Android Java Mac
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi guy,
I am a bit confused about Applet. To run any Java program by a JVM it must have a static main method that will be called by the JVM, but in an applet we do not have any main method. The init method will initilize the applet but. How does the JVM get access to the instance of the applet?

As I know there are two way of running an applet.
1. Via a web browser by embedding the applet in a HTML page
2. Using the appletviewer tool provided by Sun in its JDK distribution.

In the second case I can imagine the appletviewer has a main class that has a main method that will create the applet instance and call the method present in it.
But in the first case when its run by a web browser how does the web browser invoke the applet?

There is also another case where there are various JVM impl. like MS Java and Sun Java. If both are installed on then they both must be following a common spec to run a applet?


Thanks in advance.
 
Ulf Dittmer
Rancher
Posts: 42969
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What you ask is called the "applet life cycle", and it's described in many places, e.g. here. The bottom line line is that the browser has to call the various applet methods at appropriate times, just like a servlet container calls a servlets methods at various times.

I'm not sure what the question about Sun JVM vs. MS JVM is getting at; can you elaborate a bit? All JVMs must implement the JVM spec; it's the browser that calls into the JVM to make applets work.
 
Suman Mummaneni
Ranch Hand
Posts: 96
Android Java Mac
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you. You cleared my doubt on the first one.

The question regarding the JVM's is how will the browser know which JVM to invoke when it has to run the applet.
Usually windows comes with the Microsoft JVM. If I install a Sun's JRE its will install the Sun's JVM also and add extension to the Internet Explorer. Now my question is do we need to add some special code in the applet to tell the browser that it should only invoke the Sun's JVM not the Microsoft one? Or its just the browser that decides which one to invoke based on the byte code it gets.
 
Ulf Dittmer
Rancher
Posts: 42969
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The applet can't decide which JVM is used - that's up to the browser. I think if the Sun plugin is installed for IE, then it will be used, and never the MS JVM. Either way, it's not decided by looking at the applet, it's a fixed setting for the browser.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic