This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

javac -cp legal?

 
Stu Thompson
Hooplehead
Ranch Hand
Posts: 136
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

Thanks,

Stu
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Stu Thompson
Hooplehead
Ranch Hand
Posts: 136
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK, thanks. I sure wish I had a definative answer...but then again I wish I was a zillionair.
 
Peter Heide
Ranch Hand
Posts: 31
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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

C:\dev\source
C:\dev\destination1
C:\dev\destination2

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();
e.show();
}
}

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
pause

 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24204
34
Chrome Eclipse IDE Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
javac -cp definitely doesn't work in JDK 1.4, so it must be new in Tiger; the docs just haven't caught up.
 
Ulf Dittmer
Rancher
Pie
Posts: 42966
73
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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...
 
Stu Thompson
Hooplehead
Ranch Hand
Posts: 136
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

Stu
 
Cameron Wallace McKenzie
author and cow tipper
Saloon Keeper
Posts: 4968
1
Hibernate Spring Tomcat Server
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

Cheers!

-Cameron McKenzie
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic