class03 Notes - 1 1 IST 240 Today (1/22) Using Classes: Ch...

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

View Full Document Right Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon

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

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

Unformatted text preview: 1 1 IST 240 Today (1/22) Using Classes: Ch 3 Read Ch 3 Accelerated program Work with others on semester-long project, skip in-class exercises and homeworks, but take the 2 exams If interested, email Jung-woo ( jwsohn@psu.edu ) with your Java background by this Friday (1/25). Due: Hwk#1, Ch 2: Ex 2.2-2.6, 2.8, today at midnight Hwk #2 Ch 3: Ex 3.1-3.4, 3.8-3.9, 3.12; PP 3.2 Due: Sun 1/27 at midnight For Thursday (1/24) Read: Ch 4 Play with Scratch Help on homework problems 2 Accelerated Option: How much programming experience do I need? I can create a class with methods and attributes I can create an instance of a class I can call a method of an instance of a class with parameters I can write if , for and while loops I can debug and problem solve when a program does not do what I expect I can break a problem down into algorithms and classes and implement them CCTM: Course material developed by James King (james.king@londonmet.ac.uk) Ideally: 2 3 3.1 Creating Objects A variable holds either a primitive type or a reference to an object A class name can be used as a type to declare an object reference variable String title; No object is created with this declaration An object reference variable holds the address of an object The object itself must be created separately null title num This is just a holding cell for future pointers to Strings. 4 3.1 Creating Objects Generally, we use the new operator to create an object title = new String ("Java Software Solutions"); This calls the String constructor , which is a special method that sets up the object Creating an object is called instantiation An object is an instance of a particular class 3 5 3.1 Invoking Methods We've seen that once an object has been instantiated, we can use the dot operator to invoke its methods count = title.length() A method may return a value , which can be used in an assignment or expression A method invocation can be thought of as asking an object to perform a service 6 3.1 References Note that a primitive variable contains the value itself, but an object variable contains the address of the object An object reference can be thought of as a pointer to the location of the object Rather than dealing with arbitrary addresses, we often depict a reference graphically "Steve Jobs" name1 num1 38 4 7 3.1 Assignment Revisited The act of assignment takes a copy of a value and stores it in a variable For primitive types num1 38 num2 96 Before: num2 = num1; num1 38 num2 38 After: 8 3.1 Reference Assignment For object references, assignment copies the address name2 = name1; name1 name2 Before: "Steve Jobs" "Steve Wozniak" name1 name2 After: "Steve Jobs" 5 9 3.2 The String Class Because strings are so common, we don't have to use the new operator to create a String object title = "Java Software Solutions"; This is special syntax that works only...
View Full Document

This note was uploaded on 03/31/2008 for the course IST 240 taught by Professor Tracymullen during the Spring '08 term at Pennsylvania State University, University Park.

Page1 / 17

class03 Notes - 1 1 IST 240 Today (1/22) Using Classes: Ch...

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

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