GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing javaevolved.dev — Locale constructors to Locale.of() | java.evolved
Date/Time
Beginner
Locale constructors to Locale.of()Create language and region locales with Locale.of() instead of deprecated constructors. Code Comparison
✕ Deprecated constructor
Locale brazilianPortuguese =
new Locale("pt", "BR");
✓ Java 19+
Locale brazilianPortuguese =
Locale.of("pt", "BR");
See a problem with this code? Let us know.
Why the modern way wins
✅
Supported APIAvoids deprecated constructors. 👁
Clear constructionThe named factory communicates intent. 🧩
Consistent styleMatches modern JDK value-object factories. Old Approach
Locale constructors
Modern Approach
Locale.of()
Since JDK
19
Difficulty
Beginner
JDK Support
Locale constructors to Locale.of()
Available
Available since JDK 19 (September 2022) How it works
Locale factory methods replace constructors deprecated in JDK 19. The factory form is clearer, aligns with other value-based APIs, and centralizes locale creation. Related Documentation
Proof
Related patterns
Date/Time
Beginner
Date formattingPre-Java 8
// Not thread-safe!
SimpleDateFormat sdf =
new SimpleDateFormat("yyyy-MM-dd");
String formatted = sdf.format(date);
// Must synchronize for concurrent use
Java 8+
DateTimeFormatter fmt =
DateTimeFormatter.ofPattern(
"uuuu-MM-dd");
String formatted =
LocalDate.now().format(fmt);
// Thread-safe, immutable
JDK 8+
→
Date/Time
Beginner
java.time API basicsPre-Java 8
// Mutable, confusing, zero-indexed months Calendar cal = Calendar.getInstance(); cal.set(2025, 0, 15); // January = 0! Date date = cal.getTime(); // not thread-safe Java 8+
LocalDate date = LocalDate.of(
2025, Month.JANUARY, 15);
LocalTime time = LocalTime.of(14, 30);
Instant now = Instant.now();
// immutable, thread-safe
JDK 8+
→
Strings
Beginner
String.formatted()Java 8
String msg = String.format(
"Hello %s, you are %d",
name, age
);
Java 15+
String msg =
"Hello %s, you are %d"
.formatted(name, age);
JDK 15+
→
|
| You are visitor 01402503 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |