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
Author

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:
c:/java/pack1/pack2/abc.java
c:/java/pack1/pack3/hello.java

1.c:/java/pack1/pack2/abc.java
***********abc.java**********

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

2.c:/java/pack1/pack3/hello.java
*********Hello.java*********

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

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

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 hello.java, 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\hello.java
c:\java>java pack1.pack3.hello
[ July 01, 2004: Message edited by: Sandeep Jindal ]

SCJP 5.0
http://sites.google.com/site/duddlutechnologies/home
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 (anton.golovin@gmail.com) 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: http://aspose.com/file-tools
 
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.