| Author |
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. Thanks
|
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
|
|
Hi, 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:\mydir1go to c:\mydir1 and type, c:\mydir1>javac -d . MyPreviousClass.javac:\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... Regards, Uma......
|
 |
Munish Gulati
Ranch Hand
Joined: Aug 06, 2003
Posts: 37
|
|
Thanks Uma Now I got the point
|
 |
 |
|
|
subject: Package Problem
|
|
|