tags:

views:

84

answers:

2

I have two classes Hello1 and Hello, and I'm calling class Hello1 constructor within Hello class, but when I trying to compile the Hello class with command

javac Hello.java

I'm getting compile time error:

Hello.java:6:cannot find the symbol
symbol: class Hello1
location: class Hello
Hello1=new Hello();
^
Hello.java:6:cannot find the symbol
symbol: class Hello1
location: class Hello
Hello1=new Hello();
           ^

But when I try to compile the compile the class with command:

javac Hello.java Hello1.java

it's working fine, but why I have to use this command every time to compile the class? Why the compiler can't use the already compiled .class Hello1 file, so that next time I use the command javac Hello.java.

+1  A: 

You need to add the current directory to your classpath so the compiler can find it. By default, the classpath does not include the current working directory, so any .class files which have already been compiled won't be seen by the compiler. To do this, compile like this:

javac Hello.java -cp .
Adam Rosenfield
just as I thought !
Tom
+1  A: 

You need to set the classPath with -cp .

Raymond Roestenburg
Posting from an iPhone is not the fastest way to answer a question :)
Raymond Roestenburg