Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Package creation

 
Neelima Paramsetty
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,
i created a directory called pack1.
in this i defiene a super class like this

After compiling this,i define a child class like this

when compiling child1.java .it is giving error like this"super class pack.parent1 of pack.child1
not found"
anybody help me to run this class.
thanks in advance,
Neelima
[ edited to preserve formatting using the [code] and [/code] UBB tags -ds ]
[ July 15, 2003: Message edited by: Dirk Schreckmann ]
 
Dirk Schreckmann
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The compiler needs to be able to locate the base of your package structure through the CLASSPATH setting. So, the folder that holds the pack folder, needs to be somehow included in the CLASSPATH.
Try the following. (I'm working from my K:\java\temp folder.)
1. Create the pack folder - K:\java\temp\pack
2. Inside the K:\java\temp\pack folder, create parent1.java
3. From the command line, cd to K:\java\temp\pack and compile.
K:\java\temp\pack> javac parent1.java
It should compile successfully.
4. Inside the K:\java\temp\pack folder, create child1.java
5. From the command line, cd to K:\java\temp (NOT K:\java\temp\pack) and compile.
K:\java\temp> javac pack\child1.java
It should compile successfully, if your CLASSPATH is configured to include the current working directory (specified with a simple . - period). If it doesn't compile, then fix your CLASSPATH accordingly. Feel free to ask about how to do so.
6. You can now run the child1 program from the command line.
K:\java\temp>java pack.child1
And it should output the following.
Hello
Hello
Neelima Paramsetty
7. Any luck?
[ April 12, 2004: Message edited by: Dirk Schreckmann ]
 
James Clinton
Ranch Hand
Posts: 190
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Using an IDE Tool will ease your classpath stress as you can setup/edit/customise them for individual projects.
Try using Forte by Sun Microsystems for example..its free.
 
Dirk Schreckmann
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Let me suggest that once you figure out the whole CLASSPATH thing, it's easy. I'd suggest not using an IDE at first. Using one will hide some of those details that a programmer might do well to be familiar with.
 
Neelima Paramsetty
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dirk Schreckmann ,
Thanks for ur help.How to fix my class path?It is giving error when compiling child,java.
thanks,
Neelima
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic