Fundamentals of Software Development 1Slide 1 Methods: Defining, Invoking, Executing “There is a difference between knowing the path and walking the path.”

Slides:



Advertisements
Similar presentations
Introduction to Eclipse. Start Eclipse Click and then click Eclipse from the menu: Or open a shell and type eclipse after the prompt.
Advertisements

Fundamentals of Software Development 1Slide 1 Recap: Constructors, the new operator and the this object Three ideas:Three ideas: –How to write a constructor.
1 Classes, Encapsulation, Methods and Constructors (Continued) Class definitions Instance data Encapsulation and Java modifiers Method declaration and.
Chapter 4: Writing Classes
Introduction to Object-Oriented Programming CS 21a: Introduction to Computing I First Semester,
1 Inheritance Reserved word protected Reserved word super Overriding methods Class Hierarchies Reading for this lecture: L&L 8.1 – 8.5.
©2004 Brooks/Cole Chapter 6 Methods. Figures ©2004 Brooks/Cole CS 119: Intro to JavaFall 2005 Using Methods We've already seen examples of using methods.
Fundamentals of Software Development 1Slide 1 Why have interfaces? A Java interface is the “face” that one class shows othersA Java interface is the “face”
Objects and Classes First Programming Concepts. 14/10/2004Lecture 1a: Introduction 2 Fundamental Concepts object class method parameter data type.
Fundamentals of Software Development 1Slide 1 Today’s Summary UML class diagrams – –Why classes are important – –UML class diagrams – relationships – –UML.
Java: How to Program Methods Summary Yingcai Xiao.
Fundamentals of Software Development 1Slide 1 Methods: Defining, Invoking, Executing “There is a difference between knowing the path and walking the path.”
Fundamentals of Software Development 1Slide 1 Interfaces Outline:Outline: –Generic interface versus Java interface –What a (Java) interface is: Its syntaxIts.
CPEN Digital System Design Chapter 9 – Computer Design
Java Methods By J. W. Rider. Java Methods Modularity Declaring methods –Header, signature, prototype Static Void Local variables –this Return Reentrancy.
Dale Roberts Object Oriented Programming using Java - Class Constructors Dale Roberts, Lecturer Computer Science, IUPUI Department.
CIS162AD - C# Methods, Menus, and Dialog Boxes 05_methods_menus.ppt.
UNIT - 1Topic - 1. An electronic device, operating under the control of instructions stored in its own memory unit, that can accept data (input), manipulate.
Introduction to Object-Oriented Programming
Macros. There are three basic phases for C programming. preprocessing, compiling, and linking. C input file is first passed to a preprocessing program.
Introduction to Java and Object-Oriented Programming AJSS Computer Camp Department of Information Systems and Computer Science Ateneo de Manila University.
1 Module Objective & Outline Module Objective: After completing this Module, you will be able to, appreciate java as a programming language, write java.
Classes CS 21a: Introduction to Computing I First Semester,
Chapter 4 MARIE: An Introduction to a Simple Computer.
Topic 3 – The General Form of a C Program. CISC 105 – Topic 3 The General Form of a C Program Now, all of the basic building blocks of a C program are.
Methods F Hello World! F Java program compilation F Introducing Methods F Declaring Methods F Calling Methods F Passing Parameters by value F Overloading.
FIRST JAVA PROGRAM. JAVA PROGRAMS Every program may consist of 1 or more classes. Syntax of a class: Each class can contain 1 or more methods. public.
Programming Logic and Design Using Methods. 2 Objectives Review how to use a simple method with local variables and constants Create a method that requires.
Lecture 2: Introduction to C Programming. OBJECTIVES In this lecture you will learn:  To use simple input and output statements.  The fundamental data.
CPSC 230 Computers and Programming I Spring 2003 Dr. Lynn Lambert.
Lecture 14 Today’s topics MARIE Architecture Registers Buses
CS221 Algorithm Basics. What is an algorithm? An algorithm is a list of instructions that transform input information into a desired output. Each instruction.
Loops (cont.). Loop Statements  while statement  do statement  for statement while ( condition ) statement; do { statement list; } while ( condition.
BEGINNING PROGRAMMING.  Literally – giving instructions to a computer so that it does what you want  Practically – using a programming language (such.
1 Functions, Part 1 of 2 Topics Using Predefined Functions Programmer-Defined Functions Using Input Parameters Function Header Comments.
Polymorphism, Virtual Methods and Interfaces Version 1.1.
4.3 Functions. Functions Last class we talked about the idea and organization of a function. Today we talk about how to program them.
Functions Functions, locals, parameters, and separate compilation.
C# Programming Methods.
Methods.
POLYMORPHISM Chapter 6. Chapter Polymorphism  Polymorphism concept  Abstract classes and methods  Method overriding  Concrete sub classes and.
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.
1 Karel – Chapter 6 Instructions That Repeat Note: Original slides provided by and modified for Mr. Smith’s AP Computer Science.
Invoking methods in the Java library. Jargon: method invocation Terminology: Invoking a method = executing a method Other phrases with exactly the same.
Functions, Part 1 of 3 Topics  Using Predefined Functions  Programmer-Defined Functions  Using Input Parameters  Function Header Comments Reading 
Programming Fundamentals Enumerations and Functions.
Introduction to Methods ISYS 350. Methods Methods can be used to break a complex program into small, manageable pieces – This approach is known as divide.
Computer Programming II Lecture 4. Functions - In C++ we use modules to divide the program into smaller and manageable code. These modules are called.
Programming Logic and Design Fifth Edition, Comprehensive Chapter 7 Using Methods.
Fundamentals of Software Development 1Slide 1 Today’s Summary InterfacesInterfaces –What are they? –Why are they important? –How do they relate to WordGames?
Recap: The design of Word Games
What should we teach regarding…
Chapter 4: Writing Classes
Programmazione I a.a. 2017/2018.
2011/11/20: Lecture 15 CMSC 104, Section 4 Richard Chang
2008/11/05: Lecture 15 CMSC 104, Section 0101 John Y. Park
Chapter 6 Methods: A Deeper Look
Learning Outcomes List all Edison’s Sensors and actions
Functions, Part 1 of 3 Topics Using Predefined Functions
Classes, Encapsulation, Methods and Constructors (Continued)
Learning Objectives Classes Constructors Principles of OOP
HELLO THERE. THIS IS A TEST SLIDE SLIDE NUMBER 1.
METHODS, CLASSES, AND OBJECTS A FIRST LOOK
Functions, Part 1 of 3 Topics Using Predefined Functions
Fundamental OOP Programming Structures in Java: Comments, Data Types, Variables, Assignments, Operators.
Fundamentals of Software Development 1
Programming Languages and Paradigms
Functions, Part 1 of 3 Topics Using Predefined Functions
2008/11/05: Lecture 15 CMSC 104, Section 0101 John Y. Park
Corresponds with Chapter 5
Presentation transcript:

Fundamentals of Software Development 1Slide 1 Methods: Defining, Invoking, Executing “There is a difference between knowing the path and walking the path.” ~ Morpheus“There is a difference between knowing the path and walking the path.” ~ Morpheus “There is a difference between defining a method and invoking a method.” ~ 120 Prof.“There is a difference between defining a method and invoking a method.” ~ 120 Prof.

Fundamentals of Software Development 1Slide 2 Methods Defining, Invoking, Executing Defining a MethodDefining a Method –Specifying stepwise directions for a method… For example you specify how a robot can pick up a soda can (think of this as “teaching”)you specify how a robot can pick up a soda can (think of this as “teaching”) Invoking a MethodInvoking a Method –Asking to activate a method… For example you ask the robot to pick up a soda canyou ask the robot to pick up a soda can Executing a MethodExecuting a Method –Processing the stepwise instructions specified in the method… For example the robot carries out your command to pick up the soda canthe robot carries out your command to pick up the soda can

Fundamentals of Software Development 1Slide 3 Defining a Method Format:Format: methodName (ParameterType ParameterName, …) { methodName (ParameterType ParameterName, …) { // Stepwise instructions } ExampleExample String transform (String inputString) { return “Caps:” + inputString.toUpperCase() } Questions?

Fundamentals of Software Development 1Slide 4 Invoking and Executing a Method Format: object.method(arguments)Format: object.method(arguments) Invoke a String method:Invoke a String method: –"Hello".toUpperCase() yields "HELLO" –"Hello".substring(3) yields "lo" –"Hello".substring(1, 3) yields "el" –"Hello".substring(0) yields "Hello“ Stringmethoddotarguments, in parentheses Numbering starts at zero Questions?

Fundamentals of Software Development 1Slide 5 Signature Signature of a method specifies its input and output but not its definitionSignature of a method specifies its input and output but not its definition –Methods in the same class may have the same name (overloading) –But each method must have a unique signature

Fundamentals of Software Development 1Slide 6 Interfaces –Methods may have the same name (overloading) –But each method must have a unique footprint

Fundamentals of Software Development 1Slide 7 Interface (Signatures) An interface contains the signature but not body for each methodAn interface contains the signature but not body for each method –Each method must have a unique footprint. For example: interface Clock { Time getTime(); Time getTime(); void setTime(Time x); void setTime(Time x); void setTime(Time x, Station s); void setTime(Time x, Station s);} Two methods may have the same name as long as their signature is different.