Exam Review 10/01/2014 Happy October. The Exam  Will be in Canvas  Two parts  Part A is recall – closed book, closed notes ◦Quizzes, in class activity.

Slides:



Advertisements
Similar presentations
STRING AN EXAMPLE OF REFERENCE DATA TYPE. 2 Primitive Data Types  The eight Java primitive data types are:  byte  short  int  long  float  double.
Advertisements

© 2010 Pearson Addison-Wesley. All rights reserved. Addison Wesley is an imprint of Starting Out with Java: From Control Structures through Objects Fourth.
Chapter 7 User-Defined Methods. Chapter Objectives  Understand how methods are used in Java programming  Learn about standard (predefined) methods and.
Methods. int month; int year class Month Defining Classes A class contains data declarations (static and instance variables) and method declarations (behaviors)
1 Fall 2009ACS-1903 Methods – Ch 5 A design technique referred to as stepwise refinement (or divide and conquer, or functional decomposition) is used to.
COMP 14 Introduction to Programming Miguel A. Otaduy May 25, 2004.
COMP 14 Introduction to Programming Mr. Joshua Stough February 28, 2005 Monday/Wednesday 11:00-12:15 Peabody Hall 218.
The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL Adrian Ilie COMP 14 Introduction to Programming Adrian Ilie July 8, 2005.
Java Programming: From Problem Analysis to Program Design, 4e Chapter 7 User-Defined Methods.
Lesson 6 Functions Also called Methods CS 1 Lesson 6 -- John Cole1.
Chapter 7: User-Defined Methods
11 Chapter 5 METHODS. 22 INTRODUCTION TO METHODS A method is a named block of statements that performs a specific task. Other languages use the terms.
Introduction to Methods
CSM-Java Programming-I Spring,2005 Introduction to Objects and Classes Lesson - 1.
© The McGraw-Hill Companies, 2006 Chapter 4 Implementing methods.
By Nicholas Policelli An Introduction to Java. Basic Program Structure public class ClassName { public static void main(String[] args) { program statements.
11 Chapter 5 METHODS CONT’D. 22 MORE ON PASSING ARGUMENTS TO A METHOD Passing an Object Reference as an Argument to a Method Objects are passed by reference.
Copyright © 2012 Pearson Education, Inc. Chapter 6: Functions.
Final Exam Review Closed book Closed laptop One sheet of notes permitted SE-0010 Dr. Mark L. Hornick 1.
Math class services (functions) Primitive vs reference data types Scanner class Math class services (functions) Primitive vs reference data types Scanner.
Chapter 5, Methods Java How to Program, Late Objects Version, 10/e
Introduction to Java Lecture Notes 3. Variables l A variable is a name for a location in memory used to hold a value. In Java data declaration is identical.
Methods Chapter Why Write Methods? Methods are commonly used to break a problem down into small manageable pieces. This is called divide and conquer.
Starting Out with Java: From Control Structures through Objects Fifth Edition by Tony Gaddis Chapter 5: Methods.
1 Methods Introduction to Methods Passing Arguments to a Method More About Local Variables Returning a Value from a Method Problem Solving with Methods.
Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 5-1 Why Write Methods? Methods are commonly used to break a problem down.
Aside: Running Supplied *.java Programs Just double clicking on a *.java file may not be too useful! 1.In Eclipse, create a project for this program or.
Methods CSCI 1301 What is a method? A method is a collection of statements that performs a specific task. Pre-Defined methods: available in Java library.
1 Predefined Classes and Objects Chapter 3. 2 Objectives You will be able to:  Use predefined classes available in the Java System Library in your own.
Chapter 5 : Methods. Why Write Methods?  Methods are commonly used to break a problem down into small manageable pieces. This is called divide and conquer.
Chapter 5 : Methods Part 2. Returning a Value from a Method  Data can be passed into a method by way of the parameter variables. Data may also be returned.
Method Examples CS 139 Algorithm Development 10/06/2008.
LESSON 5 – Assignment Statements JAVA PROGRAMMING.
CPSC 233 Tutorial 5 February 9 th /10 th, Java Classes Each Java class contains a set of instance variables and methods Instance Variables: Type.
CSCI 51 Introduction to Programming Dr. Joshua Stough February 24, 2009.
CPSC 233 Tutorial January 21 st /22 nd, Linux Commands.
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.
Chapter 5 Methods. 2 Contents 1. Introduction to Methods 2. Passing Arguments to a Method 3. More about Local Variables 4. Returning a Value from a Method.
Yanal Alahmad Java Workshop Yanal Alahmad
Java Primer 1: Types, Classes and Operators
by Tony Gaddis and Godfrey Muganda
Methods.
Lecture 6 C++ Programming
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.
if-else-if Statements
CMSC 202 Static Methods.
CS 200 Using Objects Jim Williams, PhD.
Chapter Topics Chapter 5 discusses the following main topics:
Starting Out with Java: From Control Structures through Objects
Chapter 3 Introduction to Classes, Objects Methods and Strings
Starting Out with Java: From Control Structures through Objects
Group Status Project Status.
Classes and Objects 5th Lecture
IFS410 Advanced Analysis and Design
Chapter 4 Writing Classes.
Chapter 5: Methods Starting Out with Java: From Control Structures through Objects Third Edition by Tony Gaddis.
Chap 1 Chap 2 Chap 3 Chap 5 Surprise Me
Programs and Classes A program is made up from classes
Chapter 6 – Methods Topics are:
Starting Out with Java: From Control Structures through Objects
Lecture 5- Classes, Objects and Methods
Classes and Objects Static Methods
Object Oriented Programming in java
Chapter 5: Methods Starting Out with Java: From Control Structures through Objects Third Edition by Tony Gaddis.
Chapter 5: Methods Starting Out with Java: From Control Structures through Objects Third Edition by Tony Gaddis.
Names of variables, functions, classes
Happy October Exam Review 10/01/2014.
Math class services (functions)
Presentation transcript:

Exam Review 10/01/2014 Happy October

The Exam  Will be in Canvas  Two parts  Part A is recall – closed book, closed notes ◦Quizzes, in class activity ◦Know the terminology ◦Be able to evaluate expressions  Part B is coding – open book, closed notes, closed “examples” ◦You will have a shell program that you will need to fill in ◦Prompts are given in the program itself ◦You may use whatever editor you prefer ◦You may NOT use code from labs since they were done with a partner.

Lab EnergyDriver Energy public kineticEnergy(double mass, double velocity) public static…main() { Energy ed; ed = new Energy() energy = ed.kineticEnergy(100, 30); }

What is tester? Energy tester; tester tester = new Energy() kineticEnergy tester contains a reference to an Energy object. The object has [data] and methods.

Primitive vs Reference types PRIMITIVE  The space at declaration time holds the value.  There are only 8. ◦byte ◦short ◦int ◦long ◦float ◦double ◦char ◦boolean REFERENCE  The space at declaration time holds the reference to the value (object).  There are as many as you want to make.  Examples include: ◦DecimalFormat ◦Scanner ◦String ◦NumberFormat

Primitives, cont  We think of primitive containers as holding values.  Java can widen primitives to match the larger types but can only narrow by using the cast operation.  int count;  double sum;  count = sum is illegal, but  count = (int) sum is legal since we are saying take the integer part only.

1-7 Object-Oriented Programming Object Attributes (data) typically private to this object Methods (behaviors / procedures) Other objects Programming Interface

Calling methods “static”  Examples: Math class  No need for a specific version of Math. You are just using its functions.  total = Math.pow(25.0, 3);  value = Math.abs(-250 * 4);  value = Math.abs(Math.pow( * 4); not static  Examples: String class  Which String do we mean? object or specific set of data.  String message;  message = “CS 139 Exam”;  size = message.length();  part = message.substring(5);

5-9 void Methods and Value-Returning Methods  A void method is one that simply performs a task and then terminates. System.out.println("Hi!");  A value-returning method not only performs a task, but also sends a value back to the code that called it. int number = Integer.parseInt( " 700 " );  It is possible to have a value returning method not save the result. keyboard.nextLine(); // consume the new line static method, class name non static method, must have an object. This was created by declaring keyboard to be a Scanner then instantiating the Scanner.

5-10 Parts of a Method Header public static void displayMessage () { System.out.println("Hello"); } Method Modifiers Return Type Method Name Parameter List

5-11 Calling a Method  A method executes when it is called.  The main method is automatically called when a program starts, but other methods are executed by method call statements. displayMessage();  Notice that the method modifiers and the void return type are not written in the method call statement. Those are only written in the method header.  Examples: SimpleMethod.java, LoopCall.java, CreditCard.java, DeepAndDeeper.javaSimpleMethod.javaLoopCall.javaCreditCard.java DeepAndDeeper.java

5-12 Passing a Reference as an Argument showLength(name); public static void showLength(String str) { System.out.println(str + " is " + str.length() + " characters long."); str = "Joe" // see next slide } address “Warren” Both variables reference the same object The address of the object is copied into the str parameter.

5-13 String s are Immutable Objects  String s are immutable objects, which means that they cannot be changed. When the line str = "Joe"; is executed, it cannot change an immutable object, so creates a new object.  See example: PassString.javaPassString.java address “Warren” “Joe” The name variable holds the address of a String object The str variable holds the address of a different String object

5-14 Defining a Value-Returning Method public static int sum(int num1, int num2) { int result; result = num1 + num2; return result; } Return type This expression must be of the same data type as the return type The return statement causes the method to end execution and it returns a value back to the statement that called the method.

Other questions