• 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
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

regarding package concept in java class not found

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Friends,
Don't mistake me.This is small doubt for you.i need one clarification from you regarding package concept in java.
I have develop the sample class called Foo.java it is available under directory D:\rram
public class Foo {
public Foo() { System.out.println("Foo"); }
}
It will compile Success
another file Name is Bar.java it is available under directory D:\rram
package com.test;
import Foo;
public class Bar {
public Bar() { System.out.println("Bar"); }
public static void main(String[] args) {
Bar bar = new Bar();
Foo foo = new Foo();
}
}
I have try to compile this program i got the Following error:
Bar.java:4: Class Foo not found in import.
import Foo;
^
1 error
can any one help me to solving this problem
regards
ramanarayanan
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Raman,
Welcome to JavaRanch! Please only post your question to one forum; a bartender can always move it to another one if you picked the wrong one.
Anyway, the answer is that the Java folks at Sun now strongly discourage putting classes into the "default" package, and for the last few revisions of the standard Java compiler, importing classes from the "default" package (the one with no name, otherwise known as "no package") is simply not supported. Other Java compilers may indeed support this, as it's not technically illegal -- for example, IBM's "Jikes" compiler does.
 
Ranch Hand
Posts: 135
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
create a directory named foo in D:\rram and put Foo class in foo direvtory.
Add D:\rram to classpath
add line
package foo;
to your java class Foo
in test file use statement
import foo.*;

Then it'll work.
Always following java coding conventions.
 
Idly Vada
Ranch Hand
Posts: 135
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I forgot.
You should create a directory called com in D:\rram and in D:\rram\com create a directory test. And put Bar.java in D:\rram\com\test\
The package hierarchy should match directory hierarchy

Now ur program will work
 
Politics n. Poly "many" + ticks "blood sucking insects". Tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic