aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes what is an unnamed package... Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "what is an unnamed package..." Watch "what is an unnamed package..." New topic
Author

what is an unnamed package...

kay lin
Ranch Hand

Joined: May 20, 2004
Posts: 132
Hi :
I was just studying for the SCJP 1.4 exam..and reading some of the reference notes online...and it says:

# if no package declaration is found, the class or interface is made part of an unnamed package
# every implementation of Java must provide for at least one unnamed package
# most systems allow for one unnamed package per directory

i know that if you are running Windows..then java packages are in the form of directories...if the package is name. but what about if the package is not named...for example..you dont declare the package in your class file, that will compile as well..but then what is the "unnamed package" then in this case??

plz lemme know

many thanks

please let me know
ankur rathi
Ranch Hand

Joined: Oct 11, 2004
Posts: 3830
Originally posted by dog lin:


# if no package declaration is found, the class or interface is made part of an unnamed package


If there is no package statement ( must be first line if there is ) in your source file it means that you are working in default project .

For more detail if your source file is in bin folder then you will compile your file like this :

javac MyFile.java

and run like this :

java MyFile

And if suppose your have myPackage in the begining of your source file , then in the bin folder you may create one folder with name myPackage & put your source file in that folder .

for compilation :

javac myPackage/MyFile.java

for execution :

java mypackage.MyFile


hope i have given lots of unnecessary details ...

[ January 08, 2005: Message edited by: rathi ji ]
[ January 08, 2005: Message edited by: rathi ji ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: what is an unnamed package...