SlideShare une entreprise Scribd logo
1  sur  34
Télécharger pour lire hors ligne
Java and effective programming.
Is it possible?
Łukasz Koniecki
April 14th, 2016
https://github.com/lkoniecki/EffectiveJava
Whoami
•Software Architect in the Dynatrace,
•Worked as Software Developer and Team Lead,
•10+ years of experience with Java – Enterprise
Application mostly,
•Main area of interest: optimization and application
performance
APM
What this workshop is about?
•Showing examples on good, better and the best
solutions to some common design problems,
•Signaling some commons programming anti-
patterns you should avoid,
•Having fun solving simple Java programming puzzles
What this workshop is not about?
•Learning programming from scratch,
•Learning Java from the beginning,
•Solving all possible Java problems
Design
patterns
POJO with multiple instance members
Telescoping constructor pattern
JavaBean pattern
Builder pattern
Example
The moral
• There are many ways of implementing the same algorithm/functionality,
• There are reusable patterns that you should use (on every possible level:
implementation, integration, deployment etc.
Exercise 1
Specification
• Given the lists of strings as an input, method groupBy in the Example1 class
should return map with all strings that occurred in the input list as key and
number of string occurrences as value,
Example:
For a given input list {„John”, „Aaron”, „John” „Adam”, „Adele”} method
should return following map { {„John”, 2}, {„Aaron”, 1}, {„Adam”, 1},
{„Adele”, 1}}
• Method should throw IllegalArgumentException if elements list is null,
• Method should return empty map if elements list is empty.
Functional
programming
Java7-ish vs. stream-like version
But… Is it safe?
Benchmark results
Moral
• Functional programming is more about coding convenience,
• You should not mix imperative and functional programming
styles,
• Developer must be familiar with how streams work and behave
(e.g. parallel stream execution),
• Must be used with caution (see: 10 Subtle Mistakes When Using
the Streams API)
Generics
What you should know about generics?
•Compile time type check rather than runtime check,
•Generic types are invariant (compare with covariant
arrays)
•List<Integer> is not subtype of List<Number>,
•Can be confusing when implementing API contract,
•Use wildcards with caution.
Example
Moral
•Always try to get into your API consumer shoes,
•Remember the rule:
Producer – <? extends V>
Consumer - <? super V>
Exercise 2
Specification
• Implement union method in the Exercise2 class, so that it returns set being
an union of two sets passed as an argument,
• Change it’s definition so that the following line of code compiles
• Method should throw IllegalArgumentException if any set passed as an
argument is null,
• Remember that producer – super, consumer – extends…
Set<Number> result = Excercise2.union(new HashSet<Integer>(), new HashSet<Number>());
Java/C++/Python/JavaScript
is your favorite?
Be the dev we need!
Visit http://gdansk.dynatrace.pl
Credits
•Joshua Bloch - Effective programming in Java (2nd
edition)
•Nicolai Parlog - Stream performance
Java and effective programming. Is it possible? - IAESTE Case Week 2016

Contenu connexe

Tendances

Language Engineering in the Cloud
Language Engineering in the CloudLanguage Engineering in the Cloud
Language Engineering in the Cloud
lennartkats
 
Test-driven language development
Test-driven language developmentTest-driven language development
Test-driven language development
lennartkats
 
c3ee900a-894b-4680-894c-42f77ffd4446-160308162303
c3ee900a-894b-4680-894c-42f77ffd4446-160308162303c3ee900a-894b-4680-894c-42f77ffd4446-160308162303
c3ee900a-894b-4680-894c-42f77ffd4446-160308162303
Robert Warren
 

Tendances (20)

Java basics training 1
Java basics training 1Java basics training 1
Java basics training 1
 
AspectMock
AspectMockAspectMock
AspectMock
 
What's New in C# ? C# 6, 7.0, 7.1 and 7.2
What's New in C# ? C# 6, 7.0, 7.1 and 7.2What's New in C# ? C# 6, 7.0, 7.1 and 7.2
What's New in C# ? C# 6, 7.0, 7.1 and 7.2
 
Using Aspects for Language Portability (SCAM 2010)
Using Aspects for Language Portability (SCAM 2010)Using Aspects for Language Portability (SCAM 2010)
Using Aspects for Language Portability (SCAM 2010)
 
Password locker project
Password locker project Password locker project
Password locker project
 
me-and-python
me-and-pythonme-and-python
me-and-python
 
Language Engineering in the Cloud
Language Engineering in the CloudLanguage Engineering in the Cloud
Language Engineering in the Cloud
 
Internal domain-specific languages
Internal domain-specific languagesInternal domain-specific languages
Internal domain-specific languages
 
Test-driven language development
Test-driven language developmentTest-driven language development
Test-driven language development
 
c3ee900a-894b-4680-894c-42f77ffd4446-160308162303
c3ee900a-894b-4680-894c-42f77ffd4446-160308162303c3ee900a-894b-4680-894c-42f77ffd4446-160308162303
c3ee900a-894b-4680-894c-42f77ffd4446-160308162303
 
The Spoofax Language Workbench (SPLASH 2010)
The Spoofax Language Workbench (SPLASH 2010)The Spoofax Language Workbench (SPLASH 2010)
The Spoofax Language Workbench (SPLASH 2010)
 
Journey with XP a case study in embedded domain by Pradeep Kumar NR
Journey with XP a case study in embedded domain  by Pradeep Kumar NRJourney with XP a case study in embedded domain  by Pradeep Kumar NR
Journey with XP a case study in embedded domain by Pradeep Kumar NR
 
Systematic Evaluation of the Unsoundness of Call Graph Algorithms for Java
Systematic Evaluation of the Unsoundness of Call Graph Algorithms for JavaSystematic Evaluation of the Unsoundness of Call Graph Algorithms for Java
Systematic Evaluation of the Unsoundness of Call Graph Algorithms for Java
 
Tweakers Developers Summit 2019 - Angular for backend developers
Tweakers Developers Summit 2019 - Angular for backend developersTweakers Developers Summit 2019 - Angular for backend developers
Tweakers Developers Summit 2019 - Angular for backend developers
 
How to Create Python scripts
How to Create Python scriptsHow to Create Python scripts
How to Create Python scripts
 
Java 8 Lambdas
Java 8 LambdasJava 8 Lambdas
Java 8 Lambdas
 
Being Good Developer
Being Good DeveloperBeing Good Developer
Being Good Developer
 
Getting started with scala cats
Getting started with scala catsGetting started with scala cats
Getting started with scala cats
 
java token
java tokenjava token
java token
 
Practices and tools for building better API (JFall 2013)
Practices and tools for building better API (JFall 2013)Practices and tools for building better API (JFall 2013)
Practices and tools for building better API (JFall 2013)
 

En vedette

European Green IT Webinar 2014 - Green Code Lab (France)
European Green IT Webinar 2014 - Green Code Lab (France)European Green IT Webinar 2014 - Green Code Lab (France)
European Green IT Webinar 2014 - Green Code Lab (France)
GreenLabCenter
 
Green-Language programming presentation
Green-Language programming presentationGreen-Language programming presentation
Green-Language programming presentation
Lorraine Cruz
 
Introduction to the Green Code
Introduction to the Green CodeIntroduction to the Green Code
Introduction to the Green Code
buffalogreencode
 
3.2 System Design For Eco Efficiency
3.2 System Design For Eco Efficiency3.2 System Design For Eco Efficiency
3.2 System Design For Eco Efficiency
LeNS_slide
 

En vedette (20)

European Green IT Webinar 2014 - Green Code Lab (France)
European Green IT Webinar 2014 - Green Code Lab (France)European Green IT Webinar 2014 - Green Code Lab (France)
European Green IT Webinar 2014 - Green Code Lab (France)
 
Technology, apps, and websites you need to know about
Technology, apps, and websites you need to know aboutTechnology, apps, and websites you need to know about
Technology, apps, and websites you need to know about
 
Presentation Joost Visser / SIG - what can be green about software- Workshop ...
Presentation Joost Visser / SIG - what can be green about software- Workshop ...Presentation Joost Visser / SIG - what can be green about software- Workshop ...
Presentation Joost Visser / SIG - what can be green about software- Workshop ...
 
Green-Language programming presentation
Green-Language programming presentationGreen-Language programming presentation
Green-Language programming presentation
 
Introduction to the Green Code
Introduction to the Green CodeIntroduction to the Green Code
Introduction to the Green Code
 
Green Programming
Green ProgrammingGreen Programming
Green Programming
 
Green Software Lab
Green Software LabGreen Software Lab
Green Software Lab
 
3.2 System Design For Eco Efficiency
3.2 System Design For Eco Efficiency3.2 System Design For Eco Efficiency
3.2 System Design For Eco Efficiency
 
Green it
Green it  Green it
Green it
 
Green Code Lab Challenge 2015 Subject Details
Green Code Lab Challenge 2015 Subject DetailsGreen Code Lab Challenge 2015 Subject Details
Green Code Lab Challenge 2015 Subject Details
 
Towards Software Sustainability Assessment
Towards Software Sustainability AssessmentTowards Software Sustainability Assessment
Towards Software Sustainability Assessment
 
Ten green bottles
Ten green bottlesTen green bottles
Ten green bottles
 
說服性科技 Persuasive technology
說服性科技 Persuasive technology說服性科技 Persuasive technology
說服性科技 Persuasive technology
 
Software and Sustainability
Software and SustainabilitySoftware and Sustainability
Software and Sustainability
 
How Green are Java Best Coding Practices? - GreenDays @ Rennes - 2014-07-01
How Green are Java Best Coding Practices? - GreenDays @ Rennes - 2014-07-01How Green are Java Best Coding Practices? - GreenDays @ Rennes - 2014-07-01
How Green are Java Best Coding Practices? - GreenDays @ Rennes - 2014-07-01
 
Sissa OSWC Malaga 2008
Sissa OSWC Malaga 2008Sissa OSWC Malaga 2008
Sissa OSWC Malaga 2008
 
Green ICT, sustainability and Open Source
Green ICT, sustainability and Open  SourceGreen ICT, sustainability and Open  Source
Green ICT, sustainability and Open Source
 
The Green Lab - [01-B] Case study presentation
The Green Lab - [01-B] Case study presentationThe Green Lab - [01-B] Case study presentation
The Green Lab - [01-B] Case study presentation
 
The Green Lab - [03 A] Experiment planning
The Green Lab - [03 A] Experiment planningThe Green Lab - [03 A] Experiment planning
The Green Lab - [03 A] Experiment planning
 
The Green Lab - [02 A] The experimental process
The Green Lab - [02 A] The experimental processThe Green Lab - [02 A] The experimental process
The Green Lab - [02 A] The experimental process
 

Similaire à Java and effective programming. Is it possible? - IAESTE Case Week 2016

The View - Lotusscript coding best practices
The View - Lotusscript coding best practicesThe View - Lotusscript coding best practices
The View - Lotusscript coding best practices
Bill Buchan
 
A-Brief-Introduction-To-JAVA8_By_Srimanta_Sahu
A-Brief-Introduction-To-JAVA8_By_Srimanta_SahuA-Brief-Introduction-To-JAVA8_By_Srimanta_Sahu
A-Brief-Introduction-To-JAVA8_By_Srimanta_Sahu
Srimanta Sahu
 
Code reviews
Code reviewsCode reviews
Code reviews
Roger Xia
 
More than Programming!
More than Programming!More than Programming!
More than Programming!
Sophy Eung
 
Practices and tools for building better APIs
Practices and tools for building better APIsPractices and tools for building better APIs
Practices and tools for building better APIs
NLJUG
 

Similaire à Java and effective programming. Is it possible? - IAESTE Case Week 2016 (20)

Effective programming in Java - Kronospan Job Fair 2016
Effective programming in Java - Kronospan Job Fair 2016Effective programming in Java - Kronospan Job Fair 2016
Effective programming in Java - Kronospan Job Fair 2016
 
Learn java theory presentation
Learn java theory presentationLearn java theory presentation
Learn java theory presentation
 
The View - Lotusscript coding best practices
The View - Lotusscript coding best practicesThe View - Lotusscript coding best practices
The View - Lotusscript coding best practices
 
Java+8-New+Features.pdf
Java+8-New+Features.pdfJava+8-New+Features.pdf
Java+8-New+Features.pdf
 
Topic production code
Topic production codeTopic production code
Topic production code
 
A-Brief-Introduction-To-JAVA8_By_Srimanta_Sahu
A-Brief-Introduction-To-JAVA8_By_Srimanta_SahuA-Brief-Introduction-To-JAVA8_By_Srimanta_Sahu
A-Brief-Introduction-To-JAVA8_By_Srimanta_Sahu
 
Code reviews
Code reviewsCode reviews
Code reviews
 
Practices and Tools for Building Better APIs
Practices and Tools for Building Better APIsPractices and Tools for Building Better APIs
Practices and Tools for Building Better APIs
 
How can JAVA Performance tuning speed up applications.pdf
How can JAVA Performance tuning speed up applications.pdfHow can JAVA Performance tuning speed up applications.pdf
How can JAVA Performance tuning speed up applications.pdf
 
Testing practicies not only in scala
Testing practicies not only in scalaTesting practicies not only in scala
Testing practicies not only in scala
 
Designing function families and bundles with java's behaviors parameterisatio...
Designing function families and bundles with java's behaviors parameterisatio...Designing function families and bundles with java's behaviors parameterisatio...
Designing function families and bundles with java's behaviors parameterisatio...
 
Cracking OCA and OCP Java 8 Exams
Cracking OCA and OCP Java 8 ExamsCracking OCA and OCP Java 8 Exams
Cracking OCA and OCP Java 8 Exams
 
More than Programming!
More than Programming!More than Programming!
More than Programming!
 
Java 8 - Features Overview
Java 8 - Features OverviewJava 8 - Features Overview
Java 8 - Features Overview
 
TMPA-2015: The Application of Parameterized Hierarchy Templates for Automated...
TMPA-2015: The Application of Parameterized Hierarchy Templates for Automated...TMPA-2015: The Application of Parameterized Hierarchy Templates for Automated...
TMPA-2015: The Application of Parameterized Hierarchy Templates for Automated...
 
Golden Rules of API Design
Golden Rules of API DesignGolden Rules of API Design
Golden Rules of API Design
 
Java Custom Annotations- Part1
Java Custom Annotations- Part1Java Custom Annotations- Part1
Java Custom Annotations- Part1
 
DAA Unit 1.pdf
DAA Unit 1.pdfDAA Unit 1.pdf
DAA Unit 1.pdf
 
Core java programming tutorial - Brainsmartlabs
Core java programming tutorial - BrainsmartlabsCore java programming tutorial - Brainsmartlabs
Core java programming tutorial - Brainsmartlabs
 
Practices and tools for building better APIs
Practices and tools for building better APIsPractices and tools for building better APIs
Practices and tools for building better APIs
 

Dernier

+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Victor Rentea
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 
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
 

Dernier (20)

[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 
Six Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal OntologySix Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal Ontology
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
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
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
 
Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
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
 
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelMcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..
 
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
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
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
 
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
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
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
 

Java and effective programming. Is it possible? - IAESTE Case Week 2016

  • 1. Java and effective programming. Is it possible? Łukasz Koniecki April 14th, 2016
  • 3.
  • 4.
  • 5. Whoami •Software Architect in the Dynatrace, •Worked as Software Developer and Team Lead, •10+ years of experience with Java – Enterprise Application mostly, •Main area of interest: optimization and application performance
  • 6. APM
  • 7.
  • 8. What this workshop is about? •Showing examples on good, better and the best solutions to some common design problems, •Signaling some commons programming anti- patterns you should avoid, •Having fun solving simple Java programming puzzles
  • 9. What this workshop is not about? •Learning programming from scratch, •Learning Java from the beginning, •Solving all possible Java problems
  • 11.
  • 12. POJO with multiple instance members
  • 17. The moral • There are many ways of implementing the same algorithm/functionality, • There are reusable patterns that you should use (on every possible level: implementation, integration, deployment etc.
  • 19. Specification • Given the lists of strings as an input, method groupBy in the Example1 class should return map with all strings that occurred in the input list as key and number of string occurrences as value, Example: For a given input list {„John”, „Aaron”, „John” „Adam”, „Adele”} method should return following map { {„John”, 2}, {„Aaron”, 1}, {„Adam”, 1}, {„Adele”, 1}} • Method should throw IllegalArgumentException if elements list is null, • Method should return empty map if elements list is empty.
  • 22. But… Is it safe?
  • 24. Moral • Functional programming is more about coding convenience, • You should not mix imperative and functional programming styles, • Developer must be familiar with how streams work and behave (e.g. parallel stream execution), • Must be used with caution (see: 10 Subtle Mistakes When Using the Streams API)
  • 26. What you should know about generics? •Compile time type check rather than runtime check, •Generic types are invariant (compare with covariant arrays) •List<Integer> is not subtype of List<Number>, •Can be confusing when implementing API contract, •Use wildcards with caution.
  • 28. Moral •Always try to get into your API consumer shoes, •Remember the rule: Producer – <? extends V> Consumer - <? super V>
  • 30. Specification • Implement union method in the Exercise2 class, so that it returns set being an union of two sets passed as an argument, • Change it’s definition so that the following line of code compiles • Method should throw IllegalArgumentException if any set passed as an argument is null, • Remember that producer – super, consumer – extends… Set<Number> result = Excercise2.union(new HashSet<Integer>(), new HashSet<Number>());
  • 31.
  • 32. Java/C++/Python/JavaScript is your favorite? Be the dev we need! Visit http://gdansk.dynatrace.pl
  • 33. Credits •Joshua Bloch - Effective programming in Java (2nd edition) •Nicolai Parlog - Stream performance