Architecture Java Runtime Environment
Architecture Java Runtime Environment
Architecture Java Runtime Environment
Java technology can download from the internet and run. An applet is
typically embedded inside a web page and runs in the context of a browser.
An
applet
must
be
a
subclass
of
the java.applet.Applet class.
The Applet class provides the standard interface between the applet and the
browser environment.
There are some important differences between an applet and a standalone
Java application, including the following:
When a user views an HTML page that contains an applet, the code for
the applet is downloaded to the user's machine.
The JVM on the user's machine creates an instance of the applet class
and invokes various methods during the applet's lifetime.
Applets have strict security rules that are enforced by the Web
browser. The security of an applet is often referred to as sandbox
security, comparing the applet to a child playing in a sandbox with
various rules that must be followed.
Other classes that the applet needs can be downloaded in a single Java
Archive (JAR) file.
Architecture
Java Runtime Environment
With the Java Plug-in, applets are not run in the JVM inside the browser.
Instead, they are executed in a separate process. The same JVM process can
be shared between multiple applets, or applets may be placed into different
processes depending on whether the existing JVMs match the applet
requirements and have enough resources to execute the applet. An applet
can request specific version of JRE to be used and can specify what options
need to be passed to the JVM. An applet can also request to be executed in
the separate JVM.
The browser and the applet can still communicate with one another,
however. Existing APIs have been re-engineered to use process sockets, so
things continue to work as they did before, only better. This architecture
provides a number of benefits:
With that architecture, a new JRE can be launched whenever it is needed. But
an applet will run in an existing JRE as long as:
a.
The JRE version required by the applet matches an existing JRE, and
b. The JRE's launch parameters satisfy the applet's requirements
Thread Considerations
A web browser's JavaScript interpreter engine is single thread. The Java Plugin is capable of managing multiple threads. The Java Plug-in creates a
separate worker thread for every applet. Applets themselves may be multithreaded. Applets making JavaScript to Java calls and vice versa should be
designed with the thread related issues in mind.
The following picture shows the thread interactions between the JavaScript
Interpreter, Java Plug-in and an applet (i.e. Java).
When the JavaScript interpreter is idle, the Java Plug-in executes a JavaScript
to Java call on the per applet worker thread (JavaScript Interpreter Not Busy
scenario).
Applet Privileges
All applets should be signed with a certificate from a recognized certificate
authority. The user must agree to run an applet and having a valid certificate
provides the user with some assurance that the applet is safe to run. An
applet runs in a secure sandbox that prevents it from interacting with the
users system, unless authorized. To obtain that authorization, the applet
must request permissions when it is launched and the user must agree to run
the applet. Permissions are needed to:
Print
Access the file system
Sandbox Applets
Sandbox applets are restricted to the security sandbox and can perform the
following operations:
They can make network connections to the host and port they came
from. Protocols must match, and if a domain name is used to load
the applet, the domain name must be used to connect back to the
host, not the IP address.
They
can
easily
display
HTML
documents
using
the showDocument method of the java.applet.AppletContext class.
They can invoke public methods of other applets on the same page.
Applets that are loaded from the local file system (from a directory
in the user's CLASSPATH) have none of the restrictions that applets
loaded over the network do.
When launched by using JNLP, sandbox applets can also perform the
following operations:
o
They can store data on the client, decide how applets should
be downloaded and cached, and much more. See JNLP API for
more information about developing applets by using the JNLP
API.
See System
Privileged applets
Privileged applets do not have the security restrictions that are imposed on
sandbox applets and can run outside the security sandbox.
Applet Hierarchy
Running state
3.
4.
Dead state
The life cycle of an applet is begin on that time when the applet is first loaded into the
browser and called the init() method.
The init() method is called only one time in the life cycle on an applet.
The init() method is basically called to read the PARAM tag in the html file.
The init () method retrieve the passed parameter through the PARAM tag of html file using get
Parameter() method .
All the initialization such as initialization of variables and the objects like image, sound file are
loaded in the init () method .
After the initialization of the init() method user can interact with the Applet
Syntax:
public void init()
{
Statements
}
Running State
After initialization, this state will automatically occur by invoking the start method of applet
class which again calls the run method and which calls the paint method.
The running state also occurs from idle state when the applet is reloaded.
This method may be called multiples time when the Applet needs to be started or restarted.
For Example if the user wants to return to the Applet, in this situation the start Method() of an
Applet will be called by the web browser and the user will be back on the applet.
The idle state will make the execution of the applet to be halted temporarily.
Applet moves to this state when the currently executed applet is minimized or when the user
switches over to another page.
From the idle state the applet can move to the running state.
The stop() method can be called multiple times in the life cycle of applet Or should be called
at least one time.
For example the stop() method is called by the web browser on that time When the user
leaves one applet to go another applet
Syntax:
public void stop()
{
Statements
}
Dead State
When the applet programs terminate, the destroy function is invoked which makes an applet
to be in dead state.
The destroy() method is called only one time in the life cycle of Applet like init() method.
Syntax:
public void destroy()
{
Statements
}
Display State
The applet is said to be in display state when the paint method is called.
This method can be used when we want to display output in the screen.
paint() method is must in all applets when we want to draw something on the applet window.
1.
26.
27.
28.
29.
30.
31.
32.