Locale Sensitive Case Conversion Turkish

Case conversion changes meaning under the Turkish locale, so fixed words like protocol names must pin Locale.ROOT instead of trusting the default.

JavaForm Validation

Code

snippet
import java.util.Locale;

public class CaseRules {

    public static void main(String[] args) {
        Locale turkish = Locale.of("tr", "TR");

        // the default rule: i uppercases to I
        System.out.println("root: " + "i".toUpperCase(Locale.ROOT));

        // the Turkish rule: i becomes the dotted capital İ, a different character
        System.out.println("tr: " + "i".toUpperCase(turkish));

        // the split goes both ways: I lowercases to dotless ı, not i
        System.out.println("tr lower: " + "I".toLowerCase(turkish));

        // no-Locale overloads follow the JVM default locale; results can vary per machine
        System.out.println("default: " + "i".toUpperCase());

        // fixed words such as protocol names must pin Locale.ROOT for casing
        System.out.println("header: " + "content-type".toUpperCase(Locale.ROOT));
    }
}

What the demo splits

Under Locale.ROOT, i uppercases to I, the rule every ASCII code path assumes. Passing Locale.of(“tr”, “TR”) instead makes the same call produce the dotted capital İ, a different code point with different matching semantics.

The split runs both directions: I under Turkish lowercases to dotless ı, not i. The no-Locale toUpperCase follows whatever the JVM default is, which is why the demo pins Locale.ROOT for content-type; fixed identifiers must not change shape per machine.

Points worth noting

  • Turkish dotless ı and dotted İ are distinct Unicode letters.
  • Default-locale calls are a portability hazard in protocol and wire code.

Interactive Tools for This Topic

FAQ

Why pin Locale.ROOT for protocol names?
Without an explicit locale the JVM default decides; on a Turkish machine the dotted İ would corrupt fixed identifiers during uppercasing. Locale.ROOT keeps the ASCII rule everywhere.