Skip to main content

JAVA Identifiers

 JAVA Identifiers  

A name in java program is called identifiers. It may be a class name, method name, variable name, and label name.


class Test

{

      public static void main(string[] args)

     {

           int x = 10;

     }

}

*Text in red color are identifiers.     


Rules to define Java Identifiers:

Rule 1: The only allowed characters in java identifiers are:

          1) a to z

          2) A to Z

          3) 0 to 9

          4) _ (Underscore)

          5) $

Rule 2: If we are using any other character we will get a compile-time error.

         1) total_number   ----------> Valid

         2) Total#              ----------> Invalid

Rule 3: Identifiers are not allowed to starts with digits:

         1) ABC123          -----------> Valid

         2) 123ABC         ------------> Invalid

Rule 4: Java identifiers are case sensitive up course java language itself treated as case sensitive language.

Rule 5: There is no length limit for java identifiers but it is not recommended to take more than 15 lengths.

Rule 6: We can't use reserved words as identifiers.

Comments

Popular posts from this blog

Java Reserved Words

  Java Reserved Words   In java, some identifiers are reserved to associate some functionality or meaning such type of reserved identifiers is called reserved words. > Reserved words for data types (8) byte short int long float char double boolean > Reserved words for flow control (11) if else switch case default for do while break continue return > Keywords for modifiers (11) public private protected static final abstract synchronized native strictfp (1.2 version) transient volatile > Keywords for exception handling (6) try catch finally throw throws assert (1.4 version) > Class related keywords (6) class package import extends implements interface > Object related keywords (4) new super instanceof this > Void return type keywords: If a method won't return anything compulsory that method should be declared with the void return type in java but it is optional in C++ void > Unused keywords : goto: Create several problems in old languages and hence it i

Data Types in Java

Every variable has a type, every expression has a type and all types are strictly define moreover every assignment should be checked by the compiler by the type compatibility hence java language is considered as strongly typed programming language. Integral data types:- byte: Size: 1 byte (8 bits) Range:  -128 to 127 byte data type is best suitable if we are handling data in terms of streams either from the file or from the network. short: The most rarely used data type in Java is short. Size: 2 byte Range: -32768 to 32767 short data type is best suitable for 16-bit processors like 8086 but these processors are completely outdated and hence the corresponding short data type is also out data type. int: Size: 4 byte Range: -2147483678 to 2147483647 long: Whenever int is not enough to hold big values than we should go for long data type. Size: 8byte Range: -263 to 263-1 All the data types (byte, short, int, and long) can be used to represent whole numbers. If we want to represent real num