File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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
JavaRanch » Java Forums » Java » Java in General
Bookmark "import mypack.*; (asterisk and without asterisk)" Watch "import mypack.*; (asterisk and without asterisk)" New topic

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();;
/***problem *********************/
i am using jdk1.3
"c:\java" current dir.
when compiled at Dos prompt
c:\java> javac -d . --> creates directory pack1-->puts A.class in that dir.
now when compiling
C:\java> javac

C:\Java> javac cannot resolve symbo
symbol : constructor A ()
location: class A
A obj =new A();
^ cannot resolve symbo
symbol : method call ()
location: class A;
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

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 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 in the default package
import pack1.*
recompiles 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.
I agree. Here's the link:
subject: import mypack.*; (asterisk and without asterisk)
It's not a secret anymore!