wood burning stoves 2.0*
The moose likes Associate Certification (SCJA,OCAJ 5/6) and the fly likes javac -cp legal? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Associate Certification (SCJA,OCAJ 5/6)
Bookmark "javac -cp legal?" Watch "javac -cp legal?" New topic

javac -cp legal?

Stu Thompson
Ranch Hand

Joined: Jun 14, 2006
Posts: 136
The Sun java docs (http://java.sun.com/j2se/1.5.0/docs/tooldocs/windows/classpath.html) and whizlabs SCJA exam simulator say that the -cp option is only valid for the java command, and not javac.

BUT, when i type javac at the command line I see -cp as an option.

So which is it for the exam? I think I am inclined to go for whatever Sun says in the documentation.



"This is not to say that design is unnecessary. But after a certain point, design is just speculation." --Philip Chu
marc weber

Joined: Aug 31, 2004
Posts: 11343

Originally posted by Stu Thompson:
...BUT, when i type javac at the command line I see -cp as an option...

And it works too.

This looks like an omission in the documentation to me. Maybe I'm wrong, but I would go with javac's implementation and say that -cp is fine with javac.

"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
Stu Thompson
Ranch Hand

Joined: Jun 14, 2006
Posts: 136
OK, thanks. I sure wish I had a definative answer...but then again I wish I was a zillionair.
Peter Heide
Ranch Hand

Joined: Nov 04, 2006
Posts: 31
The javac options ��classpath <path>� and ��cp <path>� both have the same meaning, which is:

Specify where to find user class files

To test the option I used the following example under Windows. Both javac options worked the same way.

1.Create the following directories


2.Create the following file Echo.java and put it to directory c:\dev\source\

public class Echo {
public void show () {
System.out.println("Hello world");

3.Create the following file EchoTestDrive.java and put it to directory c:\dev\source\

public class EchoTestDrive {
public static void main(String [] args) {
Echo e = new Echo();

4. Create the following batch file Echo.bat in the directory c:\dev\ and run it

cd c:\dev\source
javac -d c:\dev\destination1 Echo.java
javac -classpath c:\dev\destination1 -d c:\dev\destination2 EchoTestDrive.java
javac -cp c:\dev\destination1 -d c:\dev\destination2 EchoTestDrive.java

Ernest Friedman-Hill
author and iconoclast

Joined: Jul 08, 2003
Posts: 24183

javac -cp definitely doesn't work in JDK 1.4, so it must be new in Tiger; the docs just haven't caught up.

[Jess in Action][AskingGoodQuestions]
Ulf Dittmer

Joined: Mar 22, 2005
Posts: 41062
Putting on my geezer hat: I think -cp did work in all versions on the Microsoft Java SDK. They probably got tired of typing so may letters, just like they used com.ms... for all their classes instead of com.microsoft...

Ping & DNS - my free Android networking tools app
Stu Thompson
Ranch Hand

Joined: Jun 14, 2006
Posts: 136
Oh, interesting that it is new for Java 5.

I am really only interested what the exam will be like as that's where it will count. (Soon...) The plan is to take Marc's advice and stick with reality rather than documentation.

And M$ JVM coders are the only lazy gits around...count me in that group too. -cp is a good thing.

Cameron Wallace McKenzie
author and cow tipper
Saloon Keeper

Joined: Aug 26, 2006
Posts: 4968

Well, I think everyone has answered the wrong question.

We're in the SCJA forum, and you asked "which is it for the exam?"

The answer is neither!

-cp is not tested on the SCJA exam, and certainly not for the javac utility.

From the Sun objectives:

"Demonstrate the proper use of the "javac" command (including the command-line options: -d and �classpath), and demonstrate the proper use of the "java" command (including the command-line options: -classpath, -D and �version)."

This exam covers a huge and broad amount of information, but much of it at a high level. The people that have talked to me after failing (because they didn't buy my book, of course ) the exam are experts at syntax and every single javac and java switch, but they don't have a good feel for the proper application of JSPs, when to use Web Services, the drawbacks of distributed programming with Applets and/or Servlets, and big picture stuff like that.

For the Sun Certified Java Associate exam (SCJA), you must keep to the objectives, otherwise you'll be studying the wrong things (like -cp). -cp is an SCJP topic.


-Cameron McKenzie
I agree. Here's the link: http://aspose.com/file-tools
subject: javac -cp legal?
Similar Threads
NoClassDefFoundError - where to put Javamail JAR file?
package javax.servlet does not exist!!!
how to import an API not in jdk ?
package javax.servlet.http does not exist