Class Notes (1,200,000)
US (500,000)
Cornell (1,000)
CS (100)
CS 2110 (30)
Gries (30)
Lecture 1

# CS 2110 Lecture Notes - Lecture 1: Natural Number, Strong And Weak Typing

Department
Computer Science
Course Code
CS 2110
Professor
Gries
Lecture
1

This preview shows half of the first page. to view the full 2 pages of the document.
Lecture 1 - Types
Type: Set of values together with operations on them
Ex: Integer
…, -3, -2, -1, 0, 1, 2, 3, ...
Matlab and Python are weakly typed
Ex: x = ; x = Hello World
Java is strongly typed
Ex: int x; x = 100
First we declare x as an int type, then we can store
something in it
So if we then wrote x = Hello World; we would get an
error, because Hello World is not an int
Back to type int
Values can only be in the range -^ … ^ - 1
Integer.MAX_VALUE: name for max int value, i.e. 2^(31)-1
So what happens if you type in Integer.MAX_VALUE + 1?
You get -2^(31)
THAT’S WILD…. IT WRAPS AROUND
Type double
Like floats in Python
Ex:
21.0
Returns 21.0
21E5
Returns 2100000.0
21E20
Returns 2.1E210
So if we want to let d be a double
d=21E20
ERROR!
You didn’t declare d as a double
You need first double d; d = 21E20
find more resources at oneclass.com
find more resources at oneclass.com