This week's book giveaway is in the Agile and other Processes forum.
We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line!
See this thread for details.
The moose likes Java in General and the fly likes imports Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Java in General
Reply Bookmark "imports" Watch "imports" New topic
Author

imports

Kathy Lynch
Greenhorn

Joined: Feb 26, 2001
Posts: 25
I think I am missing something fundamental here. I have the understanding that when you have an import statement like:
import something.somethingElse.*;
that imports all classes in the somethingElse package. But sometimes I get an error unless I explicitly say
import something.somethingElse.MyClass;
Can someone tell my why I sometimes have to explicitly list the class and othertimes package.* works?
Thanks in advance!
Paul Keohan
Ranch Hand

Joined: Mar 15, 2000
Posts: 411
I don't know if this is the answer but sometimes I make mistakes here by assuming that .* will import ALL subdirectories. It only imports the files that are in this particular directory.

import com.mystuff.*;
will not import the following class
com.mystuff.classes.myFirstClass
but it will import
com.mystuff.mySecondClass

Hope this helps.....
Paul
Art Metzer
Ranch Hand

Joined: Oct 31, 2000
Posts: 241
Paul's right.
I just thought I'd add, that's why, if you ever use event listeners with the AWT, you have to say at the beginning of your class:

You won't get away with just:

Art
Cindy Glass
"The Hood"
Sheriff

Joined: Sep 29, 2000
Posts: 8521
Also there are cases where more than one class that you are importing contains a class with the same name.
Import java.util.*;
Import java.sql.*;
Now when you want to use the Date class, you have to explicitly name which Date that you want to use.


"JavaRanch, where the deer and the Certified play" - David O'Meara
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: imports
 
Similar Threads
reference to List(interface) is ambiguous
Using import * statements use more memory than stricter imports?
imports
If import statement is not given in the question
question about imports