SlideShare une entreprise Scribd logo
1  sur  22
Télécharger pour lire hors ligne
Miroslav Wengner
New Java features
Simplified Design Patterns
Benedikt Neumayr
Safe Harbour Statement
All what you will hear can be di
ff
erent, this presentation is for
motivational purposes …
Miroslav Wengner
• Husband, Father, Software Engineer, Author, Blogger, Technology Enthusiast
• JCP: Executive Committee Board Member, OpenJDK Committer
• Java Mission Control Project, Open-Source projects
• Co-Author of Robo4J Project (Duke Award)
• Java Champion, JavaOne RockStar
• Principal Engineer at OpenValue
Benedikt Neumayr
• Human
• Managing Director at OpenValue
• Software Architect
• Expert for Project Consolidation
• Java Enthusiast
• Group Of Talented and Motivated Individuals
• Netherlands, Germany, Switzerland, Austria…
• Fun, Development, Trainings, Migration and
more…
Agenda
• Java Platform and OpenJDK
• SOLID thinking about design patterns
• Simplifying objects creation
• Thinking structural
• Enforcing behaviour at runtime
• Touching concurrency
• Conclusion
• Q/A
Java Platform and OpenJDK
• Compiler => byte-code
• JIT => instructions
• JVM Interpreter => EXPECTED RESULT
• Byte code optimisation: inlining, elimination, scalarization
static factory_method.Car produce(java.lang.String);
descriptor: (Ljava/lang/String;)Lfactory_method/Car;
fl
ags: (0x0008) ACC_STATIC
Code:
stack=7, locals=5, args_size=1
0: new #7 // class factory_method/FactoryMethodEvent
3: dup
…
19: aload_3
20: invokevirtual #17 // Method java/lang/String.hashCode:()I
23: lookupswitch { // 2
3135580: 48
3556498: 63
default: 75
}
48: aload_3
49: ldc #23 // String fast
51: invokevirtual #25 // Method java/lang/String.equals:(Ljava/lang/Object;)Z
SOLID thinking about design patterns
• SOLID principles:
• Single responsibility, Open-Close, Liskov Substitution
• Interface Segregation, Dependency Inversion
• Do NOT Repeat Yourself, Separation of Concerns, CAP
• Programming languages and technology agnostic
• Micro-services Architecture, Distributed systems
• Domain Driven Design, Data streaming (LM, AI)
• Extendability, Maintainability or Security
split?
More pieces there…
?
?
SOLID thinking about design patterns
• Design Pattern Types: Creational, Structural, Behavioural => Concurrency (services, runtime)
• Important projects
• Project Valhalla: performance gains through generic API, primitives and value types, ML and BigData apps
• Hidden Classes(JEP-371), Warnings for Value-Based Classes (JEP-390)…
• Project Panama: interconnecting JVM and well de
fi
ned non-java APIs, easier access for I/O apps
• Foreign Function & Memory API (JEP-424), Vector API (JEP-426)…
• Project Amber: improving productivity through Java language evolution
• Local-Variable Type inference (JEP-286), Switch Extension (JEP-361),
• TextBlocks (JEP-378), Records (JEP-395), Pattern Matching for instanceof (JEP-394)
• Sealed Classes (JEP-409), UTF-8 by Default(JEP-400), Record Patterns(JEP-405) …
• Project Loom: easy to use, hight-throughput, lightweight concurrency and programming approaches
• Virtual Threads (JEP-425), Structured Concurrency(JEP-428)…
?
Simplifying objects creation
• Candidates: Factory or Builder, what is the di
ff
erence ?
• wrapping or step by step till the end, complement, testable…
• Others:
Abstract Factory, Prototype, Singleton, Object pool
Lazy initialisation, Dependency Injection
?
Simplifying objects creation
Builder in JDK: StringBuilder or
public class Thread implements Runnable { //JDK19(Preview)
public sealed interface Builder
permits Builder.OfPlatform,
Builder.OfVirtual,
ThreadBuilders.BaseThreadBuilder {..}}
Factory in JDK: Java Collection framework: List, Set or Map
static <E> List<E> of(E e1, E e2, E e3) {
return ImmutableCollections.listFromTrustedArray(e1, e2, e3);
}
static <K, V> Map<K, V> of(K k1, V v) {
return new ImmutableCollections.Map1<>(k1, v1);
}
?
Simplifying objects creation
record FastCar(String type) implements Car {…
sealed interface Factory permits CarFactory {…
final class CarFactory {
static Vehicle produce(String type) {
var result = switch (type) {
case "fast" -> {
…
yield new FastCar(“super”);
}
case String s
when s.length() > 10 -> new SlowCar()
…
?
Thinking structural
• How to organise a code (instructions) around instantiated objects
• Candidates: Adapter, Flyweight
• Others: Composite, Decorator, Facade, Filter, Module, Front-
Module, Controller, Marker, Proxy, Twin
?
Thinking structural
Adapter in JDK:
public final class Spliterators {…
public static<T> Iterator<T> iterator(Spliterator<? extends T> spliterator) {
Objects.requireNonNull(spliterator);
class Adapter implements Iterator<T>, Consumer<T> {…}}}
public Collections {…
public static <T> ArrayList<T> list(Enumeration<T> e) {…}
Flyweight in JDK:
wrapper classes Integer, Byte, Character and valueOf(…) method uses Cache.
example: return IntegerCache.cache[i + (-IntegerCache.low)];
?
Thinking structural
?
var engine = counter++ % 2 == 0 ? new DieselEngine() : new ElectricEngine();
var fastCar = new FastCar(engine);
class FastCar {
…
FastCar(Engine engine){…}
public void drive(){
if (engine instanceof ElectricEngine ee) {
ee.checkBatteries();
}
engine.run();
…
sealed interface Engine {
void run();
}
Enforcing behaviour at runtime
• What about runtime?
• maintain information exchange between the objects
• Flexibility and maintainability: JVM and codebase
• Candidates: Chain of Responsibility, Command, Caching
• Others: State, Strategy , Interpreter, Iterator, Mediator, Memento,
Null Object, Observer, Pipeline, Template method, Visitor…
?
Enforcing behaviour at runtime
Chain of Responsibility in JDK
public class Logger {
public void log (Level level, Supplier<String> msgSupplier)
//overloaded method, Levels: OFF, SEVERE, WARNING …
Command in JDK:
java.lang.Runnable, java.lang.Callable
Caching in JDK
java.util.Locale
private static class Cache extends LocaleObjectCache<Object, Locale> {
private static final Cache LOCALECACHE = new Cache();
?
Touching concurrency
• What about code running in parallel?
• Multithreaded nature of the problem
• Design patterns combination…
• Candidate: Thread Pool Pattern
• Others: Active Object, Async Method Invocation, Balking,
Double-Checked Locking, Read-Write Lock, Scheduler …
?
Touching concurrency
?
var threadPerTaskExecutor = Executors.newThreadPerTaskExecutor(threadFactory);
var executor = Executors.newVirtualThreadPerTaskExecutor();
threadPerTaskExecutor.execute(() -> {
while (active.get()){
executor.submit(new ComputableTask(counter));
}
})
package dependency (JMC 8.3)
Conclusion
• Design Patterns and new JDK features helps to:
• improve code clarity: Sealed Classes, Pattern Matching
• reduce verbosity: Switch Statement improvements, Records
• enforce maintainability: Project Amber, Project Loom
• simpli
fi
ed composition: VirtualThreads, StructuredConcurrency, Switch, Local-Variable Type
• observability, pro
fi
ling, debugging and understanding
• Java as the 1st language for the JVM
?
Q / A
twitter: @openvalue
email: benedikt@openvalue.de
twitter: @miragemiko
github:@mirage22
email: miro@openvalue.de
Thank YOU !
References:
• Project Amber: https://openjdk.org/projects/amber/
• Project Valhalla: https://openjdk.org/projects/valhalla/
• Project Panama: https://openjdk.org/projects/panama/
• JFR Project: https://github.com/openjdk/jmc
• OpenJDK: https://openjdk.org/
• foojay.io: https://foojay.io/today/author/miro-wengner/
• OpenValue Blog: https://openvalue.blog/
Book In Progress: Practical Design Patterns for Java Developers [PACKT]

Contenu connexe

Similaire à New Java features: Simplified Design Patterns[LIT3826]

Byteman and The Jokre, Sanne Grinovero (JBoss by RedHat)
Byteman and The Jokre, Sanne Grinovero (JBoss by RedHat)Byteman and The Jokre, Sanne Grinovero (JBoss by RedHat)
Byteman and The Jokre, Sanne Grinovero (JBoss by RedHat)
OpenBlend society
 
Java Programming and J2ME: The Basics
Java Programming and J2ME: The BasicsJava Programming and J2ME: The Basics
Java Programming and J2ME: The Basics
tosine
 

Similaire à New Java features: Simplified Design Patterns[LIT3826] (20)

Nashorn: JavaScript that doesn’t suck (ILJUG)
Nashorn: JavaScript that doesn’t suck (ILJUG)Nashorn: JavaScript that doesn’t suck (ILJUG)
Nashorn: JavaScript that doesn’t suck (ILJUG)
 
Byteman and The Jokre, Sanne Grinovero (JBoss by RedHat)
Byteman and The Jokre, Sanne Grinovero (JBoss by RedHat)Byteman and The Jokre, Sanne Grinovero (JBoss by RedHat)
Byteman and The Jokre, Sanne Grinovero (JBoss by RedHat)
 
Javaforum 20110915
Javaforum 20110915Javaforum 20110915
Javaforum 20110915
 
CS8392 OOP
CS8392 OOPCS8392 OOP
CS8392 OOP
 
Spark + H20 = Machine Learning at scale
Spark + H20 = Machine Learning at scaleSpark + H20 = Machine Learning at scale
Spark + H20 = Machine Learning at scale
 
Java withrealworldtechnology
Java withrealworldtechnologyJava withrealworldtechnology
Java withrealworldtechnology
 
Java Programming and J2ME: The Basics
Java Programming and J2ME: The BasicsJava Programming and J2ME: The Basics
Java Programming and J2ME: The Basics
 
oop unit1.pptx
oop unit1.pptxoop unit1.pptx
oop unit1.pptx
 
Getting Started with Java
Getting Started with JavaGetting Started with Java
Getting Started with Java
 
Google App Engine Java, Groovy and Gaelyk
Google App Engine Java, Groovy and GaelykGoogle App Engine Java, Groovy and Gaelyk
Google App Engine Java, Groovy and Gaelyk
 
Java1 in mumbai
Java1 in mumbaiJava1 in mumbai
Java1 in mumbai
 
Introduction to java
Introduction to java Introduction to java
Introduction to java
 
Java Programming concept
Java Programming concept Java Programming concept
Java Programming concept
 
Letest
LetestLetest
Letest
 
1 java programming- introduction
1  java programming- introduction1  java programming- introduction
1 java programming- introduction
 
JAVA PROGRAM CONSTRUCTS OR LANGUAGE BASICS.pptx
JAVA PROGRAM CONSTRUCTS OR LANGUAGE BASICS.pptxJAVA PROGRAM CONSTRUCTS OR LANGUAGE BASICS.pptx
JAVA PROGRAM CONSTRUCTS OR LANGUAGE BASICS.pptx
 
JS Essence
JS EssenceJS Essence
JS Essence
 
Java programming and security
Java programming and securityJava programming and security
Java programming and security
 
Static analysis of java enterprise applications
Static analysis of java enterprise applicationsStatic analysis of java enterprise applications
Static analysis of java enterprise applications
 
Implementing a JavaScript Engine
Implementing a JavaScript EngineImplementing a JavaScript Engine
Implementing a JavaScript Engine
 

Plus de Miro Wengner

Plus de Miro Wengner (10)

Boost delivery stream with code discipline engineering
Boost delivery stream with code discipline engineeringBoost delivery stream with code discipline engineering
Boost delivery stream with code discipline engineering
 
ASML_FlightRecorderMeetsJava.pdf
ASML_FlightRecorderMeetsJava.pdfASML_FlightRecorderMeetsJava.pdf
ASML_FlightRecorderMeetsJava.pdf
 
DevDays: Profiling With Java Flight Recorder
DevDays: Profiling With Java Flight RecorderDevDays: Profiling With Java Flight Recorder
DevDays: Profiling With Java Flight Recorder
 
JMC/JFR: Kotlin spezial
JMC/JFR: Kotlin spezialJMC/JFR: Kotlin spezial
JMC/JFR: Kotlin spezial
 
Plug Hardware and Play Java
Plug Hardware and Play JavaPlug Hardware and Play Java
Plug Hardware and Play Java
 
From Concept to Robotic Overlord with Robo4J
From Concept to Robotic Overlord with Robo4J From Concept to Robotic Overlord with Robo4J
From Concept to Robotic Overlord with Robo4J
 
JavaOne 2016 :: Bringing Robot online with Robo4j Framework
JavaOne 2016 :: Bringing Robot online with Robo4j FrameworkJavaOne 2016 :: Bringing Robot online with Robo4j Framework
JavaOne 2016 :: Bringing Robot online with Robo4j Framework
 
JavaOne presentation - building steps :: Number42 is alive
JavaOne presentation - building steps :: Number42 is alive JavaOne presentation - building steps :: Number42 is alive
JavaOne presentation - building steps :: Number42 is alive
 
The Robot under dictate of the LegoMindStorm Java Concurrency API
The Robot under dictate of the LegoMindStorm Java Concurrency APIThe Robot under dictate of the LegoMindStorm Java Concurrency API
The Robot under dictate of the LegoMindStorm Java Concurrency API
 
How RaspberryPi workers building GraphDatabase
How RaspberryPi workers building GraphDatabaseHow RaspberryPi workers building GraphDatabase
How RaspberryPi workers building GraphDatabase
 

Dernier

Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 

Dernier (20)

Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 

New Java features: Simplified Design Patterns[LIT3826]

  • 1. Miroslav Wengner New Java features Simplified Design Patterns Benedikt Neumayr
  • 2. Safe Harbour Statement All what you will hear can be di ff erent, this presentation is for motivational purposes …
  • 3. Miroslav Wengner • Husband, Father, Software Engineer, Author, Blogger, Technology Enthusiast • JCP: Executive Committee Board Member, OpenJDK Committer • Java Mission Control Project, Open-Source projects • Co-Author of Robo4J Project (Duke Award) • Java Champion, JavaOne RockStar • Principal Engineer at OpenValue
  • 4. Benedikt Neumayr • Human • Managing Director at OpenValue • Software Architect • Expert for Project Consolidation • Java Enthusiast
  • 5. • Group Of Talented and Motivated Individuals • Netherlands, Germany, Switzerland, Austria… • Fun, Development, Trainings, Migration and more…
  • 6. Agenda • Java Platform and OpenJDK • SOLID thinking about design patterns • Simplifying objects creation • Thinking structural • Enforcing behaviour at runtime • Touching concurrency • Conclusion • Q/A
  • 7. Java Platform and OpenJDK • Compiler => byte-code • JIT => instructions • JVM Interpreter => EXPECTED RESULT • Byte code optimisation: inlining, elimination, scalarization static factory_method.Car produce(java.lang.String); descriptor: (Ljava/lang/String;)Lfactory_method/Car; fl ags: (0x0008) ACC_STATIC Code: stack=7, locals=5, args_size=1 0: new #7 // class factory_method/FactoryMethodEvent 3: dup … 19: aload_3 20: invokevirtual #17 // Method java/lang/String.hashCode:()I 23: lookupswitch { // 2 3135580: 48 3556498: 63 default: 75 } 48: aload_3 49: ldc #23 // String fast 51: invokevirtual #25 // Method java/lang/String.equals:(Ljava/lang/Object;)Z
  • 8. SOLID thinking about design patterns • SOLID principles: • Single responsibility, Open-Close, Liskov Substitution • Interface Segregation, Dependency Inversion • Do NOT Repeat Yourself, Separation of Concerns, CAP • Programming languages and technology agnostic • Micro-services Architecture, Distributed systems • Domain Driven Design, Data streaming (LM, AI) • Extendability, Maintainability or Security split? More pieces there… ? ?
  • 9. SOLID thinking about design patterns • Design Pattern Types: Creational, Structural, Behavioural => Concurrency (services, runtime) • Important projects • Project Valhalla: performance gains through generic API, primitives and value types, ML and BigData apps • Hidden Classes(JEP-371), Warnings for Value-Based Classes (JEP-390)… • Project Panama: interconnecting JVM and well de fi ned non-java APIs, easier access for I/O apps • Foreign Function & Memory API (JEP-424), Vector API (JEP-426)… • Project Amber: improving productivity through Java language evolution • Local-Variable Type inference (JEP-286), Switch Extension (JEP-361), • TextBlocks (JEP-378), Records (JEP-395), Pattern Matching for instanceof (JEP-394) • Sealed Classes (JEP-409), UTF-8 by Default(JEP-400), Record Patterns(JEP-405) … • Project Loom: easy to use, hight-throughput, lightweight concurrency and programming approaches • Virtual Threads (JEP-425), Structured Concurrency(JEP-428)… ?
  • 10. Simplifying objects creation • Candidates: Factory or Builder, what is the di ff erence ? • wrapping or step by step till the end, complement, testable… • Others: Abstract Factory, Prototype, Singleton, Object pool Lazy initialisation, Dependency Injection ?
  • 11. Simplifying objects creation Builder in JDK: StringBuilder or public class Thread implements Runnable { //JDK19(Preview) public sealed interface Builder permits Builder.OfPlatform, Builder.OfVirtual, ThreadBuilders.BaseThreadBuilder {..}} Factory in JDK: Java Collection framework: List, Set or Map static <E> List<E> of(E e1, E e2, E e3) { return ImmutableCollections.listFromTrustedArray(e1, e2, e3); } static <K, V> Map<K, V> of(K k1, V v) { return new ImmutableCollections.Map1<>(k1, v1); } ?
  • 12. Simplifying objects creation record FastCar(String type) implements Car {… sealed interface Factory permits CarFactory {… final class CarFactory { static Vehicle produce(String type) { var result = switch (type) { case "fast" -> { … yield new FastCar(“super”); } case String s when s.length() > 10 -> new SlowCar() … ?
  • 13. Thinking structural • How to organise a code (instructions) around instantiated objects • Candidates: Adapter, Flyweight • Others: Composite, Decorator, Facade, Filter, Module, Front- Module, Controller, Marker, Proxy, Twin ?
  • 14. Thinking structural Adapter in JDK: public final class Spliterators {… public static<T> Iterator<T> iterator(Spliterator<? extends T> spliterator) { Objects.requireNonNull(spliterator); class Adapter implements Iterator<T>, Consumer<T> {…}}} public Collections {… public static <T> ArrayList<T> list(Enumeration<T> e) {…} Flyweight in JDK: wrapper classes Integer, Byte, Character and valueOf(…) method uses Cache. example: return IntegerCache.cache[i + (-IntegerCache.low)]; ?
  • 15. Thinking structural ? var engine = counter++ % 2 == 0 ? new DieselEngine() : new ElectricEngine(); var fastCar = new FastCar(engine); class FastCar { … FastCar(Engine engine){…} public void drive(){ if (engine instanceof ElectricEngine ee) { ee.checkBatteries(); } engine.run(); … sealed interface Engine { void run(); }
  • 16. Enforcing behaviour at runtime • What about runtime? • maintain information exchange between the objects • Flexibility and maintainability: JVM and codebase • Candidates: Chain of Responsibility, Command, Caching • Others: State, Strategy , Interpreter, Iterator, Mediator, Memento, Null Object, Observer, Pipeline, Template method, Visitor… ?
  • 17. Enforcing behaviour at runtime Chain of Responsibility in JDK public class Logger { public void log (Level level, Supplier<String> msgSupplier) //overloaded method, Levels: OFF, SEVERE, WARNING … Command in JDK: java.lang.Runnable, java.lang.Callable Caching in JDK java.util.Locale private static class Cache extends LocaleObjectCache<Object, Locale> { private static final Cache LOCALECACHE = new Cache(); ?
  • 18. Touching concurrency • What about code running in parallel? • Multithreaded nature of the problem • Design patterns combination… • Candidate: Thread Pool Pattern • Others: Active Object, Async Method Invocation, Balking, Double-Checked Locking, Read-Write Lock, Scheduler … ?
  • 19. Touching concurrency ? var threadPerTaskExecutor = Executors.newThreadPerTaskExecutor(threadFactory); var executor = Executors.newVirtualThreadPerTaskExecutor(); threadPerTaskExecutor.execute(() -> { while (active.get()){ executor.submit(new ComputableTask(counter)); } }) package dependency (JMC 8.3)
  • 20. Conclusion • Design Patterns and new JDK features helps to: • improve code clarity: Sealed Classes, Pattern Matching • reduce verbosity: Switch Statement improvements, Records • enforce maintainability: Project Amber, Project Loom • simpli fi ed composition: VirtualThreads, StructuredConcurrency, Switch, Local-Variable Type • observability, pro fi ling, debugging and understanding • Java as the 1st language for the JVM ?
  • 21. Q / A twitter: @openvalue email: benedikt@openvalue.de twitter: @miragemiko github:@mirage22 email: miro@openvalue.de Thank YOU !
  • 22. References: • Project Amber: https://openjdk.org/projects/amber/ • Project Valhalla: https://openjdk.org/projects/valhalla/ • Project Panama: https://openjdk.org/projects/panama/ • JFR Project: https://github.com/openjdk/jmc • OpenJDK: https://openjdk.org/ • foojay.io: https://foojay.io/today/author/miro-wengner/ • OpenValue Blog: https://openvalue.blog/ Book In Progress: Practical Design Patterns for Java Developers [PACKT]