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

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

Department
Computer Science
Course Code
CS 2110
Professor
Gries
Lecture
1

This preview shows half of the first page. to view the full 1 pages of the document.
CS 2110
Lecture 1 - Types
oType: 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 = 100; 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 -2^(31) … 2^(31) - 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