This week's giveaway is in the Spring forum.
We're giving away four copies of Learn Spring Security (video course) and have Eugen Paraschiv on-line!
See this thread for details.
Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

package and import

 
adam Lui
Ranch Hand
Posts: 186
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
which one comes first in declaration in a class?
which one is only allowed with one and only one?
 
Justin Russo
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Adam

if both are included "package" has to be the first to be included and then followed by the "import"..

if there is only one class "package" is not required unless you have included your class within a package.

"import" is not required if you are refering to classes defined in java.lang package which is loaded by the JVM classloader before you class is executed.
 
Burkhard Hassel
Ranch Hand
Posts: 1274
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Howdy,

import is never required

you may say e.g.

java.util.List myList = new java.util.Vector();

without importing anything.

Imports are only for saving some typing work.


Yours,
Bu.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic