Last week, we had the author of TDD for a Shopping Website LiveProject. Friday at 11am Ranch time, Steven Solomon will be hosting a live TDD session just for us. See for the agenda and registration link
It is well proven fact that we can have only one public class per source code file. But I cannot understand what is the reason behind it to keep only one public class in a file. I want to know that why java developer have included this restriction in java laguage.
Note: Some compilers might allow more than one public class per .java file. However, we recommend that you use the convention of one public class per file because it makes public classes easier to find and works for all compilers.
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.
Please revise your display name to meet the JavaRanch Naming Policy. To maintain the friendly atmosphere here at the ranch, we like folks to use real (or at least real-looking) names, with a first and a last name.
Putting a slight twist on the question. Is it common practice to include multiple classes (obviously not public) within one source file? It likely makes sense if the classes are related or you want to have all of your classes in a given package inside one file but other than that, I don't see any advantage. Is there something I am missing?
Thanks chris that answer my question on it. But still as such I dont see any problem if they allow more than one public class in a file.
There can be little complexity in term of finding the name of the class and file but that is there when we dont have any public class in a file. In other words java allow us to to give any name to source file if we dont have public class in a file.
According to my understanding it can be a Java Convention to name a file with any of the name of the class present in a file rather than restricting it to name the file according to public class present in it.
Yes, my master! Here is the tiny ad you asked for:
free, earth-friendly heat - a kickstarter for putting coin in your pocket while saving the earth