Happy October Exam Review 10/01/2014.

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.
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.
Lesson 6 Functions Also called Methods CS 1 Lesson 6 -- John Cole1.
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.
CSM-Java Programming-I Spring,2005 Introduction to Objects and Classes Lesson - 1.
By Nicholas Policelli An Introduction to Java. Basic Program Structure public class ClassName { public static void main(String[] args) { program statements.
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.
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.
Applications Development
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.
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.
Chapter 5 Defining Classes II Copyright © 2010 Pearson Addison-Wesley. All rights reserved.
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.
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.
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.
Functions + Overloading + Scope
User-Written Functions
Java Programming: From Problem Analysis to Program Design, 3e Chapter 7 User-Defined Methods.
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
Type Conversion, Constants, and the String Object
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:
Review for Final Exam.
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
Based on slides created by Bjarne Stroustrup & Tony Gaddis
Defining Classes and Methods
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
Math class services (functions)
Presentation transcript:

Happy October Exam Review 10/01/2014

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 static…main() { Energy ed; ed = new Energy() energy = ed.kineticEnergy(100, 30); } public kineticEnergy(double mass, double velocity)

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

Primitive vs Reference types The space at declaration time holds the value. There are only 8. byte short int long float double char boolean 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.

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

Calling methods “static” not 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(-250.0 * 4); 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);

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.

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

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.java

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

Strings are Immutable Objects Strings 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.java The name variable holds the address of a String object address “Warren” The str variable holds the address of a different String object address “Joe”

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

Other questions