DOC PREVIEW
UNF COP 2551 - Lecture Notes

This preview shows page 1-2-3-4-29-30-31-32-33-60-61-62-63 out of 63 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 63 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 63 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 63 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 63 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 63 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 63 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 63 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 63 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 63 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 63 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 63 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 63 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 63 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 63 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

Java – Software Solutions….Objects and Primitive DataIntroductory Notions Introduction to ObjectsIntroduction to ObjectsObjects and ClassesInheritanceUsing ObjectsThe print MethodAbstractionAbstraction (continued)Character StringsString ConcatenationSlide 14Overloading OperatorsEscape SequencesEscape sequences (continued)Slide 18Public Directory for Roses.javaVariablesSlide 21AssignmentGeometry example…ConstantsPrimitive DataNumeric Primitive DataSlide 27CharactersSlide 29Boolean2.5 Arithmetic Expressions (p. 80)Division and RemainderOperator PrecedenceSlide 34Assignment RevisitedSlide 36Data ConversionsSlide 38Slide 392.6 Creating Objects (p. 87)Creating Objects - ConstructorsCreating ObjectsString MethodsSlide 442.7 Class Libraries (p.91)PackagesThe import DeclarationSlide 48Random Class from java.util package2.8 Class Methods (p. 98)The Keyboard ClassKeyboard InputReading Keyboard InputBufferedReader Class and its methods p. 287-288Wrapper ClassesSlide 56Continuing…2.9 Formatting Output (p. 103)More…Stated a little differently…Slide 60More on Formatting OutputSlide 62SummaryJava – Software Solutions…. Chapter 2: Objects and Primitive Data2Objects and Primitive DataNow we can explore some more fundamental programming conceptsChapter 2 focuses on:predefined objectsprimitive datathe declaration and use of variablesexpressions and operator precedencecreating and using objectsclass libraries3Introductory NotionsNeed ability to create and use objects.Provide ‘services’Objects are fundamental to writing programs in an OOP language.Objects ‘do’ all the things we want:Manipulate stringsMake computationsDo input/outputDraw shapes…4 Introduction to ObjectsAn object represents something with which we can interact in a programAn object provides a collection of services that we can tell it to perform for usThe services are defined by methods in a class that defines the objectA class represents a concept, and an object represents the embodiment of a classA class can be used to create multiple objects5Introduction to ObjectsObjects also manage dataMaybe primitive; maybe complex (like integers, floats…)Most complex data consists if primitive data…A data type defines a set of values and operations that can be performed on those values.Think: integers; +, -, *, /, no division by zero… Objects is defined by a class – an abstraction; a generalization. Objects are ‘instances’ of a class.Operations (methods) are defined by methods in the class.Methods – a collection of programming statements with a given name that perform some kind of operation6Objects and ClassesBank AccountA class(the concept)Class = BankAccountJohn’s Bank AccountBalance: $5,257An object(a realization)(an ‘instantiation’)Bill’s Bank AccountBalance: $1,245,069Mary’s Bank AccountBalance: $16,833Multiple objectsfrom the same class. Has attributes (data). Has methods (operations)Classes ‘encapsulate’ attributes and methods.7InheritanceOne class can be used to derive another via inheritanceClasses can be organized into inheritance hierarchiesBank AccountAccountCharge AccountSavings AccountChecking AccountThink: Gender Men Women Mothers non-Mothers8Using ObjectsThe System.out object represents a destination to which we can send outputIn the Lincoln program, we invoked the println method of the System.out object:System.out.println ("Whatever you are, be a good one.");objectmethodinformation provided to the method(parameters)Notice the ‘notation’ for referencing the method: object.methodWe are SENDING A MESSAGE to the object, System.out.We are requesting that the object perform a ‘service’ for us by invoking.the services of its method, println.9The print MethodThe System.out object provides another service as wellThe print method is similar to the println method, except that it does not advance to the next lineTherefore anything printed after a print statement will appear on the same lineSee Countdown.java (page 65)Sending a message (fig. 2.2)mainCountdown System.outprintln//println//lprint// others…10AbstractionAn abstraction hides (or suppresses) the right details at the right time. We ‘abstract out’ common characteristics. An object is abstract in that we don't have to think about its internal details in order to use it.  encapsulate attributes and methods and provide services (have ‘responsibilities’) to other objects through the sending of messages. For example, we don't have to know how the println method inside the object System.out actually works in order to invoke it. We know when we send a message to the object System.out (we send messages by invoking its ‘methods’) with the parameters (“ “) the object will print out the contents enclosed in quotes.11Abstraction (continued)Of course, we have ‘levels’ of abstraction – germane to the problem at hand.CarFordMustangRed Mustang that belongs to …..Are all levels of abstraction! Each is more and more specific, but all have the ‘is-a’ characteristics. More later…..Classes and their objects help us write complex software12Character StringsEvery character string is an object in Java, defined by the String classEvery string literal, delimited by double quotation marks, represents a String objectTwo fundamental string operations:1) The string concatenation operator (+) is used to append one string to the end of anotherIt can also be used to append a number to a stringA string literal cannot be broken across two lines in a program13String ConcatenationThe plus operator (+) is also used for arithmetic additionThe function that the + operator performs depends on the type of the information on which it operatesIf both operands are strings, or if one is a string and one is a number, it performs string concatenationIf both operands are numeric, it adds themThe + operator is evaluated left to right (associativity)Parentheses can be used to force the operation orderSee Addition.java (page 70); Let’s look at some code:14//********************************************************************// Facts.java Author: Lewis/Loftus//// Demonstrates the use of the string concatenation operator and the// automatic conversion of an integer to a


View Full Document

UNF COP 2551 - Lecture Notes

Download Lecture Notes
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Lecture Notes and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Lecture Notes 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?