SlideShare ist ein Scribd-Unternehmen logo
1 von 55
Effective Java


Presentation of the Joshua Bloch's Book.




                                                             www.supinfo.com
                                           Copyright © SUPINFO. All   rights reserved
Effective Java

    The Speaker
                         Professional Experiences:
                         - Bug Out PC         - Groupe Open
                         - ADF                - Atos Worldline
                         - Adullact           - Xebia IT
                         - Webpulser
                         - Audaxis
                         Training:
                         - DUT Informatique / Montpellier
                         - Supinfo B3 / Montpellier
                         - Supinfo M1 / Lille
                         - STA Java Lille / Valenciennes
       Brice Argenson
-    59253@supinfo.com   Certifications:
     brice.argenson      - SCJP 6
     @bargenson          - SCWCD 5
Effective Java

Agenda

   Develop more effectively ?
        Creating and Destroying objects
        Classes and Interfaces
        Methods
        General Programming
   The Book
   About the Author
Effective Java




                 Develop more effectively ?

                 Good practices
Develop more effectively ?

Creating and Destroying objects
     Item 1: Consider static factory methods instead of
                       constructors.

   Public constructor is the normal way for a class to allow
    a client to obtain an instance of itself.
   Another technique is to provide a public static factory
    method !
Develop more effectively ?

Creating and Destroying objects
     Item 1: Consider static factory methods instead of
                       constructors.

  First advantage : They have names !


    BigInteger(int bitLength, int certainty, Random rnd)
  Constructs a randomly generated positive BigInteger that is
         probably prime, with the specified bitLength.


   BigInteger.probablePrime(int bitLength, Random rnd)
   Returns a positive BigInteger that is probably prime, with
                    the specified bitLength.
Develop more effectively ?

Creating and Destroying objects
     Item 1: Consider static factory methods instead of
                       constructors.

  Second advantage : They are no required to create a
   new object each time they’re invoked.
Develop more effectively ?

Creating and Destroying objects
     Item 1: Consider static factory methods instead of
                       constructors.

  Third advantage : They can return an object of any
   subtype of their return type.
Develop more effectively ?

Creating and Destroying objects
     Item 1: Consider static factory methods instead of
                       constructors.

  Fourth advantage : They reduce the verbosity of
   creating parameterized type instances.
Develop more effectively ?

Creating and Destroying objects
     Item 1: Consider static factory methods instead of
                       constructors.



  First disadvantage : Classes without public or protected
   constructors cannot be sub-classed.


  Second disadvantage : They are not readily
   distinguishable from other static methods.
Develop more effectively ?

Creating and Destroying objects
      Item 2: Consider a builder when faced with many
                  constructor parameters.



  Static factories and constructors share a limitation: they
   don’t scale well to large members of optional parameters.


  Traditionally, two patterns are used :
       Telescoping constructor pattern.
       JavaBeans pattern.
Develop more effectively ?

Creating and Destroying objects
Develop more effectively ?

Creating and Destroying objects
      Item 2: Consider a builder when faced with many
                  constructor parameters.




  Telescoping constructor pattern :
       Hard to write.
       Harder to read :
Develop more effectively ?

Creating and Destroying objects
Develop more effectively ?

Creating and Destroying objects
      Item 2: Consider a builder when faced with many
                  constructor parameters.


  JavaBeans pattern :
       Easier to write.
       Easier to read :




       But JavaBean may be in an inconsistent state
        partway through its construction !
Develop more effectively ?

Creating and Destroying objects
Develop more effectively ?

Creating and Destroying objects
      Item 2: Consider a builder when faced with many
                  constructor parameters.


  Builder pattern :
       Easy to write.
       Easy to read :




       Simulates named optional parameters.
       Consistent state control.
Develop more effectively ?

Creating and Destroying objects
         Item 5: Avoid creating unnecessary objects.




   Is this statement correct ?
Develop more effectively ?

Creating and Destroying objects
         Item 5: Avoid creating unnecessary objects.




   Improved version :
Develop more effectively ?

Creating and Destroying objects
         Item 5: Avoid creating unnecessary objects.



   Is this code correct ?
Develop more effectively ?

Creating and Destroying objects
         Item 5: Avoid creating unnecessary objects.
   Improved version (about 250 times faster for 10 million
    invocations) :
Develop more effectively ?

Creating and Destroying objects
         Item 5: Avoid creating unnecessary objects.




   Is this code correct ?
Develop more effectively ?

Creating and Destroying objects
         Item 5: Avoid creating unnecessary objects.




   Improved version (6.3 times faster) :
Develop more effectively ?

Classes and Interfaces
        Item 16: Favor composition over inheritance.




   Inheritance is a powerful way to achieve code reuse
        But not always the best !
   Inheritance from ordinary concrete classes across
    package boundaries is dangerous !


       Unlike method invocation, inheritance violates
                      encapsulation.
Develop more effectively ?

Classes and Interfaces
        Item 16: Favor composition over inheritance.
Develop more effectively ?

Classes and Interfaces
        Item 16: Favor composition over inheritance.




   What this code display ?
Develop more effectively ?

Classes and Interfaces
        Item 16: Favor composition over inheritance.
Develop more effectively ?

Classes and Interfaces
        Item 16: Favor composition over inheritance.
Develop more effectively ?

