ArtsAutosBooksBusinessEducationEntertainmentFamilyFashionFoodGamesGenderHealthHolidaysHomeHubPagesPersonal FinancePetsPoliticsReligionSportsTechnologyTravel

ECLIPSE IDE - Demistfying JAVA packages and jar files

Updated on August 5, 2014

What is a JAVA package?

A JAVA package in simplest terms is a collection of classes which are part of a JAVA project. All classes for a project can belong to a single package, however when a project is large and complex a strategy of organizing classes is generally implemented. Multiple packages are used to organize classes which are somehow related, perhaps by functionality or related to a specific application (such as a database application).

A Simple Package Study in ECLIPSE

Let's just take the simplest case of the Hello World! tutorial application in ECLIPSE.

If you followed my tutorial "ECLIPSE IDE - A Walk Through Creating the "Hello World!" Tutorial Application" or worked through the tutorial on you own. there is a point where you create the class HelloWorld. In creating the class, the screen presented has a entry for a package name (which is not required to be specified)..Since the tutorial did not indicate the need for an entry, if you followed the instructions explicitly, you didn't enter anything. A yellow caution symbol and message was raised when you clicked on FINISH.

You might have become aware of a warning message which appears when clicked FINISH. The message illustrated below says the use of a default package is discouraged and you wondered why.


Warning about Default Package Use

What is the difference between default and named packages?

Let's perform an experiment to demonstrate the differences. Let's assume that you have a project and need to create 3 classes. We will create the classes first without specifying a package name, then repeat the experiment creating the three classes in a packaged named HelloProgramPackage. Now let's look at the directory structure in each case.

Classes Created in Default Package

Note that in the project source (Hello World) the class files appear in the src subdirectory.
Note that in the project source (Hello World) the class files appear in the src subdirectory.

Classes Created in a Named Package

Specifying a package name results in a subdirectory of src to be created with the package name.
Specifying a package name results in a subdirectory of src to be created with the package name.

Packages and jar files

Specifying a package name when you create classes help to segregate associated related files. For a complex application there may be classes with different functionality. When creating them it would be best to keep them separate. Also, it would segregate class files form other files which might be created in the src sub-directory of the project sub-directory of the workspace. For now, for our purposes of learning ECLIPSE the best practice is to always create a class in a named package. In our next lesson, we will look at the standard, formal naming of packages.

Another advantage has to do with the philosophy of using an IDE such as ECLIPSE. Rather than creating all of code for an application from scratch, code can be shared and reused. A well defined and documented package can be distributed.

So, where do Jar files come into play?

As a package can become quite large, a convenience for distributing and using them is by means of a jar file. The jar extension to the file name stands for Java ARchive. jar fiiles are compressed files similar to zip files. They can be created (compressed) or extracted (uncompressed).

More on .jar Files

You can open a command prompt window and type jar to see if it is on your path. if you get a error message you can set up your environment by performing the following steps:

  1. Click on Computer from the Start
  2. Select Properties
  3. Select Advanced Setting
  4. Click the Environment Variables button
  5. Under System Variables click New
  6. Enter the variable name as JAVA_HOME
  7. Enter the path to the JDK (Java Development Kit)
  8. Click OK
  9. Click Apply Changes


Start a command prompt and type jar.

Use the two following illustrations as an outline.

Setting Up the JAVA_HOME Environmental Variable

Running jar from the Command Line

Knowing how to use the jar command may prove quite useful.
Knowing how to use the jar command may prove quite useful.
Cast your vote for Value to You of This Tutorial

Wrap-Up and What's Next

In this tutorial we have discussed creation of packages and given a hint as to why named package specification is a best practice. The definition of a jar file given and the procedure for setting up JAVA_HOME will aid in the use of the jar executable in future.

In a previous tutorial we discussed the file structure some what in depth. In the next tutorial we will take a closer look at both the "anatomy" of both the ECLIPSE product and the developer's workspace.

working

This website uses cookies

As a user in the EEA, your approval is needed on a few things. To provide a better website experience, hubpages.com uses cookies (and other similar technologies) and may collect, process, and share personal data. Please choose which areas of our service you consent to our doing so.

For more information on managing or withdrawing consents and how we handle data, visit our Privacy Policy at: https://corp.maven.io/privacy-policy

Show Details
Necessary
HubPages Device IDThis is used to identify particular browsers or devices when the access the service, and is used for security reasons.
LoginThis is necessary to sign in to the HubPages Service.
Google RecaptchaThis is used to prevent bots and spam. (Privacy Policy)
AkismetThis is used to detect comment spam. (Privacy Policy)
HubPages Google AnalyticsThis is used to provide data on traffic to our website, all personally identifyable data is anonymized. (Privacy Policy)
HubPages Traffic PixelThis is used to collect data on traffic to articles and other pages on our site. Unless you are signed in to a HubPages account, all personally identifiable information is anonymized.
Amazon Web ServicesThis is a cloud services platform that we used to host our service. (Privacy Policy)
CloudflareThis is a cloud CDN service that we use to efficiently deliver files required for our service to operate such as javascript, cascading style sheets, images, and videos. (Privacy Policy)
Google Hosted LibrariesJavascript software libraries such as jQuery are loaded at endpoints on the googleapis.com or gstatic.com domains, for performance and efficiency reasons. (Privacy Policy)
Features
Google Custom SearchThis is feature allows you to search the site. (Privacy Policy)
Google MapsSome articles have Google Maps embedded in them. (Privacy Policy)
Google ChartsThis is used to display charts and graphs on articles and the author center. (Privacy Policy)
Google AdSense Host APIThis service allows you to sign up for or associate a Google AdSense account with HubPages, so that you can earn money from ads on your articles. No data is shared unless you engage with this feature. (Privacy Policy)
Google YouTubeSome articles have YouTube videos embedded in them. (Privacy Policy)
VimeoSome articles have Vimeo videos embedded in them. (Privacy Policy)
PaypalThis is used for a registered author who enrolls in the HubPages Earnings program and requests to be paid via PayPal. No data is shared with Paypal unless you engage with this feature. (Privacy Policy)
Facebook LoginYou can use this to streamline signing up for, or signing in to your Hubpages account. No data is shared with Facebook unless you engage with this feature. (Privacy Policy)
MavenThis supports the Maven widget and search functionality. (Privacy Policy)
Marketing
Google AdSenseThis is an ad network. (Privacy Policy)
Google DoubleClickGoogle provides ad serving technology and runs an ad network. (Privacy Policy)
Index ExchangeThis is an ad network. (Privacy Policy)
SovrnThis is an ad network. (Privacy Policy)
Facebook AdsThis is an ad network. (Privacy Policy)
Amazon Unified Ad MarketplaceThis is an ad network. (Privacy Policy)
AppNexusThis is an ad network. (Privacy Policy)
OpenxThis is an ad network. (Privacy Policy)
Rubicon ProjectThis is an ad network. (Privacy Policy)
TripleLiftThis is an ad network. (Privacy Policy)
Say MediaWe partner with Say Media to deliver ad campaigns on our sites. (Privacy Policy)
Remarketing PixelsWe may use remarketing pixels from advertising networks such as Google AdWords, Bing Ads, and Facebook in order to advertise the HubPages Service to people that have visited our sites.
Conversion Tracking PixelsWe may use conversion tracking pixels from advertising networks such as Google AdWords, Bing Ads, and Facebook in order to identify when an advertisement has successfully resulted in the desired action, such as signing up for the HubPages Service or publishing an article on the HubPages Service.
Statistics
Author Google AnalyticsThis is used to provide traffic data and reports to the authors of articles on the HubPages Service. (Privacy Policy)
ComscoreComScore is a media measurement and analytics company providing marketing data and analytics to enterprises, media and advertising agencies, and publishers. Non-consent will result in ComScore only processing obfuscated personal data. (Privacy Policy)
Amazon Tracking PixelSome articles display amazon products as part of the Amazon Affiliate program, this pixel provides traffic statistics for those products (Privacy Policy)
ClickscoThis is a data management platform studying reader behavior (Privacy Policy)