Types and Literals in Java


Java was constructed to be platform independant. This means it can run on any platform, machine or operating system, without recompilation. Simply copy the executable files. This is because compiled Java is not compiled to machine code (binary and assembler) but compiled to a tokenised code which is recognised and interpreted by a browser. Note that Java is only very slightly slower in execution time than C and C++. Strict rules applied to the enforcement of primitive data types helps to enforce platform independence. This due to a number of reasons.

Numeric Types

There are multiple types of numeric literals.

Char Types

char types are 2-byte, 16-bit Unicode characters. This makes no difference to the way that strings and characters are dealt with in most cases in Java. The first 128 Unicode characters are the same as in the ASCII character set. Certain platforms may have problems with Unicode characters. Thus Java allows for the \u escape sequence to be used for the dipplay of those Unicode characters.

The complete list of Java escape sequences is shown below.

\b		Backspace
\t		Horizontal tab
\n		Newline
\f		Form feed
\r		Carriage return
\"		Double quote
\'		Single quote
\\		Backslash
\xxx		Character corresponding to octal value xxx. xxx lies between 000 and 377.
\uxxxx		Unicode character corresponding to hexadecinal digits xxxx.