• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
Bartenders:
  • Carey Brown
  • Tim Holloway
  • Joe Ess

import mypack.*; (asterisk and without asterisk)  RSS feed

 
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
/* 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
 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!