Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

package problem

 
dimpsonu arora
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 180
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Anton Golovin
Ranch Hand
Posts: 476
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.)
 
K Anshul
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic