Presentation is loading. Please wait.

Presentation is loading. Please wait.

Effective Java Source: Effective Java, Jason Arnold

Similar presentations


Presentation on theme: "Effective Java Source: Effective Java, Jason Arnold"— Presentation transcript:

1 Effective Java Source: Effective Java, Jason Arnold
Advanced Programming Effective Java Source: Effective Java, Jason Arnold Advanced Programming. All slides copyright: Chetan Arora

2 Advanced Programming. All slides copyright: Chetan Arora
Coding Convention Function and Class Names Variable Names: Different convention for local, class and static variables Length of each function Object Oriented Advanced Programming. All slides copyright: Chetan Arora

3 Advanced Programming. All slides copyright: Chetan Arora
Static Factory public static Boolean valueOf(boolean b) { return (b ? Boolean.TRUE : Boolean.FALSE); } Unlike constructors they have names: Better Readability Can return null Can return a subclass: compact API. Control number of instances floating around, Singletons Caching Advanced Programming. All slides copyright: Chetan Arora

4 Advanced Programming. All slides copyright: Chetan Arora
Singletons Single Instance Private Constructor Static Factory Advanced Programming. All slides copyright: Chetan Arora

5 Util Class Private Constructor

6 public class Person { private final Date birthDate; public Person(Date birthDate) { this.birthDate = birthDate; } public boolean isBabyBoomer() { Calendar gmtCal = Calendar.getInstance(TimeZone.getTimeZone("GMT")); gmtCal.set(1946, Calendar.JANUARY, 1, 0, 0, 0); Date boomStart = gmtCal.getTime(); gmtCal.set(1965, Calendar.JANUARY, 1, 0, 0, 0); Date boomEnd = gmtCal.getTime(); return birthDate.compareTo(boomStart) >= 0 && birthDate.compareTo(boomEnd) < 0;

7 Advanced Programming. All slides copyright: Chetan Arora
Static Blocks class Person { private final Date birthDate; public Person(Date birthDate) { this.birthDate = birthDate; } //The starting and ending dates of the baby boom. private static final Date BOOM_START; private static final Date BOOM_END; static { Calendar gmtCal = Calendar.getInstance(TimeZone.getTimeZone("GMT")); gmtCal.set(1946, Calendar.JANUARY, 1, 0, 0, 0); BOOM_START = gmtCal.getTime(); gmtCal.set(1965, Calendar.JANUARY, 1, 0, 0, 0); BOOM_END = gmtCal.getTime(); public boolean isBabyBoomer() { return birthDate.compareTo(BOOM_START) >= 0 && birthDate.compareTo(BOOM_END) < 0; Advanced Programming. All slides copyright: Chetan Arora


Download ppt "Effective Java Source: Effective Java, Jason Arnold"

Similar presentations


Ads by Google