Study Guides (400,000)
US (230,000)
Cornell (1,000)
CS (90)
CS 2110 (70)
Gries (2)
Study Guide

CS 2110- Midterm Exam Guide - Comprehensive Notes for the exam ( 60 pages long!)


Department
Computer Science
Course Code
CS 2110
Professor
Gries
Study Guide
Midterm

This preview shows pages 1-3. to view the full 60 pages of the document.
Cornell
CS 2110
MIDTERM EXAM
STUDY GUIDE

Only pages 1-3 are available for preview. Some parts have been intentionally blurred.

Only pages 1-3 are available for preview. Some parts have been intentionally blurred.

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
You're Reading a Preview

Unlock to view full version

Only pages 1-3 are available for preview. Some parts have been intentionally blurred.

Lecture 2 - Objects
oLike in Python, parameter is the variable inside a method
Argument is when you call the method
oCreating a new object
new javax.swing.JFrame()
This is just an example
Creates a JFrame Object.
Value of this expression is a pointer to the new object
JFrame@25c7f37d for example is the value
Example
First write javax.swing.JFrame h;
This lets us know the type for h
Then write h = new javax.swing.JFrame()
Now the object name is stored in h
oNote: Procedure is a method that does not return a value
oTo call methods from outside, you do h.<method>()
oSpecifications BEFORE you write class definition.
NOT LIKE PYTHON
&^^^^^^^^
^^^^
REMEMBER THAT
oNote: You’re declaration of your variable can be made shorter by combining the
two lines
Remember for an int
Int x;
x = 5
Now we can combine the two
int x = 5
oSo for class definitions, if we want to make something of class CC for example
CC g= new CC();
Creates variable g, stores the object of type CC’s name in g
oSubclasses
If we do public class CC extends javax.swing.JFrame {...}
We get C as a subclass of JFrame
WOAAAAAAAAAAAAAAAH
oDeclaring methods in class definitions
Functions:
Inside the braces {...}, you
1. First comment /** … */
2. Write public int area() {...}
int is the type of value the function will return
area is the name of the function
Parameters go in parentheses
3. Write return <whatever you want to return> inside the braces
OF THE FUNCTION {...}
Ex: return getWidth() * getHeight();
find more resources at oneclass.com
find more resources at oneclass.com
You're Reading a Preview

Unlock to view full version