This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes Beginning Java and the fly likes Couple of questions on jar files. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Couple of questions on jar files." Watch "Couple of questions on jar files." New topic
Author

Couple of questions on jar files.

Pavan Kumar Dittakavi
Ranch Hand

Joined: Feb 12, 2011
Posts: 104

Hi All,

I have couple of questions related to jar files. As we know jar files are zipped files which contains classes and other manifest files in it.

1.My first question is, since it is a zipped file, how can an application locate a specific class from it at runtime...is it that applications extract the contents of jar files at runtime and then pick up an appropriate class?. Is there any special mechanisms that come into picture here?

2.Can jar files be delay loaded just as dlls.

Thanks,
Pavan.
Mansukhdeep Thind
Ranch Hand

Joined: Jul 27, 2010
Posts: 1157

Do one thing. Copy any jar file to the desktop. Extract its contents to a folder. Then open the manifest file and see what does it contain. Let me know in case you have further doubts..


~ Mansukh
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38441
    
  23
Why to the desktop?
Mansukhdeep Thind
Ranch Hand

Joined: Jul 27, 2010
Posts: 1157

Campbell Ritchie wrote:Why to the desktop?

Not necessary to desktop only. Important thing is to copy at a separate place and then extract, not the original archive. There is a chance it might get corrupted.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

Extracting data from a jar file might corrupt the jar? That's extremely unlikely.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38441
    
  23
Mansukhdeep Thind wrote: . . . Important thing is to copy at a separate place and then extract, not the original archive. There is a chance it might get corrupted.
Agree. Create a temporary folder, extract it inside that, then you can delete the folder.


And if you are careless and didn’t copy it, the jar file too
Pavan Kumar Dittakavi
Ranch Hand

Joined: Feb 12, 2011
Posts: 104

Hi,..sorry for the late reply. I have extracted a jar file and I could see different type of entries in it for instance, the version of the jar file, the jdk version that has been used for creating it and other entries like the main method that would get executed if one tries to run the jar file.

Just wanted to convey one of my questions again. Since jar file sort of compresses/binds together different classes, would they be unbundled/extracted when the jvm decides to run on of the classes' methods,...say for instance its main method.

Thanks,
Pavan.
Joanne Neal
Rancher

Joined: Aug 05, 2005
Posts: 3477
    
  13
Pavan Kumar Dittakavi wrote:1.My first question is, since it is a zipped file, how can an application locate a specific class from it at runtime...is it that applications extract the contents of jar files at runtime and then pick up an appropriate class?. Is there any special mechanisms that come into picture here?

Unless it specifically says something about this in the Java language Specification, then it is probably entirely up to the JVM developer whether they extract all the files in one go or just extract them as needed.

Pavan Kumar Dittakavi wrote:2.Can jar files be delay loaded just as dlls.

Jar files are not loaded - classes are. And classes are only loaded when they are required.


Joanne
 
jQuery in Action, 2nd edition
 
subject: Couple of questions on jar files.