Classes and Interfaces
        Item 16: Favor composition over inheritance.

   Design of the InstrumentedSet is extremely flexible :
        Implement the Set interface.
        Receive an argument also of type Set.
   With inheritance, we could work only with HashSet.
   With composition, we can work with any Set
    implementation !
Develop more effectively ?

Classes and Interfaces
Develop more effectively ?

Classes and Interfaces
     Item 20: Prefer class hierarchies to tagged classes.

   Tagged classes are verbose, error-prone, inefficient and
    just a pallid imitation of a class hierarchy.


   Here is the class hierarchy corresponding to the original
    class :
Develop more effectively ?

Classes and Interfaces
     Item 20: Prefer class hierarchies to tagged classes.
Develop more effectively ?

Classes and Interfaces
     Item 20: Prefer class hierarchies to tagged classes.




   Class hierarchies are more flexible and provide better
    compile-time type checking.
   Suppose we need a square shape :
Develop more effectively ?

Methods

   Consider the following class :
Develop more effectively ?

Methods

   Consider the following code :




   Do you see the problem ?
Develop more effectively ?

Methods
        Item 39: Make defensive copies when needed.



   To protect the internals of a Period instance from this
    sort of attack:
        You must make defensive copy of each mutable
         parameter to the constructor !
Develop more effectively ?

Methods
             Item 41: Use overloading judiciously.

   What does the following program prints ?
Develop more effectively ?

Methods
             Item 41: Use overloading judiciously.




   The program print : “Unknown Collection” three times.


   The choice of which overloading to invoke is made at
    compile time !
        Not like overridden methods…
Develop more effectively ?

Methods
             Item 41: Use overloading judiciously.



   What does the following program prints ?
Develop more effectively ?

Methods
             Item 41: Use overloading judiciously.




   The program print : [-3, -2, -1] [-2, 0, 2].
   The remove method is overloaded inside List class :
        remove(E) : delete the E element inside the list.
        remove(int) : delete the element at the specified
         position.
Develop more effectively ?

Methods
             Item 41: Use overloading judiciously.




   Refrain from overloading methods with multiple
    signatures that have the same number of parameters.


   If you can’t, at least avoid situations where the same set
    of parameters can be passed to different overloadings
    by the addition of casts.
Develop more effectively ?

General Programming
    Item 48: Avoid float and double if exact answers are
                          required.




   What does the following program prints ?
Develop more effectively ?

General Programming
    Item 48: Avoid float and double if exact answers are
                          required.




   It prints you can afford 3 items and you have
    $0.3999999999999999 left…


   The float and double types are designed primarily for
    scientific and engineering calculations.
        They perform binary floating-point arithmetic with
         approximations !
   They should not be used where exact results are
    required.
Develop more effectively ?

General Programming
    Item 48: Avoid float and double if exact answers are
                          required.




   A correct version of the previous program :
Develop more effectively ?

General Programming
                  Item 55: Optimize judiciously.
      "More computing sins are committed in the name of
    efficiency (without necessarily achieving it) than for any
          other single reason - including blind stupidity."
                                                    - W.A. Wulf

   “We should forget about small efficiencies, say about 97%
    of the time: premature optimization is the root of all evil.”
                                             - Donald E. Knuth

   “The First Rule of Program Optimization: Don't do it. The
   Second Rule of Program Optimization (for experts only!):
                        Don't do it yet.”
                                         - Michael A. Jackson
Develop more effectively ?

General Programming
                  Item 55: Optimize judiciously.




   Strive to write good programs rather than fast ones.
   Strive to avoid design decisions that limit performance.
   Consider the performance consequence of your API
    design decisions.
   Measure performance before and after each attempted
    optimization.
Effective Java




                 The Book

                 For all the other tips !
The Book

The original version


       Effective Java
           Second Edition


           Joshua BLOCH


      Addison Wesley editions



 "I sure wish I had this book ten years ago. Some might think that I
          don't need any Java books, but I need this one.”
 - James Gosling, Fellow and Vice President, Sun Microsystems, Inc.
The Book

The translated version

         Java Efficace
     Guide de programmation


           Joshua BLOCH
  Traduction d’Alexis Moussine-Pouchkine



           Vuilbert editions




               http://www.amazon.fr/Java-efficace-
Bloch/dp/2711748057/ref=sr_1_1?ie=UTF8&s=books&qid=12985674
                           25&sr=8-1
Effective Java




                 About the Author

                 For all the other tips !
About the Author

Joshua Bloch

                       Chief Java architect at Google.
                       Jolt Award winner.
                       Previously a distinguished
                        engineer at Sun Microsystems and
                        a senior systems designer at
                        Transarc.
                       Led the design and implementation
                        of numerous Java platform
                        features.

   http://googleresearch.blogspot.com/
   @joshbloch
About the Author

Bibliographie
 Effective Java: Programming Language Guide
     ISBN 0201310058, 2001.
     Second edition: ISBN 978-0-321-35668-0, 2008.
About the Author

Bibliographie
 Java Puzzlers: Traps, Pitfalls, and Corner Cases
     ISBN 032133678X, 2005 (co-authored with Neal Gafter).
About the Author

Bibliographie
 Java Concurrency in Practice
     ISBN 0321349601, 2006 (co-authored with Brian
      Goetz, Tim Peierls, Joseph Bowbeer, David Holmes, and
      Doug Lea).
Effective Java

The end

Weitere ähnliche Inhalte

Was ist angesagt?

