File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Default package doubt

 
saloni jhanwar
Ranch Hand
Posts: 583
Firefox Browser Notepad Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator




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
 
Matthew Brown
Bartender
Posts: 4549
8
Java Netbeans IDE Scala
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 583
Firefox Browser Notepad Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 296
Eclipse IDE Firefox Browser Tomcat Server
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
saloni jhanwar
Ranch Hand
Posts: 583
Firefox Browser Notepad Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4549
8
Java Netbeans IDE Scala
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 583
Firefox Browser Notepad Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic