Understanding packaging

I have three sets of java coding with the following packaging and import statements:

Date.java

package com.deitel.jhtp3.ch08;

Employee.java

package com.deitel.jhtp3.ch08;

EmployeeTest.java

import com.deitel.jhtp3.ch08.Employee

Both Date.java and Employee.java are located in this subfolder:

c:\JavaWork\com\deitel\jhtp3\ch08

Meanwhile Employee is located in the following parent folder:

c:\JavaWork

My classpath is set this way:

set classpath=c:\JavaWork

I'm attempting to follow the example exactly as shown in my study book. I've compiled Date.java without any problem. However, my attempt to compile Employee.java doesn't work and I get this error message:

/*

C:\JavaWork\com\deitel\jhtp3\ch08\Employee.java:8: cannot resolve symbol

symbol : class Date

location: class com.deitel.jhtp3.ch08.Employee

private Date birthDate;

*/

I don't understand what the problem may be. I've tried moving Employee.java up the line a bit by putting it in the "deitel" folder. Then I included an import statement for it as well as changed the packaging statement for Date.java. But it still doesn't work. Please help me understand what will "always" work.

[1444 byte] By [vaschons] at [2007-9-26 3:00:54]
# 1
Are you sure that you correctly compiled Date.java?Try this: delete the existing class files. Compile withc:\JavaWork> javac EmployeeTest.java
jsalonen at 2007-6-29 10:58:28 > top of Java-index,Archived Forums,New To Java Technology Archive...
# 2
... and the correct way of compiling Date.java would bec:\JavaWork> javac com/deitel/jhtp3/ch08/Date.java(though it isn't necessary if the Date class is used in EmployeeTest)
jsalonen at 2007-6-29 10:58:28 > top of Java-index,Archived Forums,New To Java Technology Archive...
# 3

okay, just to clarify, everything initially starts with EmployeeTest.java which calls upon (or imports) Employee.java. Now Employee.java can't really do it's deal without the help of Date.java. So it makes since to attempt to compile them in the reverse order.

Date.java compiles just fine. However, Employee.java will not compile - giving me an error message saying that it cannot find Date.class, although they are in the exact same subfolder folder.

I haven't even gotten to EmployeeTest.java yet since I know it cannot possibly compile without the help of Employee.java. Should the two modules in the subdirectory not be in the same folder?

vaschons at 2007-6-29 10:58:28 > top of Java-index,Archived Forums,New To Java Technology Archive...
# 4
include "." in the classpath. that probably is the problem.
parthasarkar at 2007-6-29 10:58:28 > top of Java-index,Archived Forums,New To Java Technology Archive...
# 5

> I haven't even gotten to EmployeeTest.java yet since

> I know it cannot possibly compile without the help of

> Employee.java.

Not quite right; if EmployeeTest uses Employee and Date (directly or not) javac will automatically compile them. It's not like in C or C++ ... The order in which you compile files makes no difference in java. But do delete the file Date.class first.

> Date.java compiles just fine.

Even if you don't get warnings or compile errors it still may be compiled in the wrong way... See above for the correct way to compile it.

(and, like Partha Sarkar said, it would be good to include "." in the classpath, if you want to work in other directories than c:\java)

jsalonen at 2007-6-29 10:58:28 > top of Java-index,Archived Forums,New To Java Technology Archive...
# 6
... in other directories than c:\javawork, that is.
jsalonen at 2007-6-29 10:58:28 > top of Java-index,Archived Forums,New To Java Technology Archive...