Exam 2 Review - Intro to Computer Science
Intro to Computer Science
- Exam Structure
- ArrayList
- Multidimensional Arrays
- Object-Oriented Programming
- Pillars
- Patterns
- Strings
- Inheritance
- This is Super
- Conclusions
Structure
Overview
The exam will take place during class time. It will be composed of two parts:
- Google Form Quiz (40%)
- GitHub Assignment (60%)
Accepting the Exam
Students must accept the exam by…
- Clicking the link provided by the instructor to the Google Form.
- Clicking the link provided by the instructor to the GitHub Assignment, and following the instructions therein to “accept” the assignment.
Submitting the Exam
Students must submit the exam by the end of the exam period.
- Click the Submit button on the Google Form.
push
the GitHub Assignment code to GitHub.
Verifying Your Submission
Students must verify on your own that you have actually submitted the exam.
- See the confirmation message on the Google Quiz after clicking submit.
- Click the link provided by the instructor to the GitHub Assignment, and verifying that your code has been pushed to the repository.
ArrayList
Main themes
- a class in the Java API (i.e.
java.util.ArrayList
) - behaves similarly to the fundamental primitive array data structure, but has a malleable length and stores only objects
- easy to
add()
,remove()
, andget()
objects to/from anArrayList
. - odd syntax, e.g.
ArrayList<Alien> = new ArrayList<Alien>()
, which we won’t talk about (called Java “generics”)
Multidimensional Arrays
Main themes
- must first understand one-dimensional arrays
- two-dimensional arrays can be visualized as tables with rows and columns
- first dimension is like the rows
- second dimension is like the columns
- declaring, allocating, and assigning values
- looping through multi-dimensional arrays
- the ‘standard’ way using nested counter-based loops
- using the foreach type of loop (e.g.
for (String[] val : values) { /* ... */ }
)
- ragged arrays exist
- passing arrays as arguments to methods
Object-Oriented Programming
Main themes
Basic object-oriented programming
- Classes are a sort of representation of Platonic idealism and a solution to the metaphysical problem of universals.
- Classes are essentially custom data types.
- Classes are reference types in Java.
- Objects are instances of a class.
- Defining a class
- Constructors
- Instance methods and properties
- Static methods and properties
- Instantiating an object
Pillars
Main themes
The 4 pillars of object-oriented programming theory:
- abstraction
- encapsulation
- inheritance
- polymorphism
Patterns
Main themes:
private
for instance properties and methods- getters and setters to provide public access for
private
properties, where desired - perform validation in setters
- always use those setters, even within the same class file
- overloaded methods and contructors provide multiple variants of the same action
static
for shared properties and methodsfinal
for values that never change- inheritance vs. composition
Strings
Main themes:
String
is a class in the Java API, not a fundamental primitive data type.- because different objects are stored at different locations in memory, compare the value of two
String
objects with its custom.equals()
method, not==
. String
is designed following the principle of object-oriented abstraction (e.g..length()
rather than.length
)- Encapsulated within every
String
is achar
array. - Because
String
has been designed to be immutable and quite limited, a variety of helper classes exist to work around that (e.g.StringBuilder
, Apache Commons Lang’sStringUtils
, etc)
Inheritance
Main themes:
- Child classes inherit properties and methods of parent classes, except…
private
properties and methods are not inherited…- …but
private
properties are still accessible via any inheritedpublic
getters and setters - constructors are not inherited, but are accessible via the
super
keyword
- use of the
super
keyword to refer to code belonging to the parent class
Polymorphism
Polymorphism goes hand-in-hand with inheritance.
- child objects can be considered to be of their parent class.
- e.g., if
B
inherits fromA
, then aB
object can be referred to as both aB
and anA
object. - can be useful when storing objects of a variety of child types into a single array typed as the parent type.
- that allows you to easily loop through them all.
typeof
operator allows you to check whether an object is of a given type.
Processing
Processing as a case study in inheritance:
- inheritance of many useful properties (e.g.
width
,height
,mouseX
,mouseY
) - inheritance of many useful methods (e.g.
ellipse()
,rect()
,image()
, etc) - inheritance of behaviors (e.g.
draw()
method magically called every 1/60th second,mouseX
andmouseY
automagically assigned the mouse position values) - abstraction: we don’t need to know how it works, just how to use it
- some poor quality design (e.g. we should not be able to directly access
width
,height
,mouseX
andmouseY
- we should be using getters)
This is Super
Main themes:
- the
this
keyword, when used within a method, refers to the object upon which that method was called. - you cannot use the
this
keyword within astatic
method, since that method can never be called on an object. - the
super
keyword, when used within a method, refers to code in the parent class. - a call to the parent class’s constructor can be added to a child class constructor, if useful (e.g.
super()
orsuper(someArgs)
Conclusions
- Thanks. Bye.