This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
I have read that the java (public) class name should match with the java file name. But why does this rule not apply when the java file does not contain a public class. I tried compiling and executing a java file (Learning.java). This file contains a class , Class Test. I expected it not to complie. But it did and worked file. Also after compiling a new Class File "Test.class" was created. I would like to know the reason.
No real reason; it's actually not even a real rule, just an optional rule that may be enforced by the implementation. The very first Java compiler did it to make it easy to find the source code for classes it hadn't compiled yet; other compilers have followed in its footsteps. But don't expect anything fancier than that.