This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
Actually In java The Filename should match with the Public class inside that filename, Not with the class which has main method.
This is a requirement of the Java reference compiler released by Sun.
And this is the reason what I found on SDN network, which says
it's in the JLS. Section 7.6: "When packages are stored in a file system (�7.2.1), the host system may choose to enforce the restriction that it is a compile-time error if a type is not found in a file under a name composed of the type name plus an extension (such as .java or .jav) if either of the following is true:
* The type is referred to by code in other compilation units of the package in which the type is declared. * The type is declared public (and therefore is potentially accessible from code in other packages).
This restriction implies that there must be at most one such type per compilation unit. This restriction makes it easy for a compiler for the Java programming language or an implementation of the Java virtual machine to find a named class within a package; for example, the source code for a public type wet.sprocket.Toad would be found in a file Toad.java in the directory wet/sprocket, and the corresponding object code would be found in the file Toad.class in the same directory." [ June 11, 2007: Message edited by: prateek chaudhari ]
It helps the compiler to locate the dependent java files which also need to be compiled.
The Zen of Java Programming.
Joined: Sep 17, 2006
Originally posted by prateek chaudhari: ... as posted ...
Since you seem to have this well in hand.
I call my business Belvedere. ( Named after the 1958 Plymouth Belvedere ) My (pet project) is called Alice. The main() class for Alice is now: N:\Alice\Alice.java ~ the first line of that file is package Belvedere; "\r" Say I want to move everything over to the ubiquitous C:\ attachment point. I call the class Alice because it is part of the contract specifications that only baccalaureate grads with field experience will have access to the program, and that they will read the documentation for the program before using it.
Based on my reading, "wet/sprocket" would be appropriate for Toadie the Roadie, but I should create a directory named Alice and change the package names to Alice or or create a directory name Belvedere ( belvedere ?) Belvedere would be a master name that would never be the name of a Program, Class or Java Source File.
The size of N:\Alice\Alice.java is 30.5 MB (32,034,152 bytes), so it is well past the point I should have corrected this. There are numerous sub-packages that do various things and I have becomed accustomed (adj. Frequently practiced, used, or experienced; ) to using these package names while writing in Java.