I have just picked up learning Java. . .
and I just wanted to know what was the thinking behind the developers to make only one public class per file and also give the file name as per the public class.
Thus when a debugger halts at a statement it can it can provide the actual point of discrepancy.
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.
The Java Language Specification
Its a bit difficult for me to grasp your answers as they have lots of technical jargon.
1. The Java compiler in itself is a very very complex piece of software, so...putting a restricting on the Java developer to name his file just for the sake of get the compiler to work a bit easier isn't fitting into my understanding.
2. Even so what about the non public classes that a programmer can write into his source files, I mean in addition to the single public class there may be lots on other classes too!. . .
There are obviously benefits to having it either way.
Those who designed it fell to one side of that fence.
This restriction is not yet enforced by the compiler, although it's necessary for efficient package importation.
Ref: Once Upon an Oak...