Math107Ch4 - Introduction To Scientific Programming Chapter...

Info iconThis preview shows pages 1–9. Sign up to view the full content.

View Full Document Right Arrow Icon
Introduction To Scientific Programming Chapter 4 – Defining Classes and Methods
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
S.Horton/107/Ch. 4 Slide 2 Overview I. A. Classes B. Objects C. Methods D. Variables I. OOP - Encapsulation I. Revisits A. Scope B. Pass-by-value vs. Pass-by-address C. I. Putting It All Together
Background image of page 2
S.Horton/107/Ch. 4 Slide 3 Motivation Wouldn’t it be very handy to have software already available that accomplish tasks that occur frequently? In fact, it is one of the central goals of software engineering to make software development fast, efficient, and error-free. This is accomplished by using or reusing software components that have already been developed, debugged, and tested. This leads us to an organizing structure that has been developed over time for most modern programming languages. In Java, this is called “Classes”.
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
S.Horton/107/Ch. 4 Slide 4 Software Organizational Hierarchy Level of Organization Primitive Data Types Primitive Data Types - int, double , Code Statement Code Statement - =, public, if, … - while, for, … Operators Operators +,-, /,%, … Object Object - data + method(s) Code block Code block - { … } Methods Methods - Action or value return Low Class Class - group of objects High Package Package - groups of classes
Background image of page 4
S.Horton/107/Ch. 4 Slide 5 I. Introducing Classes and Methods “Top-Down” A. Classes B. Objects C. Methods D. Variables OOP - Encapsulation … and then
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
S.Horton/107/Ch. 4 Slide 6 I.-A. Classes A class is an abstract, bundled (data + code) structure that programmers use to accomplish frequent and/or repetitive tasks. A class is a general blueprint for constructing specific instances of that blueprint. (In general, a Class itself does not execute). Examples: an Automobile class, an AddressBook class, a BankAccount class, a Matrix Class, a Complex class, … A class is made up of data and Methods (actions on the data). When a specific copy of a class is created (or instantiated), this specific instance is called an Object .
Background image of page 6
S.Horton/107/Ch. 4 Slide 7 Example: String Class String is a class It contains data (a sequence of characters) It contains methods that perform actions and return values on a String type Coding convention for Classes: make first letter of name uppercase Note: Classes are additional (non-primitive) data types! A specific string is called a String object This is a specific instance of a class Each object inherits the structure of the class (data storage and methods)
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Slide 8 Example: String Class Example: read characters typed in by user from the keyboard and output the number of characters entered String userInput; System.out.println(“Are you finished?”); userInput = SavitchIn.readLine(); System.out.println(userInput.length()); A String Class method Console: Are you finished? Yes
Background image of page 8
Image of page 9
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 09/08/2011 for the course MATH 107 taught by Professor Christinashow during the Spring '08 term at Mesa CC.

Page1 / 44

Math107Ch4 - Introduction To Scientific Programming Chapter...

This preview shows document pages 1 - 9. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online