File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes Compiling many classes Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Compiling many classes" Watch "Compiling many classes" New topic

Compiling many classes

yen cheong

Joined: Aug 14, 2001
Posts: 27
I'm new to Java and need some help with compiling my classes. I have 3 public classes in 3 separate .java files. I need to somehow compile these classes together, so that they are visible to each other as one class creates an object from one of the other classes. Do I need to put them all in a package? Please can you help
Bosun Bello
Ranch Hand

Joined: Nov 06, 2000
Posts: 1510
Not neccessarily. If they are in the same directory, without a package statement in any of them (default package), they are visible to each other.


So much trouble in the world -- Bob Marley
yen cheong

Joined: Aug 14, 2001
Posts: 27
Thanks for your reply
Normally I would compile a class using the following syntax:
But when I have 3 separate files,, in the same directory which need to be connected- what syntax do I use.
Jason Ford
Ranch Hand

Joined: Aug 02, 2001
Posts: 54
Bosun is right: without a package statement, the compiler will set the classes to use the default package, grouping the classes in the same directory into the package.
As for the compiler needing to know about the type information, javac is smart enough to find the class. I read this here:

[If the search for a class] produces a source file but no class file: javac compiles the source file and uses the resulting class file.

Finally, to make it easier for yourself, you should use a wildcard to compile your source files, like javac *.java

I agree. Here's the link:
subject: Compiling many classes
It's not a secret anymore!