Are lowercase class names allowed

I successfully executed my program when declaring a class name, starting with a lowercase letter. I do not understand why he is asked to start with the first capital letter.

+6
source share
3 answers

You can declare it lowercase, but the agreement must start with a capital letter. Agreements were created to make it easier for others to read and understand your code.

In contrast to this definition:

class someClass { otherClass b = null; } 

Binding to conventions even helps Stack to colorize your code in such a way as to make it more readable:

 class SomeClass { OtherClass b = null; } 
+8
source

This is not a question, but rather a question. Java naming conventions dictate that class names must begin with an uppercase letter. By following the conventions, others (including us and your trainers, bosses, and colleagues) can better understand and evaluate your code. If you need our help in the future with your code, this can make a big difference. Some specific rules may have some local variability, so you will want to learn and follow all the specific rules of your office / school.

See the Java Naming Conventions for more information.

+13
source

In addition, some code / IDE editors will wrap or supplant the associated generated code file names based on the capital letter in your class file.

For example, Android Studio ( https://developer.android.com/sdk/installing/studio.html ) will read the name of the Java activity class and insert a hyphen or underline when switching from capital to lowercase for the layout file name.

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

Adhering to the naming conventions for your classes, your source code will not only make it easier to track and learn others, but it will be much easier for you to navigate and track the files in your project. Naming conventions are all.

+1
source

Source: https://habr.com/ru/post/973316/


All Articles