SlideShare a Scribd company logo
1 of 22
Download to read offline
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]

More Related Content

Similar to New Java features: Simplified Design Patterns[LIT3826]

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)Tomer Gabel
 
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
 
Javaforum 20110915
Javaforum 20110915Javaforum 20110915
Javaforum 20110915Squeed
 
Spark + H20 = Machine Learning at scale
Spark + H20 = Machine Learning at scaleSpark + H20 = Machine Learning at scale
Spark + H20 = Machine Learning at scaleMateusz Dymczyk
 
Java Programming and J2ME: The Basics
Java Programming and J2ME: The BasicsJava Programming and J2ME: The Basics
Java Programming and J2ME: The Basicstosine
 
Getting Started with Java
Getting Started with JavaGetting Started with Java
Getting Started with JavaMichael Redlich
 
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 GaelykGuillaume Laforge
 
Introduction to java
Introduction to java Introduction to java
Introduction to java Java Lover
 
Java Programming concept
Java Programming concept Java Programming concept
Java Programming concept Prakash Poudel
 
1 java programming- introduction
1  java programming- introduction1  java programming- introduction
1 java programming- introductionjyoti_lakhani
 
Static analysis of java enterprise applications
Static analysis of java enterprise applicationsStatic analysis of java enterprise applications
Static analysis of java enterprise applicationsAnastasiοs Antoniadis
 
Implementing a JavaScript Engine
Implementing a JavaScript EngineImplementing a JavaScript Engine
Implementing a JavaScript EngineKris Mok
 

Similar to 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
 

More from Miro Wengner

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 engineeringMiro Wengner
 
ASML_FlightRecorderMeetsJava.pdf
ASML_FlightRecorderMeetsJava.pdfASML_FlightRecorderMeetsJava.pdf
ASML_FlightRecorderMeetsJava.pdfMiro Wengner
 
DevDays: Profiling With Java Flight Recorder
DevDays: Profiling With Java Flight RecorderDevDays: Profiling With Java Flight Recorder
DevDays: Profiling With Java Flight RecorderMiro Wengner
 
JMC/JFR: Kotlin spezial
JMC/JFR: Kotlin spezialJMC/JFR: Kotlin spezial
JMC/JFR: Kotlin spezialMiro Wengner
 
Plug Hardware and Play Java
Plug Hardware and Play JavaPlug Hardware and Play Java
Plug Hardware and Play JavaMiro Wengner
 
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 Miro Wengner
 
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 FrameworkMiro Wengner
 
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 Miro Wengner
 
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 APIMiro Wengner
 
How RaspberryPi workers building GraphDatabase
How RaspberryPi workers building GraphDatabaseHow RaspberryPi workers building GraphDatabase
How RaspberryPi workers building GraphDatabaseMiro Wengner
 

More from 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
 

Recently uploaded

New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024BookNet Canada
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphNeo4j
 
Snow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter RoadsSnow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter RoadsHyundai Motor Group
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersThousandEyes
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr LapshynFwdays
 
Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024Neo4j
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
APIForce Zurich 5 April Automation LPDG
APIForce Zurich 5 April  Automation LPDGAPIForce Zurich 5 April  Automation LPDG
APIForce Zurich 5 April Automation LPDGMarianaLemus7
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptxLBM Solutions
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...Fwdays
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Alan Dix
 

Recently uploaded (20)

New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
 
Snow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter RoadsSnow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter Roads
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping Elbows
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 
Vulnerability_Management_GRC_by Sohang Sengupta.pptx
Vulnerability_Management_GRC_by Sohang Sengupta.pptxVulnerability_Management_GRC_by Sohang Sengupta.pptx
Vulnerability_Management_GRC_by Sohang Sengupta.pptx
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
 
Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
APIForce Zurich 5 April Automation LPDG
APIForce Zurich 5 April  Automation LPDGAPIForce Zurich 5 April  Automation LPDG
APIForce Zurich 5 April Automation LPDG
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptx
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
 

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]