• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Devaka Cooray
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • Paul Clapham
Sheriffs:
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Saloon Keepers:
  • Tim Holloway
Bartenders:

package location

 
Ranch Hand
Posts: 92
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,
say for example i have
package A
 
amal shah
Ranch Hand
Posts: 92
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 1274
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 coderanch, 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.
 
amal shah
Ranch Hand
Posts: 92
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
it dosen't work burkhard......am using jdk 1.4.1
how to go about it
help appreciated

thanking you
amal shah
 
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
See if this tutorial helps. I think it picks up right about where you are now. Let me know how it fits.
 
Burkhard Hassel
Ranch Hand
Posts: 1274
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Marshal
Posts: 81617
593
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
    Posts: 92
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    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
    Posts: 92
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    the two files are as:

    //beerexpert.java
    package A;
    import java.util.*;
    public class beerexpert
    {
    }
    //beer.java
    package B;
    import A.*;
    public class beer
    {
    }
     
    Ranch Hand
    Posts: 1847
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    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.
     
    amal shah
    Ranch Hand
    Posts: 92
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    thanks to all....got the point
     
    Evil is afoot. But this tiny ad is just an ad:
    The new gardening playing cards kickstarter is now live!
    https://www.kickstarter.com/projects/paulwheaton/garden-cards
    reply
      Bookmark Topic Watch Topic
    • New Topic