Support for bidirectional data

The runtime environment includes support for bidirectional data, where text is written from right to left and also from left to right.

Within the Java™ runtime environment, character data is manipulated as Unicode UTF-16 values. However, character data outside the Java runtime environment frequently conforms to different encodings. For this reason, file input/output operations, along with the conversion of bytes to characters and back, also involve conversion from an external encoding to UTF-16 and back. You can specify the external encoding, for example in the constructor of an InputStreamReader or OutputStreamWriter object, or rely on a default encoding.

Through its implementation of the Unicode standard, the Java runtime environment supports many languages, which have various alphabets or scripts.These languages include Arabic and Hebrew, whose scripts are written from right to left. Because Arabic and Hebrew text is frequently mixed with other languages (and numbers), which are written from left to right, the Java runtime environment must be able to handle bidirectional data.

Bidirectional data is more variable than non-bidirectional data because it can be stored not only in various encodings, but also in various layouts. Each layout is a combination of rules for the ordering of the characters (for Arabic and Hebrew) and the shaping of Arabic letters (choosing the appropriate shape of an Arabic letter from several possibilities).

For the same reasons that the Java runtime environment transforms data from external encodings into internal encodings and back, it should transform bidirectional data from external layouts to the layout used within the Java runtime environment, and back. For example, older applications might store data in a visual layout while Java APIs assume an implicit layout (also known as logical layout).

In the Java runtime environment, you can request that layout transformations are run for bidirectional data whenever encoding conversions are run. These transformations are disabled by default. To enable the transformations, set the JAVABIDI system property when you start your Java application. For more information, see -DJAVABIDI.

You can also use the Bidirectional Layout Engine API directly in your Java code. For more information, see Bidirectional support in the API reference documentation.