Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Are class names allowed to be lower case [closed]

I ran my program successfully when declaring a class name starting with a lower case letter. I don't understood why it is asked to start with first capital letter.

like image 829
shreya Avatar asked Aug 04 '14 13:08

shreya


3 Answers

You can declare it with lower case, but the convention is to start with a capital letter. The conventions were created to make it easier on others to read and understand your code.

Unlike this definition :

class someClass 
{
    otherClass b = null;
}

Sticking with the conventions even helps Stack Overflow color your code in a way that makes it more readable :

class SomeClass
{
    OtherClass b = null;
}
like image 115
Eran Avatar answered Sep 23 '22 21:09

Eran


It's not a matter of can but rather a matter of should. Java naming conventions dictate that class names should begin with an upper case letter. By following conventions, others (including us and your instructors, bosses and co-workers) can better understand and evaluate your code. If you need our help in the future with your code, this can make a big difference. There can be some local variability in some specific rules, so you will want to learn and follow all the specific rules of your office / school.

For more on this, please see Java Naming Conventions.

like image 23
Hovercraft Full Of Eels Avatar answered Sep 21 '22 21:09

Hovercraft Full Of Eels


Also, some code editors/IDEs will hyphenate or space out related generated code file names based on capitalization in your class file.

For instance, Android Studio(https://developer.android.com/sdk/installing/studio.html) will read a Java Activity's class name, and insert a hyphen or underscore when you transition from a capital to a lower case letter for the file name of the layout.

An example: When creating a new activity(which is just a new class) called "MyActivity.java", Android Studio will also create a new layout file called "activity_my.xml" and link to it in the java file.

By sticking to the convention of capitalizing your class names, not only is your source code easier for others to follow and learn, but it will be much easier for you to navigate and keep track of files in your project. Naming conventions are everything.

like image 20
carterh062 Avatar answered Sep 22 '22 21:09

carterh062