SlideShare a Scribd company logo
Jason Kuan
Effective Java (2nd)
Item 1: Consider static factory
methods instead of constructors
public class Person {

private String name;

private int age;



public Person(String name, int age) {

this.name = name;

this.age = age;

}

}
public static void main(String args[]) {

Person person = new Person("John",20);

}
public class Person {

private String name;

private int age;



private Person(String name, int age) {

this.name = name;

this.age = age;

}
public static Person createPersonWithNameAndAge(String name, int age) {

return new Person(name, age);

}


}
public static void main(String args[]) {

Person person = Person.createPersonWithNameAndAge("John",20);
}
Item 2: Consider a builder when
faced with many constructorparameters
public static void main(String args[]) {

MyCharacter character = new MyCharacter.Builder("Merry")

.wearHead(" ")

.wearBody(" T")

.wearPants(" ")

.build();
System.out.println(">>> Item 2:" + character.toString());
}
Item 49: Prefer primitive
types to boxed primitives
int preIntA = 20;

int preIntB = 20;



Integer boxIntA = new Integer(20);

Integer boxIntB = new Integer(20);



System.out.println(">>> preIntA:" + preIntA +", preIntB:" + preIntB);

System.out.println(">>> preEqual? :" + (preIntA == preIntB));



System.out.println(">>> boxIntA:" + boxIntA +", boxIntB:" + boxIntB);

System.out.println(">>> boxEqual? :" + (boxIntA == boxIntB));
Macbook Air 10.11.5 (2013)
public static void main(String args[]) {
Long sum = 0L;

for (long i = 0; i < Integer.MAX_VALUE /100 ; i++) {

sum += i;

}
}
vs
public static void main(String args[]) {
long sum = 0L;

for (long i = 0; i < Integer.MAX_VALUE /100 ; i++) {

sum += i;

}
} 0.936 sec
29.438 sec
MAX_VALUE = 2^31 -1
Integer a = new Integer(20);

int b = 10;

Integer c = a + b;



System.out.println(">>> c = " + c);
Integer c = a + b;
b boxing!→ Integer
Integer c
—————————————————————————-
Integer a = new Integer(20);

int b = 10;

int c = a + b;



System.out.println(">>> c = " + c);
int c = a + b;
a unboxing!→ int
int c
Why need boxed primitive type ?
!#Correct
List<Integer> boxList = new ArrayList<>();

boxList.add(3);
!#Compiler Time Error
List<int> preList = new ArrayList<>();
Type argument cannot be of primitive type
Item 41: Use overloading
judiciously
public class CalculatorMachine {



public CalculatorMachine() {

}

public int add(int a, int b){

return a+b;

}

public int add(int a, int b, int c){

return a+b+c;

}

public int add(double a, double b){

return (int) (a+b);

}

}
public static void main(String args[]) {
CalculatorMachine calculator = new CalculatorMachine();

System.out.println(">>> Item 41:" + calculator.add(1, 5));

System.out.println(">>> Item 41:" + calculator.add(1, 5, 8));

System.out.println(">>> Item 41:" + calculator.add(1.1, 4.3));
}
public static void main(String args[]) {
Set<Integer> set = new TreeSet<>();

List<Integer> list = new ArrayList<>();



for (int i = 51; i $% 56; i++) {

set.add(i); !# [51, 52, 53, 54, 55]

list.add(i); !# [51, 52, 53, 54, 55]

}



set.remove(52);

list.remove(52);



System.out.println(">>> Item 41: set = " + set.toString());

System.out.println(">>> Item 41: list = " + list.toString());
}
public static void main(String args[]) {
Set<Integer> set = new TreeSet<>();

List<Integer> list = new ArrayList<>();



for (int i = 51; i $% 56; i++) {

set.add(i); !# [51, 52, 53, 54, 55]

list.add(i); !# [51, 52, 53, 54, 55]

}



set.remove(52);

list.remove((Integer)52);



System.out.println(">>> Item 41: set = " + set.toString());

System.out.println(">>> Item 41: list = " + list.toString());
}
ref:
https://github.com/HackathonHackers/
programming-ebooks/blob/master/Java/Effective
%20Java%20%282nd%20Edition%29.pdf
code:
https://github.com/jason9075/soohoobookTechTalk

More Related Content

What's hot

Gems of GameplayKit. UA Mobile 2017.
Gems of GameplayKit. UA Mobile 2017.Gems of GameplayKit. UA Mobile 2017.
Gems of GameplayKit. UA Mobile 2017.
UA Mobile
 
Mozilla とブラウザゲーム
Mozilla とブラウザゲームMozilla とブラウザゲーム
Mozilla とブラウザゲーム
Noritada Shimizu
 
BingoConsoleApp
BingoConsoleAppBingoConsoleApp
BingoConsoleApp
Imtiazur Syed
 
