wood burning stoves 2.0*
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
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Java File Name" Watch "Java File Name" New topic
Author

Java File Name

dina raj
Greenhorn

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 (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.
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24183
    
  34

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: http://aspose.com/file-tools
 
subject: Java File Name
 
Similar Threads
Compiling a java code having different file name and class name
Source File naming rules
name of a non-plublic class
Head1stJava - pg 88 - 24 lines of confusion
Package Problem