Successfully reported this slideshow.

Evolving with Java - How to remain Relevant and Effective

1

Share

Loading in …3
×
1 of 93
1 of 93

Evolving with Java - How to remain Relevant and Effective

1

Share

Download to read offline

Slides from my GIDS 2019 presentation - Evolving with Java - How to remain relevant and effective. In this presentation, I share examples of evolving with Java to overcome the pain points.

Slides from my GIDS 2019 presentation - Evolving with Java - How to remain relevant and effective. In this presentation, I share examples of evolving with Java to overcome the pain points.

More Related Content

Related Books

Free with a 14 day trial from Scribd

See all

Related Audiobooks

Free with a 14 day trial from Scribd

See all

Evolving with Java - How to remain Relevant and Effective

  1. 1. Evolving with Java - How to Remain Relevant & Effective Naresha K, Technical Excellence Coach | Consultant | Agile & Cloud Transformation Catalyst @naresha_k https://blog.nareshak.com/
  2. 2. Business
  3. 3. Time to Market | Speed of Delivery
  4. 4. Economy
  5. 5. About Me
  6. 6. http://nareshak.blogspot.com/
  7. 7. http://nareshak.blogspot.com/
  8. 8. Relevant?
  9. 9. Effective?
  10. 10. public static void main(String[] args) { List<Integer> numbers = List.of(1, 2, 3, 4, 5, 6); List<Integer> result = numbers.stream() .map(ParallelStreams::computeHeavyArithmetic) .collect(Collectors.toList()); System.out.println(result); } public static void main(String[] args) { List<Integer> numbers = List.of(1, 2, 3, 4, 5, 6); List<Integer> result = numbers.parallelStream() .map(ParallelStreams::computeHeavyArithmetic) .collect(Collectors.toList()); System.out.println(result); }
  11. 11. public static void main(String[] args) { List<Integer> numbers = List.of(1, 2, 3, 4, 5, 6); List<Integer> result = numbers.stream() .map(ParallelStreams::computeHeavyArithmetic) .collect(Collectors.toList()); System.out.println(result); } public static void main(String[] args) { List<Integer> numbers = List.of(1, 2, 3, 4, 5, 6); List<Integer> result = numbers.parallelStream() .map(ParallelStreams::computeHeavyArithmetic) .collect(Collectors.toList()); System.out.println(result); }
  12. 12. private static Logger LOGGER = LoggerFactory .getLogger(MyClass.class);
  13. 13. All models are wrong, but some are useful. George Box https://en.wikipedia.org/wiki/All_models_are_wrong
  14. 14. Pain!
  15. 15. Suffering Pain!
  16. 16.  Pain is the hammer of the gods to break A dead resistance in the mortal’s heart https://dhavaldalal.wordpress.com/2006/08/02/pain-and-suffering/
  17. 17. public static String concatWithPlus(String[] values) { String result = ""; for (int i = 0; i < values.length; i++) { result += values[i]; } return result; }
  18. 18. public static String concatWithStringBuffer(String[] values) { StringBuffer buffer = new StringBuffer(); for (int i = 0; i < values.length; i++) { buffer.append(values[i]); } return buffer.toString(); }
  19. 19. Java 1.4
  20. 20. Java 5
  21. 21. Maintainability?
  22. 22. ‘+’ vs StringBuffer Level of Abstraction API Contract Concatenation Concatenation Thread Safety
  23. 23. Favour higher level of abstraction
  24. 24. Premature optimisation is the root of all evil ~ Donald Knuth
  25. 25. Rule 1: Don’t Rule 2: Don’t, yet Rule 3: Profile before optimising http://wiki.c2.com/?RulesOfOptimization
  26. 26. YAGNI http://wiki.c2.com/?MakeItWorkMakeItRightMakeItFast
  27. 27. Make it work Make it Right Make it Fast http://wiki.c2.com/?MakeItWorkMakeItRightMakeItFast
  28. 28. Red Green Refactor TDD
  29. 29. Java 11
  30. 30. public static void main(String[] args) { List numbers = Arrays.asList(1, 2, 3, 4, 5); Iterator iterator = numbers.iterator(); while (iterator.hasNext()) { Number number = (Number) iterator.next(); System.out.println(number); } } Java 1.4
  31. 31. public static void main(String[] args) { List numbers = Arrays.asList(1, 2, 3, 4, 5); Iterator iterator = numbers.iterator(); while (iterator.hasNext()) { Number number = (Number) iterator.next(); System.out.println(number); } } List<Number> numbers = Arrays.asList(1, 2, 3, 4, 5); for(Number number : numbers) { System.out.println(number); } Java 1.4 Java 5
  32. 32. Syntactic Sugar
  33. 33. Minimise Moving Parts Imperative -> Declarative
  34. 34. Fail fast Runtime -> Compile time
  35. 35. /** * * @param customer * @return This method returns orders * of customer */ public List getOrdersOfCustomer(Customer customer);
  36. 36. /** * This method returns orders of customer * @param customer Customer whose orders to be fetched * @return List containing Order objects of the * specified Customer */ public List getOrdersOfCustomer(Customer customer);
  37. 37. public List<Order> getOrdersOfCustomer(Customer customer); public List<OrderSummary> getOrdersOfCustomer(Customer customer);
  38. 38. Self Documenting Code
  39. 39. DRY Principle
  40. 40. List<Integer> numbers = List.of(1, 2, 3, 4, 5, 6); int sumOfSquaresOfEvenNumbers = 0; for (Integer number : numbers) { if(number % 2 == 0) { sumOfSquaresOfEvenNumbers += number * number; } } System.out.println(sumOfSquaresOfEvenNumbers);
  41. 41. List<Integer> numbers = List.of(1, 2, 3, 4, 5, 6); int sumOfSquaresOfEvenNumbers = 0; for (Integer number : numbers) { if(number % 2 == 0) { sumOfSquaresOfEvenNumbers += number * number; } } System.out.println(sumOfSquaresOfEvenNumbers); Predicate<Integer> isEven = (number) -> number % 2 == 0; Function<Integer, Integer> square = (number) -> number * number; List<Integer> numbers = List.of(1, 2, 3, 4, 5, 6); Integer sum = numbers.stream() .filter(isEven) .map(square) .collect(Collectors. summingInt(Integer::intValue)); System.out.println(sum); Java 8
  42. 42. Declarative Code
  43. 43. Smaller Units
  44. 44. Improved Readability
  45. 45. Easy to Modify
  46. 46. Are you confident enough to refactor? Tests give courage
  47. 47. Predicate<Integer> isEven = (number) -> number % 2 == 0; Function<Integer, Integer> square = (number) -> number * number; List<Integer> numbers = List.of(1, 2, 3, 4, 5, 6); Integer result = numbers.stream() .filter(isEven) .map(square) .findFirst().orElse(-1); System.out.println(result); Java 8
  48. 48. Predicate<Integer> isEven = (number) -> number % 2 == 0; Function<Integer, Integer> square = (number) -> number * number; List<Integer> numbers = List.of(1, 2, 3, 4, 5, 6); Integer result = numbers.stream() .filter(isEven) .map(square) .findFirst().orElse(-1); System.out.println(result); List<Integer> numbers = List.of(1, 2, 3, 4, 5, 6); int suqareOfFirstEvenNumber = -1; for (Integer number : numbers) { if(number % 2 == 0) { suqareOfFirstEvenNumber += number * number; break; } } System.out.println(suqareOfFirstEvenNumber); Java 8
  49. 49. What you see is not what you get
  50. 50. Lazy Evaluation
  51. 51. Understand one level below the abstraction you deal with
  52. 52. Food pizza = new Pizza(); Person friend = new Person("Ravi"); friend.getMouth().setFood(pizza);
  53. 53. Food pizza = new Pizza(); Person friend = new Person("Ravi"); friend.getMouth().setFood(pizza); Person friend = new Person("Ravi"); Edible food = new Pizza(); friend.offer(food);
  54. 54. Encapsulation
  55. 55. public static String readTemplate(String path) { Path templatePath = Paths.get(path); BufferedReader bufferedReader = Files.newBufferedReader(templatePath); // read from bufferedReader return ""; }
  56. 56. public static String readTemplate(String path) { Path templatePath = Paths.get(path); try { BufferedReader bufferedReader = Files.newBufferedReader(templatePath); } catch (IOException e) { e.printStackTrace(); } // read from bufferedReader return ""; }
  57. 57. Use checked exceptions Judiciously
  58. 58. Most people talk about Java the language, and this may sound odd coming from me, but I could hardly care less. At the core of the Java ecosystem is the JVM. - James Gosling, Creator of the Java Programming Language(2011, TheServerSide)
  59. 59. http://zeroturnaround.com/rebellabs/the-adventurous-developers-guide-to-jvm-languages-java-scala-groovy- fantom-clojure-ceylon-kotlin-xtend/
  60. 60. https://www.tiobe.com/tiobe-index/
  61. 61. https://www.jetbrains.com/research/devecosystem-2018/
  62. 62. https://www.jetbrains.com/research/devecosystem-2018/
  63. 63. package com.nareshak.demo data class Person(val firstName: String, val lastName: String)
  64. 64. package com.nareshak.demo; import lombok.Getter; import lombok.Setter; @Getter @Setter public class Person { private String firstName; private String lastName; }
  65. 65. package com.nareshak.demo; import lombok.Getter; import lombok.Setter; @Getter @Setter public class Person { private String firstName; private String lastName; }
  66. 66. package com.nareshak.demo; import lombok.Data; @Data public class Person { private String firstName; private String lastName; }
  67. 67. Overcoming the paradigm inertia
  68. 68. Move beyond Syntax
  69. 69. Feel the pain and act upon it
  70. 70. I have not experienced the pain, yet.
  71. 71. JPMS - Java Modules
  72. 72. Automatic Resource Management
  73. 73. Thank You

×