Monday, August 18, 2008

zip vs jar. When to use what? Which one is performant?


zip vs jar. When to use what? Which one is performant?

jar - the default 'jar' utility (and a file format as well. Read more about the JAR file format in this article - JAR, WAR, and EAR >>) is the Sun's implementation which has been written in Java language. This is obviously slower (though only slightly) than those 'jar' utilities which have been written using C language. 'fastjar' is an example of a 'jar' tool written in C. Though it has its own limitations, but it's slightly faster than the default 'jar' implementation supplied by Sun Microsystems with JDK.

'jar' mainly supports class, audio, and image file formats and whenever a new file is added to a jar file then the utility first checks the format of the file and accordingly it may need to the MANIFEST file or any other indexes if applicable. Read more about the manifest file in this article - MANIFEST file of a jar file >>

zip - this is a simple archiving and compressing tool (and a file format as well). In fact the JAR file is also internally archived and comprssed as a zip file only. Unlike a jar file it doesn't maintain any additional information about the files or the type of the files contained in the archive. Obviously this archiving tool is much more faster than 'jar', and hence this is recommended in the cases where the archiving of the files is all what the user needs.

jar vs zip

  • jar involves extra overhead and hence not as faster as zip.
  • jar maintains extra information and hence an application or tool can use that information for an intelligent processing of the contents of the 'jar' file. For example: a 'jar' file can be made executable and the tool will automatically check the MANIFEST file to get the class file whose main() method will be run to start the execution. Another example is the use of INDEX.LIST file to implement the JarIndex mechanism for faster search of the contents of a JAR file. Read more about it in this article - JarIndex mechanism >>
  • jar utility has been written in Java as well as in C. The default implementation of this utility shipped with JDK is a Java based implementation and hence it may not be as performant as a C-language based implmentation such as 'fastjar'. So the performance of a 'jar' tool also depends upon which implementation one uses. This is not the case with the native 'zip' utility.
Thus we see that 'zip' will almost always have better performance and hence recommended if the user is interested only in archiving and 'jar' should be used only when the extra information supplied with the resultant JAR files are being used (or will be used in the future) by the application (or the tool) in some way or the other.



Share/Save/Bookmark


3 comments:

Anonymous said...

hi,geek

how can we create explorer like functionality in java/j2ee.
is there any method to create it without using swing.

thanks.

Anonymous said...

hi, geek
i want to refresh my page automatically whenever any event(eg.remove link)occur.
plz help me.

thanks

Geek said...

Hello Ranvijay,

Please find below the answers to your questions:-

How to implement a explorer type functionality using Java/J2EE?

I believe you're looking to implement menus which can expand and collapse just like the Windows Explorer tree. If that's the case using a plain JSP is not advisable. You can use the JavaServer Faces technology instead.

You can either think of using the plain JSF or any of the several even better alternatives including Apache MyFaces, ADF Faces, etc.

You just need to create a master-detail relationship as per your requirements and then you can use the 'tree' component to implement the expanding-collapsing menus very easily.

You may like to go through the following links to learn more:-

JSF Documentation: http://java.sun.com/javaee/javaserverfaces/reference/docs/index.html
Developing sample Web App with JSF: http://java.sun.com/developer/technicalArticles/GUI/JavaServerFaces/
Apache MyFaces: http://myfaces.apache.org/index.html
Integration strategy for Struts and JSF: http://www.mail-archive.com/struts-dev@jakarta.apache.org/msg08457.html

Refreshing page automatically based on some event

Agan using a plain JSP will make the implementation very difficult (if at all possible). You can use JSF PPR (Partial Page Rendering) to implement any such scenario in just few minutes. Apache MyFaces and ADF Faces take the ease and power of implementation few notches even higher than JSF.

Apache MyFaces PPR: http://myfaces.apache.org/trinidad/devguide/ppr.html


Hope the info helps. Keep visiting/posting!