Skip to main content

Constants

Numbers

A number in the source code - e.g. 1234 - is parsed as an int if the value can be successfully stored in an integer (minimum value of -2ˆ31 and a maximum value of (2ˆ31)-1). If not, it is parsed as a long (minimum value of -2ˆ31 and a maximum value of (2ˆ31)-1). If it cannot be parsed as a long, it is parsed as a double. Finally, if that fails, a parse error occurs.

If a number is suffixed by b, it is parsed as a byte. e.g. 1b is a byte with value 1.

If a number is suffixed by s, it is parsed as a short. e.g. 1s is a short with value 1.

If a number is suffixed by l, it is parsed as a long. e.g. 1l is a long with value 1.

If a number is suffixed by f, it is parsed as a float. e.g. 1f is a float with value 1.

If a number is suffixed by d, it is parsed as a double. e.g. 1d is a double with value 1.

If a number is suffixed by q, it is parsed as a decimal. e.g. 1q is a decimal with value 1.

Strings

A string is created by wrapping the string with double quotes, as in "Hello world".

To create a string that contains double quotes or to multi-line string, use triple double quotes, as in """This is a string that has a "quote inside it" as an example."""

Booleans

Boolean values is created with the keyword true and false.

Nulls

The null value is created with the keyword null.