Literals

by Michael Thomas

(Tutorial Home Page)

by Michael Thomas

(Tutorial Home Page)

Objectives (topics)

Topic Notes
Literal - Integers & Floating Point 10L or 10l  = 10 as a long
10.0D or 10.0d = 10 as a double
10.0F or 10.0f = 10 as a float

Integers - default data types & casting:

  • 10 - is an int, unless casted.
  • (byte) 10 - is a byte
  • 10L - is a long

Floating Points - default data types & casting:

  • 10.0 - is a double, unless casted.
  • (float) 10.0 - is a float
  • 10.0F  - is a float
  • 10.0D - is a double

Exponents:

  • 10E3  = 10 * 1000 = 10,000  (10e3 - also works)
  • 10.5E4 = 10.5 * 10,000 = 105,000
Literals - boolean Example of boolean literals
  • blnExample = true;  //true (lowercase only)
  • blnExample = false; //false (lowercase only)
Literals - char Example of char literals
  • charExample = 'A';
  • charExample = 'a';
  • charExample = 'Z';
  • charExample = 'z';
  • charExample = '0';  //Not a number or digit!
  • charExample = '9';  //Not a number or digit!
  • charExample = '\u0041';  //Unicode - same as 'A'
  • charExample = '\u005A';  //Unicode - same as 'Z'
  • charExample = '\u0061';  //Unicode - same as 'a'
  • charExample = '\u007A';  //Unicode - same as 'z'
  • charExample = '\u0030';  //Unicode - same as '0'
  • charExample = '\u0039';  //Unicode - same as '9'
Literals - Bases Literals for Bases
  • 1 - Decimal-base10   (ex: int MyInt = 1;)
  • 01 - Octal-base8 (leading zero)  (ex: int MyInt = 01;)
  • 0x1 - Hexadecimal-base16 (leading 0x)  (ex: int MyInt = 0x1;)
  • '\u0000' - Unicode base 16
  • '\u000' - Unicode base 8