jQuery in Action, 2nd edition*
The moose likes Java in General and the fly likes regarding package concept in java class not found Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "regarding package concept in java class not found " Watch "regarding package concept in java class not found " New topic
Author

regarding package concept in java class not found

ramanarayanan
Greenhorn

Joined: Sep 08, 2003
Posts: 3
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

Joined: Jul 08, 2003
Posts: 24184
    
  34

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.


[Jess in Action][AskingGoodQuestions]
Idly Vada
Ranch Hand

Joined: Sep 02, 2003
Posts: 135
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

Joined: Sep 02, 2003
Posts: 135
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
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: regarding package concept in java class not found