日期:2014-05-20  浏览次数:20581 次

Java-基础
一个Java文件,若其中的类包含了一个public类,那么要求这个public类的类名与Java文件名相同。
1、Java中为何要这么规定?
2、若是规范的话,能否提供下定义此规范的相关资料?
3、这种规定对编程有什么好处?

---------
求高手解惑
Java文件

------解决方案--------------------
Naming Conventions

packages
    lowercase.
    Consider using the recommended domain-based conventions described in the Java Language Specification, page 107 as prefixes. (For example, EDU.oswego.cs.dl.) 
files
    The java compiler enforces the convention that file names have the same base name as the public class they define. 

参考:http://g.oswego.edu/dl/html/javaCodingStd.html

JLS中应该会有描述的,自己看下吧:http://docs.oracle.com/javase/specs/jls/se7/jls7.pdf