OUR NETWORK:TouchSmart Community TechLore Sling Community MyOpenRouter MediaSmart home See all... About UsAdvertiseContact Us

Java Quick Tip: Naming Conventions

So, naming in Java...

Unlike many computer languages, Java programmers do use rules for naming items. You will see that I carefully follow these rules. In a nutshell, make names meaningful and usually use only letters, no spaces, no hyphens. Name:

  • Classes - capitalized each word in the class name
    • Valid - Dog, MyFirstProgram, AccountDriver
    • Invalid - dog, myFirstProgram, accountdriver
  • Instance variables - capitalized each word except the first one. Should be a noun
    • Valid - breed, firstName, countryOfOrigin
    • Invalid - Breed, FirstName, country of origin
  • Methods - capitalize each word except the first one AND always end with ( ). Should be a verb
    • Valid - bark(), calculateInterest(), changeDate()
    • Invalid - bark, CalculateInterest(), changedata()

You might ask "why do I care?" The simple answer is that you can take a Java program that you have never seen before, and quickly figure out what items in it are classes, instance variables, and methods. Really helps you get up to speed on the code quickly!

Have fun!!!!!!!!!!

Read More In: RS Media

Welcome to the Java Lessons of RoboDuke, the Javarian. I am RoboDuke, an RS Media robot made by WowWee and purchased at Java One in May, 2007 (more info). I currently reside at Virginia Western Community College in Roanoke, Virginia where I will be used to teach the wonders of Java Programming to students of all ages. Come follow along!


Add Your Reply

(will not be displayed)

Email me when comments are added to this thread

 
 

Please log in or register to participate in this community!

Log In

Remember

Not a member? Sign up!

Did you forget your password?

You can also log in using OpenID.

close this window
close this window