Java Naming Conventions: Classes & Methods

Instructor: Martin Gibbs

Martin has 16 years experience in Human Resources Information Systems and has a PhD in Information Technology Management. He is an adjunct professor of computer science and computer programming.

Wouldn't it be confusing if some traffic lights were blue, purple, and pink? Even if you knew to stop on purple or red, it would be a very strange world. The same is true of Java naming conventions. It makes sense to follow a standard. This lesson will cover the accepted conventions for naming classes and methods.

Classes and Methods

Before we get into the naming conventions, let's quickly review classes and methods.

Remember that a class is a building plan for an object. There may be hundreds of instances of a customer, but there is only one Customer class. This class defines the setup for future objects of that class. In object-oriented programming, those objects are called instances of that class. A method is a set of instructions within the class. It is an action to be taken, such as return or set a value.

Now that we've gone over the basics, let's review the best practices for naming methods and classes.

Naming: General Reminders

It is generally good coding practice to be concise, yet descriptive. If you have ever seen a file folder with a dozen documents, all labeled generically labeled (Doc1, Doc2, ...), you know how frustrating it can be to work without naming conventions.

Java certainly will allow you to name your variables var1, var2, and var3. You can name classes and methods the same way, and not follow any type of guideline. However, anyone working with your code will not be very happy with you! Therefore, it is important to follow a convention. There are no set laws for naming. The guidelines in this lesson will cover the common naming conventions for classes and methods.

Naming Conventions: Classes

Take a look at the following class declaration in Java:

public class Customer {
  //Customer class code here

You'll notice that the name of the class is capitalized. This is a distinguishing feature for classes. When you name variables, they should start with lowercase letters. Therefore, creating a new instance of Customer, you can easily distinguish the class from the variable:

public class Customer {
  //Customer class code here
Customer customer = new Customer();

By following the naming convention, we've been able to have a variable name (customer) share the name of the class (Customer). Since the class is capitalized, it is very clear which item is which.

Naming Conventions: Methods

While class names start with capital letters, methods should begin with a lowercase letter. Any other words you need as part of the method name will be uppercase. NO SPACES are allowed in the names! Also, since a method is an action (where the class is the blueprint), method names should be verbs. Then it is clear that an action is being taken.

To unlock this lesson you must be a Member.
Create your account

Register to view this lesson

Are you a student or a teacher?

Unlock Your Education

See for yourself why 30 million people use

Become a member and start learning now.
Become a Member  Back
What teachers are saying about
Try it risk-free for 30 days

Earning College Credit

Did you know… We have over 200 college courses that prepare you to earn credit by exam that is accepted by over 1,500 colleges and universities. You can test out of the first two years of college and save thousands off your degree. Anyone can earn credit-by-exam regardless of age or education level.

To learn more, visit our Earning Credit Page

Transferring credit to the school of your choice

Not sure what college you want to attend yet? has thousands of articles about every imaginable degree, area of study and career path that can help you find the school that's right for you.

Create an account to start this course today
Try it risk-free for 30 days!
Create an account