• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

why this doesn't work on java 1.4?

 
Ranch Hand
Posts: 1873
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,
I was using jdk1.2.2 (well might sound too old but thats what it is) on my unix system and my code was compiling okay but when I tried it on java1.4 and faced a problem.
In java1.4 I think- we have to put classes in a package as we can't use classes in the default package in the other classes which are there in some specific packages. e.g.,
if I have a directory
/usr/home/maulin/java/pk1
and i'm in /usr/home/maulin/java currently.
I have A.java in pk1 directory and A class in package pk1.
Now, I have B.java in /usr/home/maulin/java directory and B.java is not in any package.
A.java is as,
package pk1;
import B;
public class A {
public static void main(String[] args) {
B b = new B();
}
}
B.java is as,
public class B {
}

if I remain in /usr/home/maulin/java and try to compile like,
javac pk1/A.java then it complains that it can't find class B.
This is using java1.4 if I use java1.2 then it works. Why they dis-allowed the use of 'default' package (B is in default package - the current directory)?
Regards
Maulin
 
Maulin Vasavada
Ranch Hand
Posts: 1873
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
you can assume I am having current directory in CLASSPATH etc. If I put B.java in package pk2 and create pk2 directory and do 'import pk2.*' in A.java and do things it works....
Regards
Maulin
 
A feeble attempt to tell you about our stuff that makes us money
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic