This week's giveaway is in the Spring forum.
We're giving away four copies of REST with Spring (video course) and have Eugen Paraschiv on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Java File Name Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Java File Name" Watch "Java File Name" New topic

Java File Name

dina raj

Joined: Dec 06, 2005
Posts: 17
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 ( 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.
Ernest Friedman-Hill
author and iconoclast

Joined: Jul 08, 2003
Posts: 24195

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.

[Jess in Action][AskingGoodQuestions]
wise owen
Ranch Hand

Joined: Feb 02, 2006
Posts: 2023
See Another thread.
I agree. Here's the link:
subject: Java File Name
It's not a secret anymore!