Unit 2 - Test Case Design
Unit 2 - Test Case DesignUnit 2 - Test Case Design
Unit 2 - Test Case DesignSelvi Vts
 
Testen mit, durch und in Scrum
Testen mit, durch und in ScrumTesten mit, durch und in Scrum
Testen mit, durch und in ScrumFrank Düsterbeck
 
Clean code and Code Smells
Clean code and Code SmellsClean code and Code Smells
Clean code and Code SmellsMario Sangiorgio
 
Hexagonal architecture - message-oriented software design
Hexagonal architecture  - message-oriented software designHexagonal architecture  - message-oriented software design
Hexagonal architecture - message-oriented software designMatthias Noback
 
Coding Standards & Best Practices for iOS/C#
Coding Standards & Best Practices for iOS/C#Coding Standards & Best Practices for iOS/C#
Coding Standards & Best Practices for iOS/C#Asim Rais Siddiqui
 
Coding Best Practices
Coding Best PracticesCoding Best Practices
Coding Best Practicesmh_azad
 
자동화된 Test Case의 효과
자동화된 Test Case의 효과자동화된 Test Case의 효과
자동화된 Test Case의 효과도형 임
 
Clean Code Principles
Clean Code PrinciplesClean Code Principles
Clean Code PrinciplesYeurDreamin'
 
소프트웨어 테스팅
소프트웨어 테스팅소프트웨어 테스팅
소프트웨어 테스팅영기 김
 
So you think you can write a test case
So you think you can write a test caseSo you think you can write a test case
So you think you can write a test caseSrilu Balla
 
Java exception handling ppt
Java exception handling pptJava exception handling ppt
Java exception handling pptJavabynataraJ
 
Deep learning based code smell detection - Qualifying Talk
Deep learning based code smell detection - Qualifying TalkDeep learning based code smell detection - Qualifying Talk
Deep learning based code smell detection - Qualifying TalkSayed Mohsin Reza
 

Was ist angesagt? (20)

Unit 2 - Test Case Design
Unit 2 - Test Case DesignUnit 2 - Test Case Design
Unit 2 - Test Case Design
 
Clean Code
Clean CodeClean Code
Clean Code
 
Testen mit, durch und in Scrum
Testen mit, durch und in ScrumTesten mit, durch und in Scrum
Testen mit, durch und in Scrum
 
Unit Testing in Java
Unit Testing in JavaUnit Testing in Java
Unit Testing in Java
 
Coding conventions
Coding conventionsCoding conventions
Coding conventions
 
Clean code and Code Smells
Clean code and Code SmellsClean code and Code Smells
Clean code and Code Smells
 
Introduction To C#
Introduction To C#Introduction To C#
Introduction To C#
 
Test cases
Test casesTest cases
Test cases
 
Hexagonal architecture - message-oriented software design
Hexagonal architecture  - message-oriented software designHexagonal architecture  - message-oriented software design
Hexagonal architecture - message-oriented software design
 
Coding Standards & Best Practices for iOS/C#
Coding Standards & Best Practices for iOS/C#Coding Standards & Best Practices for iOS/C#
Coding Standards & Best Practices for iOS/C#
 
Coding standard
Coding standardCoding standard
Coding standard
 
Coding Best Practices
Coding Best PracticesCoding Best Practices
Coding Best Practices
 
자동화된 Test Case의 효과
자동화된 Test Case의 효과자동화된 Test Case의 효과
자동화된 Test Case의 효과
 
Clean Code Principles
Clean Code PrinciplesClean Code Principles
Clean Code Principles
 
소프트웨어 테스팅
소프트웨어 테스팅소프트웨어 테스팅
소프트웨어 테스팅
 
Java platform
Java platformJava platform
Java platform
 
