Tutorial by Examples

A hexadecimal number is a value in base-16. There are 16 digits, 0-9 and the letters A-F (case does not matter). A-F represent 10-16. An octal number is a value in base-8, and uses the digits 0-7. A binary number is a value in base-2, and uses the digits 0 and 1. All of these numbers result in ...
Since Java 7 it has been possible to use one or more underscores (_) for separating groups of digits in a primitive number literal to improve their readability. For instance, these two declarations are equivalent: Java SE 7 int i1 = 123456; int i2 = 123_456; System.out.println(i1 == i2); // tru...
String and character literals provide an escape mechanism that allows express character codes that would otherwise not be allowed in the literal. An escape sequence consists of a backslash character (\) followed by one ore more other characters. The same sequences are valid in both character an st...
Integer literals provide values that can be used where you need a byte, short, int, long or char instance. (This example focuses on the simple decimal forms. Other examples explain how to literals in octal, hexadecimal and binary, and the use of underscores to improve readability.) Ordinary integ...
Boolean literals are the simplest of the literals in the Java programming language. The two possible boolean values are represented by the literals true and false. These are case-sensitive. For example: boolean flag = true; // using the 'true' literal flag = false; // using the 'fa...
String literals provide the most convenient way to represent string values in Java source code. A String literal consists of: An opening double-quote (") character. Zero or more other characters that are neither a double-quote or a line-break character. (A backslash (\) character alters t...
The Null literal (written as null) represents the one and only value of the null type. Here are some examples MyClass object = null; MyClass[] objects = new MyClass[]{new MyClass(), null, new MyClass()}; myMethod(null); if (objects != null) { // Do something }...
Floating point literals provide values that can be used where you need a float or double instance. There are three kinds of floating point literal. Simple decimal forms Scaled decimal forms Hexadecimal forms (The JLS syntax rules combine the two decimal forms into a single form. We treat t...
Character literals provide the most convenient way to express char values in Java source code. A character literal consists of: An opening single-quote (') character. A representation of a character. This representation cannot be a single-quote or a line-break character, but it can be an escap...

Page 1 of 1