?
Solved

Java Packages question

Posted on 2006-04-17
4
Medium Priority
?
199 Views
Last Modified: 2010-03-31
Hello,

Again simple things send me nuts.

Here is the scenario..

I have two classes in the same package.
1. I need to make thoese two classes available to the outside the package so any other java application can instantiate it

2. I MUST allow any of these two classes to create an instance of the other.

This is an example os I have.....

package a.b.c.d;

class X
{
}
=======================
package a.b.c.d;

import a.b.c.d.*;

class Y
{
  public static void main(String [] args)
 {
   X   xx = new X();   //I am getting an error saying that it cannot find the class.
  }
}

I have set the CLASSPATH to a.b.c.d.

Whats the solution.
0
Comment
Question by:prain
4 Comments
 
LVL 14

Expert Comment

by:StillUnAware
ID: 16470837
The classpath should point to parent directory of a package a.b.c.d. In other words do this:

say Your parent dir is c: then
1) add to classpath c:
2) put Your source to c:\a\b\c\d
3) compile the source and make sure it stays in a directory c:\a\b\c\d
4) now run Your code in c: like that:  java a.b.c.d.Y

it should work
0
 

Author Comment

by:prain
ID: 16472793
Ok. I was wrong in writing that classpath line. Well I have set the classpath correctly - to the parent.

I  does not work.

Where are the experts here?
0
 
LVL 92

Accepted Solution

by:
objects earned 300 total points
ID: 16473662
> import a.b.c.d.*;

thats not needed as class is in same package

> class X

declare the class public

public class X

same for class Y
0
 
LVL 30

Expert Comment

by:Mayank S
ID: 16475510
Have a look at this for a brush up on classpath:

http://www.mindprod.com/jgloss/classpath.html
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
Suggested Courses
Course of the Month17 days, 9 hours left to enroll

831 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question