Class 16 - Types and Events, continued Matthew Hashim Click...

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

View Full Document Right Arrow Icon
12/4/09 Click to edit Master subtitle style Types and Events, continued Matthew Hashim 10/20/2009 11
Background image of page 1

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

View Full DocumentRight Arrow Icon
MGMT 290D 12/4/09 Goals for Today n Understand the difference between Java’s fundamental and class types n Build complex Java expressions n Better understand and use Java’s Scanner and PrintStream classes 22
Background image of page 2
MGMT 290D 12/4/09 Reference Types n Two distinguishing features of reference types ¨ Reference variable initialization ¨ The encapsulation of behaviors and attributes 33
Background image of page 3

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

View Full DocumentRight Arrow Icon
MGMT 290D 12/4/09 Reference Variable Initialization n Usually involves use of the new operator n new operation ¨ Request memory for an object of the indicated type ¨ Returns a reference to that object n Example of a new operation ¨ Scanner keyboard = new Scanner(System.in) ; ¨ keyboard is a handle to a Scanner object n Exception to the rule: initialization of a String object ¨ Example: String tTwist = "Unique New York"; 44
Background image of page 4
MGMT 290D 12/4/09 Reference Variable Initialization (continued) n Comparison with initialization of primitives ¨ Reference type only stores object address (reference) ¨ Primitives store the value indicated by the type n null value: a special zero reference n Reference type set to null does not refer to an object n Example: String tongueTwister = null; n boolean tests can be applied to objects set to null 55
Background image of page 5

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

View Full DocumentRight Arrow Icon
MGMT 290D 12/4/09 Sending Messages n Reference types are classes containing methods n Primitives are not classes and do not contain methods n How to compute with reference types ¨ Send a message to an object n Pattern: referenceVariable.methodName() n Ex: int monthNumber = keyboard.nextInt(); ¨ Send nextInt() to object referenced by keyboard 66
Background image of page 6
MGMT 290D 12/4/09 Sending Messages (continued) n Two ways to identify object appropriate messages ¨ Type the name of a handle and a period ¨ Search the method list for the class in the Java API n Java API (application programming interface)
Background image of page 7

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

View Full DocumentRight Arrow Icon
Image of page 8
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 29

Class 16 - Types and Events, continued Matthew Hashim Click...

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

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