It's not a secret anymore!*
The moose likes Java in General and the fly likes import java.*;  ???? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "import java.*;  ????" Watch "import java.*;  ????" New topic
Author

import java.*; ????

Barry Burd
Author
Ranch Hand

Joined: Jun 18, 2003
Posts: 118
    
    5

Why does the following code compile without errors?
import java.*;
class MyClass2 {
}
Since "java" isn't the name of an API package, I should get an error message, right?
The following code gives me error messages when I try to compile it:
import javax.*;
class MyClass2 {
}
What gives?


Java For Dummies, 6th Edition, Java Programming for Android Developers For Dummies
Ali Gohar
Ranch Hand

Joined: Mar 18, 2004
Posts: 572
But both are working well at my side. I am using JBuilder X. I have tried both are working well.
Jason Fox
Ranch Hand

Joined: Jan 22, 2004
Posts: 114
How do you figure that java.* isn't a package? Obviously, there are no (public, anyway) classes that reside at that level, but isn't it still considered part of the package (directory) structure? I'm actually not quite sure about this, and would love to hear a more in-depth explanation.
Barry Burd
Author
Ranch Hand

Joined: Jun 18, 2003
Posts: 118
    
    5

I don't know whether to call "java" a package or not. One way or another, I'm using Java 1.5 beta and in that compiler
import java.*;
gives me no error message. But
import javax.*;
gives me an error message. Is there any reason for me to use the statement "import java.*;" ? Is there anything I can do once I've used it that I can't do (at least not without using fully qualified names) if I
haven't used it?
Tim West
Ranch Hand

Joined: Mar 15, 2004
Posts: 539
One thought...
Could this be because of the workaround for the JavaDoc bug where packages that are empty produce no doco at the package level? The 'java' package has package-level doco (ie, the welcome screen on the API, but I don't think the javax package does.
If that's the case, maybe 'import java.*' is allowed because you import one undocumented class with no public constructors, and 'import javax.*' is illegal because there are no classes directly in javax. (That said, is it illegal to import an empty "package", I couldn't work it out from the JLS
Anyway, just a thought - I would have thought that this bug'd be fixed by the release of the 1.5 API, maybe I'll check the bug parade later...

--Tim
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: import java.*; ????
 
Similar Threads
Package Problem
Scope of variable declarartions in for loop
Top level class??
How used to package
Help!!! I know packages cant be this difficult. :-(