























































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
The key points are: First Look at Java, Simple Expressions, Class Definitions, References and Pointers, Java Language System, Colored Points, Java Terminology, Object-Oriented Style, Java Class Definitions, Primitive Types
Typology: Slides
1 / 63
This page cannot be seen from the preview
Don't miss anything!
























































Chapter Thirteen Modern Programming Languages, 2nd ed. (^) Docsity.com 1
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. (^) Docsity.com 2
Chapter Thirteen Modern Programming Languages, 2nd ed. 4
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 g rey Things I can do: move report x report y
My x: 17 My y: 25 My color: light g rey Things I can do: move report x report y
Docsity.com
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. 5
My x: 10 My y: 50 My color: black Things I can do: move report x report y
Docsity.com
Chapter Thirteen Modern Programming Languages, 2nd ed. 7
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
Docsity.com
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. (^) Docsity.com 8
byte : -2 7 ..2 7 - short : -2 15 ..2 15 - long : -2 63 ..2 63 -1, written with trailing L float : IEEE 32-bit standard, written with trailing F ( 1.2e-5 , 1e3 )
Chapter Thirteen Modern Programming Languages, 2nd ed. (^) Docsity.com 10
Constructed types are all reference types: they are references to objects
Chapter Thirteen Modern Programming Languages, 2nd ed. (^) Docsity.com 11
Chapter Thirteen Modern Programming Languages, 2nd ed. 13
My data: Hello there My length: 11 Things I can do: report my length report my ith char make an uppercase version of myself etc.
"Hello there"
Docsity.com
int : + , - , ***** , / , % , unary –
double : + , - , ***** , / , unary –
Chapter Thirteen Modern Programming Languages, 2nd ed. 14
Java Expression Value 1+23 7 15/7 2 15%7 1 -(55) -**
Java Expression Value 13.02.0 26. 15.0/7.0 2.*
Docsity.com
The usual comparison operators < , <= , >= , and > , on numeric types Equality == and inequality != on any type, including double (unlike ML)
Chapter Thirteen Modern Programming Languages, 2nd ed. 16
Java Expression Value 1<=2 true 1==2 false true!=false true
Docsity.com
&& and || , short-circuiting, like ML’s andalso and orelse ! , like ML’s not a?b:c , like ML’s if a then b else c
Chapter Thirteen Modern Programming Languages, 2nd ed. 17
Java Expression Value 1<=2 && 2<=3 true 1<2 || 1>2 true 1<2? 3 : 4 3
Docsity.com
a=b : changes a to make it equal to b Assignment is an important part of what makes a language imperative
Chapter Thirteen Modern Programming Languages, 2nd ed. (^) Docsity.com 19
Why does a=1 make sense, but not 1=a? Expressions on the right must have a value: a , 1 , a+1 , f() (unless void ), etc. Expressions on the left must have memory locations: a or d[2] , but not 1 or a+ These two attributes of an expression are sometimes called the rvalue and the lvalue
Chapter Thirteen Modern Programming Languages, 2nd ed. (^) Docsity.com 20