File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes import mypack.*; (asterisk and without asterisk) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "import mypack.*; (asterisk and without asterisk)" Watch "import mypack.*; (asterisk and without asterisk)" New topic
Author

import mypack.*; (asterisk and without asterisk)

Rayudu addagarla
Ranch Hand

Joined: Aug 17, 2000
Posts: 39
/* class A*/
package pack1;
public class A{
public void call(){
System.out.println("Hello Darling");
}
}
/*******************************************/
/* class B which uses class A by importing pack1*/
import pack1.*;
public class B{
public static void main(String args[ ]){
A obj =new A();
obj.call();
}
}
/***problem *********************/
i am using jdk1.3
"c:\java" current dir.
when compiled at Dos prompt
c:\java> javac -d . A.java --> creates directory pack1-->puts A.class in that dir.
now when compiling B.java
C:\java> javac B.java

C:\Java> javac B.java
B.java:6: cannot resolve symbo
symbol : constructor A ()
location: class A
A obj =new A();
^
B.java:7: cannot resolve symbo
symbol : method call ()
location: class A
obj.call();
^
2 errors
but it works fine and compiles and output IF
i keep
import pack1.A in class B instead of import pack1.*;
i have set the classpath to the current directory
c:\java>set classpath=%classpath%;.;
/* dot indicates current dir */
Can anyone help me the problem the asterisk with and without

Good luck for Certfication.
Mark Ziebell
Greenhorn

Joined: Oct 08, 2001
Posts: 4
Sorry no explanation but an interesting problem.
Perhaps the answer is that it is not good practice to have the A.java in the default package of B when it is not part of the default package.
So the rule is
import pack1.A
does not get confused with A.java in the default package
import pack1.*
recompiles A.java in the default package and puts the class file in the same directory (ie does not use javac -d . when it recompiles A)
Of course using an IDE such as Visual Age for Java prevents you from ever having a java file not in its own package.
Regards
Mark
 
Don't get me started about those stupid light bulbs.
 
subject: import mypack.*; (asterisk and without asterisk)