Class name convention in java [closed]

ぃ、小莉子 提交于 2020-01-09 02:30:14

问题


What is the naming convention of classes in java, for example should all classes be in upper case like MYCLASS.java ?

as some classes like com.sun.org.apache.bcel.internal.generic. ANEWARRAY. can be found in Sun's library as well

Note: I have read all naming convention from Oracle but I could not find anything which says we should name a class with All Uppercase.


回答1:


Class Names should be in CamelCase. Try to use nouns because a class is normally representing something in the real world.

The Documentation states the following:

Class names should be nouns, in mixed case with the first letter of each internal word capitalized. Try to keep your class names simple and descriptive. Use whole words-avoid acronyms and abbreviations (unless the abbreviation is much more widely used than the long form, such as URL or HTML).




回答2:


Java has a very well described naming / coding convention.

You can look it up here http://www.oracle.com/technetwork/java/javase/documentation/codeconvtoc-136057.html

Technically it doesn't matter how you name you classes as long as public classes are in a .java-source file with the same name as the class.




回答3:


The quoted class com.sun.org.apache.bcel.internal.generic.ANEWARRAY looks to be from the deep innerworking of Java (internal.generic), i.e. not for developer use. As such its really outside of the naming convention. I can only speculate as to why its all in capitals, perhaps to emphasise this point that it shouldn't be used.




回答4:


Usually the best practise is to use Upper CamelCase.anyway there will be no compilation issues with other conventions.see more details about conventions




回答5:


After browsing through many links I came to know there is no java convention which suggests us to name a class in all uppercases. However we do so there will not be any error.

One appropriate reason is mentioned by CloudyMarble that we can use this convention if the abbreviation is more famous like HTML.

Also I would like to add some info about ANEWARRAY, this class comes under Apache license Source and Create new array of references.



来源:https://stackoverflow.com/questions/16537620/class-name-convention-in-java

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!