Class 18 - Types and Expressions, continued 1 Goals for...

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

View Full Document Right Arrow Icon
Types and Expressions, continued 1
Background image of page 1

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

View Full DocumentRight Arrow Icon
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 2 MGMT 29000-002
Background image of page 2
Reference Types n Two distinguishing features of reference types ¨ Reference variable initialization ¨ The encapsulation of behaviors and attributes 3 MGMT 29000-002
Background image of page 3

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

View Full DocumentRight Arrow Icon
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"; 4 MGMT 29000-002
Background image of page 4
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 5 MGMT 29000-002
Background image of page 5

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

View Full DocumentRight Arrow Icon
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 6 MGMT 29000-002
Background image of page 6
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) ¨ Includes method names, parameters, return types, etc. n
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.

This note was uploaded on 04/04/2012 for the course MGMT 290 taught by Professor Staff during the Fall '08 term at Purdue University-West Lafayette.

Page1 / 30

Class 18 - Types and Expressions, continued 1 Goals for...

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