wood burning stoves
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Package Problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Make it so: Java DB Connections & Transactions this week in the JDBC forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Package Problem" Watch "Package Problem" New topic

Package Problem

Munish Gulati
Ranch Hand

Joined: Aug 06, 2003
Posts: 37
//File Name:MyPreviousClass.java
//reciding at path c:\mydir1\mydir2\MyPreviousClass.java
package mydir2;
public class MyPreviousClass{
public void aMethod(){
//File Name:MyCurrentClass.java
//reciding at path c:\mydir1\mydir2\MyCurrentClass.java
package mydir2;
import mydir2.MyPreviousClass;
public class MyCurrentClass{
public void aNewMethod(){
MyPreviousClass mpc=new MyPreviousClass();
I have compiled the class MyPreviousClass.java with the command
c:\mydir1\mydir2> javac MyPreviousClass.java
My Problem:
Now how and from where to compile the class MyCurrentClass.java ?
Actually I am not ok with the package funda...pls explain the reason for ur answer..and a bit about the package funda so that i can grasp the subject.

Munish Gulati<br />SCJP 1.4<br />Albert Einstein: There are only two ways to live your life. One is as though nothing is a miracle. The other is as though everything is a miracle.
Uma Balu
Ranch Hand

Joined: Aug 22, 2003
Posts: 61
U can compile the other class also, from the same directory, since the second class is also placed in the same package.
Since both the classes are in the same package, the statement,

is not necessary.
Moreover, you need not explicitly create physical folder and then compile the classes. Try this,
  • Create both the classes in the folder c:\mydir1
  • go to c:\mydir1 and type, c:\mydir1>javac -d . MyPreviousClass.java
  • c:\mydir1>javac -d . CurrentClass.java

  • The -d option followed by the location( "." indicates the current folder, u can also say, javac -d c:\temp filename.java) will automatically create the required folders, specified as the name of the package(here, mydir2) and place the .class file there.
    U can execute the files as
    c:\mydir1> java mydir2.CurrentClass
    Hope this helps u...
    Munish Gulati
    Ranch Hand

    Joined: Aug 06, 2003
    Posts: 37
    Thanks Uma
    Now I got the point
    I agree. Here's the link: http://aspose.com/file-tools
    subject: Package Problem
    It's not a secret anymore!