Wednesday, 26 June 2013

Java Naming Conventions

Hai friend Good morning! Welcome to Java session. Today we are going to discuss some naming conventions to be followed in Java.


Class names in Java should start with capital letter. If the class name contains two words, the first letter of both the words should be capital. Also method names should start with small letter and the sebsequent word first letter should be capital. Every statement in Java should end with semicolon.

Java language has certain keywords. Keywords are certain words which are having special meaning to Java and hence these keywords should not be used for other purpose other than for what they are meant to.

In Java if you want to store any value then you should declare one variable to hold the value. Variable is nothing but named memory location where a value can be stored. Also remember that variable value changes during program execution. That's why it is termed is variable. Some times it is also referred as Identifier. There are some rules when you are going to name variables.


Variable naming conventions in Java:

  • Keywords are not allowed to name a variable.
  • Variable name can contain any number of characters. But it is recommended not to go for long names because it is difficult to remember it at a later stage.
  • Variable name should not contain any special characters except $ and _. I mean $ and _ are the only special characters that are allowed to name a variable.
  • Variable name should always start with an alphabet or special character $ or _. It should not start with a number.Of course the second character onwards numbers are allowed. Even though first character can be $ or _ it is not recommendd to use them.
  • Java is case sensitive. That means upper (capital) and lower (small) case letters are always treated as different.

No comments:

Post a Comment