my dog learned polymorphism
The moose likes Beginning Java and the fly likes Very dumb question about Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Very dumb question about "import"" Watch "Very dumb question about "import"" New topic

Very dumb question about "import"

Jake Barnes

Joined: Jan 15, 2010
Posts: 4
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:

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

Joined: Sep 29, 2008
Posts: 12617

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:
subject: Very dumb question about "import"
jQuery in Action, 3rd edition