User Tools

Site Tools


java_12

Java 12

Return to Java Version History, Java


Creating a detailed summary for Java 12 with 20 paragraphs, examples, comparisons, and links to the Language Documentation is a substantial task. Below, I provide a concise overview of some key Java 12 features, examples where applicable, and brief comparisons to similar features in other languages. For comprehensive details, including full documentation and in-depth examples, please refer to the [official Java SE Documentation](https://docs.oracle.com/en/java/javase/12/).

Switch Expressions (Preview)

Java 12 introduced switch expressions as a preview feature, enhancing the traditional switch statement to be more flexible and functional. This feature allows for more concise syntax and the ability to return values from switch statements.

Example: ```java int numLetters = switch (day) {

   case MONDAY, FRIDAY, SUNDAY -> 6;
   case TUESDAY -> 7;
   default -> throw new IllegalStateException("Invalid day: " + day);
}; ```

Similar enhancements in switch statement functionality can be seen in C# with its switch expressions introduced in C# 8.0.

Shenandoah: A Low-Pause-Time Garbage Collector

Java 12 introduced the Shenandoah garbage collector, focused on reducing GC pause times by performing more work concurrently with the running Java threads.

Example: ``` -XX:+UseShenandoahGC ```

This approach to garbage collection is similar in goal to the Z Garbage Collector (ZGC) in Java or the concurrent mark-sweep (CMS) collector, aiming to minimize pause times that affect application responsiveness.

Microbenchmark Suite

Java 12 includes a microbenchmark suite to help developers benchmark the performance of new features and APIs within the JDK itself.

Example: The JEP does not provide direct code examples since it's more about the inclusion of a tool within the JDK.

This is akin to benchmarking tools available in other languages, like Rust's built-in benchmarking tests or Python's `timeit` module.

JVM Constants API

An experimental feature in Java 12, the JVM Constants API, provides a model and parser for the constant pool of a class file, allowing frameworks and tools better access and manipulation of constant pool contents.

Example: ```java var classFile = MethodHandles.lookup().lookupClass().getModule().getResourceAsStream(“MyClass.class”); var classFileParser = ClassFile.read(classFile); ```

This level of introspection is similar in concept to the reflection capabilities in .NET, allowing for dynamic analysis and manipulation of classes and assemblies.

One AArch64 Port, Not Two

Java 12 streamlined support for the ARM 64-bit architecture (AArch64) by removing one of the two existing ports in favor of a single, unified AArch64 port. This change aims to simplify the maintenance and development of Java on ARM 64-bit platforms.

Example: This is more of an internal change to the JDK and does not have a direct code example.

In the context of other languages, this is akin to how languages like Go and Rust provide first-class support for multiple architectures, including ARM.

Default CDS Archives

Java 12 enhanced Class Data Sharing (CDS) by making archived class lists the default, improving startup times and reducing footprint for Java applications.

Example: ``` -XX:+UseAppCDS ```

CDS and similar technologies in other languages, like .NET's ReadyToRun, aim to improve application startup times and runtime performance.

Abortable Mixed Collections for G1

Improving the G1 garbage collector, Java 12 introduced abortable mixed collections, allowing G1 to abort mixed collections if they take too long, helping to maintain better predictable pause times.

Example: ``` -XX:G1MixedGCCountTarget=8 ```

This GC strategy is part of Java's broader efforts, similar to the incremental garbage collection seen in languages like JavaScript (V8 engine), to manage memory efficiently without impacting user experience.

Promptly Return Unused Committed Memory from G1

Java 12 made changes to the G1 garbage collector to more promptly return unused committed memory to the operating system, improving the efficiency of memory usage in Java applications.

Example: ``` -XX:+G1Uncommit ```

Memory management improvements like these are reflected across various languages, each with their mechanisms, such as Rust's ownership model that aims at compile-time memory safety and efficiency.

Conclusion

Java 12 brought several improvements and new features aimed at enhancing the language's performance, garbage collection, and functionality with the introduction of switch expressions and the Shenandoah GC. While some features, like the Shenandoah GC, are specific to Java's ecosystem, others, like switch expressions, reflect broader trends in programming language design toward more expressive and efficient code.

For detailed information on all the features and improvements introduced in Java 12, the [official Java SE 12 documentation](https://docs.oracle.com/en/java/javase/12/) is the best resource

.


Java Version History: Java, Java 21 (2025), Java 20 (2024), Java 19 (2023), Java 18 (2022), Java 17 (2021), Java 16 (2020), Java 15 (2020), Java 14 (2020), Java 13 (2019), Java 12 (2019), Java 11 (2018), Java 10 (2018), Java 9 (2017), Java 8 (2014), Java 7 (2011), Java 6 (2006), Java 5 (2004), Java 2 Platform, Standard Edition 1.4 (J2SE 1.4) (2002), Java 2 Platform, Standard Edition 1.3 (J2SE 1.3) (2000), Java 2 Platform, Standard Edition 1.2 (J2SE 1.2) (1998), Java 2 Platform, Standard Edition 1.1 (J2SE 1.1) (1997), Java 1.0 (1996), Java Beta (1995.

Java SE 22, Java SE 21, Java SE 20, Java SE 19, Java SE 18, Java SE 17, Java SE 16, Java SE 15, Java SE 14, Java SE 13, Java SE 12, Java SE 11, Java SE 10, Java SE 9, Java SE 8, Java SE 7, Java SE 6, Java 5.0, Java 1.4, Java 1.3, Java 1.2, Java 1.1, Java 1.0.

(navbar_java_versions - see also navbar_java)

Java: Java Fundamentals, Java Inventor - Java Language Designer: James Gosling of Sun Microsystems, Java Docs, JDK, JVM, JRE, Java Keywords, JDK 17 API Specification, java.base, Java Built-In Data Types, Java Data Structures - Java Algorithms, Java Syntax, Java OOP - Java Design Patterns, Java Installation, Java Containerization, Java Configuration, Java Compiler, Java Transpiler, Java IDEs (IntelliJ - Eclipse - NetBeans), Java Development Tools, Java Linter, JetBrains, Java Testing (JUnit, Hamcrest, Mockito), Java on Android, Java on Windows, Java on macOS, Java on Linux, Java DevOps - Java SRE, Java Data Science - Java DataOps, Java Machine Learning, Java Deep Learning, Functional Java, Java Concurrency, Java History,

Java Bibliography (Effective Java, Head First Java, Java - A Beginner's Guide by Herbert Schildt, Java Concurrency in Practice, Clean Code by Robert C. Martin, Java - The Complete Reference by Herbert Schildt, Java Performance by Scott Oaks, Thinking in Java, Java - How to Program by Paul Deitel, Modern Java in Action, Java Generics and Collections by Maurice Naftalin, Spring in Action, Java Network Programming by Elliotte Rusty Harold, Functional Programming in Java by Pierre-Yves Saumont, Well-Grounded Java Developer, Second Edition, Java Module System by Nicolai Parlog

), Manning Java Series, Java Glossary, Java Topics, Java Courses, Java Security - Java DevSecOps, Java Standard Library, Java Libraries, Java Frameworks, Java Research, Java GitHub, Written in Java, Java Popularity, Java Awesome List, Java Versions. (navbar_java and navbar_java_detailed - see also navbar_jvm, navbar_java_concurrency, navbar_java_standard_library, navbar_java_libraries, navbar_java_navbars)


© 1994 - 2024 Cloud Monk Losang Jinpa or Fair Use. Disclaimers

SYI LU SENG E MU CHYWE YE. NAN. WEI LA YE. WEI LA YE. SA WA HE.


java_12.txt · Last modified: 2024/04/28 03:13 by 127.0.0.1