Thursday, February 18, 2016

Java Identifiers Part 2

Hi All...!

Today post is about the regulations we have to follow when we creating a Java Identifiers, this is not a must to follow if we follow these regulations we can create easy to read codes and quality code.

Let's see what are these regulations,

1) class names

class names must start with capital letters and if class name have more than one word each words' first letter must be capitalize.

ex: NewClass, MyClass

2) Interface names

Same as the class names

3) package names

all letters in package name must be simple

ex: newpackage, homepackage

4) method names

Method names must follow camel case, that means all letters in the first word must be simple and if there are more than one word for the name all words after first word must capitalize it's first letter.

ex: printBill, selectLetter

5) variable names

Same as the method names.

6) constant names

All letters must be capitalize and if name contain more than one word those words must connect by using underscore "_".

ex: MAX_VALUE, MAX_HEIGHT

Tuesday, February 2, 2016

Java Identifiers Part 1

Hi All...!

To I'm going to teach you guys what are the Java Identifiers, Java Identifiers are names of Java classes, interfaces, variables, methods, packages, objects and constants.

There is some rules and regulations to follow when we create names (Identifiers). If we break those rules it will cause to compilation errors but if we don't follow the regulations it will make our code difficult to read and also difficult to maintain and modify.

Let's take a look at what are those rules we must follow when creating a Identifier.

  1. We can't use spaces in Java identifiers.
  2. We can't use spacial characters like !@#%^&*() in Java identifiers. 
  3. We can't use Java Key-words as identifiers.(you can find Key-word chart bellow)
  4. We can only use a letter, _, $ to start identifier.
  5. After we start a identifier by using a letter, _, $ we can use any combinations of letters, _, $ and NUMBERS
If we follow above rule we can create a legal identifiers.



Let's take a look at some examples,