Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Java File Name

 
dina raj
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 24208
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
wise owen
Ranch Hand
Posts: 2023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
See Another thread.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic