13 - Click to edit Master subtitle style Chapter Thirteen...

Info iconThis preview shows pages 1–10. 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

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: Click to edit Master subtitle style Chapter Thirteen Modern Programming Languages, 2nd ed. A First Look At Java Chapter Thirteen Modern Programming Languages, 2nd ed. 11 Chapter Thirteen Modern Programming Languages, 2nd ed. Outline ■ 13.2 Thinking about objects ■ 13.3 Simple expressions and statements ■ 13.4 Class definitions ■ 13.5 About references and pointers ■ 13.6 Getting started with a Java language system Chapter Thirteen Modern Programming Languages, 2nd ed. 22 Chapter Thirteen Modern Programming Languages, 2nd ed. Example ■ Colored points on the screen ■ What data goes into making one? – Coordinates – Color ■ What should a point be able to do? – Move itself – Report its position Chapter Thirteen Modern Programming Languages, 2nd ed. 33 Chapter Thirteen Modern Programming Languages, 2nd ed. Chapter Thirteen Modern Programming Languages, 2nd ed. 44 My x: 5 My y: 20 My color: black Things I can do: move report x report y My x: 20 My y: 10 My color: dark grey Things I can do: move report x report y My x: 17 My y: 25 My color: light grey Things I can do: move report x report y Chapter Thirteen Modern Programming Languages, 2nd ed. Java Terminology ■ Each point is an object ■ Each includes three fields ■ Each has three methods ■ Each is an instance of the same class Chapter Thirteen Modern Programming Languages, 2nd ed. 55 My x: 10 My y: 50 My color: black Things I can do: move report x report y Chapter Thirteen Modern Programming Languages, 2nd ed. Object-Oriented Style ■ Solve problems using objects: little bundles of data that know how to do things to themselves ■ Not the computer knows how to move the point , but rather the point knows how to move itself ■ Object-oriented languages make this way of thinking and programming easier Chapter Thirteen Modern Programming Languages, 2nd ed. 66 Chapter Thirteen Modern Programming Languages, 2nd ed. Java Class Definitions: A Peek Chapter Thirteen Modern Programming Languages, 2nd ed. 77 public class Point { private int x,y; private Color myColor; public int currentX() { return x; } public int currentY() { return y; } public void move(int newX, int newY) { x = newX; y = newY; } } field definitions method definitions Chapter Thirteen Modern Programming Languages, 2nd ed. Outline ■ 13.2 Thinking about objects ■ 13.3 Simple expressions and statements ■ 13.4 Class definitions ■ 13.5 About references and pointers ■ 13.6 Getting started with a Java language system Chapter Thirteen Modern Programming Languages, 2nd ed. 88 Chapter Thirteen Modern Programming Languages, 2nd ed. Primitive Types We Will Use ■ int : -231..231-1, written the usual way ■ char : 0..216-1, written 'a' , '\n' , etc., using the Unicode character set ■ double : IEEE 64-bit standard, written in decimal ( 1.2 ) or scientific ( 1.2e-5 , 1e3 ) ■ boolean : true and false ■ Oddities: void and null Chapter Thirteen Modern Programming Languages, 2nd ed....
View Full Document

This note was uploaded on 09/30/2011 for the course CS 6371 taught by Professor Hamlen during the Spring '11 term at University of Texas at Dallas, Richardson.

Page1 / 63

13 - Click to edit Master subtitle style Chapter Thirteen...

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

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