Saturday, January 10, 2009

Packages and packages

My first instinct when I had created an applet, with a beginning, a middle and an end, was to deploy it - to make it run outside the NetBeans IDE. I needed to revisit packaging not least because the first lesson in the Deployment Trail is entitled Packaging Programs in JAR Files (my italics). What induced Sun to use such confusing nomenclature? It was only after spending hours pouring over every word in the Packaging trail, that I realised that the two concepts are wholly unrelated.

The term package in the context of classes and interfaces refers to an implicitly defined collection of source code files. Belonging to a "package" is an attribute of a source code file, given in the first line of code.

The term package when used in the Java tutorial in the context of deployment has the more common (in my opinion) meaning of bundle of files, or archive, like a zip or rar file. And the file extension of the package even sounds like rar. It is in fact jar, which is presumably an abbreviation of "java archive".

Having sorted that out, I am now ready to start the first lesson in the packaging (second meaning above) trail: Using JAR Files: The Basics. After describing a .jar file in the previous paragraph as like a zip file, I am pleased to read in the first line of this lesson: "JAR files are packaged with the ZIP file format". Why can't they call the sodding things zip files and shorten the Java learning curve a bit?

The lesson continues with instructions on how to create and view jar files and various other routine tasks, and more interestingly how to run an application packaged as a JAR file. Given that most readers will have worked with PKZip and other archiving tools, I shall refrain from plodding through these lessons line by line, but I shall refer to them as I need them.

No comments: