<< August 1, 2008 | Home | August 3, 2008 >>

Saturday Java Quiz: Know Your javac Command

Yesterday at lunch, I asked Charles: "It's Friday today, isn't it?" Charles said back: "That's sad."

Sadder still, even after the Friday-ness was confirmed, it didn't occur to me that I have been negligent of my Friday Java Quiz duties for two weeks in a roll.

So here goes, a day late, but just as punishing and irrelevant.

The set up: You have the Sun JDK (or OpenJDK) installed with javac and friends in your $PATH. You do not have $CLASSPATH set. And you have a bunch of jar files sitting in a directory, say, /usr/share/java. And you have written a class Foo.java in your home directory that uses a class in one of the jar files.

Q: Which of the following commands will successfully compile Foo.java:

  1. javac Foo.java
  2. export CLASSPATH=`echo /usr/share/java/* | tr ' ' :` ; javac Foo.java
  3. javac -classpath ".:/usr/share/java/*" Foo.java

You are allowed to check the man page for javac, but don't start to try out the commands before you have read the man page.

The command shown are Linux commands and as shown, won't work on Windows. Windows users should try the Windows equivalents of the above.

Tags :