I want to make a desktop application- an analog-clock with the option of setting alarms using java. For rendering all the graphics and the button features, a Swing applet is the answer.

But the problem is that I want to run the applet onto the desktop and so need an applet viewer like thing. Applet viewer comes with the JDK and I think installing entire JDK on a system for running just a simple alarm clock is really not a good idea at all because it will take a lot of space.

Is there a way out? Can I get just the applet viewer (or anything similar to that) instead of entire JDK so that I can run my applet? Or is there any other way I can do my project using Java?

  • 3
    Make it a standard java application that used the JRE rather than an applet that needs the JDK to view it
    – Deco
    Mar 2 '13 at 14:17
  • Thanks @Deco....it would be rather a better option than making it just Windows compatitable app. Mar 4 '13 at 13:39
  • Why are you worried about a couple hundred megabytes when your system drive is a at least 40 billion megabytes large?
    – Ramhound
    Mar 5 '13 at 18:55
  • @Ramhound - Actually the desktop application I want to make is an analog alarm clock (in Java) and so as anyone in my place would have wanted, I want it to take minimum space on the hard disk and provide best results. Even 10MB matters a lot for this application. Mar 7 '13 at 13:05
  • @DecodingLife - If its a desktop application then the desktop has to have Java ( JRE ) installed. The application itself can be as small as you want to make it.
    – Ramhound
    Mar 7 '13 at 14:09

You need appletviewer to debug java applets, if you want just to run them you need a Java Runtime Environment (JRE) and the Java plugin for your favourite browser.

But if you just need a clock, you can do it just with javascript and HTML5: http://www.neilwallis.com/projects/html5/clock/index.php

  • I want to run it as a general desktop application. Don't want to run in a webpage/browser. Mar 2 '13 at 13:35
  • 1
    In that case you don't have to develop an Applet, but a Swing application with a main() method. Applets aren't meant to be standalone applications. Mar 2 '13 at 13:39
  • 1
    This will not work on Chrome after April of 2015. Chrome is removing the NPAPI and plugins will no longer be an option.
    – avgvstvs
    Apr 9 '15 at 17:10
  • @avgvstvs are you sure that the clock needs NPAPI? Isn't it just HTML5? Apr 9 '15 at 19:06
  • Your first answer discussed a JRE and a java plugin for your favorite browser. If that browser is chrome, after this month it won't work.
    – avgvstvs
    Apr 9 '15 at 22:15

I'm reluctant to post this an answer however there isn't really any way of doing what you want. There is no way around it as the Java code needs the JVM to execute. Well, there is one way around it and that is to use a Java to EXE compiler such as Excelsior. I don't know too much about it other than it can take your Java code and once you have ran it through their compiler you are left with a native exe (I'm assuming you mean windows) that does not rely on a JVM.

Just to expand, I'm not really a Java developer so I'm unsure of how many other tools there are that do what Excelsior JET do; however do be careful as many Java-To-EXE tools don't actually compile your code into a native PE binary, but simply wrap your .jar file into an EXE and still require a JVM to run.

  • The Excelsior JET Runtime actually includes our own JVM. It is just designed to work with both natively compiled and regular classes. Mar 7 '13 at 3:52

To run any Java code, one needs the JVM (Java Virtual Machine) installed on the system. On most systems, this is installed as part of the the JRE (Java Runtime Environment). Developers typically install the JDK (Java Development Kit) which is a superset of the JRE that also includes compilers, debuggers, and associated tools.

Looking at Java SE Technologies at a Glance from Oracle, one can see the additional tools that are part of the JDK that do not come with the JRE.

Applets are part of the applet runtime plugin, the AppletViewer is part of the JDK. One does not need the JDK to see an applet if the applet is hosted on a web page.

If this does not need to be part of a web page, one should instead consider using a stand alone environment that is part of the Java SE world. Swing is under the "User Interface Libraries" in the chart on the oracle page which falls under the JRE.

Writing for a stand alone Java SE (rather than an applet) should make this easier to build and run. See Java : Swing application on Wikipedia to get a very basic idea of a hello world app using this framework. Note in particular the public static void main(final String[] args) { ... } method that exists within the class - this is how one invokes a Java SE application.

If one wanted to avoid needing a separate install of a JVM, it is possible though this comes with various restrictions. The most well known of these is the commercial Excelsior package (its not exactly 'inexpensive'). Excelsior compiles to native code and includes a runtime (the JET runtime) that is capable of dynamically loading other .class files. There also exists gcj, though it appears to be... stale and without any recent (four years) updates. Please read the status page and note that it likely won't fit your needs (java.awt: A lot of code exists, but not enough for use in real applications.)

If you are going to write a java application, your best bet is to have the JRE (one doesn't need the full JDK) on the target machine and build for that. The JRE isn't that big and may very well already be on the target machines.

  • you are mixing up the terms "JVM" and "JRE". A Java app needs a JVM to run, whether it has been reduced to native code using GCJ or Excelsior JET or not. A JVM provides memory management / garbage collection facilities, isolates Java and native execution contexts, and so on. So you cannot avoid needing a JVM. What you can avoid is needing the Oracle JRE. With Excelsior JET, you can also avoid needing some parts of the Java SE API. Mar 7 '13 at 3:58
  • 1
    Look at Java SE Technologies at a Glance from Oracle. The JVM is the virtual machine that comes as part of the Java Runtime Environment. This is the 'HotSpot' item under the 'Java Virtual Machines' column. The JRE also contains the libraries for applets, swing, RMI, JNDI, etc... From the JRE page: The JRE provides the libraries, Java virtual machine, ...
    – user40980
    Mar 7 '13 at 4:22
  • Excelsior claims "An Ahead-Of-Time (AOT) compiler takes as input your jars and class files and produces a conventional native executable for the target platform, such as Windows EXE or Linux ELF binary.". The JET page reads "deploy your Java products without dependency on the JRE" - as the JRE contains the JVM, one would assume this also means it doesn't need the JVM. It has its own runtime that is not the JVM.
    – user40980
    Mar 7 '13 at 4:26
  • See Excelsior JET FAQ, question "How does it work from the technical point of view?" under General Information: "Excelsior JET Runtime is a complete Java Virtual Machine that implements version 6 of the Java SE platform." Mar 8 '13 at 5:00
  • @DmitryLeskov I've updated the information on Excelsior - is that correct now?
    – user40980
    Mar 8 '13 at 16:50

For applet to run without JDK ie not through appletviewer you can follow these steps -

  1. Embed it in HTML using applet tag -
applet ARCHIVE="jar file or external jar files if any" code ="class name with .class extn" width = 800 height =500> 
  1. Create jar file for your code.
  2. Sign all your jar files using jarsigner
  3. Run your HTML file with JRE installed for browsers

you can view your applet in browser with this anywhere.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.