Final Review. From ArrayLists to Arrays The ArrayList : used to organize a list of objects –It is a class in the Java API –the ArrayList class uses an.

Slides:



Advertisements
Similar presentations
Fields, Constructors, Methods
Advertisements

Further abstraction techniques Abstract classes and interfaces 5.0.
CS 211 Inheritance AAA.
Designing classes How to write classes in a way that they are easily understandable, maintainable and reusable 4.0.
Chapter 3 Data Abstraction: The Walls. © 2005 Pearson Addison-Wesley. All rights reserved3-2 Abstract Data Types Modularity –Keeps the complexity of a.
OOP in Java Nelson Padua-Perez Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Java Software Solutions Foundations of Program Design Sixth Edition by Lewis.
Objects First with Java A Practical Introduction using BlueJ
© 2006 Pearson Addison-Wesley. All rights reserved4-1 Chapter 4 Data Abstraction: The Walls.
Aalborg Media Lab 23-Jun-15 Inheritance Lecture 10 Chapter 8.
Chapter 14 Generics and the ArrayList Class Copyright © 2010 Pearson Addison-Wesley. All rights reserved.
Make Sure You Know All This!. Objects First with Java - A Practical Introduction using BlueJ, © David J. Barnes, Michael Kölling 2 Objects and Classes.
© 2006 Pearson Addison-Wesley. All rights reserved4-1 Chapter 4 Data Abstraction: The Walls.
CO320 Introduction to Object- Oriented Programming Michael Kölling 3.0.
OOP in Java Fawzi Emad Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
5.0 Objects First with Java A Practical Introduction using BlueJ David J. Barnes Michael Kölling.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Java Software Solutions Foundations of Program Design Sixth Edition by Lewis.
Chapter 8 More Object Concepts
Introduction to Object Oriented Programming. Object Oriented Programming Technique used to develop programs revolving around the real world entities In.
5.0 Objects First with Java A Practical Introduction using BlueJ Introduction to Computer Science I Instructor: Allyson Anderson.
Object Oriented Design: Identifying Objects
Features of Object Oriented Programming Lec.4. ABSTRACTION AND ENCAPSULATION Computer programs can be very complex, perhaps the most complicated artifact.
An Introduction to Java Chapter 11 Object-Oriented Application Development: Part I.
APCS Java AB 2004 Review of CS1 and CS2 Review for AP test #1 Sources: 2003 Workshop notes from Chris Nevison (Colgate University) AP Study Guide to go.
Chapter 7 Object-Oriented Design Concepts
Chapter 14 Generics and the ArrayList Class Slides prepared by Rose Williams, Binghamton University Copyright © 2008 Pearson Addison-Wesley. All rights.
Object Based Programming Chapter 8. 2 In This Chapter We will learn about classes Garbage Collection Data Abstraction and encapsulation.
Designing classes How to write classes in a way that they are easily understandable, maintainable and reusable 5.0.
Chapter 12 Object Oriented Design.  Complements top-down design  Data-centered view of design  Reliable  Cost-effective.
Object Oriented Software Development
Chapter 12: Collections by Lewis and Loftus (Updated by Dan Fleck) Coming up: Collections.
Chapter 6 Introduction to Defining Classes. Objectives: Design and implement a simple class from user requirements. Organize a program in terms of a view.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Java Software Solutions Foundations of Program Design Sixth Edition by Lewis.
5.0 Objects First with Java A Practical Introduction using BlueJ David J. Barnes Michael Kölling.
Designing Classes. Software changes Software is not like a novel that is written once and then remains unchanged. Software is extended, corrected, maintained,
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Chapter 26 - Java Object-Based Programming Outline 26.1Introduction.
CS451 - Lecture 2 1 CS451 Lecture 2: Introduction to Object Orientation Yugi Lee STB #555 (816) * Acknowledgement:
Object-Oriented Programming. Objectives Distinguish between object-oriented and procedure-oriented design. Define the terms class and object. Distinguish.
Java™ How to Program, 9/e © Copyright by Pearson Education, Inc. All Rights Reserved.
UMass Lowell Computer Science Java and Distributed Computing Prof. Karen Daniels Fall, 2000 Lecture 9 Java Fundamentals Objects/ClassesMethods Mon.
Object-Oriented Programming © 2013 Goodrich, Tamassia, Goldwasser1Object-Oriented Programming.
Reviewing for the Midterm Covers chapters 1 to 5, 7 to 9 Instructor: Scott Kristjanson CMPT 125/125 SFU Burnaby, Fall 2013.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved Chapter 11 Object-Oriented.
Java Software Solutions Lewis and Loftus Chapter 9 1 Copyright 1997 by John Lewis and William Loftus. All rights reserved. Enhanced Class Design -- Introduction.
Refactoring Agile Development Project. Lecture roadmap Refactoring Some issues to address when coding.
Inheritance and Class Hierarchies Chapter 3. Chapter 3: Inheritance and Class Hierarchies2 Chapter Objectives To understand inheritance and how it facilitates.
Java Programming, Second Edition Chapter Twelve Advanced Inheritance Concepts.
CS 5JA Introduction to Java Pop Quiz Define/Explain encapsulation. In object-oriented programming, encapsulation refers to the grouping of data and the.
Classes, Interfaces and Packages
Objects First With Java A Practical Introduction Using BlueJ Designing classes How to write classes in a way that they are easily understandable, maintainable.
1 COS 260 DAY 12 Tony Gauvin. 2 Agenda Questions? 5 th Mini quiz –Chapter 5 40 min Assignment 3 Due Assignment 4 will be posted later (next week) –If.
Object orientation and Packaging in Java Object Orientation and Packaging Introduction: After completing this chapter, you will be able to identify.
1 COS 260 DAY 22 Tony Gauvin. 2 Agenda Questions? 9 th Mini Quiz corrected –Good results Assignment 5 Not corrected yet Assignment 6 Posted (one more)
Mid-Year Review. Coding Problems In general, solve the coding problems by doing it piece by piece. Makes it easier to think about Break parts of code.
CSC 243 – Java Programming, Spring, 2014 Week 4, Interfaces, Derived Classes, and Abstract Classes.
6.0 Objects First with Java A Practical Introduction using BlueJ David J. Barnes Michael Kölling.
Object Based Programming Chapter 8. 2 Contrast ____________________ Languages –Action oriented –Concentrate on writing ________________ –Data supports.
Review. Objects First with Java - A Practical Introduction using BlueJ, © David J. Barnes, Michael Kölling Objects and Classes Objects and Classes –State.
Data Abstraction: The Walls
Object-Oriented Design
Objects First with Java A Practical Introduction using BlueJ
Functional Processing of Collections (Advanced)
Objects First with Java A Practical Introduction using BlueJ
Object Based Programming
Slides by Steve Armstrong LeTourneau University Longview, TX
Objects First with Java A Practical Introduction using BlueJ
Fundaments of Game Design
COS 260 DAY 23 Tony Gauvin.
Objects First with Java A Practical Introduction using BlueJ
Further abstraction techniques
Presentation transcript:

Final Review

From ArrayLists to Arrays The ArrayList : used to organize a list of objects –It is a class in the Java API –the ArrayList class uses an array internally to manage the list of objects Array: used to organize a list of objects that uses special syntax to access elements –Once initialized, cannot change size (does not grow/shrink automatically) –Can store primitive values or objects Why use an array? –Time & space overhead Copyright © 2012 Pearson Education, Inc.

From ArrayLists to Arrays The ArrayList : –Methods: add, remove, get, size Array: –No methods. Constant length. –Direct access to the contents of each element. Both can use the for-each loop, or a for loop using an index over the elements in the collection Copyright © 2012 Pearson Education, Inc.

Testing and Debugging Testing -To check if the method, the class, the program behaves as expected, both for good and bad inputs. Testing techniques –Manual Walkthroughs (for loop example – mmm) –Unit Testing: testing individual parts of an application can be single methods, classes, or groups of classes –Application Testing: test the complete application as a whole –Regression Testing: test new version of application with passing test cases from previous version –Print statements (primitive)

Testing and Debugging II Debugging -process of isolating the cause of a bug/error/failure & designing a way to fix it Debugging steps –Craft a test case (input) that exposes the bug –Refine that input to be the minimal input required to cause the bug –If the fix is not obvious, manually walk thru the code, writing down each execution step & keeping track of the values of each variable –Once you fully understand the code, you should be able to spot the bug & suggest a fix –Make the fix & rerun the test cases; none should fail now

Recursion A recursive method is a method that invokes itself A recursive method must be structured to handle both the base case and the recursive case Each call to the method sets up a new execution environment, with new parameters and local variables As with any method call, when the method completes, control returns to the method that invoked it (which may be an earlier invocation of itself)

Object Oriented Design The creation of software involves four basic activities: – establishing the requirements – creating a design – implementing the code – testing the implementation These activities are not strictly linear – they overlap and interact Software requirements specify the tasks that a program must accomplish – what to do, not how to do it Objects First with Java - A Practical Introduction using BlueJ, © David J. Barnes, Michael Kölling

Object Oriented Design II A software design specifies how a program will accomplish its requirements A software design specifies how the solution can be broken down into manageable pieces and what each piece will do An object-oriented design determines which classes and objects are needed, and specifies how they will interact Low level design details include how individual methods will accomplish their tasks Objects First with Java - A Practical Introduction using BlueJ, © David J. Barnes, Michael Kölling

Identifying Classes and Objects The core activity of object-oriented design is determining the classes and objects that will make up the solution The classes may be part of a class library, reused from a previous project, or newly written One way to identify potential classes is to identify the objects discussed in the requirements Objects are generally nouns, and the services that an object provides are generally verbs Objects First with Java - A Practical Introduction using BlueJ, © David J. Barnes, Michael Kölling

How can we achieve good design? Cohesion: each code unit (method/class) should be responsible for 1 and only 1 well-defined task Why we want high cohesion: localize changes to one well-defined place Cohesive code is easier for others to understand, & modify Cohesive code is easier to reuse, thus reducing code duplication Responsibility-driven design (RDD): store data where it’s predominantly manipulated Coupling: the degree to which 2 classes are inter-dependent When the implementation of a class changes, other classes should not be affected (when the interface changes, they might be) Why we avoid tight-coupling: more work to modify code; can’t just change 1 class, have to change all the tightly-coupled classes Encapsulation: what a class/method does is visible to the outside (to other classes) by not how it does it

Inheritance Inheritance allows a software developer to derive a new class from an existing one The existing class is called the parent class, or superclass, or base class The derived class is called the child class or subclass As the name implies, the child inherits characteristics of the parent That is, the child class inherits the methods and data defined by the parent class

Abstract classes Static type checking sometimes requires a particular method in the superclass But there is no obvious shared implementation for the method according to the subclasses. Define the method as abstract

Abstract classes and methods Abstract methods have abstract in the signature. Abstract methods have no body. Abstract methods make the class abstract. Abstract classes cannot be instantiated. Concrete subclasses complete the implementation. Copyright © 2012 Pearson Education, Inc.

Interfaces All methods are abstract. There are no constructors. All methods are public. All fields are public, static and final. Strong separation of functionality from implementation. – Though parameter and return types are mandated. Clients interact independently of the implementation. Copyright © 2012 Pearson Education, Inc.

Collections Collections can be implemented in many different ways Collections should be abstractions That is, they should hide unneeded details We want to separate the interface of the structure from its underlying implementation This helps manage complexity and makes it possible to change the implementation without changing the interface Copyright © 2012 Pearson Education, Inc.

Links Recall that an object reference is a variable that stores the address of an object A reference also can be called a pointer Object references can be used to create links between objects This allows to create collections using linked or double linked lists structures

Exceptions We saw that a moment ago