Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

regarding package concept in java class not found

 
ramanarayanan
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • 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
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24208
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • 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.
 
Idly Vada
Ranch Hand
Posts: 135
  • Mark post as helpful
  • send pies
  • 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
  • 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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic