• 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

Compiling many classes

 
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi
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
Thanks
Yen
 
Ranch Hand
Posts: 1514
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.

Bosun
 
yen cheong
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Bosun
Thanks for your reply
Normally I would compile a class using the following syntax:
javac class1.java
But when I have 3 separate files class1.java, class2.java, class3.java in the same directory which need to be connected- what syntax do I use.
Thanks
Yen-yei
 
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
reply
    Bookmark Topic Watch Topic
  • New Topic