• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

javac -cp legal?

 
Hooplehead
Posts: 136
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Sheriff
Posts: 11343
Mac Safari Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 136
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
OK, thanks. I sure wish I had a definative answer...but then again I wish I was a zillionair.
 
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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

 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 136
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
author and cow tipper
Posts: 5009
1
Hibernate Spring Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic