I am trying to use borland to compile a bean and getting following error: --- "DBHandler.java": Package C:\Documents and Settings\an08627\jbproject\osg\sqlValues\src\osg\DBHandler.java stated in source unnamed package does not match directory C:\Documents and Settings\an08627\jbproject\osg\sqlValues\src\osg\DBHandler.java. --- HELP!! I will provide more info if requested.
OK I fixed the error but I dont understand why. By adding 'package osg' instead of using 'import osg.FormBean;'(which is commented out above) I didnt get the error. I am trying to use Advanced form processing using JSP
java world example. I guess I dont understand the difference between Importing a class and using a 'package' directive. thanks. Need anyting else let me know. [ July 13, 2004: Message edited by: jim gemlo ]
package declarations are used to organize classes. import statements are used to tell the compiler where to find dependencies.
If the class Foo is declared to be in the package fubar, then the fully qualified name of this class would be fubar.Foo. If code in a different package wants to reference the Foo class, it needs to either fully qualify any references to the name of the class, fubar.Foo, or import fubar.Foo and then make reference to it as simply Foo.
So, packages are a mechanism for creating name spaces in which to organize classes, while import statements are used to inform the compiler where dependency class definitions exist, and to provide programmers a mechanism to not have to type the fully qualified name of a class every time it's referenced.
So when i create a bunch of related classes say in Borland, it automatically places them in a package with a name that I give it. Then lets say the package I created was foobar. In foobar I have two classes Foo andBar. I want to access Class Bar from within Foo. Since they are both under package foobar I dont need to do anything special. Correct? And if this is correct, does the compiler check the whole package when checking for a class? For example lets say from class Bar I try to access class Snickers but this class is under foobar.candy.
Now lets say that I have another class in packageTest Called score. If I want to use class Bar in class score[/] I need to have the following line of code in class [i]score: import fobar.Bar.
Thanks for all responces. I think I understand but need to know if the above thought is correct. [ July 14, 2004: Message edited by: jim gemlo ]
Joined: Dec 10, 2001
I want to access Class Bar from within Foo. Since they are both under package foobar I dont need to do anything special. Correct?
You wouldn't need an import statement, or need to otherwise fully qualify references to class Bar from within class Foo.
And if this is correct, does the compiler check the whole package when checking for a class? For example lets say from class Bar I try to access class Snickers but this class is under foobar.candy.
It doesn't work that way. The package foobar.candy is not inside or otherwise a part of package foobar. They're entirely different packages, as far as the compiler is concerned. (Other tools that make use of Java classes and source code do treat foobar.candy as being a "sub" part of foobar.)
Now lets say that I have another class in packageTest Called score. If I want to use class Bar in class score I need to have the following line of code in class score: import fobar.Bar.
If you're stating, in order to reference the class Bar definition in package foobar from a class not in package boobar, you need to either fully qualify references to the class name, which is foobar.Bar, or you need to import foobar.Bar, then that's a correct understanding. [ July 14, 2004: Message edited by: Dirk Schreckmann ]
Joined: Feb 24, 2004
Thank you VERY much. I understand now completely. Thanks again GREAT SITE!!