Reviewing for the Midterm Covers chapters 1 to 5, 7 to 9 Instructor: Scott Kristjanson CMPT 125/125 SFU Burnaby, Fall 2013.

Slides:



Advertisements
Similar presentations
Chapter 41 Variables and JSP Control Structures JavaServer Pages By Xue Bai.
Advertisements

Chapter 7 User-Defined Methods. Chapter Objectives  Understand how methods are used in Java programming  Learn about standard (predefined) methods and.
Chapter 10 Introduction to Arrays
Data Types in Java Data is the information that a program has to work with. Data is of different types. The type of a piece of data tells Java what can.
Inheritance Inheritance Reserved word protected Reserved word super
George Blank University Lecturer. CS 602 Java and the Web Object Oriented Software Development Using Java Chapter 4.
Road Map Introduction to object oriented programming. Classes
1 Chapter 4 Language Fundamentals. 2 Identifiers Program parts such as packages, classes, and class members have names, which are formally known as identifiers.
Aalborg Media Lab 21-Jun-15 Software Design Lecture 2 “ Data and Expressions”
Aalborg Media Lab 23-Jun-15 Inheritance Lecture 10 Chapter 8.
Terms and Rules Professor Evan Korth New York University (All rights reserved)
Chapter 4: Writing Classes Presentation slides for Java Software Solutions Foundations of Program Design Third Edition by John Lewis and William Loftus.
CS102--Object Oriented Programming Review 1: Chapter 1 – Chapter 7 Copyright © 2008 Xiaoyan Li.
Introduction to Java Appendix A. Appendix A: Introduction to Java2 Chapter Objectives To understand the essentials of object-oriented programming in Java.
METHODS Introduction to Systems Programming - COMP 1005, 1405 Instructor : Behnam Hajian
Instructor: Alexander Stoytchev CprE 185: Intro to Problem Solving (using C)
Writing Classes (Chapter 4)
Introduction to Object Oriented Programming. Object Oriented Programming Technique used to develop programs revolving around the real world entities In.
Review Chapters 1 to 4 Instructor: Scott Kristjanson CMPT 125/125 SFU Burnaby, Fall 2013.
Chapter 2: Basic Elements of Java J ava P rogramming: From Problem Analysis to Program Design, From Problem Analysis to Program Design, Second Edition.
JAVA Tokens. Introduction A token is an individual element in a program. More than one token can appear in a single line separated by white spaces.
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.
Hello.java Program Output 1 public class Hello { 2 public static void main( String [] args ) 3 { 4 System.out.println( “Hello!" ); 5 } // end method main.
Object Based Programming Chapter 8. 2 In This Chapter We will learn about classes Garbage Collection Data Abstraction and encapsulation.
Java Programming: From Problem Analysis to Program Design, 4e Chapter 2 Basic Elements of Java.
Java Programming: From Problem Analysis to Program Design, 5e Chapter 2 Basic Elements of Java.
1 Chapter 3 Syntax, Errors, and Debugging Fundamentals of Java: AP Computer Science Essentials, 4th Edition Lambert / Osborne.
Chapter 6 Introduction to Defining Classes. Objectives: Design and implement a simple class from user requirements. Organize a program in terms of a view.
Chapter 3 Syntax, Errors, and Debugging Fundamentals of Java.
CSCI 1100/1202 April 1-3, Program Development The creation of software involves four basic activities: –establishing the requirements –creating.
Using Classes and Objects Chapters 3 Creating Objects – Section 3.1 The String Class – Section 3.2 The Scanner Class – Section 2.6 Instructor: Scott Kristjanson.
CIS 270—Application Development II Chapter 8—Classes and Objects: A Deeper Look.
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.
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.
Operators and Expressions. 2 String Concatenation  The plus operator (+) is also used for arithmetic addition  The function that the + operator performs.
CSC 1051 – Algorithms and Data Structures I Dr. Mary-Angela Papalaskari Department of Computing Sciences Villanova University Course website:
 In the java programming language, a keyword is one of 50 reserved words which have a predefined meaning in the language; because of this,
Java Software Solutions Lewis and Loftus Chapter 6 1 Copyright 1997 by John Lewis and William Loftus. All rights reserved. Objects for Organizing Data.
Inheritance and Class Hierarchies Chapter 3. Chapter 3: Inheritance and Class Hierarchies2 Chapter Objectives To understand inheritance and how it facilitates.
Classes, Interfaces and Packages
Chapter 11: Inheritance and Composition. Introduction Two common ways to relate two classes in a meaningful way are: – Inheritance (“is-a” relationship)
Recursion Chapter 17 Instructor: Scott Kristjanson CMPT 125/125 SFU Burnaby, Fall 2013.
© 2006 Pearson Addison-Wesley. All rights reserved 1-1 Chapter 1 Review of Java Fundamentals.
Terms and Rules II Professor Evan Korth New York University (All rights reserved)
Instructor: Alexander Stoytchev CprE 185: Intro to Problem Solving (using C)
Java Programming: From Problem Analysis to Program Design, Second Edition 1 Lecture 1 Objectives  Become familiar with the basic components of a Java.
Chapter 2: Data and Expressions. Variable Declaration In Java when you declare a variable, you must also declare the type of information it will hold.
C# Fundamentals An Introduction. Before we begin How to get started writing C# – Quick tour of the dev. Environment – The current C# version is 5.0 –
CSE 501N Fall ‘09 03: Class Members 03 September 2009 Nick Leidenfrost.
Instructor: Scott Kristjanson CMPT 125/125 SFU Burnaby, Fall 2013
UMass Lowell Computer Science Java and Distributed Computing Prof. Karen Daniels Fall, 2000 Lecture 10 Java Fundamentals Objects/ClassesMethods.
UML Diagrams and Software Testing Instructor: Scott Kristjanson CMPT 135 SFU Surrey, Spring 2016.
Lecture 3: More Java Basics Michael Hsu CSULA. Recall From Lecture Two  Write a basic program in Java  The process of writing, compiling, and running.
© 2006 Pearson Education Chapter 2: Objects and Primitive Data Presentation slides for Java Software Solutions for AP* Computer Science A 2nd Edition by.
Object Based Programming Chapter 8. 2 Contrast ____________________ Languages –Action oriented –Concentrate on writing ________________ –Data supports.
© 2004 Pearson Addison-Wesley. All rights reserved August 27, 2007 Primitive Data Types ComS 207: Programming I (in Java) Iowa State University, FALL 2007.
About the Presentations
Chapter 4: Writing Classes
Java Programming: From Problem Analysis to Program Design, 4e
Primitive Types Vs. Reference Types, Strings, Enumerations
CS139 – Fall 2010 How far we have come
Object Based Programming
Starting JavaProgramming
Chapter 2: Basic Elements of Java
Group Status Project Status.
Midterm Review October 23, 2006 ComS 207: Programming I (in Java)
Review for Midterm 3.
Presentation transcript:

Reviewing for the Midterm Covers chapters 1 to 5, 7 to 9 Instructor: Scott Kristjanson CMPT 125/125 SFU Burnaby, Fall 2013

Slides based on Java Foundations 3rd Edition, Lewis/DePasquale/Chase 2 Scott Kristjanson – CMPT 125/126 – SFU Wk07.5 Slide 2 Things to Review Review the Class Slides: Key Things to Take Away – Do you understand these the points? Review Slides, especially if some Key Points are unclear Make use of the Textbook Answer Self-Review Questions at back of each chapter Select Exercises and Programming Projects to practice Review Quiz and Assignments Do you understand how to answer Assignment 3 Written Questions? Review Quiz #1 and Assignment #2 questions, then see the solutions Get some Coding Practice! Sign up on CodingBat.com and work through the problems there

Slides based on Java Foundations 3rd Edition, Lewis/DePasquale/Chase 3 Scott Kristjanson – CMPT 125/126 – SFU Wk07.5 Slide 3 Review the Class Slides Week 01 wk01.3 – Background Info, Introduction Week 02 wk02.1 – Introduction to Java wk02.3 – Intro to Objects and String and Scanner Objects wk02.5 – Packages Enums and Wrappers Week 03 wk03.1 – Boolean Expressions, Conditionals, Definite Loops Week 04 wk04.1 – Structured Analysis and Data Flow Diagrams wk04.3 – Review Week 05 wk05.1 – Writing Classes wk05.5 – Quiz 1 Solutions Week 06 wk06.1 – Testing wk06.3 – Arrays wk06.5 – Inheritance Week 07 wk07.3 – Polymorphism

Wk02.1 Slides: Introduction to Java Chapters 1 and 2 The Java Language – Section 1.1 Data & Expressions – Sections 2.1 – 2.5 Instructor: Scott Kristjanson CMPT 125/125 SFU Burnaby, Fall 2013

Slides based on Java Foundations 3rd Edition, Lewis/DePasquale/Chase 5 Scott Kristjanson – CMPT 125/126 – SFU Wk07.5 Slide 5 Ch 1&2 - Key Things to take away: The print and println methods are two services provided by the System.out object In Java, the + operator is used both for addition and for string concatenation An escape character can be used to represent a character that would otherwise cause a compile error A variable is a name for a memory location used to hold a value of a particular data type Accessing data leaves them intact in memory, but an assignment statement overwrites old data One cannot assign a value of one type to a variable of an incompatible type Constants hold a particular value for the duration of their existence Java has two types of numeric values: integer and floating point. There are four integer data types and two floating point data types Java using 16-bit Unicode character set to represent character data Expressions are combinations of operators and operands used to perform a calculation The type of result produced by arithmetic division depends on the types of the operands Java follows a well-defined set of precedence rules that governs the order in which operators will be evaluated in an expression Narrowing conversions should be avoided because they can lose information

Wk02.3 Slides: Using Classes and Objects Chapters 3 Creating Objects – Section 3.1 The String Class – Section 3.2 The Scanner Class – Section 2.6 Instructor: Scott Kristjanson CMPT 125/125 SFU Burnaby, Fall 2013

Slides based on Java Foundations 3rd Edition, Lewis/DePasquale/Chase 7 Scott Kristjanson – CMPT 125/126 – SFU Wk07.5 Slide 7 Key Things to take away: Object declarations create place holders which point to an object in memory The new operator instantiates a new instance of the class Strings are immutable – changing a string creates a new instance A variable holds either a primitive type or a reference to an object Assigning variables of primitive types copies the value Assigning variables of class types copies a reference to the object The String class provides useful methods for working with strings length concat substring toUpperCase Etc The System.in object represents the standard input stream The Scanner Class provides methods for reading input values

Wk02.5 Slides: Using Classes and Objects Chapters 3 Section 3.3 Packages Section 3.4 Random Class Section 3.5 Math Class Section 3.7 Enumerated Types Instructor: Scott Kristjanson CMPT 125/125 SFU Burnaby, Fall 2013

Slides based on Java Foundations 3rd Edition, Lewis/DePasquale/Chase 9 Scott Kristjanson – CMPT 125/126 – SFU Wk07.5 Slide 9 Key Things to take away: The Java API contains standard set of class definitions Class definitions can be reused by importing packages Packages exist for creating random numbers, math, and formatting You can create your own set of libraries as a package Java provides wrapper classes for primitive data types so they can be used just like any other object

Wk03.1 Slides Conditionals and Loops Chapter 4 Instructor: Scott Kristjanson CMPT 125/125 SFU Burnaby, Fall 2013

Slides based on Java Foundations 3rd Edition, Lewis/DePasquale/Chase 11 Scott Kristjanson – CMPT 125/126 – SFU Wk07.5 Slide 11 Key Things to take away: Flow of Control determines which statements get executed Expressions can form complex conditions using logical operators AND and OR evaluation are short-circuited in Java Selection statements chose different execution paths based on conditions If then ; If then else ; Switch {Case 1, Case 2, … Case N} Java supports two styles of Indefinite Loops: While ; Do while ; Java suports two styles of definite Loops: for ( initialization ; condition ; increment ) ; For-each using Iterators

Wk Wk05.5 Slides: Writing Classes Chapter 5 Instructor: Scott Kristjanson CMPT 125/125 SFU Burnaby, Fall 2013

Slides based on Java Foundations 3rd Edition, Lewis/DePasquale/Chase 13 Scott Kristjanson – CMPT 125/126 – SFU Wk07.5 Slide 13 Key Things to take away: Class and Method Design Data Flow Diagrams help get a design started Problem Specification: Nouns become Classes, Verbs become Methods Decompose methods that get too complex Class and Method Coding Methods and Variables have Scope – where they can be seen Public Scope allows access by users of the Class Private Scope used to encapsulate data and internal helper methods Invoking a method copies the actual parameters into the formal parameters Object Parameters contain references to the actual object and can be modified Testing Methodical Testing is important step, every program has bugs Testing can be black box (functional) or white box (implementation) Four types of tests: Unit, Integration, System, Regression Println’s and the Eclipse Debugger are essential tools for debugging

Wk04.3 Slides: Review Chapters 1 to 4 Instructor: Scott Kristjanson CMPT 125/125 SFU Burnaby, Fall 2013

Slides based on Java Foundations 3rd Edition, Lewis/DePasquale/Chase 15 Scott Kristjanson – CMPT 125/126 – SFU Wk07.5 Slide 15 Key Things to take away: Flow of Control determines which statements get executed Expressions can form complex conditions using logical operators AND and OR evaluation are short-circuited in Java Selection statements chose different execution paths based on conditions If then ; If then else ; Switch {Case 1, Case 2, … Case N} Java supports two styles of Indefinite Loops: While ; Do while ; Java suports two styles of definite Loops: for ( initialization ; condition ; increment ) ; For-each using Iterators

Wk05.5 Slides: Quiz #1 Solutions Instructor: Scott Kristjanson CMPT 125/125 SFU Burnaby, Fall 2013

Slides based on Java Foundations 3rd Edition, Lewis/DePasquale/Chase 17 Scott Kristjanson – CMPT 125/126 – SFU Wk07.5 Slide 17 Question 3 Work out the logic one step at a time: True when A is false => !A Either B or C are true => B || C AND => both the above must be true => !A && B || C But remember to check precedence! => !A && B || C is evaluated as =>( !A && B)|| C That’s not right! Need to add parenthesis => !A && (B || C) !A && (B || C) ABC!AB||C!A && (B || C) FFFTFF FFTTTT FTFTTT FTTTTT TFFFFF TFTFTF TTFFTF TTTFTF Validate using a Truth Table:

Slides based on Java Foundations 3rd Edition, Lewis/DePasquale/Chase 18 Scott Kristjanson – CMPT 125/126 – SFU Wk07.5 Slide 18 Question 4 For full marks, Do not go through the loop 9 times, execute the loop 5 times Realize that you can increment counter by 2 within the loop, not by 1 twice Declare the loop variable within the for loop If you do not remember HOW to write a Java for loop… Use Appendix J – it was attached at the back! for (int i=1; i <= 9; i += 2) { System.out.println(i); }

Slides based on Java Foundations 3rd Edition, Lewis/DePasquale/Chase 19 Scott Kristjanson – CMPT 125/126 – SFU Wk07.5 Slide 19 Question 5 x x x √ Follow the flow of control: (Sum > MAX) is true since (100 > 10) So must call Print1, not Print2 No {} around else, Print3 not part of the if So Print3 must get printed as well Print3 is not doing addition, so not 110 Print3 doing String Concatenation So will print “100”+”10” => “10010” x x

Wk06.3 Slides: Arrays Chapter 7 Instructor: Scott Kristjanson CMPT 125/125 SFU Burnaby, Fall 2013

Slides based on Java Foundations 3rd Edition, Lewis/DePasquale/Chase 21 Scott Kristjanson – CMPT 125/126 – SFU Wk07.5 Slide 21 Key Things to take away: Arrays are an ordered collection on Array Elements Array Elements may be Primitive Data Types, or Objects Arrays are objects Arrays cannot be extended once created Command Line Parameters are passed as an Array of Strings Variable Length Parameter lists passed as an Array of Objects Array Elements may be other Arrays Arrays may be one, two, or multidimensional

Wk06.5 Slides: Inheritance Chapter 8 Instructor: Scott Kristjanson CMPT 125/125 SFU Burnaby, Fall 2013

Slides based on Java Foundations 3rd Edition, Lewis/DePasquale/Chase 23 Scott Kristjanson – CMPT 125/126 – SFU Wk07.5 Slide 23 Key Things to take away: Inheritance Inheritance is the process of deriving a new class from an existing class Inheritance allows software reuse of existing software Inheritance creates an IS-A relationship between parent and child classes Protected visibility provides encapsulation and allows inheritance A parents constructor can and should by invoked by the child via super A child class can override a parents methods by redefining them A child of one class can be the parent of another All Java classes are derived from the Object class An Abstract class cannot be instantiated, it represents a concept Abstract classes must be declared in the child before it can be instantiated Private members of a class and not be seen directly in the child class The final modifier can be used to restrict inheritance

Wk07.3 Slides: Polymorphism Chapter 9 Instructor: Scott Kristjanson CMPT 125/125 SFU Burnaby, Fall 2013

Slides based on Java Foundations 3rd Edition, Lewis/DePasquale/Chase 25 Scott Kristjanson – CMPT 125/126 – SFU Wk07.5 Slide 25 Key Things to take away: Polymorphism The term polymorphism literally means “having many forms” A polymorphic reference is a variable that can refer to different types of objects at different points in time The method invoked through a polymorphic reference can change from one invocation to the next It is the type of the object being referenced, not the reference type, that determines which method is invoked Interfaces allow true encapsulation and hide implementation details Interfaces are critical for supporting GUIs and other functions cleanly

Slides based on Java Foundations 3rd Edition, Lewis/DePasquale/Chase 26 Scott Kristjanson – CMPT 125/126 – SFU Wk07.5 Slide 26 Review the Quiz Solutions and Assignments Try to do the Quiz again It should be now be much easier now. See how long it takes you. Review the solutions and compare to your answers. Look at the kind of problems – midterm will be similar Assignments 2 and 3: Review the questions – midterm will be similar There will be programming questions

Slides based on Java Foundations 3rd Edition, Lewis/DePasquale/Chase 27 Scott Kristjanson – CMPT 125/126 – SFU Wk07.5 Slide 27 Review Assignment 2 Solutions Part A – Written Question Solutions a2WriteUp Operator Precedence Generating Random Numbers Definite Loops Indefinite Loops Part B – Programming Solutions RandomAvg.java AvgNums.java Distance.java MoneyChanger.java MoneyCounter.java

Slides based on Java Foundations 3rd Edition, Lewis/DePasquale/Chase 28 Scott Kristjanson – CMPT 125/126 – SFU Wk07.5 Slide 28 Review Assignment 3 Questions Review the Parts A and B Written Questions Work on the Written Questions (Part A is due Monday in Lab). Review Part C Programming Problems Try to solve questions 1 to 4 before the Midterm Exam if you can

Slides based on Java Foundations 3rd Edition, Lewis/DePasquale/Chase 29 Scott Kristjanson – CMPT 125/126 – SFU Wk07.5 Slide 29 Practice your Programming Skills Sign up to CodingBat.com and work through the examples.CodingBat.com It will give you immediate feedback and track your progress. Be sure that you know how to: write boolean expressions and if-then-else conditions know how to concatenate, compare, and manipulate Strings write for, while, and do loops index into arrays, pass arrays as parameters, 1 and 2 dimensions

Slides based on Java Foundations 3rd Edition, Lewis/DePasquale/Chase 30 Scott Kristjanson – CMPT 125/126 – SFU Wk07.5 Slide 30 Key things you should know for the midterm: You should be able to: Understand flow of control and the importance of braces Describe the various phases of software testing Write boolean expressions using correct operator precedence Write programs using if-then-else, for, while, do, switch know how to concatenate, compare, and manipulate Strings Understand how Primitive Data and Objects parameters work Work with Arrays and indexing of Arrays, arrays of objects Explain elements of good design including coupling and cohesion Be able to create a data flow diagram based on a problem description Understand the principles of inheritance and polymorphism Understand how dynamic-binding of methods enables polymorphism Describe what an Abstract class is Describe what an Interface is used for Understand the function of modifiers public, private, static, and final Be able to use the super and this keywords within methods