This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Java in General and the fly likes package problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "package problem" Watch "package problem" New topic

package problem

dimpsonu arora
Ranch Hand

Joined: Aug 13, 2003
Posts: 51
Hi All,
I am making two directories pack2 and pack3 under c:/java/pack1. The directory structure is:


package pack1.pack2;
public class abc
public void abc()
System.out.println("Hello I am ABC.");


package pack1.pack3;
import pack1.pack2.*;
public class hello
public static void main(String args[])
abc obj=new abc();;
System.out.println("Hello World");

When I try to compile it gives compilation error at
import pack1.pack2.*; does not exist.
Plz help..............
Chinmay Bedarkar

Joined: Apr 20, 2004
Posts: 3
compile ur code from c:\java as

c:\java>javac -d . pack1\pack2\*.java pack1\pack3\*.java

this will compile the 2 classes. To run, stay in c:\java
and run it as

c:\java>java pack1.pack3.hello

this should work well.
Sandeep Jindal
Ranch Hand

Joined: Aug 25, 2003
Posts: 180
in addition to what Chinmay has said, instead of compiling all the files/packages separately, u can compile one main/parent file, it will automatically compile all the dependent files.

So your command can be :

c:\java>javac pack1\pack3\
c:\java>java pack1.pack3.hello
[ July 01, 2004: Message edited by: Sandeep Jindal ]

SCJP 5.0
Anton Golovin
Ranch Hand

Joined: Jul 02, 2004
Posts: 476
You named a method in your abc class the same as the class, which is only reserved for constructors (which may not have the void key word.)

Anton Golovin ( SCJP, SCJD, SCBCD, SCWCD, OCEJWSD, SCEA/OCMJEA [JEE certs from Sun/Oracle]
K Anshul
Ranch Hand

Joined: May 19, 2004
Posts: 71
Originally posted by Anton Golovin:
You named a method in your abc class the same as the class, which is only reserved for constructors (which may not have the void key word.)

You may name a method same as the name of the class but it is not a good practice at all.
I agree. Here's the link:
subject: package problem
Similar Threads
Compiling java files in different packages with single javac command
error while compiling
Package still not working
package trouble
Trouble with packages.