wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes package location Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "package location" Watch "package location" New topic
Author

package location

amal shah
Ranch Hand

Joined: May 05, 2006
Posts: 92
Hello,
say for example i have
package A
amal shah
Ranch Hand

Joined: May 05, 2006
Posts: 92
Hello,
say for example i have
package A
class something
{}

package B
import A.*;
class anotherthing
{}

now in order to use classes of package A......where should we place the package A java file...i.e. in which folder....i believe it is supposed to be placed where jdk is installed.....but where....help appreciated

thanking you
amal shah
Burkhard Hassel
Ranch Hand

Joined: Aug 25, 2006
Posts: 1274
As a start make two folders, A and B and store them in the folder named "bin" in the folder that's named something like "jdk1.5.0" or comparable. Your .java files then go into these folder A xor B.

But you have to improve your code also a little, first a semikolon is missing in the package statements of your classes. Second "something" has to be public, otherwise the import statement in the other class will produce a compiler error since class something will be visible in its own package only with no (=default) access modifier.

Yours,
Bu.


all events occur in real time
amal shah
Ranch Hand

Joined: May 05, 2006
Posts: 92
it dosen't work burkhard......am using jdk 1.4.1
how to go about it
help appreciated

thanking you
amal shah
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
See if this tutorial helps. I think it picks up right about where you are now. Let me know how it fits.


A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
Burkhard Hassel
Ranch Hand

Joined: Aug 25, 2006
Posts: 1274
amal shah originally wrote

it dosen't work burkhard......am using jdk 1.4.1

should work with 1.4.1 as with 1.5.0
perhaps try without packackes and a mini java programm if you can compile anything to figure out where the problem is.
Yours,
Bu.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39784
    
  28
Please don't put your folders in "bin." That folder is for keeping .exe files from the jdk in.

Use this procedure for command prompt use; [if you use an IDE give the IDE a suitable path to a "java programs" folder, then let the IDE take care of all the packages.]

  • Create a folder called "programs" or something like that.
  • Put all your .java files in it.
  • In the example you have quoted, compile the files in "A" before the files in "B." As a general rule, any file without an "import" statement should be compiled first.
  • Then compile the files which use those files in an import statement.
  • Navigate to the location of the .java files.
  • Use this sort of command line: c\JavaPrograms>javac -d . MyFile.java[enter] The -d means create directories, and the . means start from the current location.
  • Run the file by prefixing the package name to the class name, eg c\JavaPrograms>java mypackage.MyClass[enter]

  • In the example Stan James quoted the link to, you might have to say
    java com.mytoppackage.mysubpackage.MyClass[enter], because there are nested folders.

    There are other ways to handle packages; read what the Java Tutorial says about them.
    amal shah
    Ranch Hand

    Joined: May 05, 2006
    Posts: 92
    i am still unable to solve the problem...
    this is what i have

    both the below files are in c:\desktop\scwcd
    //beerexpert.java //beer.java
    package A; package B;
    import java.util.*; import A.*;
    public class beerexpert public class beer
    { {
    } }

    now i set the classpath as...
    set classpath=.;%classpath%;c:\desktop\scwcd

    so now it can search for package A....
    then i compile as
    javac beer.java
    //compiler error
    (1) package A does not exist
    (2)cannot resolve symbol
    symbol:class beerexpert

    pls help...is there something that am unaware of

    thanking you
    amal shah
    amal shah
    Ranch Hand

    Joined: May 05, 2006
    Posts: 92
    the two files are as:

    //beerexpert.java
    package A;
    import java.util.*;
    public class beerexpert
    {
    }
    //beer.java
    package B;
    import A.*;
    public class beer
    {
    }
    Jeroen T Wenting
    Ranch Hand

    Joined: Apr 21, 2006
    Posts: 1847
    seems you don't bother to read tutorials?
    because if you had read any introductory text you'd know what to do.

    Most likely explanation: remember that Java is case sensitive.


    42
    amal shah
    Ranch Hand

    Joined: May 05, 2006
    Posts: 92
    thanks to all....got the point
     
    I agree. Here's the link: http://aspose.com/file-tools
     
    subject: package location