Effective Java Source: Effective Java, Jason Arnold

Slides:



Advertisements
Similar presentations
8 Copyright © 2005, Oracle. All rights reserved. Object Life Cycle and Inner Classes.
Advertisements

Chapter 5: The Singleton Pattern
Object Oriented Programming with Java
Singleton vs utility class  at first glance, the singleton pattern does not seem to offer any advantages to using a utility class  i.e., a utility class.
Variable types We have already encountered the idea of a variable type. It is also possible to think about variables in terms of their kind, namely: 1)
Jan Ron McFadyen1 Singleton To guarantee that there is at most one instance of a class we can apply the singleton pattern. Singleton Static.
Oct Ron McFadyen1 Singleton To guarantee that there is at most one instance of a class we can apply the singleton pattern. Singleton Static.
Inheritance The objectives of this chapter are: To explore the concept and implications of inheritance Polymorphism To define the syntax of inheritance.
Copyright by Scott GrissomCh 5 Sophisticated Behavior Slide 1 Java Class Library a very large collection of classes for you to use as needed the challenge.
Spring 2010ACS-3913 Ron McFadyen1 Singleton To guarantee that there is at most one instance of a class we can apply the singleton pattern. Singleton Static.
Lecture 5: Objects and Classes, cont’d Continue with the Player example Introduce GOAL as a final static variable that applies to all objects of the class.
CS102--Object Oriented Programming Review 1: Chapter 1 – Chapter 7 Copyright © 2008 Xiaoyan Li.
Winter 2007ACS-3913 Ron McFadyen1 Singleton To guarantee that there is at most one instance of a class we can apply the singleton pattern. Singleton Static.
Programming in Java; Instructor:Moorthy Introduction, Objects, Classes, Libraries1 Programming in Java Introduction.
Java Programming, Second Edition Chapter Four Advanced Object Concepts.
1 Identifiers  Identifiers are the words a programmer uses in a program  An identifier can be made up of letters, digits, the underscore character (
Advanced Programming Rabie A. Ramadan vPro/ Lecture 1.
BPJ444: Business Programming Using Java Classes and Objects Tim McKenna
ECE 452 / CS 446 / SE464 Design Patterns: Part 2 - Answers A Tutorial By Peter Kim Partially based on the tutorial by Michał Antkiewicz.
By Nicholas Policelli An Introduction to Java. Basic Program Structure public class ClassName { public static void main(String[] args) { program statements.
Effective Java: Creating and Destroying Objects Last Updated: Fall 2012.
Java Objects and Classes. Overview n Creating objects that belong to the classes in the standard Java library n Creating your own classes.
Comp 248 Introduction to Programming Chapter 4 & 5 Defining Classes Part C Dr. Aiman Hanna Department of Computer Science & Software Engineering Concordia.
Singleton and Basic UML CS340100, NTHU Yoshi. What is UML Unified Modeling Language A standardized general-purpose modeling language in the field of software.
The Singleton Pattern SE-2811 Dr. Mark L. Hornick 1.
02/14/2005 Introduction to Programming with Java, for Beginners Midterm 1 Review.
CMSC 341 Java Packages, Classes, Variables, Expressions, Flow Control, and Exceptions.
Lecture 71 CS110 Lecture 8 February 19, 2004 Announcements –hw3 due tonight –hw4 available, due Thursday February 26 –exam Tuesday March 2 Agenda –questions.
Threads and Singleton. Threads  The JVM allows multiple “threads of execution”  Essentially separate programs running concurrently in one memory space.
Spring 2009 Programming Fundamentals I Java Programming XuanTung Hoang Lecture No. 8.
Chapter 5 Defining Classes II Copyright © 2010 Pearson Addison-Wesley. All rights reserved.
Java Coding 5 – Part 2 David Davenport Computer Eng. Dept., Bilkent University Ankara - Turkey. To object or not…
Object Oriented Programming I ( ) Dr. Adel hamdan Part 03 (Week 4) Dr. Adel Hamdan Date Created: 7/10/2011.
Csci 490 / Engr 596 Special Topics / Special Projects Software Design and Scala Programming Spring Semester 2010 Lecture Notes.
AP Refresher Module Introduction to Java Advanced Programming. All slides copyright: Chetan Arora.
Advanced Programming Practice Questions Advanced Programming. All slides copyright: Chetan Arora.
JAVA ACCESS MODIFIERS. Access Modifiers Access modifiers control which classes may use a feature. A classes features are: - The class itself - Its member.
Programming in Java Transitioning from Alice. Becomes not myFirstMethod but …. public static void main (String[] arg) { // code for testing classes goes.
1 Design Patterns prepared for COMP314, Bernhard Pfahringer see links on the web page as well!
Geoff Holmes and Bernhard Pfahringer COMP206-08S General Programming 2.
Advanced Programming in Java
Advanced Programming in Java
OOP: Encapsulation &Abstraction
Objects as a programming concept
The Singleton Pattern SE-2811 Dr. Mark L. Hornick.
Effective Java: Creating and Destroying Objects
Abstract Factory Pattern
Refactoring Methods: Kevin Murphy.
CMSC 202 Static Methods.
CS240: Advanced Programming Concepts
Factory Methods Factory Method is a method that creates objects.
null, true, and false are also reserved.
עקרונות תכנות מונחה עצמים תרגול 9 – Design Patterns
Classes and Objects 5th Lecture
Java Classes and Objects 3rd Lecture
What is Singleton Category: Creational pattern
Singleton Pattern Pattern Name: Singleton Pattern Context
Singleton design pattern
Advanced Programming in Java
Advanced Programming in Java
CS 350 – Software Design Singleton – Chapter 21
Which best describes the relationship between classes and objects?
Effective Java: 3rd Edition Creating and Destroying Objects
Classes and Objects Static Methods
Object Oriented Programming
Effective Java: Creating and Destroying Objects
Chapter 4 Constructors Section 4.4
Object Oriented Programming with Java
CS 240 – Advanced Programming Concepts
Chapter 5 Classes.
Presentation transcript:

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

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

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

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

Util Class Private Constructor

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;

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