Top Banner
Chapter 4 Procedural Methods
12

Chapter 4 Procedural Methods. Learning Java through Alice © Daly and Wrigley Objectives Identify classes, objects, and methods. Identify the difference.

Jan 02, 2016

Download

Documents

Angelica Morris
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Chapter 4 Procedural Methods. Learning Java through Alice © Daly and Wrigley Objectives Identify classes, objects, and methods. Identify the difference.

Chapter 4

Procedural Methods

Page 2: Chapter 4 Procedural Methods. Learning Java through Alice © Daly and Wrigley Objectives Identify classes, objects, and methods. Identify the difference.

Learning Java through Alice © Daly and Wrigley

Objectives• Identify classes, objects, and methods.• Identify the difference between a procedure method and a

function method.• Differentiate between parameters and arguments.• Write procedure methods with parameters.• Explain the purpose of the Java API.

2

Page 3: Chapter 4 Procedural Methods. Learning Java through Alice © Daly and Wrigley Objectives Identify classes, objects, and methods. Identify the difference.

Learning Java through Alice © Daly and Wrigley

Procedure Methods

A procedural method is a coordinated sequence of instructions that will be carried out when requested.

3

Page 4: Chapter 4 Procedural Methods. Learning Java through Alice © Daly and Wrigley Objectives Identify classes, objects, and methods. Identify the difference.

Learning Java through Alice © Daly and Wrigley

Java Programming Interface (API)

http://docs.oracle.com/javase/8/docs/api/

4

Page 5: Chapter 4 Procedural Methods. Learning Java through Alice © Daly and Wrigley Objectives Identify classes, objects, and methods. Identify the difference.

Learning Java through Alice © Daly and Wrigley

Method Syntax

The syntax for a method is: modifier static returntype methodname ( list of

parameters ) { .... statements to do inside of method }

• Modifiers determine the scope of a method. ▫ public means that the method is available in the current class

(program) and other classes. ▫ private means that you intend to use the variable or method in the

current program. • Return Type

▫ Data type: int, double, float, etc. ▫ No return type: void

5

Page 6: Chapter 4 Procedural Methods. Learning Java through Alice © Daly and Wrigley Objectives Identify classes, objects, and methods. Identify the difference.

Learning Java through Alice © Daly and Wrigley

Naming Methods• Consists of letters, digits, underscores (_) or $ (no spaces

allowed). • First character can't be a digit. • Cannot be keywords.• Stylistic Rule: all method names begin with a lowercase letter

with all other words beginning with uppercase letter such as displayIt, sumNumbers, etc.

• Method names should be meaningful.

6

Page 7: Chapter 4 Procedural Methods. Learning Java through Alice © Daly and Wrigley Objectives Identify classes, objects, and methods. Identify the difference.

Learning Java through Alice © Daly and Wrigley

Methods with No Parameters

7

Page 8: Chapter 4 Procedural Methods. Learning Java through Alice © Daly and Wrigley Objectives Identify classes, objects, and methods. Identify the difference.

Learning Java through Alice © Daly and Wrigley

Methods with No Parameters

8

Page 9: Chapter 4 Procedural Methods. Learning Java through Alice © Daly and Wrigley Objectives Identify classes, objects, and methods. Identify the difference.

Learning Java through Alice © Daly and Wrigley

Methods with Some Parameters

9

Page 10: Chapter 4 Procedural Methods. Learning Java through Alice © Daly and Wrigley Objectives Identify classes, objects, and methods. Identify the difference.

Learning Java through Alice © Daly and Wrigley

Methods with Some Parameters

10

Page 11: Chapter 4 Procedural Methods. Learning Java through Alice © Daly and Wrigley Objectives Identify classes, objects, and methods. Identify the difference.

Learning Java through Alice © Daly and Wrigley

Object Methods

11

Page 12: Chapter 4 Procedural Methods. Learning Java through Alice © Daly and Wrigley Objectives Identify classes, objects, and methods. Identify the difference.

Learning Java through Alice © Daly and Wrigley

Static Methods

12