liveBook · Manning

Locale

As explained in 100 Java Mistakes and How to Avoid Them

A locale is a set of regional and linguistic conventions that affects operations such as case conversion and number formatting.

A locale is a set of regional and linguistic conventions. In Java, the default JVM locale can silently affect operations such as case conversion and number formatting. section 6.11 section 6.2

The Turkish-locale case-conversion mistake

String type = "point"; boolean isPoint = type.toUpperCase().equals("POINT"); This can fail under the Turkish locale because Turkish maps lowercase i to uppercase İ, not I. The same problem can affect normalized XML tags, YAML keys, and internal identifiers. section 6.2

No-argument toUpperCase() and toLowerCase() use the default locale, which comes from user preferences, environment variables, or JVM properties. Case conversion can also change string length: Straße becomes STRASSE under Locale.GERMAN. section 6.2

Avoid locale-sensitive surprises by:

  • Passing an explicit locale when converting case for machine-oriented identifiers. section 6.2
  • Testing with Turkish and other relevant locales instead of assuming English behavior. section 6.2
  • Avoiding assumptions that converted text retains its original length. section 6.2

How 100 Java Mistakes and How to Avoid Them covers it

How deep it goes
Explains default-locale resolution, Turkish mappings, length changes, and reproduction through JVM configuration.
Examples
Uses Turkish I mappings, a point-type comparison, German ß, and a JVM language option.
What you can do after
Diagnose locale-dependent case failures and reproduce them by changing the JVM language setting.
How it connects
Connects locale with case conversion, default JVM settings, string normalization, and number formatting.

Also explained in

Compare how 4 books explain locale →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of 100 Java Mistakes and How to Avoid Them. The section links point to the parts of the book it draws on.