Java programming course: 20.1 Other Java features


Other Java features

The desktop application developed in this course used many, but not all, of the major facilities of the Java language. This final section provides a brief look at some of the other useful features.

In this section you will learn:

  • How you can distribute your application
  • How you can draw graphics and images to the screen
  • How to create JavaBeans
  • How to approach writing distributed client-server applications

Distributing your application

Now that you have completed the desktop application in this course, you may wonder how it might be possible to distribute it so that it can run on a different machine. When you run a Clean and Build for your project you will notice a few lines sent to the Output window, at the end of which you should see the following:

To run this application from the command line without Ant, try:
java -jar "C:\path-to-project\VirtualZoo\dist\VirtualZoo.jar"
jar:
BUILD SUCCESSFUL (total time: 3 seconds)
 

The path-to-project will be different for your computer, and it points to the path on your system in which you will find the file VirtualZoo.jar. As briefly mentioned in an earlier section, a JAR file is a Java Archive consisting of all of the compiled classes that make up your application. It also contains a manifest file, being a simple text file, which provides the JVM with information about the JAR. Because the VirtualZoo application has a class with a main() method to start it off, the manifest will contain a pointer to this. NetBeans automatically generates this for you, and you can view it by doing the following steps:

  1. Click on the Files tab (next to the Projects tab)
  2. Under the VirtualZoo node expand the dist node
  3. Under the dist node expand the VirtualZoo.jar node
  4. Under the VirtualZoo.jar node expand the META-INF node
  5. Under the META-INF node open the MANIFEST.MF file

You should see something resembling the following:

Manifest-Version: 1.0
Ant-Version: Apache Ant 1.8.2
Created-By: 1.6.0_26-b03 (Sun Microsystems Inc.)
Class-Path: lib/Utilities.jar lib/jlfgr-1_0.jar
X-COMMENT: Main-Class will be added automatically by build
Main-Class: virtualzoo.VirtualZoo
 

The Main-Class entry will tell the JRE the path to the class that contains the main() method to start the application.

If you locate the jar file on your system, you should see that its file type is Executable Jar File. You can double-click on this to launch it independently of NetBeans, and you can distribute the JAR file to any other computer that has a JRE of at least the same version installed on it.



Print
×
Stay Informed

When you subscribe, we will send you an e-mail whenever there are new updates on the site.

Related Posts

 

Comments

No comments made yet. Be the first to submit a comment
Monday, 27 October 2025

Captcha Image