• 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

import java.*; ????

 
Author
Posts: 160
11
Android Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Ranch Hand
Posts: 572
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
But both are working well at my side. I am using JBuilder X. I have tried both are working well.
 
Ranch Hand
Posts: 114
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 160
11
Android Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Ranch Hand
Posts: 539
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic