Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

what is an unnamed package...

 
kay lin
Ranch Hand
Posts: 132
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3830
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic