- It can be a class,variable or label name.They are case sensitive.
- Allowed characters are A-z,0-9 and special characters like _ and $.
- If we use any other characters we will get compile time error.
- Identifier can't start with a digit.
- Ideally there is no limit but recommended size is < 15
- Reserved Characters can't be used as identifiers.
- Predefined classes can be used as identifiers but is not recommended.
Datatypes
- Numeric (represents numbers)
- Byte (Whole numbers) - Default is 0
- Size is 8 bits
- min value is -128 and max is 127
- Negative numbers are represented in 2s complement form.
- We get PLP (possible loss of precision C.E) if we exceed the limit or assign some other data like Boolean ,String or float.
- It is suitable to handle streams of data from file or network.
- Short (Whole numbers) - Default is 0
- Size is 2 Bytes
- Range is -32768 to 32767
- It is rarely used, usually for 16 bit processors.
- Int (Whole numbers) - Default is 0
- Size is 4 Bytes
- Range is -2e31 to 2e31-1
- Helps in being robust at the cost of performance compared to C.
- Long (Long Int) (Whole numbers) - Default is 0
- Size is 8 Bytes
- Range is -2e-63 to -2e63-1
- Float vs Double (Real Numbers) - Default is 0.0
- Size is 4 vs 8 Bytes
- Range is -3.4e38 to 3.4e38 vs -1.7e308 to 1.7e308
- Accuracy in 5 to 6 decimal places vs 14 to 15 decimal places.
- Single precision vs double precision
- Size and range is not applicable, it can be either true or false (Case Sensitive)
- Else we get compile time error of Incompatible Type (I.T)
- Size is 2 Bytes to accommodate Unicode compared to C (ASCII 1 Byte)
- Range is 0 to 65535
Literals
- It is a constant to be assigned to variable.
- Decimals are 0 to 9, Octals are 0 to 7 prefixed by 0 & Hexadecimal literals are A-F (Case insensitive) prefixed by 0x.
- If the above criteria is not fullfilled we get C.E
- Long ,float and double Literals can be siffixed by l, f and d respectively (Case Insensitive).
- Floating point literals can't be specified in other datatypes than Decimals.
- We can specify floating point literal in scientific form (2.2e51).
- Boolean literals are important during evaluation of expressions.
- Char literal
- Char literals are in single inverted commas with single character ,else we get C.E.Can be in decimal,octal or hexadecimal form till 65536.No floating point literals.
- Char literals can be expressed in unicode ('\uxxxx') 4 digit hexadecimal number eg : '\u0061' > a
- Every escape character is char literal
- Any sequence of characters written within double quotes is String literal
- Promotions of Datatypes handled by compiler.
- byte>short>int>long>float>double
- char>int>long>float>double
0 Comments