Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

importing

 
Atrus Greyor
Ranch Hand
Posts: 110
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
do you have to import each section of the API indivdualy?
For example instead of:
import java.awt.*;
import java.lang.*;
couldn't you just do:
import java.*;
Thanks in advance!
 
Wai Hung
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't think you can do that
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24212
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Despite appearances, a package x.y is not, in any meaningful sense, "part of" a package x. "import x" imports only classes directly in package "x", not those in "x.y". Since there actually are no classes in the "java" package, the answer is no, "import java.*" does nothing useful.
 
Dirk Schreckmann
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm thinking that Ernest might have meant to say:
"import x.*" imports only classes directly in package "x", not those in "x.y"
 
walter kirsch
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Then, will
import "java.*.*"
do the trick?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic