aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes javac problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "javac problem" Watch "javac problem" New topic
Author

javac problem

Changchun Wang
Ranch Hand

Joined: Feb 15, 2006
Posts: 83
there is directory:
d:/test/Demo.java
------/Demo.class
------/a/Test.java



Demo.java

Test.java


I need to complie Test file
d:/test javac -cp d:/test a/Test.java
there is complie tome error "can not find symbol:class Demo"
who could explain it for me?
thanks
[ March 17, 2006: Message edited by: Changchun Wang ]
Aleksander Zielinski
Ranch Hand

Joined: Nov 11, 2005
Posts: 127
Hi,

You have to add the package statement to Demo.java, compile the file again and import statement to class Test.java to import the Demo class, because you're trying to use Demo class and there's no way to know for the compiler where that class is then.





Command line invocation depends on in which directory you are, but you can use absolute path - putting / sing at the begining of the path, so it wouldn't matter where you are.

The command line invocation would be then:

javac -cp / /Test/a/test.java

javac -cp - that's abvious

/ - this is classpath, in order to find a class (Demo.class) that is in a package (Test) you have to include in your classpath a directory that is a superdirectory of package's root directory, in our case package's root directory is "Test" and according to your description "Test's" superdirectory is system root, so we need only "/"

/Test/a/test.java - path to your source file
Changchun Wang
Ranch Hand

Joined: Feb 15, 2006
Posts: 83
Thanks !Aleksander Zielinski ,you are right and your English is well
You have to add the package statement to Demo.java, compile the file again and import statement to class Test.java to import the Demo class, because you're trying to use Demo class and there's no way to know for the compiler where that class is then.

yor meaning is we can NOT import default package's members(eg: class)
in java packages
that is say:
In user-defined packages we can NOT use the class or it's members which is declared in default package
[ March 17, 2006: Message edited by: Changchun Wang ]
Aleksander Zielinski
Ranch Hand

Joined: Nov 11, 2005
Posts: 127
Thank you.

If you ask if there have to be import and package statements, the answer is no. I just thought it would be more "proffesionall" to use directory structure packages

If you remove import and package statements from source files, then for example, if we are in directory "a" the command line invocation would be:

1). Using absolute path

javac -cp /Test Test.java

2). Using relative path

javac -cp ../ Test.java
[ March 17, 2006: Message edited by: Aleksander Zielinski ]
Vijay Raj
Ranch Hand

Joined: Oct 10, 2005
Posts: 110
Lets take the original question into consideration. Do we have to put Demo.java in a package. Can't we do w/o that. I tried it but I was unable to compile Test.java as it could not find Demo.class.

My directory structure is

/vijay/java/Demo.java
/vijay/java/Demo.class
/vijay/java/Test.java

I am compiling Test.java from the directory /vijay/java using). I have the current directory (.) in my classpath. But still, why can't the java compiler find Demo.class.

regards,
vijay.
Aleksander Zielinski
Ranch Hand

Joined: Nov 11, 2005
Posts: 127
You used -d option which tells the compiler where to put class files, but regardless of that you should be able to compile, because if you have all files in one directory "java" and used command line invocation:

javac -d . Test.java

that means that compiler should put all classes to the current directory and that in our case doesn't really matter.

What error did you get?
[ March 17, 2006: Message edited by: Aleksander Zielinski ]
Changchun Wang
Ranch Hand

Joined: Feb 15, 2006
Posts: 83
hi Vijay Raj

you can use this

d:/vijay javac -d . java/Test.java
or d:/vijay javac -d . /vijay/java/Test.java
or d:/vijay/java javac -d . -cp ../ Test.java
[ March 17, 2006: Message edited by: Changchun Wang ]
Edisandro Bessa
Ranch Hand

Joined: Jan 19, 2006
Posts: 584
Hi Aleksander,

According to your previous post...
[QUOTEIf you ask if there have to be import and package statements, the answer is no. I just thought it would be more "proffesionall" to use directory structure packages
Do you mean that classes located in default package can be used only by other classes also located in default package ?

If a given class from within a package try to access another class located in default package, will I always get compile errors ?

I'm really confused about that. Could you please explain ?


"If someone asks you to do something you don't know how to, don't tell I don't know, tell I can learn instead." - Myself
Aleksander Zielinski
Ranch Hand

Joined: Nov 11, 2005
Posts: 127
Classes located in default package cannot be imported, default package can be used only from other classes in default package. That's why one should aviod using default package in professional programming.

By the way, Edisandro I sent you a private message yesterday, please read it.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: javac problem