0% found this document useful (0 votes)
49 views37 pages

Compx201 20g Week 1

Uploaded by

jsingh482
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
49 views37 pages

Compx201 20g Week 1

Uploaded by

jsingh482
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 37

COMPX201-20G

Data Structures and Algorithms


Course Structure
• Lectures:
• Monday (K.G.06) 10am till midday.
• Tuesday (K.G.06), Wednesday (K.G.07), Thursday (K.G.06) 10am till 11am.
• Supervised Labs for working on assignments and asking questions on
course content. (R.G.06, Lab One)
• Monday, Wednesday midday till 2pm.
• Friday midday till 1pm.
• Moodle page: elearn.waikato.ac.nz/course/view.php?id=50486
• Course outline: paperoutlines.waikato.ac.nz/outline/COMPX201-
20G%20(HAM)
Course Structure: Assessment
• 100% Internally Assessed, no final exam.
• Four assignments worth 15% each. First handed out on Tuesday 17th
November. Due one week after handed out.
• Two in-class tests worth 20% each. Keep an eye on Moodle for more
info closer to the time.
• Assignments must be written to run on Linux machines in Lab 1
Plagiarism
Assignments are individual. Suspected cases of
plagiarism will be forwarded up the chain.
Examples of plagiarism include:
• Copying another student’s solution in
part or in whole.
• Providing your solution to another student.
• Using code from another source without acknowledging it.
• Actively advertising/attempting to source complete solutions from
the internet.
Ask for help when you need it.
Tools
• Eclipse, IntelliJ, Text Editors, Linux Lab
• Java Language
• Java Language API: https://docs.oracle.com/javase/7/docs/api/
• Remote access. PuTTY, Xming, Bitvise.
• ssh [email protected] (50-115)
• ssh [email protected] (90-141)
• Java API
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
Hello World
Running Java Code
javac
Java
arguments

https://docs.oracle.com/en/java/javase/13/docs/api/index.html
Flow

Also do..While loops


Identity vs Equality

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

More on this tomorrow!


Exceptions: Exception and Subclasses
• Two kinds of Exceptions in Java:
• Runtime exceptions and checked exceptions
• Checked exceptions must be handled.
• A ‘try’ block encloses code that might generate an exception.
• A ‘catch’ block processes the exception.
• A ‘finally’ block is executed regardless of if an exception actually happens.
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
Arrays

• Fixed Size (Declared on initialisation)


• Random Access
• Very efficient if you know the index of thing element in question
• Can waste memory (if you reserve but do not use)
ArrayLists

• 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.

• Everyone knows that software will inevitably contain errors or


mistakes (faults).
• Software does not fail randomly or degrade with age, so all faults are
systematic and due to poor design, implementation, etc.
• Any faults are our fault!
• Due to complexity of most software, exhaustive testing is impossible
(other than in the most trivial cases).
Testing
• Types of faults include:
• Specification faults
• Programming (logic) faults
• Errors in calculations
• Overflows/underflows (stacks, buffers, etc.)
• Use of uninitialized values
• “Program testing can be used to show the presence of bugs, but
never to show their absence!” – Edsger Dijkstra
• In other words, a successful test is one that finds an error. A test that does
not find a error tells us very little.
Black box Testing
• Uses the requirements to find faults.
• No access to internals of unit being tested. Allows complete de-
coupling between developer and tester.
• “If I call function X with arguments Y then I should get output Z (and
side effects A)”
White box Testing
• Uses the structure of code to find faults
• Tester has knowledge of internals of the unit being tested. This can
assist with deciding what elements should be focused on when
testing.
• “I can see from the code that if the first parameter is null, the
function always returns X, that cuts down on the combinations I need
to test.”
Other Testing
• Acceptance Testing. “Does the customer accept how the software
works?”
• Regression Testing. “Do all existing tests still pass? If not, a
regression has occurred and I need to monitor this issue in the
future.”
• Usability Testing. “How easy is this software for the intended users to
use? Does it suit their needs?”
Writing tests
• Before, During and After Implementation.
• Testing only after implementation risks:
• Having to remember ‘what this code does’ months after it was written
• Downstream changes resulting from tweaks to code
• Be conscience of the fact you are testing code that you wrote (when
you are).
• Pair programming
• Independent Testers
• TDD
Unit Testing
• Test the smallest testable units of the program. Each
method/function of a class.
Black box

White box
Assignment 1: Building + Testing a Linked List

You might also like