CS 2110 Lecture Notes - Lecture 1: Compile Time, Strong And Weak Typing, Operand

21 views2 pages
Published on 9 Jan 2017
School
Cornell University
Department
Computer Science
Course
CS 2110
Professor
CS 2110 Notes
Lecture 1
8/23/2016
Notes:
I. Types in Java
a. Type: Set of values together with operations on them
b. Matlab and Python are weakly typed
i. One variable can contain at different times a number, string, an array etc
ii. Shorter programs
iii. Programmer has more freedom
c. Java is strongly typed
i. A variable must be declared before it is used and can only contain values
of that type that it is declared with
ii. Programmer has to be more disciplined
iii. More errors caught at compile time (eg. Syntax error to assign a string to
int variable)
d. integer (Whole numbers)
i. Values: -1, 0, 1, 2,3
ii. Operations: +, -, *, /, %, unary
iii. Primitive operation on type int must yield int (Integer.MAX_VALUE + 1 =
Integer.MIN_VALUE; wraps around)
iv. Max value = 2e15 Integer.MAX_VALUE, Min value = Integer.MIN_VALUE
e. double
i. Values: -22.516, 24.9
ii. Operations +, -, *, /, %, unary
f. char
i. values like ‘I’
ii. Operations none
iii. Place between single quotes
iv. Is a number type
g. Primitive number types
i. Integer
1. byte 1 byte
2. short 2 bytes
3. int 4 bytes
4. long 8 bytes
ii. Real types
1. float 4 bytes
2. double 8 bytes
h. Casting among types
i. (int) 3.2; (casts double as an int)
ii. (int) is a unary prefix operator (Will truncate towards 0)
1. Unary means one operand
2. Prefix = operator comes BEFORE its operand
iii. Automatically casts from narrow to wider
iv. Must be manually cast if you want to go from wider to narrow (i.e double
to int)
v. - - 3 = 3
find more resources at oneclass.com
find more resources at oneclass.com
Unlock document

This preview shows half of the first page of the document.
Unlock all 2 pages and 3 million more documents.

Already have an account? Log in

Get OneClass Grade+

Unlimited access to all notes and study guides.

YearlyMost Popular
75% OFF
$9.98/m
Monthly
$39.98/m
Single doc
$39.98

or

You will be charged $119.76 upfront and auto renewed at the end of each cycle. You may cancel anytime under Payment Settings. For more information, see our Terms and Privacy.
Payments are encrypted using 256-bit SSL. Powered by Stripe.