Java Identifiers

Introduction

We use identifiers to name code entities, such as classes, variables, and methods.

An identifier can be sequence of uppercase and lowercase letters, numbers, or the underscore and dollar-sign characters.

They must not begin with a number.

Java identifiers is case-sensitive, so VALUE is a different identifier than Value.

Some examples of valid identifiers are

AvgValue count c1234 $test this_is_a_value

Invalid identifier names include these:

2count         //cannot start with digit
high-temp      //cannot have -
Not/ok         //cannot have /

The use of an underscore by itself as an identifier is not recommended.

public class Main { 
    public static void main (String[] args) { 
        boolean BooleanVal = true;  /* Default is false */ 

        char charval = 'G';     /* Unicode UTF-16 */ 
        charval = '\u0490';     /* Ukrainian letter Ghe(?) */ 

        byte byteval;       /*  8 bits, -127 to 127 */ 
        short shortval;     /* 16 bits, -32,768 to 32,768 */ 
        int intval;         /* 32 bits, -2147483648 to 2147483647 */ 
        long longval;       /* 64 bits, -(2^64) to 2^64 - 1 */ 

        float   floatval = 10.123456F; /* 32-bit IEEE 754 */ 
        double doubleval = 10.12345678987654; /* 64-bit IEEE 754 */ 

        String message = "Darken the corner where you are!"; 
        message = message.replace("Darken", "Brighten"); 
    } //  w w w.j  a va  2 s.c o  m
} 



PreviousNext

Related