Running Java on Non-network Local PC

Running Java on Non-network Local PC

Can a Java applet or executable run locally on a PC if the PC is not connected to a network? Example: I bring up my home page and download the latest version of my Java app. Somehow that app gets saved locally. When I’m not hooked into the network, can I run the app?

In general, the answer is yes, but persistent caching of Java applets may be more difficult to accomplish than you think. In order for a Java applet or application to run locally on your PC, it needs to have all of its class files present locally on the PC’s disk. If that has happened, you can run applets using appletviewer or a Java-enabled browser and execute standalone Java applications using the Java interpreter directly.

The trick, however, is to make sure you have all of the class files cached locally and that you know how to get to them. Browsers typically do cache the Java class files if you enable the cache, such that when you go to your home page and load any applets on there, the browser will download the class files, save a copy in the cache and then run the applet. On subsequent connections, the browser will simply check the time stamp on the class files and if the applet hasn’t changed since it was downloaded, it will use the cached copy.

If you disconnect your PC from the net and try to run the browser again to bring up that page, the browser will not be able to bring up the page or the applet, because it will first attempt to connect to the server to verify that the cached copy is still valid. To work around this limitation, you can try to look into the cache yourself to find the applet’s class files, however, beware that some browsers like Netscape rename the cached files to internally consistent names which are not necessarily human-readable any more.

In most cases, your best bet is to manually download the class files in a place where you can easily manipulate them without worrying about cache consistency issues.


Share the Post: