Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Package Compilation Problem

 
sonu arora
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First File - abc.java
--
package test;
import test.sell.*;
public class def
{
public static void main(String[] args)
{
System.out.println("Hello World!");
}
}
--
second file - def.java
--
package test.sell;
import test.*;
public class abc
{

}
--
how to compile them , error- package import test.sell does not exist.
 
sonu arora
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
oops,
first file is def.java and second is abc.java.
 
Sadanand Murthy
Ranch Hand
Posts: 382
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by sonu arora:
First File - def.java
--
package test;
import test.sell.*;
public class def
{
public static void main(String[] args)
{
System.out.println("Hello World!");
}
}
--
second file - abc.java
--
package test.sell;
import test.*;
public class abc
{

}
--
how to compile them , error- package import test.sell does not exist.

Package hierarchy generally reflects directory hierarchy.
Why are you importing test.* in abc? You will end up with circular reference if you have classes in test referencing classes in test.sell package & classes in test.sell referencing classes in test package.
The way you have it, in order to be able to compile def.java, abc.java must be compiled first so that the package test.sell will be available. However in order to compile abc.java successfully, def.java must be 1st compiled so that package test will be available.
For the simplistic hello world, you don't need abc.java. Or are you trying to accomplish more than what you have shown in the code?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic