File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes why one can not import classes from default package in java? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "why one can not import classes from default package in java?" Watch "why one can not import classes from default package in java?" New topic
Author

why one can not import classes from default package in java?

Rajesh Tarte
Ranch Hand

Joined: Nov 02, 2006
Posts: 33

why one can not import classes from default package in java?


SCJP 1.5 | SCWCD 5.0 |SCBCD
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 13875
    
  10

Up to Java 1.4 it was possible to import classes from the default package, just by writing: import ClassName;. This feature was removed in Java 5. It's not a good idea to put classes in the default package - you should always put your classes in a package.


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
Amol Nakhwa.
Greenhorn

Joined: Jan 25, 2010
Posts: 2
It is not needed to import classes from default package in java because all the classes like System, String, Integer, Array, Float,etc are from java.lang package which is considered to be default imported package in a java program.

Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 39547
    
  27
Amol Nakhwa. wrote:It is not needed to import classes from default package in java

You misunderstand what the "default package" is. What you describe refers to the fact that each source file has an implicit "import java.lang.*" statement, but that's different from the default package - Jesper's answer is spot on.


Ping & DNS - updated with new look and Ping home screen widget
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: why one can not import classes from default package in java?
 
Similar Threads
javac problem
Q of Khalid's inner class example
Unable to access classes in default package
Dependencies/weird problem
Problem retrieving javabean instance from request in JSP