Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

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

336 views

Published on

Probably most of use read book "Effective Java" by Joshua Blooch. But what "effective" programming really means? We will go through some real-life problems and talk about possible, effective solutions.

Published in: Technology
  • Login to see the comments

  • Be the first to like this

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

  1. 1. Java and effective programming. Is it possible? Łukasz Koniecki April 14th, 2016
  2. 2. https://github.com/lkoniecki/EffectiveJava
  3. 3. 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
  4. 4. APM
  5. 5. 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
  6. 6. What this workshop is not about? •Learning programming from scratch, •Learning Java from the beginning, •Solving all possible Java problems
  7. 7. Design patterns
  8. 8. POJO with multiple instance members
  9. 9. Telescoping constructor pattern
  10. 10. JavaBean pattern
  11. 11. Builder pattern
  12. 12. Example
  13. 13. 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.
  14. 14. Exercise 1
  15. 15. 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.
  16. 16. Functional programming
  17. 17. Java7-ish vs. stream-like version
  18. 18. But… Is it safe?
  19. 19. Benchmark results
  20. 20. 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)
  21. 21. Generics
  22. 22. 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.
  23. 23. Example
  24. 24. Moral •Always try to get into your API consumer shoes, •Remember the rule: Producer – <? extends V> Consumer - <? super V>
  25. 25. Exercise 2
  26. 26. 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>());
  27. 27. Java/C++/Python/JavaScript is your favorite? Be the dev we need! Visit http://gdansk.dynatrace.pl
  28. 28. Credits •Joshua Bloch - Effective programming in Java (2nd edition) •Nicolai Parlog - Stream performance

×