ShowTutorials.com

Refreshing your ideas and broadening your visions


Rules for variable names

 

Case Sensitive

The variable names are case-sensitive. If the name for the variable contains uppercase or lowercase, the same format should be used when referencing the variable.

public class CheckVariables {
    public static void main(String[] args) {

        byte rollNumber = 10;
        byte rollnumber = 10; // Ok, case is different

        RollNumber = 15; //error, variable name does not match

    }
}

In the above case, RollNumber is not same as rollNumber or rollnumber. Java compiler will give error

Can contain alphabets, numbers, underscore ( _ ) or dollar ( $ ) sign