File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes Use of package statement Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Use of package statement" Watch "Use of package statement" New topic

Use of package statement

Donald R. Cossitt
Ranch Hand

Joined: Jan 31, 2003
Posts: 401
I have not seen this documented anywhere, but in hopes of saving some other newbie a week of pounding on the desk and searching the forums and books until the wee hours, take a look at the following:
If you place package packageName; in your java file and compile from the console, you will need to type cd.. at least once and use "java lowerFolder.javaFile" before running in order to keep from getting this error:

else do not enter package packageName in your java file. I discovered this by much trial and error :roll:
doco all happy now
Much thanks to Yehor for helping me see the light.](response to question)
[ February 25, 2003: Message edited by: doco mastadon
[ February 25, 2003: Message edited by: doco mastadon ]

aliasger talib
Ranch Hand

Joined: Aug 19, 2002
Posts: 37
hi doco,
Actually, the _only_ way you can compile a Java file with a package structure is from the root folder with the package structure in the compile statment at the command prompt.
There's no other way.
Donald R. Cossitt
Ranch Hand

Joined: Jan 31, 2003
Posts: 401
Yes, I know that now. But if you compile from the console then try running the compiled java file from the same directory as java file is resident in, you will receive the error message displayed in my post. That is, unless you do not have a package statement in your compiled file then, you can run from the same directory.
A simple statement such as the one you just made would be most helpful in documentation of how to setup and USE Java. A subtle fact missing from ANY and ALL documentation that I have seen.
[ February 26, 2003: Message edited by: doco mastadon ]
Marilyn de Queiroz

Joined: Jul 22, 2000
Posts: 9059

Why did you change your display name to one that violates the JavaRanch Naming Policy?

Please change it back, or at least to a name that conforms. Thank you.

"Yesterday is history, tomorrow is a mystery, and today is a gift; that's why they call it the present." Eleanor Roosevelt
I agree. Here's the link:
subject: Use of package statement
It's not a secret anymore!