This week's book giveaway is in the OCMJEA forum.
We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Default package doubt Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Default package doubt" Watch "Default package doubt" New topic
Author

Default package doubt

saloni jhanwar
Ranch Hand

Joined: Feb 09, 2012
Posts: 583





F:\import>javac -classpath pkg pkg/ImportTest2.java
pkg\ImportTest2.java:4: error: cannot find symbol
ImportTest1 i;
^
symbol: class ImportTest1
location: class ImportTest2
1 error

Tell the difficulties that i am difficult.
Matthew Brown
Bartender

Joined: Apr 06, 2010
Posts: 4376
    
    8

You can't import the default package. So classes in the default package can only be used by other classes in that package.
saloni jhanwar
Ranch Hand

Joined: Feb 09, 2012
Posts: 583

Matthew Brown wrote:You can't import the default package. So classes in the default package can only be used by other classes in that package.

Do you mean java maintain a "Default package" and my "pkg" folder isn't a default package here ?
Sumit Patil
Ranch Hand

Joined: May 25, 2009
Posts: 296

The package name is mentioned as the fist line in a particular class as you see in ImportTest2.java.
So as per ImportTest1.java, there is not package involved with it, its default package.


Thanks & Regards, Sumeet
SCJP 1.4, SCWCD 5, LinkedIn Profile
saloni jhanwar
Ranch Hand

Joined: Feb 09, 2012
Posts: 583

Matthew Brown wrote:You can't import the default package. So classes in the default package can only be used by other classes in that package.

Thanks Matthew.
Matthew Brown
Bartender

Joined: Apr 06, 2010
Posts: 4376
    
    8

Having seen Sumit's post, I realise I may have misunderstood what you were asking. As he says, ImportTest1 doesn't have a package declaration. To fix that, it either needs to have the declaration, or it needs to be in a different folder (because folders correspond exactly to packages). But in the latter case you'll run into the problem I mentioned - ImportTest2 will not be able to import ImportTest1.
saloni jhanwar
Ranch Hand

Joined: Feb 09, 2012
Posts: 583

Matthew Brown wrote:Having seen Sumit's post, I realise I may have misunderstood what you were asking. As he says, ImportTest1 doesn't have a package declaration. To fix that, it either needs to have the declaration, or it needs to be in a different folder (because folders correspond exactly to packages). But in the latter case you'll run into the problem I mentioned - ImportTest2 will not be able to import ImportTest1.

If i could put ImportTest1 in other folder then there is no way to use it in ImportTest2 without package declaration in ImportTest1 and import statement in ImportTest2 for that.So i did this to check whether in same folder it will automatically import in ImportTest2 or not as both are in same folder here.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Default package doubt