1 Review for Midterm 2 Aaron Bloomfield CS 101-E.

Slides:



Advertisements
Similar presentations
Classes & Objects INTRODUCTION : This chapter introduces classes ; explains data hiding, abstraction & encapsulation and shows how a class implements these.
Advertisements

Based on Java Software Development, 5th Ed. By Lewis &Loftus
Lecture 9: More on objects, classes, strings discuss hw3 assign hw4 default values for variables scope of variables and shadowing null reference and NullPointerException.
 2005 Pearson Education, Inc. All rights reserved Introduction to Classes and Objects.
1 Chapter Five Selection and Repetition. 2 Objectives How to make decisions using the if statement How to make decisions using the if-else statement How.
IMPLEMENTING CLASSES Chapter 3. Black Box  Something that magically does its thing!  You know what it does but not how.  You really don’t care how.
Chapter 5 Selection Statements. Topics Controlling program flow selection –if –switch Boolean expressions –boolean primitive type –comparison operators.
Road Map Introduction to object oriented programming. Classes
Selection Statements choice of one among several blocks of code Java supports 3 kinds of selection statements: if statement – selects one block or leaves.
COMP 14 Introduction to Programming Miguel A. Otaduy May 18, 2004.
Introduction to Computers and Programming Lecture 5 Boolean type; if statement Professor: Evan Korth New York University.
Evan Korth New York University Computer Science I Classes and Objects Professor: Evan Korth New York University.
Aalborg Media Lab 23-Jun-15 Software Design Lecture 6 “Conditionals and Loops”
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Java Software Solutions Foundations of Program Design Sixth Edition by Lewis.
CS 117 Spring 2002 Review for Exam 2 March 6, 2002 open book, 1 page of notes.
Terms and Rules Professor Evan Korth New York University (All rights reserved)
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter Chapter 5 Selection Statements Primitive Type boolean.
Tutorial 4 Decision Making with Control Structures and Statements Section A - Decision Making JavaScript Tutorial 4 -Decision Making with Control.
C++ for Engineers and Scientists Third Edition
The switch Statement, DecimalFormat, and Introduction to Looping
Comp 248 Introduction to Programming Chapter 4 - Defining Classes Part A Dr. Aiman Hanna Department of Computer Science & Software Engineering Concordia.
JavaServer Pages Syntax Harry Richard Erwin, PhD CSE301/CIT304.
Programming in Java Unit 2. Class and variable declaration A class is best thought of as a template from which objects are created. You can create many.
ASP.NET Programming with C# and SQL Server First Edition Chapter 3 Using Functions, Methods, and Control Structures.
CS 101E – Exam 2 Review Spring 2007 Michele Co. Announcements Review Session Tonight, 7/7:30 p.m., OLS 009 Will be announced via In-class Exam Wednesday.
Monday, Jan 13, 2003Kate Gregory with material from Deitel and Deitel Week 2 Questions from Last Week Control Structures Functions Lab 1.
1 Relational Expressions Relational expressions: –Expressions that compare operands –Sometimes called conditions –Evaluated to yield a result –Typically.
Flow of Control Part 1: Selection
CPS120: Introduction to Computer Science Decision Making in Programs.
Page: 1 การโปรแกรมเชิงวัตถุด้วยภาษา JAVA บุรินทร์ รุจจนพันธุ์.. ปรับปรุง 15 มิถุนายน 2552 Keyword & Data Type มหาวิทยาลัยเนชั่น.
ECE122 Feb. 22, Any question on Vehicle sample code?
1 Even even more on being classy Aaron Bloomfield CS 101-E Chapter 4+
Java™ How to Program, 10/e © Copyright by Pearson Education, Inc. All Rights Reserved.
An Object-Oriented Approach to Programming Logic and Design Chapter 3 Using Methods and Parameters.
Conditional Statement Chapter 8. Conditional Statements Are statements that check an expression then may or may not execute a statement or group of statement.
3. Controlling Program Flow Methods, parameters, and return values Boolean expressions Conditional branching Loops.
Classes. Constructor A constructor is a special method whose purpose is to construct and initialize objects. Constructor name must be the same as the.
CSC 212 Object-Oriented Programming and Java Part 2.
Flow of Control Unless indicated otherwise, the order of statement execution through a method is linear: one after the other in the order they are written.
Flow of Control Chapter 3. Outline Branching Statements Java Loop Statements Programming with Loops The Type boolean.
Sections © Copyright by Pearson Education, Inc. All Rights Reserved.
Chapter 3 Introduction to Classes and Objects Definitions Examples.
Java™ How to Program, 9/e © Copyright by Pearson Education, Inc. All Rights Reserved.
Chapter 10: Classes and Data Abstraction. Objectives In this chapter, you will: Learn about classes Learn about private, protected, and public members.
Chapter 5: Making Decisions. Objectives Plan decision-making logic Make decisions with the if and if…else structures Use multiple statements in if and.
CS1101 Group1 Discussion 10 Lek Hsiang Hui comp.nus.edu.sg
 In the java programming language, a keyword is one of 50 reserved words which have a predefined meaning in the language; because of this,