Unit Testing (C#)
Unit Testing (C#)Unit Testing (C#)
Unit Testing (C#)
 
So you think you can write a test case
So you think you can write a test caseSo you think you can write a test case
So you think you can write a test case
 
Java exception handling ppt
Java exception handling pptJava exception handling ppt
Java exception handling ppt
 
Deep learning based code smell detection - Qualifying Talk
Deep learning based code smell detection - Qualifying TalkDeep learning based code smell detection - Qualifying Talk
Deep learning based code smell detection - Qualifying Talk
 

Andere mochten auch

Effective java
Effective javaEffective java
Effective javaHaeil Yi
 
Effective java
Effective javaEffective java
Effective javaEmprovise
 
Effective Java - Chapter 2: Creating and Destroying Objects
Effective Java - Chapter 2: Creating and Destroying ObjectsEffective Java - Chapter 2: Creating and Destroying Objects
Effective Java - Chapter 2: Creating and Destroying Objectsİbrahim Kürce
 
Effective Java - Generics
Effective Java - GenericsEffective Java - Generics
Effective Java - GenericsRoshan Deniyage
 
The Go Programing Language 1
The Go Programing Language 1The Go Programing Language 1
The Go Programing Language 1İbrahim Kürce
 
Effective Java - Enum and Annotations
Effective Java - Enum and AnnotationsEffective Java - Enum and Annotations
Effective Java - Enum and AnnotationsRoshan Deniyage
 
Effective java 1 and 2
Effective java 1 and 2Effective java 1 and 2
Effective java 1 and 2중선 곽
 
Effective Java - Chapter 4: Classes and Interfaces
Effective Java - Chapter 4: Classes and InterfacesEffective Java - Chapter 4: Classes and Interfaces
Effective Java - Chapter 4: Classes and Interfacesİbrahim Kürce
 
Live chym kysubrse vs toidicodedao
Live chym kysubrse vs toidicodedaoLive chym kysubrse vs toidicodedao
Live chym kysubrse vs toidicodedaoHuy Hoàng Phạm
 
Spring mvc
Spring mvcSpring mvc
Spring mvcBa Big
 
Reactive Streams and RxJava2
Reactive Streams and RxJava2Reactive Streams and RxJava2
Reactive Streams and RxJava2Yakov Fain
 
Sinh viên IT học và làm gì để không thất nghiệp
Sinh viên IT học và làm gì để không thất nghiệpSinh viên IT học và làm gì để không thất nghiệp
Sinh viên IT học và làm gì để không thất nghiệpHuy Hoàng Phạm
 
Intro to Retrofit 2 and RxJava2
Intro to Retrofit 2 and RxJava2Intro to Retrofit 2 and RxJava2
Intro to Retrofit 2 and RxJava2Fabio Collini
 
Luận văn tìm hiểu Spring
Luận văn tìm hiểu SpringLuận văn tìm hiểu Spring
Luận văn tìm hiểu SpringAn Nguyen
 
Từ Gà Đến Pro Git và GitHub trong 60 phút
Từ Gà Đến Pro Git và GitHub trong 60 phútTừ Gà Đến Pro Git và GitHub trong 60 phút
Từ Gà Đến Pro Git và GitHub trong 60 phútHuy Hoàng Phạm
 
Lap trinh java hieu qua
Lap trinh java hieu quaLap trinh java hieu qua
Lap trinh java hieu quaLê Anh
 
Từ Sinh Viên IT tới Lập Trình Viên
Từ Sinh Viên IT tới Lập Trình ViênTừ Sinh Viên IT tới Lập Trình Viên
Từ Sinh Viên IT tới Lập Trình ViênHuy Hoàng Phạm
 
Hành trình trở thành web đì ve lốp pơ
Hành trình trở thành web đì ve lốp pơHành trình trở thành web đì ve lốp pơ
Hành trình trở thành web đì ve lốp pơHuy Hoàng Phạm
 

Andere mochten auch (19)

Effective java
Effective javaEffective java
Effective java
 
Effective java
Effective javaEffective java
Effective java
 
Effective Java - Chapter 2: Creating and Destroying Objects
Effective Java - Chapter 2: Creating and Destroying ObjectsEffective Java - Chapter 2: Creating and Destroying Objects
Effective Java - Chapter 2: Creating and Destroying Objects
 
Effective Java - Generics
Effective Java - GenericsEffective Java - Generics
Effective Java - Generics
 
The Go Programing Language 1
The Go Programing Language 1The Go Programing Language 1
The Go Programing Language 1
 
Effective Java - Enum and Annotations
Effective Java - Enum and AnnotationsEffective Java - Enum and Annotations
Effective Java - Enum and Annotations
 
Effective java 1 and 2
Effective java 1 and 2Effective java 1 and 2
Effective java 1 and 2
 
Effective Java - Chapter 4: Classes and Interfaces
Effective Java - Chapter 4: Classes and InterfacesEffective Java - Chapter 4: Classes and Interfaces
Effective Java - Chapter 4: Classes and Interfaces
 
Live chym kysubrse vs toidicodedao
Live chym kysubrse vs toidicodedaoLive chym kysubrse vs toidicodedao
Live chym kysubrse vs toidicodedao
 
Spring mvc
Spring mvcSpring mvc
Spring mvc
 
Spring mvc
Spring mvcSpring mvc
Spring mvc
 
Reactive Streams and RxJava2
Reactive Streams and RxJava2Reactive Streams and RxJava2
Reactive Streams and RxJava2
 
Sinh viên IT học và làm gì để không thất nghiệp
Sinh viên IT học và làm gì để không thất nghiệpSinh viên IT học và làm gì để không thất nghiệp
Sinh viên IT học và làm gì để không thất nghiệp
 
Intro to Retrofit 2 and RxJava2
Intro to Retrofit 2 and RxJava2Intro to Retrofit 2 and RxJava2
Intro to Retrofit 2 and RxJava2
 
Luận văn tìm hiểu Spring
Luận văn tìm hiểu SpringLuận văn tìm hiểu Spring
Luận văn tìm hiểu Spring
 
Từ Gà Đến Pro Git và GitHub trong 60 phút
Từ Gà Đến Pro Git và GitHub trong 60 phútTừ Gà Đến Pro Git và GitHub trong 60 phút
Từ Gà Đến Pro Git và GitHub trong 60 phút
 
Lap trinh java hieu qua
Lap trinh java hieu quaLap trinh java hieu qua
Lap trinh java hieu qua
 
Từ Sinh Viên IT tới Lập Trình Viên
Từ Sinh Viên IT tới Lập Trình ViênTừ Sinh Viên IT tới Lập Trình Viên
Từ Sinh Viên IT tới Lập Trình Viên
 
Hành trình trở thành web đì ve lốp pơ
Hành trình trở thành web đì ve lốp pơHành trình trở thành web đì ve lốp pơ
Hành trình trở thành web đì ve lốp pơ
 

Ähnlich wie Effective Java

Java Programming
Java ProgrammingJava Programming
Java ProgrammingTracy Clark
 
The Taming Of The Code
The Taming Of The CodeThe Taming Of The Code
The Taming Of The CodeAlan Stevens
 
Building frameworks: from concept to completion
Building frameworks: from concept to completionBuilding frameworks: from concept to completion
Building frameworks: from concept to completionRuben Goncalves
 
Worse is better, for better or for worse - Kevlin Henney
Worse is better, for better or for worse - Kevlin HenneyWorse is better, for better or for worse - Kevlin Henney
Worse is better, for better or for worse - Kevlin HenneyJAX London
 
Lunch and learn as3_frameworks
Lunch and learn as3_frameworksLunch and learn as3_frameworks
Lunch and learn as3_frameworksYuri Visser
 
2010 06-24 karlsruher entwicklertag
2010 06-24 karlsruher entwicklertag2010 06-24 karlsruher entwicklertag
2010 06-24 karlsruher entwicklertagMarcel Bruch
 
Integration and Unit Testing in Java using Test Doubles like mocks and stubs
Integration and Unit Testing in Java using Test Doubles like mocks and stubsIntegration and Unit Testing in Java using Test Doubles like mocks and stubs
Integration and Unit Testing in Java using Test Doubles like mocks and stubsRody Middelkoop
 
Designing A Project Using Java Programming
Designing A Project Using Java ProgrammingDesigning A Project Using Java Programming
Designing A Project Using Java ProgrammingKaty Allen
 
Introduction to Software Build Technology
Introduction to Software Build TechnologyIntroduction to Software Build Technology
Introduction to Software Build TechnologyPhilip Johnson
 
Clean architecture - Protecting the Domain
Clean architecture - Protecting the DomainClean architecture - Protecting the Domain
Clean architecture - Protecting the DomainVictor Rentea
 
Library Managemnet System
Library Managemnet SystemLibrary Managemnet System
Library Managemnet SystemAbhishek Shakya
 
10 Ways To Improve Your Code( Neal Ford)
10  Ways To  Improve  Your  Code( Neal  Ford)10  Ways To  Improve  Your  Code( Neal  Ford)
10 Ways To Improve Your Code( Neal Ford)guestebde
 
C, C++ Interview Questions Part - 1
C, C++ Interview Questions Part - 1C, C++ Interview Questions Part - 1
C, C++ Interview Questions Part - 1ReKruiTIn.com
 
Lean Engineering: How to make Engineering a full Lean UX partner
Lean Engineering: How to make Engineering a full Lean UX partnerLean Engineering: How to make Engineering a full Lean UX partner
Lean Engineering: How to make Engineering a full Lean UX partnerBill Scott
 

Ähnlich wie Effective Java (20)

Java Programming
Java ProgrammingJava Programming
Java Programming
 
Oopp Lab Work
Oopp Lab WorkOopp Lab Work
Oopp Lab Work
 
C# features
C# featuresC# features
C# features
 
The Taming Of The Code
The Taming Of The CodeThe Taming Of The Code
The Taming Of The Code
 
Building frameworks: from concept to completion
Building frameworks: from concept to completionBuilding frameworks: from concept to completion
Building frameworks: from concept to completion
 
Worse is better, for better or for worse - Kevlin Henney
Worse is better, for better or for worse - Kevlin HenneyWorse is better, for better or for worse - Kevlin Henney
Worse is better, for better or for worse - Kevlin Henney
 
Lunch and learn as3_frameworks
Lunch and learn as3_frameworksLunch and learn as3_frameworks
Lunch and learn as3_frameworks
 
2010 06-24 karlsruher entwicklertag
2010 06-24 karlsruher entwicklertag2010 06-24 karlsruher entwicklertag
2010 06-24 karlsruher entwicklertag
 
Need 4 Speed FI
Need 4 Speed FINeed 4 Speed FI
Need 4 Speed FI
 
Django in the Real World
Django in the Real WorldDjango in the Real World
Django in the Real World
 
Integration and Unit Testing in Java using Test Doubles like mocks and stubs
Integration and Unit Testing in Java using Test Doubles like mocks and stubsIntegration and Unit Testing in Java using Test Doubles like mocks and stubs
Integration and Unit Testing in Java using Test Doubles like mocks and stubs
 
Designing A Project Using Java Programming
Designing A Project Using Java ProgrammingDesigning A Project Using Java Programming
Designing A Project Using Java Programming
 
Acceleo Code Generation
Acceleo Code GenerationAcceleo Code Generation
Acceleo Code Generation
 
Introduction to Software Build Technology
Introduction to Software Build TechnologyIntroduction to Software Build Technology
Introduction to Software Build Technology
 
Clean architecture - Protecting the Domain
Clean architecture - Protecting the DomainClean architecture - Protecting the Domain
Clean architecture - Protecting the Domain
 
10 Ways To Improve Your Code
10 Ways To Improve Your Code10 Ways To Improve Your Code
10 Ways To Improve Your Code
 
Library Managemnet System
Library Managemnet SystemLibrary Managemnet System
Library Managemnet System
 
10 Ways To Improve Your Code( Neal Ford)
10  Ways To  Improve  Your  Code( Neal  Ford)10  Ways To  Improve  Your  Code( Neal  Ford)
10 Ways To Improve Your Code( Neal Ford)
 
C, C++ Interview Questions Part - 1
C, C++ Interview Questions Part - 1C, C++ Interview Questions Part - 1
C, C++ Interview Questions Part - 1
 
Lean Engineering: How to make Engineering a full Lean UX partner
Lean Engineering: How to make Engineering a full Lean UX partnerLean Engineering: How to make Engineering a full Lean UX partner
Lean Engineering: How to make Engineering a full Lean UX partner
 

Mehr von Brice Argenson

RSpock Testing Framework for Ruby
RSpock Testing Framework for RubyRSpock Testing Framework for Ruby
RSpock Testing Framework for RubyBrice Argenson
 
Serverless Applications
Serverless ApplicationsServerless Applications
Serverless ApplicationsBrice Argenson
 
Serverless - Lunch&Learn CleverToday - Mars 2017
Serverless - Lunch&Learn CleverToday - Mars 2017Serverless - Lunch&Learn CleverToday - Mars 2017
Serverless - Lunch&Learn CleverToday - Mars 2017Brice Argenson
 
Docker 1.13 - Docker meetup février 2017
Docker 1.13 - Docker meetup février 2017Docker 1.13 - Docker meetup février 2017
Docker 1.13 - Docker meetup février 2017Brice Argenson
 
Docker 1.12 & Swarm Mode [Montreal Docker Meetup Sept. 2016]
Docker 1.12 & Swarm Mode [Montreal Docker Meetup Sept. 2016]Docker 1.12 & Swarm Mode [Montreal Docker Meetup Sept. 2016]
Docker 1.12 & Swarm Mode [Montreal Docker Meetup Sept. 2016]Brice Argenson
 
Packagez et déployez vos applications avec Docker - Montréal CloudFoundry Mee...
Packagez et déployez vos applications avec Docker - Montréal CloudFoundry Mee...Packagez et déployez vos applications avec Docker - Montréal CloudFoundry Mee...
Packagez et déployez vos applications avec Docker - Montréal CloudFoundry Mee...Brice Argenson
 
The Patterns to boost your time to market - An introduction to DevOps
The Patterns to boost your time to market - An introduction to DevOpsThe Patterns to boost your time to market - An introduction to DevOps
The Patterns to boost your time to market - An introduction to DevOpsBrice Argenson
 
Introduction to Continuous Integration with Jenkins
Introduction to Continuous Integration with JenkinsIntroduction to Continuous Integration with Jenkins
Introduction to Continuous Integration with JenkinsBrice Argenson
 
Java EE - Servlets API
Java EE - Servlets APIJava EE - Servlets API
Java EE - Servlets APIBrice Argenson
 
JS-Everywhere - SSE Hands-on
JS-Everywhere - SSE Hands-onJS-Everywhere - SSE Hands-on
JS-Everywhere - SSE Hands-onBrice Argenson
 
JS-Everywhere - LocalStorage Hands-on
JS-Everywhere - LocalStorage Hands-onJS-Everywhere - LocalStorage Hands-on
JS-Everywhere - LocalStorage Hands-onBrice Argenson
 
Soutenance mémoire : Implémentation d'un DSL en entreprise
Soutenance mémoire : Implémentation d'un DSL en entrepriseSoutenance mémoire : Implémentation d'un DSL en entreprise
Soutenance mémoire : Implémentation d'un DSL en entrepriseBrice Argenson
 

Mehr von Brice Argenson (12)

RSpock Testing Framework for Ruby
RSpock Testing Framework for RubyRSpock Testing Framework for Ruby
RSpock Testing Framework for Ruby
 
Serverless Applications
Serverless ApplicationsServerless Applications
Serverless Applications
 
Serverless - Lunch&Learn CleverToday - Mars 2017
Serverless - Lunch&Learn CleverToday - Mars 2017Serverless - Lunch&Learn CleverToday - Mars 2017
Serverless - Lunch&Learn CleverToday - Mars 2017
 
Docker 1.13 - Docker meetup février 2017
Docker 1.13 - Docker meetup février 2017Docker 1.13 - Docker meetup février 2017
Docker 1.13 - Docker meetup février 2017
 
Docker 1.12 & Swarm Mode [Montreal Docker Meetup Sept. 2016]
Docker 1.12 & Swarm Mode [Montreal Docker Meetup Sept. 2016]Docker 1.12 & Swarm Mode [Montreal Docker Meetup Sept. 2016]
Docker 1.12 & Swarm Mode [Montreal Docker Meetup Sept. 2016]
 
Packagez et déployez vos applications avec Docker - Montréal CloudFoundry Mee...
Packagez et déployez vos applications avec Docker - Montréal CloudFoundry Mee...Packagez et déployez vos applications avec Docker - Montréal CloudFoundry Mee...
Packagez et déployez vos applications avec Docker - Montréal CloudFoundry Mee...
 
The Patterns to boost your time to market - An introduction to DevOps
The Patterns to boost your time to market - An introduction to DevOpsThe Patterns to boost your time to market - An introduction to DevOps
The Patterns to boost your time to market - An introduction to DevOps
 
Introduction to Continuous Integration with Jenkins
Introduction to Continuous Integration with JenkinsIntroduction to Continuous Integration with Jenkins
Introduction to Continuous Integration with Jenkins
 
Java EE - Servlets API
Java EE - Servlets APIJava EE - Servlets API
Java EE - Servlets API
 
JS-Everywhere - SSE Hands-on
JS-Everywhere - SSE Hands-onJS-Everywhere - SSE Hands-on
JS-Everywhere - SSE Hands-on
 
JS-Everywhere - LocalStorage Hands-on
JS-Everywhere - LocalStorage Hands-onJS-Everywhere - LocalStorage Hands-on
JS-Everywhere - LocalStorage Hands-on
 
Soutenance mémoire : Implémentation d'un DSL en entreprise
Soutenance mémoire : Implémentation d'un DSL en entrepriseSoutenance mémoire : Implémentation d'un DSL en entreprise
Soutenance mémoire : Implémentation d'un DSL en entreprise
 

Kürzlich hochgeladen

Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
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.pdfsudhanshuwaghmare1
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?Igalia
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
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 WorkerThousandEyes
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 

Kürzlich hochgeladen (20)

Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
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
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
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
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 

Effective Java

  • 1. Effective Java Presentation of the Joshua Bloch's Book. www.supinfo.com Copyright © SUPINFO. All rights reserved
  • 2. Effective Java The Speaker Professional Experiences: - Bug Out PC - Groupe Open - ADF - Atos Worldline - Adullact - Xebia IT - Webpulser - Audaxis Training: - DUT Informatique / Montpellier - Supinfo B3 / Montpellier - Supinfo M1 / Lille - STA Java Lille / Valenciennes Brice Argenson - 59253@supinfo.com Certifications: brice.argenson - SCJP 6 @bargenson - SCWCD 5
  • 3. Effective Java Agenda  Develop more effectively ?  Creating and Destroying objects  Classes and Interfaces  Methods  General Programming  The Book  About the Author
  • 4. Effective Java Develop more effectively ? Good practices
  • 5. Develop more effectively ? Creating and Destroying objects Item 1: Consider static factory methods instead of constructors.  Public constructor is the normal way for a class to allow a client to obtain an instance of itself.  Another technique is to provide a public static factory method !
  • 6. Develop more effectively ? Creating and Destroying objects Item 1: Consider static factory methods instead of constructors.  First advantage : They have names ! BigInteger(int bitLength, int certainty, Random rnd) Constructs a randomly generated positive BigInteger that is probably prime, with the specified bitLength. BigInteger.probablePrime(int bitLength, Random rnd) Returns a positive BigInteger that is probably prime, with the specified bitLength.
  • 7. Develop more effectively ? Creating and Destroying objects Item 1: Consider static factory methods instead of constructors.  Second advantage : They are no required to create a new object each time they’re invoked.
  • 8. Develop more effectively ? Creating and Destroying objects Item 1: Consider static factory methods instead of constructors.  Third advantage : They can return an object of any subtype of their return type.
  • 9. Develop more effectively ? Creating and Destroying objects Item 1: Consider static factory methods instead of constructors.  Fourth advantage : They reduce the verbosity of creating parameterized type instances.
  • 10. Develop more effectively ? Creating and Destroying objects Item 1: Consider static factory methods instead of constructors.  First disadvantage : Classes without public or protected constructors cannot be sub-classed.  Second disadvantage : They are not readily distinguishable from other static methods.
  • 11. Develop more effectively ? Creating and Destroying objects Item 2: Consider a builder when faced with many constructor parameters.  Static factories and constructors share a limitation: they don’t scale well to large members of optional parameters.  Traditionally, two patterns are used :  Telescoping constructor pattern.  JavaBeans pattern.
  • 12. Develop more effectively ? Creating and Destroying objects
  • 13. Develop more effectively ? Creating and Destroying objects Item 2: Consider a builder when faced with many constructor parameters.  Telescoping constructor pattern :  Hard to write.  Harder to read :
  • 14. Develop more effectively ? Creating and Destroying objects
  • 15. Develop more effectively ? Creating and Destroying objects Item 2: Consider a builder when faced with many constructor parameters.  JavaBeans pattern :  Easier to write.  Easier to read :  But JavaBean may be in an inconsistent state partway through its construction !
  • 16. Develop more effectively ? Creating and Destroying objects
  • 17. Develop more effectively ? Creating and Destroying objects Item 2: Consider a builder when faced with many constructor parameters.  Builder pattern :  Easy to write.  Easy to read :  Simulates named optional parameters.  Consistent state control.
  • 18. Develop more effectively ? Creating and Destroying objects Item 5: Avoid creating unnecessary objects.  Is this statement correct ?
  • 19. Develop more effectively ? Creating and Destroying objects Item 5: Avoid creating unnecessary objects.  Improved version :
  • 20. Develop more effectively ? Creating and Destroying objects Item 5: Avoid creating unnecessary objects.  Is this code correct ?
  • 21. Develop more effectively ? Creating and Destroying objects Item 5: Avoid creating unnecessary objects.  Improved version (about 250 times faster for 10 million invocations) :
  • 22. Develop more effectively ? Creating and Destroying objects Item 5: Avoid creating unnecessary objects.  Is this code correct ?
  • 23. Develop more effectively ? Creating and Destroying objects Item 5: Avoid creating unnecessary objects.  Improved version (6.3 times faster) :
  • 24. Develop more effectively ? Classes and Interfaces Item 16: Favor composition over inheritance.  Inheritance is a powerful way to achieve code reuse  But not always the best !  Inheritance from ordinary concrete classes across package boundaries is dangerous ! Unlike method invocation, inheritance violates encapsulation.
  • 25. Develop more effectively ? Classes and Interfaces Item 16: Favor composition over inheritance.
  • 26. Develop more effectively ? Classes and Interfaces Item 16: Favor composition over inheritance.  What this code display ?
  • 27. Develop more effectively ? Classes and Interfaces Item 16: Favor composition over inheritance.
  • 28. Develop more effectively ? Classes and Interfaces Item 16: Favor composition over inheritance.
  • 29. Develop more effectively ? Classes and Interfaces Item 16: Favor composition over inheritance.  Design of the InstrumentedSet is extremely flexible :  Implement the Set interface.  Receive an argument also of type Set.  With inheritance, we could work only with HashSet.  With composition, we can work with any Set implementation !
  • 30. Develop more effectively ? Classes and Interfaces
  • 31. Develop more effectively ? Classes and Interfaces Item 20: Prefer class hierarchies to tagged classes.  Tagged classes are verbose, error-prone, inefficient and just a pallid imitation of a class hierarchy.  Here is the class hierarchy corresponding to the original class :
  • 32. Develop more effectively ? Classes and Interfaces Item 20: Prefer class hierarchies to tagged classes.
  • 33. Develop more effectively ? Classes and Interfaces Item 20: Prefer class hierarchies to tagged classes.  Class hierarchies are more flexible and provide better compile-time type checking.  Suppose we need a square shape :
  • 34. Develop more effectively ? Methods  Consider the following class :
  • 35. Develop more effectively ? Methods  Consider the following code :  Do you see the problem ?
  • 36. Develop more effectively ? Methods Item 39: Make defensive copies when needed.  To protect the internals of a Period instance from this sort of attack:  You must make defensive copy of each mutable parameter to the constructor !
  • 37. Develop more effectively ? Methods Item 41: Use overloading judiciously.  What does the following program prints ?
  • 38. Develop more effectively ? Methods Item 41: Use overloading judiciously.  The program print : “Unknown Collection” three times.  The choice of which overloading to invoke is made at compile time !  Not like overridden methods…
  • 39. Develop more effectively ? Methods Item 41: Use overloading judiciously.  What does the following program prints ?
  • 40. Develop more effectively ? Methods Item 41: Use overloading judiciously.  The program print : [-3, -2, -1] [-2, 0, 2].  The remove method is overloaded inside List class :  remove(E) : delete the E element inside the list.  remove(int) : delete the element at the specified position.
  • 41. Develop more effectively ? Methods Item 41: Use overloading judiciously.  Refrain from overloading methods with multiple signatures that have the same number of parameters.  If you can’t, at least avoid situations where the same set of parameters can be passed to different overloadings by the addition of casts.
  • 42. Develop more effectively ? General Programming Item 48: Avoid float and double if exact answers are required.  What does the following program prints ?
  • 43. Develop more effectively ? General Programming Item 48: Avoid float and double if exact answers are required.  It prints you can afford 3 items and you have $0.3999999999999999 left…  The float and double types are designed primarily for scientific and engineering calculations.  They perform binary floating-point arithmetic with approximations !  They should not be used where exact results are required.
  • 44. Develop more effectively ? General Programming Item 48: Avoid float and double if exact answers are required.  A correct version of the previous program :
  • 45. Develop more effectively ? General Programming Item 55: Optimize judiciously. "More computing sins are committed in the name of efficiency (without necessarily achieving it) than for any other single reason - including blind stupidity." - W.A. Wulf “We should forget about small efficiencies, say about 97% of the time: premature optimization is the root of all evil.” - Donald E. Knuth “The First Rule of Program Optimization: Don't do it. The Second Rule of Program Optimization (for experts only!): Don't do it yet.” - Michael A. Jackson
  • 46. Develop more effectively ? General Programming Item 55: Optimize judiciously.  Strive to write good programs rather than fast ones.  Strive to avoid design decisions that limit performance.  Consider the performance consequence of your API design decisions.  Measure performance before and after each attempted optimization.
  • 47. Effective Java The Book For all the other tips !
  • 48. The Book The original version Effective Java Second Edition Joshua BLOCH Addison Wesley editions "I sure wish I had this book ten years ago. Some might think that I don't need any Java books, but I need this one.” - James Gosling, Fellow and Vice President, Sun Microsystems, Inc.
  • 49. The Book The translated version Java Efficace Guide de programmation Joshua BLOCH Traduction d’Alexis Moussine-Pouchkine Vuilbert editions http://www.amazon.fr/Java-efficace- Bloch/dp/2711748057/ref=sr_1_1?ie=UTF8&s=books&qid=12985674 25&sr=8-1
  • 50. Effective Java About the Author For all the other tips !
  • 51. About the Author Joshua Bloch  Chief Java architect at Google.  Jolt Award winner.  Previously a distinguished engineer at Sun Microsystems and a senior systems designer at Transarc.  Led the design and implementation of numerous Java platform features. http://googleresearch.blogspot.com/ @joshbloch
  • 52. About the Author Bibliographie  Effective Java: Programming Language Guide  ISBN 0201310058, 2001.  Second edition: ISBN 978-0-321-35668-0, 2008.
  • 53. About the Author Bibliographie  Java Puzzlers: Traps, Pitfalls, and Corner Cases  ISBN 032133678X, 2005 (co-authored with Neal Gafter).
  • 54. About the Author Bibliographie  Java Concurrency in Practice  ISBN 0321349601, 2006 (co-authored with Brian Goetz, Tim Peierls, Joseph Bowbeer, David Holmes, and Doug Lea).