**Java Tutorials - Herong's Tutorial Examples** - v8.20, by Dr. Herong Yang

Literal Formats for Floating-Point

This section describes 2 literal formats for floating-point values: decimal and hex floating-point literals. The default floating-point literal data type is 'double'.

Java supports literals for 2 floating-point data types in 2 formats described below:

1. Decimal Floating-Point Literal - Basic rules on decimal floating-point literals:

- A floating-point value in "double" data type can be represented 2 parts: a base part and an optional exponent part.
- The base part consists of an integer part, a decimal point and a fractional part. Examples are: 365.242196, 3.14159 and 0.000000001.
- The exponent part is a sequence of decimal digits: 0, 1, 2, 3, 4, 5, 6, 7, 8, and 9 with a leading sign + or - and a prefix of e or E. Examples are: 3.65242196e2, 3.14159e0 and 1.0e-9.
- To specify values in "float" data type, suffix F or f can be added. Examples are: 3.65242196e2F, 3.14159e0F and 1.0e-9F.
- To increase readability, _ can be used as group separators. Examples are: 3.652_421_96e2F and 3.141_59e0F.

2. Hex Floating-Point Literal - Basic rules on hex floating-point literals:

- A floating-point value in "double" data type can be represented 2 parts: a base part and an exponent part.
- The base part consists of an integer part, a decimal point, a fractional part and a prefix of 0x or 0X. The base part should be evaluated as a hexadecimal number: each digit in the integer part is evaluated 16 times more than the next digit on the decimal point side. each digit in the fractional part is evaluated 16 times less than the next digit on the decimal point side. For example: 0x123.456 should be evaluated as 1*16*16 + 2*16 + 3 + 4/16 + 5/16/16 + 6/16/16.
- The exponent part is a sequence of decimal digits: 0, 1, 2, 3, 4, 5, 6, 7, 8, and 9 with a leading sign + or - and a prefix of p or P. The exponent part is evaluated with a base of 2, not 10. For example: 0x1p4 should be evaluated as 1*2*2*2*2.
- To specify values in "float" data type, suffix F or f can be added. Examples are: 0x123.456p0F and 0x1.23456p8F.
- To increase readability, _ can be used as group separators. Examples are: 0x12_345.6p-8F and 0x1.23_456p8F.

Table of Contents

Execution Process, Entry Point, Input and Output

►Primitive Data Types and Literals

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

Java Modules - Java Package Aggregation

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

Assert Statements and -ea" Option