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


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Package question" Watch "Package question" New topic
Author

Package question

John Blutarsky
Greenhorn

Joined: Jun 24, 2005
Posts: 5
I have two files:

File1.java:
class PackageTest {
void MyPrint() {
System.out.println("Hello");
}
}

File2.java:
class Test {
static public void main(String[] args) {
PackageTest pt = new PackageTest();
at.MyPrint();
}
}

It's compile fine.
Why? I don't specify nothing about "package". How File2 views File1, there isn't package keyword.

Thanks. (sorry for my english)
Srinivasa Raghavan
Ranch Hand

Joined: Sep 28, 2004
Posts: 1228
The code compiles & runs because both these classes are in the same folder ( To be more correct both classes are added to the class path ). Try to put the other class some where else and add this class ( with the whole path ) to the class path , even then you should be able to run the program.

When we give a Package statement, we are logically grouping related classes to be in one folder. This is for code readability & for easy maintenance.
[ October 13, 2005: Message edited by: Srinivasa Raghavan ]

Thanks & regards, Srini
MCP, SCJP-1.4, NCFM (Financial Markets), Oracle 9i - SQL ( 1Z0-007 ), ITIL Certified
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Package question