• 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:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Rob Spoor
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Junilu Lacar
  • Tim Cooke
Saloon Keepers:
  • Tim Holloway
  • Piet Souris
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Frits Walraven
  • Himai Minh

packages and import

 
Ranch Hand
Posts: 127
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,

I`ve got a problem and would be very appreciated for help.

I have a folder "a", two subfolders "b1" and b2".
In "b1" there`s a file named "First.java" and contains:

package b1;

class First{}


In "b2" there`s a file named "Second.java" and contains

package b2;

import b1.*;
class Second{}


When I`m trying to complie the "Second.java" file, I`m getting error: "package b1 does not exist". What`s wrong? Thank you very much for your time and answer.
 
Sheriff
Posts: 11343
Mac Safari Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When compiling Second.java, try specifying a classpath so that the import can be found. Assuming that folder "a" is directly under c:\...

javac -classpath c:\a Second.java
[ January 25, 2006: Message edited by: marc weber ]
 
Aleksander Zielinski
Ranch Hand
Posts: 127
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you Marc! I`ll be passing SCJP soon, currently learning Servlets and had problem with compiling a servlet file, so made up that little example above. Thanks to your input I added additional classpath in my environmental variables and everything works perfect, it saved me some typing in console
 
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Aleksander

I tried your code ,when compiling Second.java,I got the message:

can not read Second.java!

Let me know are you with windows XP?

How is your environment variable configured?Mine is :

c:\Program Files\Java\jdk1.5.0_06\bin

Thanks a lot.
 
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think both b1 & b2 are siblings of 'a' .How you can import b1 from b2?
 
author
Posts: 9031
21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Aleksander, et. al.,

The other thing to keep in mind is that the new SCJP exam has questions EXACTLU like this (only harder), so don't forget to study up on directory structures, classpaths, and so forth.
 
marc weber
Sheriff
Posts: 11343
Mac Safari Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
See this section from Thinking in Java for more detail.
 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi Aleksander,
1. we have to import the b1 package with its fully qualified name,
like "import a.b1.*;"
2. how to set the environment variable:
under win-2k: first go to system properties, using the shortcut key
"win-key+pause"; then go to that advanced tab; on their u can find the environment variable button, just click that button, now u go system variables part & click the "new button"; now u have to set two environment variable one is "variable name: JAVA_HOME" & "variable value: ur jdk home directory; eg. c:\jdk1.3".
then add the new value that is ur jdk bin directory, eg. c:\jdk1.3\bin", separate the new value using semicolon( .
3. click the "new button" "variable name: classpath" & "variable value: c:\jdk1.3\bin;c:\jdk1.3\bin\a\b2.*;
4. now u can compile ur Second.java file, using the below command (in command prompt)
"C:\jdk1.3\bin> javac a\b2\Second.java" (under ur jdk bin directory)
5. u can run ur class file using, "C:\jdk1.3\bin> java a.b2.Second"

try this...


J.Ramesh
 
I will suppress my every urge. But not this shameless plug:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic