- How to download and install Java plugin in a browser
- 2. Enable Java support in browsers
- 2.1. Internet Explorer
- 2.2. Google Chrome
- 2.3. Mozilla Firefox
- 2.4. Safari
- 3. Java Plugin Example
- 3.1. Java plugin lifecycle
- 3.2. Example program
- 3.3. Serving Java Plugins
- 4. Download Source Code
- Java Plug-in Framework (JPF) Project
- What is JPF?
- Main features
- What can JPF bring to your Java project?
- Current version and status
- Demo application
- Background
How to download and install Java plugin in a browser
Java applets (Plugins) were introduced in the first version of Java. From early 2010 major browsers started avoiding Java applets because of security constraints and difficulty with the underlying platforms. Java Applets are deprecated in Java 9 and are completely removed from Java 11.
Applets are usually written in Java. However, they can even be written with any other language run on JVM like Jython, Scala, Pascal, JRuby and so on.
Some advantages of Java Applets are as below,
- They can run much faster compared Javascript
- Since they run as a separate process on JVM, they get access to all the system resources including hardware
- Till the canvas support came into existence applets were the favorite to render 3D graphics
- Cross-platform, once created can be run on any platform
It is important to note that, in modern browsers, Java support has to be enabled manually as Java isn’t enabled by default.
2. Enable Java support in browsers
In this section, we will see how Java can be enabled in various browsers on the Windows platform.
2.1. Internet Explorer
- Click on Tools menu and click on Internet Options
- Go to Security tab and click on Custom Levels
- In the new popup scroll to Scripting section and enable/disable Java by going to the section Scripting of Java Applets
2.2. Google Chrome
- Click on the wrench icon on the far right of the address bar
- On the menu click on Settings
- Click on Advanced settings at the end of the Settings menu
- Click on Content Settings
- Scroll down to Plug-ins and look for Java and click on Disable link to turn on/off the Java plugins
2.3. Mozilla Firefox
- Click on the little hamburger icon (Tools menu) on the far right next to address bar and choose Add-Ons menu
- Click on Plugins from the left side menu and scroll down to the bottom
- Click on Java Applet Plugins to enable/disable Java plugins
2.4. Safari
- Go to Preferences
- Click on Security
- Scroll down to Enable Java. Enable or Disable by clicking on the checkbox
3. Java Plugin Example
In this section, I will show how to write a sample Java Plugin. I am using the IntelliJ Idea editor and in the end, I have attached the complete source code.
3.1. Java plugin lifecycle
- Init – init() method is to group initialization logic. This method runs first when the applet is run.
- Start – the start() method runs after the init method and it contains the actual code to run. This method runs each time when the plugin is restored or tabs are switched.
- Paint – paint() method is used to redraw the applet. This method is invoked after the start method and whenever the browser is refreshed and resized.
- Stop – this method is automatically called whenever the user moves off the page where the plugin sits. Stop method is called whenver the plugin window is minimized and even when the browser tabs are switched.
- Destroy – this method is automatically called whenever the browser is shut down normally. This method removes the plugin object from the memory.
3.2. Example program
In this section, I am going to show a basic plugin program that shows the applet lifecycle methods.
package com.jcg.plugin; import java.applet.Applet; import java.awt.*; public class JavaPluginDemo extends Applet < //init method is called only once, when the plugin class is initially loaded public void init() < System.out.println("Plugin initialized"); >//executed immediately after init method. It gets executed each time when the plugin //is reloaded, resized and refreshed public void start() < System.out.println("Plugin execution started"); >//executed whenever the plugin is minimized and user moved to another tab public void stop() < System.out.println("Plugin execution stopped"); >//redraws the output on the plugin. executed immediately after the start method. //executed whenever applet is resized and refreshed public void paint(Graphics g) < System.out.println("Painting the plugin"); g.drawString("Painting the applet. ", 10, 40); >//executed only once like init method. executed when the applet is closed public void destroy() < System.out.println("Plugin is bing removed"); >>
Right-click on the program and click run. This launches the applet viewer. Output in the applet viewer is as in the below image,
Output from the plugin lifecycle methods is as follows,
In the above output, you can notice that start, paint and stop methods are called multiple times. Whereas, init and destroy are called only once.
3.3. Serving Java Plugins
Plugins can be locally viewed in Applet Viewer. When it has to be served to a remote computer, it has to be served via HTML. Below is the sample HTML snippet to serve Java Plugin,
tag is used to serve the applets.
4. Download Source Code
Download
You can download the full source code of this example here: How to download and install Java plugin in a browser
Java Plug-in Framework (JPF) Project
Welcome to the Java Plug-in Framework project, the open source, LGPL licensed plug-in infrastructure library for new or existing Java projects. JPF can greatly improve the modularity and extensibility of your Java systems and minimize support and maintenance costs.
What is JPF?
JPF provides a runtime engine that dynamically discovers and loads «plug-ins». A plug-in is a structured component that describes itself to JPF using a «manifest». JPF maintains a registry of available plug-ins and the functions they provide (via extension points and extensions).
One major goal of JPF is that the application (and its end-user) should not pay any memory or performance penalty for plug-ins that are installed, but not used. Plug-ins are added to the registry at application start-up or while the application is running but they are not loaded until they are called.
Main features
Open framework architecture The framework API is designed as a set of Java interfaces and abstract classes. Developers can choose to implement their own «vision» of plug-ins and Framework runtime behavior. «Standard» or default implementations are provided by JPF so developers can start using the framework quickly and easily. Clear and consistent API design The JPF API has been carefully designed in order to reduce the the time developers need to become familiar with it. Built-in integrity check Registered plug-ins are checked for consistency during JPF start up and a detailed report of results is available. Plug-ins are self-documenting Plug-in developers may include documentation in the plug-in manifest. This includes inline comments or references to documents bundled with the plug-in. Plug-in dependency check Plug-in developers can declare dependencies between plug-ins. Dependency declarations can include the desired version ID and versions matching rules. Strongly typed extension parameters The plug-in manifest syntax provides a mechanism for declaring typed extension points parameters. This information is used by JPF when finding and loading extensions. Lazy plug-in activation Plug-in classes are loaded into memory only when they are actually needed. This feature is provided by specially designed Java class loaders instantiated for each plug-in. «On the fly» plug-in registration and activation Plug-ins can be «hot-registered» and even de-registered during application execution. What’s more, registered plug-ins can be activated and deactivated «on the fly», minimizing runtime resource usage.
What can JPF bring to your Java project?
Plug-in component model A JPF Plug-in is a component that has: a name (ID), a version identifier, code and/or other resources, a well-defined import interface, a well-defined export interface, and well-defined places where it can be extended (extension points). You can think of plug-ins as a module for your application. Divide large applications into smaller, more manageable parts Building applications as a set of independent, cooperating components is particularly useful when developing in teams. Explicitly define the systems architecture Plug-ins, prerequisites, extension points and extensions allow you to clearly define the architecture of your system in an easy-to-understand and standard way. Make the application easily extendable With extension points you can allow other developers to extend your application simply. Documentation embedded into the system This is more than javadoc. You can include documentation in the plug-in manifest and link it with any additional resources. Tight control over application consistency JPF’s built-in integrity check keeps a close watch on your application’s health, reducing maintenance costs. Improved resource reuse The JPF extension points mechanism lets you easily share your code and other resources among different applications.
Current version and status
The latest framework version is 1.0.2 for Java 2 and 1.5.1 for Java 5. It was released on May 19, 2007 and has been designated as production quality. The framework API is considered to be stable and «frozen». The runtime behavior of the framework has been reported as very stable (some projects using JPF have reported containing dozens and hundreds of plug-ins, see references).
If JPF starts successfully — it just works and works 🙂
Demo application
The best way to get a feel for JPF and how to use it is to look at the example modular application provided with JPF and try to write your own JPF plug-ins. This demo application is available from the JPF download page.
The demo application includes a «Plug-in Browser Tool» that may be useful to analyze the plug-in structure and dependencies.
Background
This project was inspired by and continues to be influenced by the Eclipse Platform — an open source Java IDE and «rich client» GUI applications platform.
The plug-in architecture used by Eclipse was taken as the basic model for JPF in early 2004. JPF is can be considered as an attempt to «decouple» the plug-in framework from Eclipse 2.x for use in any Java project. Note that although Eclipse plug-ins are visually very similar to JPF plug-ins, they are NOT compatible and thus can’t be used together.
© 2004 — 2007 JPF Team Direct e-mail: Last modified: 2007-07-02 21:33