Intermediate Java

Week 6 Review Questions

1. What are the local Java deployment options?
executable JAR, or Java Web Start
2. What does JAR stand for?
Java Archive
3. What is JAR for?
A JAR file bundles multiple files into a single archive file, usually the files associated with an application, or with an applet, so you can pass over the whole bundle of class files in one file, a JAR file.
4. What is the key feature of packages?
Classes are in a directory structure that exactly matches the package structure. As described in answer 7, a class ca.solveig.SomeClass.class is in a directory solveig, within a directory ca, within a directory classes, within the package.
5. What is the best way to guarantee the package name to be unique?
Preface your package name with the reverse name of your domain ( if you have one!). Your class names will all belong to this package, and will have names like, for example, ca.solveig.myPackagename.Classname . This means you only have to worry about in-house class name conflicts.
6. What is the purpose of manifest.mf file?
The manifest file contains information about the files packaged in a JAR file.
7. What do you need to do to put a class in a package?
Imagine a package called KrisJava, made by a person with a domain solveig.ca. Write, in each java file, a new first line package ca.solveig , making sure it is the very first line, before any import instructions. Create a directory structure to store your files. that will match your package name. The package KrisStuff will have a root directory called KrisStuff, and a subdirectory called source, with a subdirectory called ca with a subdirectory called solveig. Put all the source (.java) files here. Compile from the source directory, using the -d tag, and giving ../classes as the argument for where the files will go, and ca/solveig/ClassName.java as the argument for the file to compile. As you compile each file, it will into the correct directory structure for your package. The classes directory ( a sister directory to source) will be created, and a subdirectory ca, and a subdirectory to it called solveig, within which the .class files will be placed.
8. What do you need to do to make your compiled class land in the correct package directory? structure under the classes directory?
see answer to 7
9. On what archiving format is JAR based?
pkZIP file format
10. How do you make an executable JAR file?
Make sure that your JAR file contains a class with a main method, and make sure that the manifest contains the information about which class that MAIN-CLASS is. ( Or that you give the JAR the entry point for the main method.
11. How do you create a JAR file?
From your classes directory in your package, use the command line code jar cvmf manifest.txt nameofjar.jar ca where manifest.txt is the textfile you wrote to add info to the manifest, and ca is the extension to your domain, that you used in making your package.
12. How do you run an executable JAR file?
If you have a package, from your classes directory, in the command line, type java FullyQualified ClassName in the command line, where the class name will include the inverse domain name you based you package on, e.g. java ca.solveig.Main for my answer 7 example, where the main method is in the Main.class within the package.
13. What happens if you try to run an executable JAR, and the end-user does not have java installed?
Won't run
14. True or false: the entire package directory structure (and only the directories matching the package) must be immediately inside the JAR file?
True