Using Java Naming Conventions and Andriod Naming Issue

This article on naming conventions is based on Java, some rules apply to other programming languages as well.

I highly recommend this article to new programmers who are yet to have their own naming styles (for functions, variables, etc).

This is especially useful if you are just starting to learn programming.

If you are a experienced programmer with your own naming styles, you may want read this and see if there is anything to improve your naming techniques.

Original article: http://java.about.com/od/javasyntax/a/nameconventions.htm

Note on meaningfulness and length:

When choosing a name for an identifier make sure it’s meaningful.

Don’t worry about the length of the name. A longer name that sums up the identifier perfectly is preferable to a shorter name that might be quick to type but ambiguous.

There are 4 types of letter cases for naming:

Lowercase is where all the letters in a word are written without any capitalization e.g.

[/crayon]
Uppercase is where all the letters in a word are written in capitals. When there are more than two words in the name use underscores to separate them e.g.

[/crayon]
CamelCase (also known as Upper CamelCase) is where each new word begins with a capital letter e.g.

[/crayon]
Mixed case (also known as Lower CamelCase) is the same as CamelCase except the first letter of the name is in lowercase e.g.

[/crayon]

Standard Java Naming Conventions:

Basically, follow the naming guidelines below when you write your programs, you will find your programming process more systematic, efficient and professional than if you don’t.

Packages: Names should be in lowercase. With small projects that only have a few packages it’s okay to just give them simple (but meaningful!) names:

[/crayon]
In software companies and large projects where the packages might be imported into other classes, the names will normally be subdivided. Typically this will start with the company domain before being split into layers or features:

[/crayon]
Classes: Names should be in CamelCase. Try to use nouns because a class is normally representing something in the real world:

[/crayon]
Interfaces: Names should be in CamelCase. They tend to have a name that describes an operation that a class can do:

[/crayon]
Note that some programmers like to distinguish interfaces by beginning the name with an “I”:

[/crayon]
Methods (Functions): Names should be in mixed case. Use verbs to describe what the method does:

[/crayon]

“Methods” in Java are equivalent to “functions” in other languages like C, C++ and JavaScript.

Variables: Names should be in mixed case. The names should represent what the value of the variable represents:

[/crayon]
Only use very short names when the variables are short lived, such as in for loops:

[/crayon]
Constants: Names should be in uppercase.

[/crayon]

Android Drawable File Naming Problem – R cannot be resolved error due to capital letters

I also found some related information on naming conventions for Android Development: http://stackoverflow.com/questions/6758228/why-cant-file-names-in-the-drawable-folder-contain-special-characters-or-start

Why can’t file names in the drawable folder contain special characters or start with a capital letter?

Each file inside folder is translated into java field name inside R.java class:

[/crayon]
Hence the reason for not using special characters inside file names, as they can no be used in Java names.
As for capital letters, I guess that’s to avoid one little problem in Windows vs. Linux environment. That’s because Linux thinks that  Icon.png and  icon.png are different files, and Windows thinks that  Icon.png and  icon.png is the same file. So anyone using Linux can create application that is not compilable on Windows.

I had personally faced this problem when I was developing my own Android App for an competition. I was given some error like this:

[/crayon]
It took a while for me to realize the problem lies in the naming of the images files in the drawable folder. I changed the capital letters to small letters and problem was solved. From that experience I learnt that naming is important in programming.

Leave a Reply