File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Very dumb question about "import"

 
Jake Barnes
Greenhorn
Posts: 4
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
k, I'm just learning, and I'm fooling around with some of my first mixed Java/Groovy scripts. I've got a dumb question about how to use a class from another class. I've got these 3 files:

Main.java
DesktopOrganizerForm.java
DesktopOrganizerGreetings.groovy

The Groovy file, for now, simply has this:



Just that, nothing else. In my Main file, I had this:




All 3 files are in the same directory (folder). I tried to compile this (in NetBeans 6.8) but I got an error about the class DesktopOrganizerForm not being declared. So then I tried all kinds of import statements, including obvious stuff like:

import DesktopOrganizerForm;

Nothing worked.

Then I gave this a try, which did work:

package desktoporganizer;

I put this line in all 3 files, and suddenly NetBeans seemed to realize that the classes in one file should be available to classes in the other files. But surely this is not the right way forward? What happens when I have 50 files, or 100 files? There will come a point when I want more than 1 package. What is the right way to do this, other than putting all files in the same package?
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm not sure what the question is.

Are you asking how packages should be organized? Heck, with all the libraries and whatnot used in any non-trivial program there might be a hundreds or thousands of packages, and if you're not doing .* imports a class might have two dozen import statements (but it all depends). I just keep the imports folded, let the IDE manage them, and almost never have to think about it.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic