13 - A First Look At Java Click to edit Master subtitle...

Info icon This preview shows pages 1–13. Sign up to view the full content.

View Full Document Right Arrow Icon
Click to edit Master subtitle style Chapter Thirteen Modern Programming Languages, 2nd ed. A First Look At Java 11
Image of page 1

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

View Full Document Right Arrow Icon
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 22
Image of page 2
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 33
Image of page 3

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

View Full Document Right Arrow Icon
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
Image of page 4
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 55 My x: 10 My y: 50 My color: black Things I can do: move report x report y
Image of page 5

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

View Full Document Right Arrow Icon
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 66
Image of page 6
Chapter Thirteen Modern Programming Languages, 2nd ed. Java Class Definitions: A Peek 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
Image of page 7

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

View Full Document Right Arrow Icon
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 88
Image of page 8
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 99
Image of page 9

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

View Full Document Right Arrow Icon
Chapter Thirteen Modern Programming Languages, 2nd ed. Primitive Types We Won’t Use byte : -27..27-1 short : -215..215-1 long : -263..263-1, written with trailing L float : IEEE 32-bit standard, written with trailing F ( 1.2e-5 , 1e3 ) 1010
Image of page 10
Chapter Thirteen Modern Programming Languages, 2nd ed. Constructed Types Constructed types are all reference types: they are references to objects Any class name, like Point Any interface name (Chapter 15) Any array type, like Point[] or int[] (Chapter 14) 1111
Image of page 11

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

View Full Document Right Arrow Icon
Chapter Thirteen Modern Programming Languages, 2nd ed.
Image of page 12
Image of page 13
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern