CS231 - Week 2 Flashcards

(24 cards)

1
Q

(1) statically typed language

A

every type of variable is checked at compile time before a program is run:
1. declaration of a type is needed
2. after declaration, the data type is fixed

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

(1) dynamically typed language

A

you don’t need to say int age=20
can just say age = 20

leads to run-time errors, because the program crashes when it encounters a type it doesn’t expect

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

(1) bigO-notation (bounded idea)

A

when we investigate the Big-O notation of a program, the Big-O shows its worst case that the program can take to run.

the program is now bounded by the worst case (from the top).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

(2) class

A

a blueprint describing how objects are built
e.g. its a cookie cutter, and the objects are the cookies

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

(2) object

A

a single entity that combines data and behavior

(stores data + can have methods act on it)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

(2) instance

A

a concrete object created from a class

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

(2) field

A

a variable/attribute/state of the object

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

(2) method

A

an action (behavior) an object knows how to perform

  • when we use a method, we implement the method like reference.method (because java stores references to memory)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

(2) constructor

A

a code that creates and initializes a new object
- name matches the class name
- no return type

sets initial state of object when it is first created

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

(2) reference

A

a special variable that points to an object in memory (a pointer to memory location where the stuff is actually stored)

  • variables store references, not objects
  • assignment copies the reference
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

(2) encapsulation

A

controlling how data is accessed (the fields are private but the methods to access the fields are public)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

(2) access modifier

A

rules that limit the visibility of fields and methods (private/public)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

(2) this

A

a reference to the current object

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

(2) syntax for creating objects (creating an object e1 in an Elephant class)

A

Elephant e1 = new Elephant();

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

(2) constructor overloading

A

having multiple constructors with the same name, different parameters

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

(2) this()

A

calls another constructor in the same class
constructor hands off work to another constructor in the same class

17
Q

(2) toString()

A

string representation of current state of object

  • there’s a default toString() implementation in Java, we need to write @Override at the top of our new implementation to ignore the default version, and use our implementation instead
  • no parameters, returns String
18
Q

(2) implicit call + toString() example

A

automatically invoked method

  • an implicit toString() call:
    Java runs the toString() method automatically, even if you don’t type it out.
    this happens when you write System.out.println(p) where p isn’t a string
    or when you do concatenation and theres a variable p where it is not a string
19
Q

(2) composition

A

one object contains another
ex. a circle has a point

20
Q

(2) constant

A

value declared with final (cannot be changed)

21
Q

(2) empty/default constructor

A

sets the object to its default value
nothing in parenthesis - what happens when no input is given for the object
uses a this() so that it can delegate to the real constructor

22
Q

(2) this.

A

use this. when your box name = parameter name to differentiate between what is box and what is parameter

23
Q

(2) getters and setters

A

getters
- no parameters
- returns a value

setters
- has parameters
- returns void
- maintains invariants (validates data before assigning it to box)