Literals of Primitive Types

This section describes how to use literals to represent primitive data values in Java source code. Examples are: 911, 0x38fL, '\n', 3.14F, 1e137, 0x1p3, true, etc.

What is a literal? A literal is a string representation of a data value in a Java source code.

The following list summarizes how a data value of different primitive type can be represented in literals.

Some interesting features supported in Java on primitive type literals:

More syntax rules and examples of primitive type literals are provides in other sections of this chapter.

Last update: 2014.

Table of Contents

 About This Book

 Installing JDK 1.8 on Windows

 Execution Process, Entry Point, Input and Output

Primitive Data Types and Literals

 Data Types Supported in Java

 Integer Data Types

 Floating-Point Data Types

 Logical (Boolean) Data Type

Literals of Primitive Types

 Literal Formats for Integers

 Literal Formats for Integers - Example

 Literal Formats for Floating-Point

 Literal Formats for Floating-Point - Example

 Literal Formats for Characters

 Literal Formats for Character - Example

 Bits, Bytes, Bitwise and Shift Operations

 Managing Bit Strings in Byte Arrays

 Reference Data Types and Variables

 StringBuffer - The String Buffer Class

 System Properties and Runtime Object Methods

 Generic Classes and Parameterized Types

 Generic Methods and Type Inference

 Lambda Expressions and Method References

 Execution Threads and Multi-Threading Java Programs

 ThreadGroup Class and "system" ThreadGroup Tree

 Synchronization Technique and Synchronized Code Blocks

 Deadlock Condition Example Programs

 Garbage Collection and the gc() Method

 Outdated Tutorials

 References

 PDF Printing Version