CUDA First Programs: Computer Architecture CSE448 : UAA Alaska : Notes
CUDA First Programs: Computer Architecture CSE448 : UAA Alaska : NotesCUDA First Programs: Computer Architecture CSE448 : UAA Alaska : Notes
CUDA First Programs: Computer Architecture CSE448 : UAA Alaska : Notes
Subhajit Sahu
 
.net progrmming part2
.net progrmming part2.net progrmming part2
.net progrmming part2
Dr.M.Karthika parthasarathy
 
Efnsjdnfsuies
EfnsjdnfsuiesEfnsjdnfsuies
Efnsjdnfsuies
htmrk
 
Sokoban Game Development Using Java ( Updated using Screenshots & Class Diagr...
Sokoban Game Development Using Java ( Updated using Screenshots & Class Diagr...Sokoban Game Development Using Java ( Updated using Screenshots & Class Diagr...
Sokoban Game Development Using Java ( Updated using Screenshots & Class Diagr...
British Council
 
Java program-to-add-two-matrices
Java program-to-add-two-matricesJava program-to-add-two-matrices
Java program-to-add-two-matrices
University of Essex
 
ヘルパ・オブジェクト
ヘルパ・オブジェクトヘルパ・オブジェクト
ヘルパ・オブジェクト
幸雄 村上
 
Super Advanced Python –act1
Super Advanced Python –act1Super Advanced Python –act1
Super Advanced Python –act1
Ke Wei Louis
 
Functional JS for everyone - 4Developers
Functional JS for everyone - 4DevelopersFunctional JS for everyone - 4Developers
Functional JS for everyone - 4Developers
Bartek Witczak
 
Human-powered Javascript Compression for Fun and Gummy Bears
Human-powered Javascript Compression for Fun and Gummy BearsHuman-powered Javascript Compression for Fun and Gummy Bears
Human-powered Javascript Compression for Fun and Gummy Bears
Rui Lopes
 
[JuraSIC! Meetup] Mateusz Stasch - Monady w .NET
[JuraSIC! Meetup] Mateusz Stasch - Monady w .NET[JuraSIC! Meetup] Mateusz Stasch - Monady w .NET
[JuraSIC! Meetup] Mateusz Stasch - Monady w .NET
Future Processing
 
Mercado iOS & Swift vs Objective-C
Mercado iOS & Swift vs Objective-CMercado iOS & Swift vs Objective-C
Mercado iOS & Swift vs Objective-C
Mauricio Tremea Zaquia
 
Зависимые типы в GHC 8. Максим Талдыкин
Зависимые типы в GHC 8. Максим ТалдыкинЗависимые типы в GHC 8. Максим Талдыкин
Зависимые типы в GHC 8. Максим Талдыкин
Юрий Сыровецкий
 
The Ring programming language version 1.7 book - Part 71 of 196
The Ring programming language version 1.7 book - Part 71 of 196The Ring programming language version 1.7 book - Part 71 of 196
The Ring programming language version 1.7 book - Part 71 of 196
Mahmoud Samir Fayed
 
JavaScript Objects and OOP Programming with JavaScript
JavaScript Objects and OOP Programming with JavaScriptJavaScript Objects and OOP Programming with JavaScript
JavaScript Objects and OOP Programming with JavaScript
Laurence Svekis ✔
 
cocos2d 事例編 HungryMasterの実装から
cocos2d 事例編 HungryMasterの実装からcocos2d 事例編 HungryMasterの実装から
cocos2d 事例編 HungryMasterの実装から
Yuichi Higuchi
 
Oopsprc1c
Oopsprc1cOopsprc1c
Oopsprc1c
Ankit Dubey
 
Workers of the web - BrazilJS 2013
Workers of the web - BrazilJS 2013Workers of the web - BrazilJS 2013
Workers of the web - BrazilJS 2013
Thibault Imbert
 

What's hot (20)

Gems of GameplayKit. UA Mobile 2017.
Gems of GameplayKit. UA Mobile 2017.Gems of GameplayKit. UA Mobile 2017.
Gems of GameplayKit. UA Mobile 2017.
 
Mozilla とブラウザゲーム
Mozilla とブラウザゲームMozilla とブラウザゲーム
Mozilla とブラウザゲーム
 
BingoConsoleApp
BingoConsoleAppBingoConsoleApp
BingoConsoleApp
 
CUDA First Programs: Computer Architecture CSE448 : UAA Alaska : Notes
CUDA First Programs: Computer Architecture CSE448 : UAA Alaska : NotesCUDA First Programs: Computer Architecture CSE448 : UAA Alaska : Notes
CUDA First Programs: Computer Architecture CSE448 : UAA Alaska : Notes
 
.net progrmming part2
.net progrmming part2.net progrmming part2
.net progrmming part2
 
Efnsjdnfsuies
EfnsjdnfsuiesEfnsjdnfsuies
Efnsjdnfsuies
 
Sokoban Game Development Using Java ( Updated using Screenshots & Class Diagr...
Sokoban Game Development Using Java ( Updated using Screenshots & Class Diagr...Sokoban Game Development Using Java ( Updated using Screenshots & Class Diagr...
Sokoban Game Development Using Java ( Updated using Screenshots & Class Diagr...
 
Java program-to-add-two-matrices
Java program-to-add-two-matricesJava program-to-add-two-matrices
Java program-to-add-two-matrices
 
ヘルパ・オブジェクト
ヘルパ・オブジェクトヘルパ・オブジェクト
ヘルパ・オブジェクト
 
Super Advanced Python –act1
Super Advanced Python –act1Super Advanced Python –act1
Super Advanced Python –act1
 
Functional JS for everyone - 4Developers
Functional JS for everyone - 4DevelopersFunctional JS for everyone - 4Developers
Functional JS for everyone - 4Developers
 
Human-powered Javascript Compression for Fun and Gummy Bears
Human-powered Javascript Compression for Fun and Gummy BearsHuman-powered Javascript Compression for Fun and Gummy Bears
Human-powered Javascript Compression for Fun and Gummy Bears
 
[JuraSIC! Meetup] Mateusz Stasch - Monady w .NET
[JuraSIC! Meetup] Mateusz Stasch - Monady w .NET[JuraSIC! Meetup] Mateusz Stasch - Monady w .NET
[JuraSIC! Meetup] Mateusz Stasch - Monady w .NET
 
Mercado iOS & Swift vs Objective-C
Mercado iOS & Swift vs Objective-CMercado iOS & Swift vs Objective-C
Mercado iOS & Swift vs Objective-C
 
Зависимые типы в GHC 8. Максим Талдыкин
Зависимые типы в GHC 8. Максим ТалдыкинЗависимые типы в GHC 8. Максим Талдыкин
Зависимые типы в GHC 8. Максим Талдыкин
 
The Ring programming language version 1.7 book - Part 71 of 196
The Ring programming language version 1.7 book - Part 71 of 196The Ring programming language version 1.7 book - Part 71 of 196
The Ring programming language version 1.7 book - Part 71 of 196
 
JavaScript Objects and OOP Programming with JavaScript
JavaScript Objects and OOP Programming with JavaScriptJavaScript Objects and OOP Programming with JavaScript
JavaScript Objects and OOP Programming with JavaScript
 
cocos2d 事例編 HungryMasterの実装から
cocos2d 事例編 HungryMasterの実装からcocos2d 事例編 HungryMasterの実装から
cocos2d 事例編 HungryMasterの実装から
 
Oopsprc1c
Oopsprc1cOopsprc1c
Oopsprc1c
 
Workers of the web - BrazilJS 2013
Workers of the web - BrazilJS 2013Workers of the web - BrazilJS 2013
Workers of the web - BrazilJS 2013
 

Viewers also liked

Salud ocupacional
Salud ocupacionalSalud ocupacional
Salud ocupacional
edith2369
 
Revista lac machote 28.03.14
Revista lac   machote 28.03.14Revista lac   machote 28.03.14
Revista lac machote 28.03.14
Lac Todos
 
1.2.mariana alor.
1.2.mariana alor.1.2.mariana alor.
1.2.mariana alor.
Mariana Alor
 
amr_AA-651-Offenburg_201110.xls.pdf
amr_AA-651-Offenburg_201110.xls.pdfamr_AA-651-Offenburg_201110.xls.pdf
amr_AA-651-Offenburg_201110.xls.pdf
unn | UNITED NEWS NETWORK GmbH
 
3910-SGB-II-Halbjahresbilanz.doc.pdf
3910-SGB-II-Halbjahresbilanz.doc.pdf3910-SGB-II-Halbjahresbilanz.doc.pdf
3910-SGB-II-Halbjahresbilanz.doc.pdf
unn | UNITED NEWS NETWORK GmbH
 
Mari celeste
Mari celesteMari celeste
Mari celeste
MariValderrama
 
Yessica
YessicaYessica
Jornal da Astral
Jornal da AstralJornal da Astral
Jornal da Astral
samvile
 
CALENDARIO JUNIO 2016
CALENDARIO JUNIO 2016CALENDARIO JUNIO 2016
CALENDARIO JUNIO 2016
Colegio Los Pinos
 
Функциональное программирование - Александр Алексеев
Функциональное программирование - Александр АлексеевФункциональное программирование - Александр Алексеев
Функциональное программирование - Александр Алексеев
Aleksander Alekseev
 
Edhi tugas strategik
Edhi tugas strategikEdhi tugas strategik
Edhi tugas strategik
edhi sigit
 
Antropologia
AntropologiaAntropologia
DTNA-PräsidentObamabeiDaimler.pdf
DTNA-PräsidentObamabeiDaimler.pdfDTNA-PräsidentObamabeiDaimler.pdf
DTNA-PräsidentObamabeiDaimler.pdf
unn | UNITED NEWS NETWORK GmbH
 
Historial del sena
Historial del senaHistorial del sena
Historial del sena
sena01100
 
TIPOS DE APRENDIZAJE
TIPOS DE APRENDIZAJE TIPOS DE APRENDIZAJE
TIPOS DE APRENDIZAJE
AlanXim
 
Tablas y gráficas Excel
Tablas y gráficas ExcelTablas y gráficas Excel
Tablas y gráficas Excel
ANABEATRIZLOPEZ
 
Clearswift f5 integration
Clearswift f5 integrationClearswift f5 integration
Clearswift f5 integration
Marco Essomba
 
Eval. la contaminación acústica de nuestro ies
Eval. la contaminación acústica de nuestro iesEval. la contaminación acústica de nuestro ies
Eval. la contaminación acústica de nuestro ies
musicaies
 
Sell me this pen
Sell me this penSell me this pen
Sell me this pen
AIESECGreece
 
"Soy donante"
"Soy donante""Soy donante"
"Soy donante"
MilagroMozambique1B
 

Viewers also liked (20)

Salud ocupacional
Salud ocupacionalSalud ocupacional
Salud ocupacional
 
Revista lac machote 28.03.14
Revista lac   machote 28.03.14Revista lac   machote 28.03.14
Revista lac machote 28.03.14
 
1.2.mariana alor.
1.2.mariana alor.1.2.mariana alor.
1.2.mariana alor.
 
amr_AA-651-Offenburg_201110.xls.pdf
amr_AA-651-Offenburg_201110.xls.pdfamr_AA-651-Offenburg_201110.xls.pdf
amr_AA-651-Offenburg_201110.xls.pdf
 
3910-SGB-II-Halbjahresbilanz.doc.pdf
3910-SGB-II-Halbjahresbilanz.doc.pdf3910-SGB-II-Halbjahresbilanz.doc.pdf
3910-SGB-II-Halbjahresbilanz.doc.pdf
 
Mari celeste
Mari celesteMari celeste
Mari celeste
 
Yessica
YessicaYessica
Yessica
 
Jornal da Astral
Jornal da AstralJornal da Astral
Jornal da Astral
 
CALENDARIO JUNIO 2016
CALENDARIO JUNIO 2016CALENDARIO JUNIO 2016
CALENDARIO JUNIO 2016
 
Функциональное программирование - Александр Алексеев
Функциональное программирование - Александр АлексеевФункциональное программирование - Александр Алексеев
Функциональное программирование - Александр Алексеев
 
Edhi tugas strategik
Edhi tugas strategikEdhi tugas strategik
Edhi tugas strategik
 
Antropologia
AntropologiaAntropologia
Antropologia
 
DTNA-PräsidentObamabeiDaimler.pdf
DTNA-PräsidentObamabeiDaimler.pdfDTNA-PräsidentObamabeiDaimler.pdf
DTNA-PräsidentObamabeiDaimler.pdf
 
Historial del sena
Historial del senaHistorial del sena
Historial del sena
 
TIPOS DE APRENDIZAJE
TIPOS DE APRENDIZAJE TIPOS DE APRENDIZAJE
TIPOS DE APRENDIZAJE
 
Tablas y gráficas Excel
Tablas y gráficas ExcelTablas y gráficas Excel
Tablas y gráficas Excel
 
Clearswift f5 integration
Clearswift f5 integrationClearswift f5 integration
Clearswift f5 integration
 
Eval. la contaminación acústica de nuestro ies
Eval. la contaminación acústica de nuestro iesEval. la contaminación acústica de nuestro ies
Eval. la contaminación acústica de nuestro ies
 
Sell me this pen
Sell me this penSell me this pen
Sell me this pen
 
"Soy donante"
"Soy donante""Soy donante"
"Soy donante"
 

Similar to 20160616技術會議

java experiments and programs
java experiments and programsjava experiments and programs
java experiments and programs
Karuppaiyaa123
 
Java programs
Java programsJava programs
Java programs
TAUQEER ABBAS
 
Lezione03
Lezione03Lezione03
Lezione03
robynho86
 
Lezione03
Lezione03Lezione03
Lezione03
robynho86
 
662305 09
662305 09662305 09
Java Simple Programs
Java Simple ProgramsJava Simple Programs
Java Simple Programs
Upender Upr
 
Java_practical_handbook
Java_practical_handbookJava_practical_handbook
Java_practical_handbook
Manusha Dilan
 
Class 6 2ciclo
Class 6 2cicloClass 6 2ciclo
Class 6 2ciclo
Carlos Alcivar
 
Utility.ppt
Utility.pptUtility.ppt
Utility.ppt
BruceLee275640
 
C# labprograms
C# labprogramsC# labprograms
C# labprograms
Jafar Nesargi
 
2. Section 2. Implementing functionality in the PersonEntry. (1.5 ma.pdf
2. Section 2. Implementing functionality in the PersonEntry. (1.5 ma.pdf2. Section 2. Implementing functionality in the PersonEntry. (1.5 ma.pdf
2. Section 2. Implementing functionality in the PersonEntry. (1.5 ma.pdf
allwayscollection
 
Kotlin for Android Developers - Victor Kropp - Codemotion Rome 2018
Kotlin for Android Developers - Victor Kropp - Codemotion Rome 2018Kotlin for Android Developers - Victor Kropp - Codemotion Rome 2018
Kotlin for Android Developers - Victor Kropp - Codemotion Rome 2018
Codemotion
 
Java Program
Java ProgramJava Program
Java Program
Sudeep Singh
 
Kotlin Overview (PT-BR)
Kotlin Overview (PT-BR)Kotlin Overview (PT-BR)
Kotlin Overview (PT-BR)
ThomasHorta
 
From java to kotlin beyond alt+shift+cmd+k
From java to kotlin beyond alt+shift+cmd+kFrom java to kotlin beyond alt+shift+cmd+k
From java to kotlin beyond alt+shift+cmd+k
Fabio Collini
 
syed
syedsyed
Sam wd programs
Sam wd programsSam wd programs
Sam wd programs
Soumya Behera
 
Dotnet 18
Dotnet 18Dotnet 18
Dotnet 18
dhruvesh718
 
OBJECTS IN Object Oriented Programming .ppt
OBJECTS IN Object Oriented Programming .pptOBJECTS IN Object Oriented Programming .ppt
OBJECTS IN Object Oriented Programming .ppt
SaadAsim11
 
C# Starter L04-Collections
C# Starter L04-CollectionsC# Starter L04-Collections
C# Starter L04-Collections
Mohammad Shaker
 

Similar to 20160616技術會議 (20)

java experiments and programs
java experiments and programsjava experiments and programs
java experiments and programs
 
Java programs
Java programsJava programs
Java programs
 
Lezione03
Lezione03Lezione03
Lezione03
 
Lezione03
Lezione03Lezione03
Lezione03
 
662305 09
662305 09662305 09
662305 09
 
Java Simple Programs
Java Simple ProgramsJava Simple Programs
Java Simple Programs
 
Java_practical_handbook
Java_practical_handbookJava_practical_handbook
Java_practical_handbook
 
Class 6 2ciclo
Class 6 2cicloClass 6 2ciclo
Class 6 2ciclo
 
Utility.ppt
Utility.pptUtility.ppt
Utility.ppt
 
C# labprograms
C# labprogramsC# labprograms
C# labprograms
 
2. Section 2. Implementing functionality in the PersonEntry. (1.5 ma.pdf
2. Section 2. Implementing functionality in the PersonEntry. (1.5 ma.pdf2. Section 2. Implementing functionality in the PersonEntry. (1.5 ma.pdf
2. Section 2. Implementing functionality in the PersonEntry. (1.5 ma.pdf
 
Kotlin for Android Developers - Victor Kropp - Codemotion Rome 2018
Kotlin for Android Developers - Victor Kropp - Codemotion Rome 2018Kotlin for Android Developers - Victor Kropp - Codemotion Rome 2018
Kotlin for Android Developers - Victor Kropp - Codemotion Rome 2018
 
Java Program
Java ProgramJava Program
Java Program
 
Kotlin Overview (PT-BR)
Kotlin Overview (PT-BR)Kotlin Overview (PT-BR)
Kotlin Overview (PT-BR)
 
From java to kotlin beyond alt+shift+cmd+k
From java to kotlin beyond alt+shift+cmd+kFrom java to kotlin beyond alt+shift+cmd+k
From java to kotlin beyond alt+shift+cmd+k
 
syed
syedsyed
syed
 
Sam wd programs
Sam wd programsSam wd programs
Sam wd programs
 
Dotnet 18
Dotnet 18Dotnet 18
Dotnet 18
 
OBJECTS IN Object Oriented Programming .ppt
OBJECTS IN Object Oriented Programming .pptOBJECTS IN Object Oriented Programming .ppt
OBJECTS IN Object Oriented Programming .ppt
 
C# Starter L04-Collections
C# Starter L04-CollectionsC# Starter L04-Collections
C# Starter L04-Collections
 

Recently uploaded

VARIABLE FREQUENCY DRIVE. VFDs are widely used in industrial applications for...
VARIABLE FREQUENCY DRIVE. VFDs are widely used in industrial applications for...VARIABLE FREQUENCY DRIVE. VFDs are widely used in industrial applications for...
VARIABLE FREQUENCY DRIVE. VFDs are widely used in industrial applications for...
PIMR BHOPAL
 
Software Engineering and Project Management - Introduction, Modeling Concepts...
Software Engineering and Project Management - Introduction, Modeling Concepts...Software Engineering and Project Management - Introduction, Modeling Concepts...
Software Engineering and Project Management - Introduction, Modeling Concepts...
Prakhyath Rai
 
Optimizing Gradle Builds - Gradle DPE Tour Berlin 2024
Optimizing Gradle Builds - Gradle DPE Tour Berlin 2024Optimizing Gradle Builds - Gradle DPE Tour Berlin 2024
Optimizing Gradle Builds - Gradle DPE Tour Berlin 2024
Sinan KOZAK
 
一比一原版(CalArts毕业证)加利福尼亚艺术学院毕业证如何办理
一比一原版(CalArts毕业证)加利福尼亚艺术学院毕业证如何办理一比一原版(CalArts毕业证)加利福尼亚艺术学院毕业证如何办理
一比一原版(CalArts毕业证)加利福尼亚艺术学院毕业证如何办理
ecqow
 
Object Oriented Analysis and Design - OOAD
Object Oriented Analysis and Design - OOADObject Oriented Analysis and Design - OOAD
Object Oriented Analysis and Design - OOAD
PreethaV16
 
AI + Data Community Tour - Build the Next Generation of Apps with the Einstei...
AI + Data Community Tour - Build the Next Generation of Apps with the Einstei...AI + Data Community Tour - Build the Next Generation of Apps with the Einstei...
AI + Data Community Tour - Build the Next Generation of Apps with the Einstei...
Paris Salesforce Developer Group
 
2008 BUILDING CONSTRUCTION Illustrated - Ching Chapter 08 Doors and Windows.pdf
2008 BUILDING CONSTRUCTION Illustrated - Ching Chapter 08 Doors and Windows.pdf2008 BUILDING CONSTRUCTION Illustrated - Ching Chapter 08 Doors and Windows.pdf
2008 BUILDING CONSTRUCTION Illustrated - Ching Chapter 08 Doors and Windows.pdf
Yasser Mahgoub
 
An Introduction to the Compiler Designss
An Introduction to the Compiler DesignssAn Introduction to the Compiler Designss
An Introduction to the Compiler Designss
ElakkiaU
 
Welding Metallurgy Ferrous Materials.pdf
Welding Metallurgy Ferrous Materials.pdfWelding Metallurgy Ferrous Materials.pdf
Welding Metallurgy Ferrous Materials.pdf
AjmalKhan50578
 
Curve Fitting in Numerical Methods Regression
Curve Fitting in Numerical Methods RegressionCurve Fitting in Numerical Methods Regression
Curve Fitting in Numerical Methods Regression
Nada Hikmah
 
Digital Twins Computer Networking Paper Presentation.pptx
Digital Twins Computer Networking Paper Presentation.pptxDigital Twins Computer Networking Paper Presentation.pptx
Digital Twins Computer Networking Paper Presentation.pptx
aryanpankaj78
 
一比一原版(osu毕业证书)美国俄勒冈州立大学毕业证如何办理
一比一原版(osu毕业证书)美国俄勒冈州立大学毕业证如何办理一比一原版(osu毕业证书)美国俄勒冈州立大学毕业证如何办理
一比一原版(osu毕业证书)美国俄勒冈州立大学毕业证如何办理
upoux
 
Generative AI Use cases applications solutions and implementation.pdf
Generative AI Use cases applications solutions and implementation.pdfGenerative AI Use cases applications solutions and implementation.pdf
Generative AI Use cases applications solutions and implementation.pdf
mahaffeycheryld
 
一比一原版(uofo毕业证书)美国俄勒冈大学毕业证如何办理
一比一原版(uofo毕业证书)美国俄勒冈大学毕业证如何办理一比一原版(uofo毕业证书)美国俄勒冈大学毕业证如何办理
一比一原版(uofo毕业证书)美国俄勒冈大学毕业证如何办理
upoux
 
AI for Legal Research with applications, tools
AI for Legal Research with applications, toolsAI for Legal Research with applications, tools
AI for Legal Research with applications, tools
mahaffeycheryld
 
Gas agency management system project report.pdf
Gas agency management system project report.pdfGas agency management system project report.pdf
Gas agency management system project report.pdf
Kamal Acharya
 
Software Engineering and Project Management - Software Testing + Agile Method...
Software Engineering and Project Management - Software Testing + Agile Method...Software Engineering and Project Management - Software Testing + Agile Method...
Software Engineering and Project Management - Software Testing + Agile Method...
Prakhyath Rai
 
Data Driven Maintenance | UReason Webinar
Data Driven Maintenance | UReason WebinarData Driven Maintenance | UReason Webinar
Data Driven Maintenance | UReason Webinar
UReason
 
Embedded machine learning-based road conditions and driving behavior monitoring
Embedded machine learning-based road conditions and driving behavior monitoringEmbedded machine learning-based road conditions and driving behavior monitoring
Embedded machine learning-based road conditions and driving behavior monitoring
IJECEIAES
 
Comparative analysis between traditional aquaponics and reconstructed aquapon...
Comparative analysis between traditional aquaponics and reconstructed aquapon...Comparative analysis between traditional aquaponics and reconstructed aquapon...
Comparative analysis between traditional aquaponics and reconstructed aquapon...
bijceesjournal
 

Recently uploaded (20)

VARIABLE FREQUENCY DRIVE. VFDs are widely used in industrial applications for...
VARIABLE FREQUENCY DRIVE. VFDs are widely used in industrial applications for...VARIABLE FREQUENCY DRIVE. VFDs are widely used in industrial applications for...
VARIABLE FREQUENCY DRIVE. VFDs are widely used in industrial applications for...
 
Software Engineering and Project Management - Introduction, Modeling Concepts...
Software Engineering and Project Management - Introduction, Modeling Concepts...Software Engineering and Project Management - Introduction, Modeling Concepts...
Software Engineering and Project Management - Introduction, Modeling Concepts...
 
Optimizing Gradle Builds - Gradle DPE Tour Berlin 2024
Optimizing Gradle Builds - Gradle DPE Tour Berlin 2024Optimizing Gradle Builds - Gradle DPE Tour Berlin 2024
Optimizing Gradle Builds - Gradle DPE Tour Berlin 2024
 
一比一原版(CalArts毕业证)加利福尼亚艺术学院毕业证如何办理
一比一原版(CalArts毕业证)加利福尼亚艺术学院毕业证如何办理一比一原版(CalArts毕业证)加利福尼亚艺术学院毕业证如何办理
一比一原版(CalArts毕业证)加利福尼亚艺术学院毕业证如何办理
 
Object Oriented Analysis and Design - OOAD
Object Oriented Analysis and Design - OOADObject Oriented Analysis and Design - OOAD
Object Oriented Analysis and Design - OOAD
 
AI + Data Community Tour - Build the Next Generation of Apps with the Einstei...
AI + Data Community Tour - Build the Next Generation of Apps with the Einstei...AI + Data Community Tour - Build the Next Generation of Apps with the Einstei...
AI + Data Community Tour - Build the Next Generation of Apps with the Einstei...
 
2008 BUILDING CONSTRUCTION Illustrated - Ching Chapter 08 Doors and Windows.pdf
2008 BUILDING CONSTRUCTION Illustrated - Ching Chapter 08 Doors and Windows.pdf2008 BUILDING CONSTRUCTION Illustrated - Ching Chapter 08 Doors and Windows.pdf
2008 BUILDING CONSTRUCTION Illustrated - Ching Chapter 08 Doors and Windows.pdf
 
An Introduction to the Compiler Designss
An Introduction to the Compiler DesignssAn Introduction to the Compiler Designss
An Introduction to the Compiler Designss
 
Welding Metallurgy Ferrous Materials.pdf
Welding Metallurgy Ferrous Materials.pdfWelding Metallurgy Ferrous Materials.pdf
Welding Metallurgy Ferrous Materials.pdf
 
Curve Fitting in Numerical Methods Regression
Curve Fitting in Numerical Methods RegressionCurve Fitting in Numerical Methods Regression
Curve Fitting in Numerical Methods Regression
 
Digital Twins Computer Networking Paper Presentation.pptx
Digital Twins Computer Networking Paper Presentation.pptxDigital Twins Computer Networking Paper Presentation.pptx
Digital Twins Computer Networking Paper Presentation.pptx
 
一比一原版(osu毕业证书)美国俄勒冈州立大学毕业证如何办理
一比一原版(osu毕业证书)美国俄勒冈州立大学毕业证如何办理一比一原版(osu毕业证书)美国俄勒冈州立大学毕业证如何办理
一比一原版(osu毕业证书)美国俄勒冈州立大学毕业证如何办理
 
Generative AI Use cases applications solutions and implementation.pdf
Generative AI Use cases applications solutions and implementation.pdfGenerative AI Use cases applications solutions and implementation.pdf
Generative AI Use cases applications solutions and implementation.pdf
 
一比一原版(uofo毕业证书)美国俄勒冈大学毕业证如何办理
一比一原版(uofo毕业证书)美国俄勒冈大学毕业证如何办理一比一原版(uofo毕业证书)美国俄勒冈大学毕业证如何办理
一比一原版(uofo毕业证书)美国俄勒冈大学毕业证如何办理
 
AI for Legal Research with applications, tools
AI for Legal Research with applications, toolsAI for Legal Research with applications, tools
AI for Legal Research with applications, tools
 
Gas agency management system project report.pdf
Gas agency management system project report.pdfGas agency management system project report.pdf
Gas agency management system project report.pdf
 
Software Engineering and Project Management - Software Testing + Agile Method...
Software Engineering and Project Management - Software Testing + Agile Method...Software Engineering and Project Management - Software Testing + Agile Method...
Software Engineering and Project Management - Software Testing + Agile Method...
 
Data Driven Maintenance | UReason Webinar
Data Driven Maintenance | UReason WebinarData Driven Maintenance | UReason Webinar
Data Driven Maintenance | UReason Webinar
 
Embedded machine learning-based road conditions and driving behavior monitoring
Embedded machine learning-based road conditions and driving behavior monitoringEmbedded machine learning-based road conditions and driving behavior monitoring
Embedded machine learning-based road conditions and driving behavior monitoring
 
Comparative analysis between traditional aquaponics and reconstructed aquapon...
Comparative analysis between traditional aquaponics and reconstructed aquapon...Comparative analysis between traditional aquaponics and reconstructed aquapon...
Comparative analysis between traditional aquaponics and reconstructed aquapon...
 

20160616技術會議

  • 3. Item 1: Consider static factory methods instead of constructors public class Person {
 private String name;
 private int age;
 
 public Person(String name, int age) {
 this.name = name;
 this.age = age;
 }
 } public static void main(String args[]) {
 Person person = new Person("John",20);
 }
  • 4. public class Person {
 private String name;
 private int age;
 
 private Person(String name, int age) {
 this.name = name;
 this.age = age;
 } public static Person createPersonWithNameAndAge(String name, int age) {
 return new Person(name, age);
 } 
 } public static void main(String args[]) {
 Person person = Person.createPersonWithNameAndAge("John",20); }
  • 5. Item 2: Consider a builder when faced with many constructorparameters public static void main(String args[]) {
 MyCharacter character = new MyCharacter.Builder("Merry")
 .wearHead(" ")
 .wearBody(" T")
 .wearPants(" ")
 .build(); System.out.println(">>> Item 2:" + character.toString()); }
  • 6. Item 49: Prefer primitive types to boxed primitives int preIntA = 20;
 int preIntB = 20;
 
 Integer boxIntA = new Integer(20);
 Integer boxIntB = new Integer(20);
 
 System.out.println(">>> preIntA:" + preIntA +", preIntB:" + preIntB);
 System.out.println(">>> preEqual? :" + (preIntA == preIntB));
 
 System.out.println(">>> boxIntA:" + boxIntA +", boxIntB:" + boxIntB);
 System.out.println(">>> boxEqual? :" + (boxIntA == boxIntB));
  • 7. Macbook Air 10.11.5 (2013) public static void main(String args[]) { Long sum = 0L;
 for (long i = 0; i < Integer.MAX_VALUE /100 ; i++) {
 sum += i;
 } } vs public static void main(String args[]) { long sum = 0L;
 for (long i = 0; i < Integer.MAX_VALUE /100 ; i++) {
 sum += i;
 } } 0.936 sec 29.438 sec MAX_VALUE = 2^31 -1
  • 8. Integer a = new Integer(20);
 int b = 10;
 Integer c = a + b;
 
 System.out.println(">>> c = " + c); Integer c = a + b; b boxing!→ Integer Integer c —————————————————————————- Integer a = new Integer(20);
 int b = 10;
 int c = a + b;
 
 System.out.println(">>> c = " + c); int c = a + b; a unboxing!→ int int c
  • 9. Why need boxed primitive type ?
  • 10. !#Correct List<Integer> boxList = new ArrayList<>();
 boxList.add(3); !#Compiler Time Error List<int> preList = new ArrayList<>(); Type argument cannot be of primitive type
  • 11. Item 41: Use overloading judiciously public class CalculatorMachine {
 
 public CalculatorMachine() {
 }
 public int add(int a, int b){
 return a+b;
 }
 public int add(int a, int b, int c){
 return a+b+c;
 }
 public int add(double a, double b){
 return (int) (a+b);
 }
 } public static void main(String args[]) { CalculatorMachine calculator = new CalculatorMachine();
 System.out.println(">>> Item 41:" + calculator.add(1, 5));
 System.out.println(">>> Item 41:" + calculator.add(1, 5, 8));
 System.out.println(">>> Item 41:" + calculator.add(1.1, 4.3)); }
  • 12. public static void main(String args[]) { Set<Integer> set = new TreeSet<>();
 List<Integer> list = new ArrayList<>();
 
 for (int i = 51; i $% 56; i++) {
 set.add(i); !# [51, 52, 53, 54, 55]
 list.add(i); !# [51, 52, 53, 54, 55]
 }
 
 set.remove(52);
 list.remove(52);
 
 System.out.println(">>> Item 41: set = " + set.toString());
 System.out.println(">>> Item 41: list = " + list.toString()); }
  • 13.
  • 14.
  • 15.
  • 16. public static void main(String args[]) { Set<Integer> set = new TreeSet<>();
 List<Integer> list = new ArrayList<>();
 
 for (int i = 51; i $% 56; i++) {
 set.add(i); !# [51, 52, 53, 54, 55]
 list.add(i); !# [51, 52, 53, 54, 55]
 }
 
 set.remove(52);
 list.remove((Integer)52);
 
 System.out.println(">>> Item 41: set = " + set.toString());
 System.out.println(">>> Item 41: list = " + list.toString()); }