Compx201 20g Week 1
Compx201 20g Week 1
https://docs.oracle.com/en/java/javase/13/docs/api/index.html
Flow
String interning….
0
Structure
• Packages
• Classes/Interfaces
• Objects
• Is-A and Has-A relationships
• Overriding (Identity vs Equality)
OO Example
OO Example
Week One Content
• The Java Language
• Documentation
• Functions, Flow Control
• Identity vs Equality
• IO (Basic)
• Abstract Datatypes
• Inheritance
• References
• Arrays, Sets, Lists
• Intro to Testing
Scope and Access
• Scope
Scope and Access
• Scope
• Private, Protected, Public, Default
Scope and Access
• Scope
• Private, Protected, Public, Default
• Interface, Abstract, Concrete (Java 7)
• Abstract classes (mix implementation) vs interface signatures
• Abstract classes do not need to fulfil contracts
• Diamond Problem
Types: Primitives
• Primitives: • Conditional Operators:
• byte, short, int, long • ==, !=
• float, double • <, <=, >, >=
• char (unsigned short) • && || !
• Operations: • Default Values
• +, -, *, /, %
• =, +=, -=, *=, /=
• ++, --
• Casting
• Strings…kinda
Types: Reference Variables and Objects
• A reference variable holds the address of an object
• Any non-primitive is an object
• When declaring a reference variable without instantiating it, Java sets
the reference to the special value ‘null’.
Types: Polymorphism and Casting
0
Types: Generics
• Backed by an array.
• Variable Size (Grows as needed)
• Array qualities (Random Access, Efficient if index known)
• Can waste memory (generally requires reactive measures to avoid this: trimToSize())
• Generics and Polymorphism
• Commonly used functions: add(..), remove(int), remove(..), set(int, ..), clear(), isEmpty()
0
ArrayLists
LinkedLists
• Made up by connected ‘nodes’
• Variable Size (Grows as needed)
• Sequential access
• Generics and Polymorphism
• Cheap to operate at the ends and to add/remove
elements in the middle
• No ‘wasted’ memory, but does need extra pointers.
• Commonly used functions:
• add(..), add(int, ..), addFirst(..), addLast(..)
• Remove varients
• clear(), isEmpty()
LinkedList
0
Sets
• Various Implementations. More in Wk4, after first test.
• Only one of any Item
• When adding a Object to a set, equality is checked (.equals for objects). If
something is the same then the add function fails to add anything.
• Generics and Polymorphism
• Commonly used functions:
• add(..), remove(..), clear(), size()
• Note that there is no positions in a list so functions like add(int, ..) do not exist
Week One Content
• The Java Language
• Documentation
• Functions, Flow Control
• Identity vs Equality
• IO (Basic)
• Abstract Datatypes
• Inheritance
• References
• Arrays, Sets, Lists
• Intro to Testing
• Assignment Prep (Time Permitting)
Testing
• Building on this throughout the semester.
• Today = Mostly theory + an example.
White box
Assignment 1: Building + Testing a Linked List