Wednesday, March 12, 2008

Three simple Java Questions

As more and more tivoli products rely on Java as the primary platform, it is very important to understand the basics of Java. This article gives you some answers to Java related questions.

What is a Java Class?

As you know, everything in Java is executed in a Java Virtual Machine, which has its own instruction set. When you compile the Java code, the compiler (javac) outputs the instructions for JVM in bytecode format (cf. machine code for executables) and the output file is called "class file", usually with .class extension. The class file is platform-independent and can be executed on any platform without having to recompile the program.

What is the role of CLASSPATH?

In Windows/Unix, the PATH variable specifies the directories containing your executables, so that you do not have fully qualify the path to each command. (imagine doing /bin/ls everytime :-)). In the same way, CLASSPATH variable contains the directories containing Java class files. However, in addition to class directories, Java CLASSPATH may contain zip or jar (Java Archive) files as well in the CLASSPATH.

What is a jar file?

A java archive file is a Java distribution package containing several related .class files zipped in a single file, usually with .jar extension. The .jar files can be opened by programs such as winzip, but it is better to use the built-in jar command that comes along with JRE to extract/create it. The jar command has a syntax similar to that of Unix tar command, for example to extract the contents of test.jar file, you could run the following command.

$ jar -xvf test.jar

Hope you find this information useful.

No comments: