Home » Java » Core Java » Java Naming Conventions

About Steve Robinson

Steve Robinson

Java Naming Conventions

I wanted to write this short post to help certain people who are having a hard time memorizing the Java API classes and Method names. As you know Java is a case sensitive language and to build Java programs you need to use a lot of Built-in API classes and methods. And beginners find it really hard to memorize the method names and Class names exactly without changing the case.

But actually you need not remember the case. It would be overkill to memorize it. But if you follow the Java Naming conventions, then you need not memorize the case of the methods and classes that you will be using. 99% of the classes in the JAVA API follow this naming convention. Only 1% of the names break this rule and that is also due to programmers forgetting to name it properly (its true!). So here goes…

1. Classes:

Class names always begin with a capital letter (eg. java.util.Scanner). And if there are mutiple words in the class name then each word must also begin with a capital letter (eg. java.util.GregorianCalendar). Also package names always start with lowercase characters (util, lang, io, etc). And if there are multiple words in the package name, then you need to use uppercase for all words except for the starting word. This naming method is popularly called as UpperCamelCase which is a type of CamelCase! Interfaces also use same convention.

class MyClass {

2. Objects/Variables:

Java Naming convention specifies that instances and other variables must start with lowercase and if there are multiple words in the name, then you need to use Uppercase for starting letters for the words except for the starting word. This is called as lowerCamelCase.

String myName;
MyClass myObject;
Scanner scannerObject = new Scanner(System.in);

3. Methods:

Methods in Java also follow the same lowerCamelCase convention like Objects and variables.

void myMethod() {
String myName = scannerObject.nextLine();

4. Constant Variables:

In Java constant variables are declared using “static final” modifiers. And such variables must contain only UpperCase charachters and multiple words must be seperated using ‘_’.

static final char END_OF_FILE = 'e';

Well thats it. Again, all these conventions were created just to improve readability of code. So its your choice to use them or leave them. But if you do use them, your code will look professional. Java Compiler does expect you to use these conventions. But there are some languages where, the way you name your variables, indicates to the compiler what type of variable it is. For instance, in Ruby, for declaring a constant variable you have to use only Uppercase for entire name of the variable. Ruby compiler identifies constant variables in that way only! Thank God, Java is flexible!

Additional Resources:

Reference: Java Naming Conventions from our JCG partner Steve Robinson at Footy ‘n’ Tech blog.

Related Articles:
(0 rating, 0 votes)
You need to be a registered member to rate this.
9 Comments Views Tweet it!
Do you want to know how to develop your skillset to become a Java Rockstar?
Subscribe to our newsletter to start Rocking right now!
To get you started we give you our best selling eBooks for FREE!
1. JPA Mini Book
2. JVM Troubleshooting Guide
3. JUnit Tutorial for Unit Testing
4. Java Annotations Tutorial
5. Java Interview Questions
6. Spring Interview Questions
7. Android UI Design
and many more ....
I agree to the Terms and Privacy Policy

Leave a Reply

8 Comment threads
1 Thread replies
Most reacted comment
Hottest comment thread
7 Comment authors
mandeep kauremma williamsAnnamalaiTechieMeMazhar Recent comment authors

This site uses Akismet to reduce spam. Learn how your comment data is processed.

newest oldest most voted
Notify of

i have read your tutorial it is nice one…..now i got the worth of naming convention in java..thanx


Its a very nice tutorial. You forgot to include naming conventions for packages and interfaces. Reader can read it from here : Java naming conventions


No, He mentioned the conventions for interfaces too. Always Read carefully :)


Thanks brother, I really help me a lot , Keep it up (y).


Great post bro! This is definitely worth reading… I tried to draft a detailed explanation on the importance of naming conventions with couple of examples… You might want to look in to that ..





Nice Article.

emma williams

I seen your blog using google and I must say, this is probably one of the best well prepared articles I have come across in a long time. I have bookmarked your site for more posts. for Java Naming conventions we follow the rules like : By convention, Java programs are written entirely in lower case characters with three exceptions. The first letter of class names are capitalized to distinguish class names from member names. The names of constant fields are written entirely capital letters. For example, the built-in Java class Integer includes the constant static fields MIN_VALUE and MAX_VALUE.… Read more »

mandeep kaur
mandeep kaur

thank you for clearing my doubts