1 Programming in C++ Dale/Weems/Headington Chapter 9 Additional Control Structures (Switch, Do..While, For statements)
Quick Review of OOP Constructs Classes:  Data types for structured data and behavior  fields and methods Objects:  Variables whose data type is a class.
Chapter 7 Conditional Statements. 7.1 Conditional Expressions Conditions - compare the values of variables, constants and literals using one or more relational.
Chapter 10: Classes and Data Abstraction. Classes Object-oriented design (OOD): a problem solving methodology Objects: components of a solution Class:
Object Oriented Programming and Data Abstraction Rowan University Earl Huff.
Java Programming, Second Edition Chapter Three Using Methods, Classes, and Objects.
Review for exam 1 CS 101 Aaron Bloomfield. 2 Today’s lecture An overview of the “review” sections of chapters 1- 3 and 5 Stop me if you want me to go.
CSE 501N Fall ‘09 03: Class Members 03 September 2009 Nick Leidenfrost.
Classes CS 162 (Summer 2009). Parts of a Class Instance Fields Methods.
Information and Computer Sciences University of Hawaii, Manoa
3 Introduction to Classes and Objects.
Java Primer 1: Types, Classes and Operators
Chapter 3: Using Methods, Classes, and Objects
Road Map Introduction to object oriented programming. Classes
Expressions and Control Flow in JavaScript
Methods The real power of an object-oriented programming language takes place when you start to manipulate objects. A method defines an action that allows.
Chapter 3 Introduction to Classes, Objects Methods and Strings
Review for Exam 1 Spring 2007 CS 101/CS 101-E.
Defining Classes and Methods
NAME 436.
Review for Midterm 3.
Lesson 3. Controlling program flow. Loops. Methods. Arrays.
Presentation transcript:

1 Review for Midterm 2 Aaron Bloomfield CS 101-E

2 Test focus Test will focus on the material covered since the last midterm Chapters 4 and 5 Chapters 4 and 5 The test is cumulative, though, and can include any material covered so far

3 Chapter 4

4 Construction Constructors should initialize all the data fields to some sane value A constructor has the same name as the class A default constructor takes in no parameters If a default constructor is not specified, then Java supplies one for you that does nothing All instance variables are initialized to default values (0, false, or null) before the constructor starts To create an object, you declare the object reference then call the constructor to create the object

5 Member variables Each object has its own copy of an instance variable Instance variables are normally private Private variables and methods can only be accessed by code within that class Instance variable = member variable: a data field in an object

6 Methods Flow of control passes from the invoking statement block to the invoked method, then returns (once the method completes) back to the statement block To define a method, state it's prototype (name, return type, parameters) and the body (the statement block) You use return to return a value A method that does not return a value has return type void Object behaviors are implemented using methods Instance methods are associated with an object, as opposed to class methods, which are associated with the class Methods can access the member variables

7 Parameters Java uses pass-by-value However, an object as a parameter has the reference passed in, so it's sort of like pass- by-reference for objects However, an object as a parameter has the reference passed in, so it's sort of like pass- by-reference for objects Actual parameter: the value passed into the method Formal parameter: the value within the method

8 Method types An accessor method allows access to an attribute (member variable) of an object (that is most likely private) A mutator method allows the changing of an attribute (member variable) of an object (that is most likely private) A facilitator method performs a task for the object

9 Misc A statement block is denoted by curly braces Activation record is the name for the copy of the parameters within a method Data abstraction: hide the internals of how a method operates. An variable that is an object is really a reference The programmer “interface” is made up of the public methods

10 JFrame and Graphics JFrame is the class that represents a GUI window JFrame has methods setVisible() and setSize() Drawing on a JFrame is done by accessing its Graphics object via the getGraphics() method Graphics has methods setColor(), fillRect(), drawRect(), etc. When drawing on a Graphics object, (0,0) is in the upper-left

11 Chapter 5

12 Logical expressions Logical expression has values either true or false Java has the boolean type with values true or false Truth table: method to dissect a logical expression

13 Logical operators Three primary logical operators: and, or, not An and operation is only true when both parts are true An or operation is true when either (or both) parts are true A not operation negates (switches) the value of the expression Logical operators: and is &&, or is ||, not is ! Not operator is unary

14 Equality Two equality operators: == and != When comparing objects, == compares the references, not the objects themselves Use the.equals() method, when available, to test for object equality Don't test floating point values for equality! Instead, test for “closeness”

15 Ordering Ordering operators:, =. These only work on primitive types! Relational operators are the equality operators and the ordering operators For booleans, false is less than true For characters, ordering is based on the Unicode numbers of the characters

16 If statements An if statement has the form: if (expression) action An if-else statement has the form: if (expression) action1 else action2 An if-else-if statement is used when there are many tasks to do, depending on the logical expressions

17 Switches A switch statement is useful instead of a long-winded if-else-if block Must always put either break at the end of a switch statement block, or a comment such as '// FALL THRU' The default case means any case not matched by any of the other cases

18 Misc Operator precedence: (p 187) Short-circuit evaluation: left side is evaluated first. If the result can be determined at that point, right side is not evaluated System.exit() will terminate the program immediately Use consistent indentation!