Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Project Amber: Making Java So Easy, Even Your B...

nehasardana
September 19, 2024

Project Amber: Making Java So Easy, Even Your Boss Will Understand It!

Project Amber is a Java initiative aimed at enhancing developer productivity through targeted language improvements. This talk explores key features such as Local Variable Type Inference (var), Switch Expressions, Text Blocks, Pattern Matching for instanceof, Records, Sealed Classes, Record Patterns, and instance main methods. Each feature is designed to reduce boilerplate, improve code readability, and streamline Java programming. This is a condensed version of the full presentation to be delivered at the Dev2Next conference in Colorado.

nehasardana

September 19, 2024
Tweet

More Decks by nehasardana

Other Decks in Programming

Transcript

  1. Project Amber: Making Java So Easy, Even Your Boss Will

    Understand It! Neha Sardana @ NYJavaSIG
  2. Java Release Cadence 2023-24 Java 23 Sept 2024 Java 22

    March 2024 Java 21 Sept 2023 Java 20 March 2023
  3. Java Development Process - Key Projects • Project Amber: Small,

    incremental language enhancements (e.g., pattern matching, records, local variable type inference) • Project Loom: Lightweight concurrency and virtual threads for improved scalability • Project Valhalla: Advanced JVM features for value types and specialized generics (performance enhancements) • Project Panama: Interfacing Java with native code (e.g., better integration with C libraries) • Project ZGC/Shenandoah: Low-latency garbage collectors for performance-critical applications.
  4. Java Development Process - Key Projects Project ZGC/Shenandoah Low -latency

    garbage collectors for perform ance-critical applications Project Panam a Interfacing Java w ith native code (e.g., better integration w ith C libraries) Project Valhalla Advanced JVM features for value types and specialized generics (perform ance enhancem ents) Project Loom Lightw eight concurrency and virtual threads for im proved scalability Project Am ber Sm all, increm ental language enhancem ents (e.g., pattern m atching, records, local variable type inference)
  5. Why is Project Amber Important? • Impact on Developer Productivity

    ◦ Reduction of Boilerplate Code ◦ Simplified Patterns and Idioms ◦ Increased Focus on Core Logic • Impact on Code Readability ◦ Expressiveness ◦ Clearer Intent ◦ Consistency Across Codebases
  6. Why is Project Amber Important? • Impact on Java's Evolution

    ◦ Keeping Java Competitive ◦ Facilitating Future Enhancements ◦ Broadening Java's Appeal
  7. About Me • Toddler Mom • Vice President at Morgan

    Stanley, New York • More than 15 years of experience in Java • Co-lead New York Java SIG,NY and Garden State Java User Group,NJ • Part of Java in Education program at JCP • Enjoy travelling, yoga and cricket • Find me on LinkedIn, Twitter/X or Github linktr.ee
  8. NYJavaSig JUG Leaders - javasig.com • Barry Burd • Frank

    Greco • Jeanne Boyarsky • Neha Sardana • Rodrigo Graciano • Justin Lee Not here: • Chandra Guntur • Ray Tsang • Sai Saran Donthi
  9. Garden State JUG Leaders - gsjug.org • Scott Selikoff •

    Paul Syers • Diane Liporace • Neha Sardana • Barry Burd • Mike Redlich Not here: • Chandra Guntur
  10. What are JEPs and Preview Features • JEP - Java

    Enhanced Proposals • Preview features ◦ Experimental Features ◦ Opt-in Usage ◦ Evolving Design ◦ How to enable? ◦ Can be taken out! • Command Line: Use --enable-preview with javac and java. • Maven: Add the --enable-preview flag in the maven-compiler-plugin. • Gradle: Modify your build.gradle to include --enable-preview. • IDEs: Use the IDE settings to enable preview features for both compilation and running.
  11. Foundational Enhancements • Local-Variable Type Inference (var) (JEP 286): ◦

    Introduced in Java 10 ◦ Lets the compiler infer variable types, reducing boilerplate • Local-Variable Syntax for Lambda Parameters (JEP 323): ◦ Introduced in Java 11 ◦ Using var in lambda parameters is optional and most useful when you need to add annotations or modifiers ◦ If you use var for one parameter, you must use it for all parameters in the lambda expression
  12. Data Handling Simplifications • Records (JEP 359, JEP 384, JEP

    395): ◦ Introduced in Java 14 as preview, finalized in Java 16 ◦ Data Classes ◦ Immutable and Final ◦ Ideal for Data Transfer Objects • Sealed Classes (JEP 360, JEP 397, JEP 409): ◦ Introduced in Java 15 as preview, finalized in Java 17 ◦ Controlled Inheritance ◦ Improved Code safety ◦ Enhanced Pattern Matching
  13. Data Handling Simplifications • Text Blocks (JEP 355, JEP 368,

    JEP 378): ◦ Introduced in Java 13 as preview, finalized in 15 ◦ Multi-line String Simplification ◦ Improved Readability ◦ Automatic Formatting • String Templates (JEP 430, JEP 459, JEP 465-Withdrawn): ◦ Only exist as preview feature in Java 21 and 22 ◦ Not available in Java 23! ◦ Simplified String Concatenation ◦ Improved Safety ◦ Enhanced Readability
  14. Control Flow Improvements • Switch Expressions (JEP 325, JEP 354,

    JEP 361): ◦ Introduced in Java 12 as preview, finalized in Java 14 ◦ Simplified Syntax ◦ Return Values ◦ Exhaustiveness Checking • Pattern Matching for instanceof (JEP 305, JEP 375, JEP 394): ◦ Introduced in Java 14 as preview, finalized in Java 16 ◦ Eliminates Casting ◦ Improves Readability ◦ Safer Type Handling
  15. Control Flow Improvements • Pattern Matching for switch (JEP 406,

    420, 427, 433, 441): ◦ Introduced in Java 17 as preview, finalized in Java 21 ◦ Simplifies Control Flow ◦ Type-Safe Exhaustiveness ◦ Works with Sealed Types • Primitive Types in Patterns, instanceof, and switch (JEP 455): ◦ Introduced in Java 23 as preview ◦ Unified Type Handling ◦ Enhanced Switch Expressions ◦ Reduced Boilerplate
  16. Control Flow Improvements • Record Patterns (JEP 405, JEP 432,

    JEP 440): ◦ Introduced in Java 19 as Preview, finalized in Java 21 ◦ Pattern Matching for Data Decomposition ◦ Enhanced Readability ◦ Works with instanceof and switch • Unnamed Patterns and Variables (JEP 443, JEP 456): ◦ Introduced in Java 21 as Preview, finalized in Java 22 ◦ Ignore Unneeded Data ◦ Cleaner Syntax ◦ Enhanced Pattern Matching Flexibility
  17. New Language Features • Implicitly Declared Classes and Instance main

    Methods (JEP 445, 463, 477): ◦ Introduced in Java 21 as Preview, not finalized yet ◦ Simplifies Prototyping ◦ Reduces Boilerplate ◦ Instance-based Execution • Module Import Declarations (JEP 476): ◦ Introduced in Java 23 as Preview ◦ Simplifies Module Usage ◦ Enhanced Modularity ◦ Improved Readability
  18. New Language Features • Statements Before super(…) (JEP 447, JEP

    482): ◦ Introduced in Java 22 as Preview, Java 23 with changed description ◦ Flexible Initialization ◦ Improved Code Flow ◦ Enhanced Control
  19. Useful Links • Project Amber homepage • Blogs from Nicolai

    Parlog • Blog from Neha • Data Oriented Programming Code Samples: https://github.com/nehasardana09/project-amber-deep-dive mber-deep-dive