Comp1202: Conclusions Revision Session. Coming up Key Concepts - The Pillars HashMaps Exceptions The Exam Some Last Words.

Slides:



Advertisements
Similar presentations
Exceptions Chapter Throwing and Catching Exceptions When a program runs into a problem that it cannot handle, it throws an exception. Exceptions.
Advertisements

Exceptions: when things go wrong. Various sources of error public static doSomething() { int i = 3.0; while(!done); { int i = false } ) Syntactic errors.
Yoshi
CS 206 Introduction to Computer Science II 01 / 20 / 2009 Instructor: Michael Eckmann.
Problem Solving 5 Using Java API for Searching and Sorting Applications ICS-201 Introduction to Computing II Semester 071.
C++ Programming Languages
CIT 590 Intro to Programming Java lecture 3. Hashmaps The equivalent of python dictionaries. With both ArrayLists and Hashmaps, the syntax only allows.
CS 206 Introduction to Computer Science II 09 / 09 / 2009 Instructor: Michael Eckmann.
Mock test review Revision of Activity Diagrams for Loops,
16-Jun-15 Exceptions. Errors and Exceptions An error is a bug in your program dividing by zero going outside the bounds of an array trying to use a null.
J.43 ARRAYS  A Java array is an Object that holds an ordered collection of elements.  Components of an array can be primitive types or may reference.
Exceptions. Errors and Exceptions An error is a bug in your program –dividing by zero –going outside the bounds of an array –trying to use a null reference.
Perceptions of the Role of Feedback in Supporting 1 st Yr Learning Jon Scott, Ruth Bevan, Jo Badge & Alan Cann School of Biological Sciences.
COMP 14: Intro. to Intro. to Programming May 23, 2000 Nick Vallidis.
1 Lecture#8: EXCEPTION HANDLING Overview l What exceptions should be handled or thrown ? l The syntax of the try statement. l The semantics of the try.
A tour around Java General introduction to aspects of the language (these will be covered in more detail later) After this tour you should have a general.
Midterm Test Overview CS221 – 3/23/09. Test Curve Current median is a 71 or C- Median will be adjusted to an 81 or B- All test scores will be +10 on.
ITP © Ron Poet Lecture 1 1 IT Programming Introduction.
Comp1004: Introduction I Welcome!. Welcome to Programming Principles Dr. David Millard Dr. Julian Rathke Dr.
Peter Andreae Computer Science Victoria University of Wellington Copyright: Peter Andreae, Victoria University of Wellington Summary and Exam COMP 102.
COMP Introduction to Programming Yi Hong May 13, 2015.
Exceptions 1. Your computer takes exception Exceptions are errors in the logic of a program (run-time errors). Examples: Exception in thread “main” java.io.FileNotFoundException:
Methods and You. Up to this point, I have covered many different data types with you. Variables can be considered the nouns of an English sentence. If.
CSc 2310 Principles of Programming (Java) Dr. Xiaolin Hu.
CS 106 Introduction to Computer Science I 01 / 25 / 2010 Instructor: Michael Eckmann.
Prof. Matthew Hertz SH 1029F /
Hash Functions and the HashMap Class A Brief Overview On Green Marble John W. Benning.
Prof. Matthew Hertz WTC 207D /
IT253: Computer Organization Lecture 3: Memory and Bit Operations Tonga Institute of Higher Education.
CSCI 51 Introduction to Computer Science Dr. Joshua Stough January 20, 2009.
Exceptions Handling Exceptionally Sticky Problems.
Programming for Beginners Martin Nelson Elizabeth FitzGerald Lecture 11: Handling Errors; File Input/Output.
Some Other Collections: Bags, Sets, Queues and Maps COMP T2 Lecture 4 School of Engineering and Computer Science, Victoria University of Wellington.
Programming for Beginners Martin Nelson Elizabeth FitzGerald Lecture 15: More-Advanced Concepts.
Problem of the Day  Why are manhole covers round?
Question of the Day  A landscaper plants 5 rows of 4 trees each, but only uses 10 trees. How is this possible?
What/how do we care about a program? Robustness Correctness Efficiency (speed, space) 11/2/20151IT 179  Software Testing  Error Handling  Efficiency.
JAVA COURSE LESSON2 BY OMPUTER ENGINEEING ASSOCIATION.
Instructor: Alexander Stoytchev CprE 185: Intro to Problem Solving (using C)
Exceptions, cont’d. Factory Design Pattern COMP 401 Fall 2014 Lecture 12 9/30/2014.
VARIABLES Programmes work by manipulating data placed in memory. The data can be numbers, text, objects, pointers to other memory areas, and more besides.
Fall 2002CS 150: Intro. to Computing1 Streams and File I/O (That is, Input/Output) OR How you read data from files and write data to files.
1 Software Construction and Evolution - CSSE 375 Exception Handling – Chaining & Threading Steve Chenoweth Office: Moench Room F220 Phone: (812)
WEEK 2 Introduction to Java II CSE 252 Principles of Programming Languages LAB SECTION.
CS 106 Introduction to Computer Science I 01 / 22 / 2007 Instructor: Michael Eckmann.
ICS3U_FileIO.ppt File Input/Output (I/O)‏ ICS3U_FileIO.ppt File I/O Declare a file object File myFile = new File("billy.txt"); a file object whose name.
CS12230 Introduction to Programming Lecture 6-2 –Errors and Exceptions 1.
Chapter 8-Exception Handling/ Robust Programming.
(c) University of Washington10-1 CSC 143 Java Errors and Exceptions Reading: Ch. 15.
Exceptions Lecture 11 COMP 401, Fall /25/2014.
LECTURE 8: EXCEPTIONS CSC 212 – Data Structures. Error Handling Goals  What should we do when an error occurs?  Should alert system to the error  May.
Comp1004: Programming in Java I Variables - Primitives, Objects and Scope.
Exception Handling SWE 344 Internet Protocols & Client Server Programming.
David Evans CS201j: Engineering Software University of Virginia Computer Science Lecture 10: Programming Exceptionally.
Exception and Exception Handling. Exception An abnormal event that is likely to happen during program is execution Computer could run out of memory Calling.
Throw, Throws & Try-Catch Statements Explanations and Pictures from: Reference:
Exceptions and Error Handling. Exceptions Errors that occur during program execution We should try to ‘gracefully’ deal with the error Not like this.
Introduction to Exceptions in Java CS201, SW Development Methods.
1 Handling Errors and Exceptions Chapter 6. 2 Objectives You will be able to: 1. Use the try, catch, and finally statements to handle exceptions. 2. Raise.
Last Revision. Question1 Novice Java programmers often write code similar to, class C { public int x;... }... C[] a = new C[10]; for(int i = 0; i < a.length;
Comp1004: Environments The Java Library. Coming up Recap – Encapsulation – Constructors – Loops – Arrays – ArrayList – Iterators The Java Library – Implementation.
Coming up Implementation vs. Interface The Truth about variables Comparing strings HashMaps.
Comp1004: Conclusions Revision Session. Coming up Recap – The Basics – The Pillars – The Extras Feedback + Course Evaluation Structure of the Exam Some.
Comp1004: Introduction III Java. Content How Java Works: The JVM Writing a Class in Java – Class – Member Variables – Method – Statement Magic incantations.
Exceptions In this lecture:
Comp1202: Conclusions Revision Session.
Creating and Modifying Text part 2
Exceptions 10-Nov-18.
Comp1202: Introduction III
Comp1202: Introduction I Welcome!.
Presentation transcript:

Comp1202: Conclusions Revision Session

Coming up Key Concepts - The Pillars HashMaps Exceptions The Exam Some Last Words

The Three Pillars of OOP EncapsulationInheritancePolymorphism

HashMaps

Maps Maps are a collection type that map a key to a value put(“Alfie”,“407351”); and so on Memory Map: Name -> Phone number Alfie Jenny

Lookup Lookup is the act of supplying the key and having the value returned String num = myHashMap.get(“Alfie”); Memory myHashMap Alfie

Like a more generic array In an array you map an integer to an object –myarray[0] = “Plumber”; –System.out.println(“Job type “ + myarray[0]);

Like a more generic array In an array you map an integer to an object –myarray[0] = “Plumber”; –System.out.println(“Job type “ + myarray[0]); In a hashmap you map an object to an object E.g. String to String –myhashmap.put(“Andy”, “Plumber”); –System.out.println(“Job type “ + myhashmap.get(“Andy”));

Like a more generic array In an array you map an integer to an object –myarray[0] = “Plumber”; –System.out.println(“Job type “ + myarray[0]); In a hashmap you map an object to an object E.g. String to String –myhashmap.put(“Andy”, “Plumber”); –System.out.println(“Job type “ + myhashmap.get(“Andy”)); E.g. Names to Jobs –Name n = new Name(“Andy”, “English”); –Job j = new Job(“Plumber”, 25000); –myhashmap.put(n, j); –System.out.println(“Salary “ + myhashmap.get(n).getSalary());

Bringing it together… import java.util.HashMap; //code omitted HashMap marks; marks = new HashMap (); marks.put("Alice", 75); marks.put("Bob", 62); marks.put("Colin", 68); System.out.println("Bob got " + marks.get("Bob"));

Bringing it together… import java.util.HashMap; //code omitted HashMap marks; marks = new HashMap (); marks.put("Alice", 75); marks.put("Bob", 62); marks.put("Colin", 68); System.out.println("Bob got " + marks.get("Bob")); What is this?

Bringing it together… import java.util.HashMap; //code omitted HashMap marks; marks = new HashMap (); marks.put("Alice", 75); marks.put("Bob", 62); marks.put("Colin", 68); System.out.println("Bob got " + marks.get("Bob")); What is this? HashMap is a generic class, this means we should tell it what two types it maps together

Bringing it together… import java.util.HashMap; //code omitted HashMap marks; marks = new HashMap (); marks.put("Alice", 75); marks.put("Bob", 62); marks.put("Colin", 68); System.out.println("Bob got " + marks.get("Bob")); What is this? HashMap is a generic class, this means we should tell it what two types it maps together What is happening here?

Bringing it together… import java.util.HashMap; //code omitted HashMap marks; marks = new HashMap (); marks.put("Alice", 75); marks.put("Bob", 62); marks.put("Colin", 68); System.out.println("Bob got " + marks.get("Bob")); What is this? HashMap is a generic class, this means we should tell it what two types it maps together What is happening here? This is autoboxing – the ints are automatically turned into Integers for us

Bringing it together… import java.util.HashMap; //code omitted HashMap marks; marks = new HashMap (); marks.put("Alice", 75); marks.put("Bob", 62); marks.put("Colin", 68); System.out.println("Bob got " + marks.get("Bob")); What is this? HashMap is a generic class, this means we should tell it what two types it maps together What is happening here? This is autoboxing – the ints are automatically turned into Integers for us Which type of String comparison is being used?

Bringing it together… import java.util.HashMap; //code omitted HashMap marks; marks = new HashMap (); marks.put("Alice", 75); marks.put("Bob", 62); marks.put("Colin", 68); System.out.println("Bob got " + marks.get("Bob")); What is this? HashMap is a generic class, this means we should tell it what two types it maps together What is happening here? This is autoboxing – the ints are automatically turned into Integers for us Which type of String comparison is being used? Equality (not Identity). It is using the.equals method

Exceptions

Code that takes risks can throw Exceptions to show that something has gone wrong We can then catch that Exception and tidy up the mess try { //some code that might throw Exception throw new Exception (“Oops – cannot open file”); } catch (Exception e) { //code to run in case an Exception is thrown }

Exceptions Rather than catching an Exception you can pass it on down the call stack This allows the Exception to be handled at the best possible place But remember it must be caught somewhere!

public void processData(int data[]) { for(int i = 0; i < data.length; i++) { data[i] = processItem(data[i]); } public void processAllData() { processData(getPrimaryDataSet()); processData(getSecondaryDataSet()); } public static void main(String [] args) { processAllData(); } Exceptions Exceptions are objects that contain information about an error They are thrown by one bit of code And caught and handled by another

Exceptions Exceptions are objects that contain information about an error They are thrown by one bit of code And caught and handled by another public void processData(int data[]) { try { if(data == null) throw new Exception(“No Data to Process”); for(int i = 0; i < data.length; i++) { data[i] = processItem(data[i]); } catch(Exception e) { System.out.println(e); } public void processAllData() { processData(getPrimaryDataSet()); processData(getSecondaryDataSet()); } public static void main(String [] args) { processAllData(); }

Exceptions Exceptions are objects that contain information about an error They are thrown by one bit of code And caught and handled by another public void processData(int data[]) throws Exception { if(data == null) throw new Exception(“No Data to Process”); for(int i = 0; i < data.length; i++) { data[i] = processItem(data[i]); } public void processAllData() { try { processData(getPrimaryDataSet()); processData(getSecondaryDataSet()); } catch(Exception e) { System.out.println(e); } public static void main(String [] args) { processAllData(); }

Exceptions Exceptions are objects that contain information about an error They are thrown by one bit of code And caught and handled by another public void processData(int data[]) throws Exception { if(data == null) throw new Exception(“No Data to Process”); for(int i = 0; i < data.length; i++) { data[i] = processItem(data[i]); } public void processAllData () throws Exception { processData(getPrimaryDataSet()); processData(getSecondaryDataSet()); } public static void main(String [] args) { try { processAllData(); } catch(Exception e) { System.out.println(e); }

Exceptions Exceptions are objects that contain information about an error They are thrown by one bit of code And caught and handled by another public void processData(int data[]) throws Exception { if(data == null) throw new Exception(“No Data to Process”); for(int i = 0; i < data.length; i++) { data[i] = processItem(data[i]); } public void processAllData () throws Exception { try { processData(getPrimaryDataSet()); processData(getSecondaryDataSet()); } catch(Exception e) { resetDataSets(); throw e; } public static void main(String [] args) { try { processAllData(); } catch(Exception e) { System.out.println(e); }

Exceptions The Java API throws many different types of Exceptions You can catch them when something goes wrong (for example ArrayIndexOutOfBoun dsException) catch(Exception e) will catch all of them Next Semester you will see how to handle Exceptions in a more sophisticated way And to define your own! public void processData(int data[]) throws Exception { if(data == null) throw new Exception(“No Data to Process”); for(int i = 0; i < data.length; i++) { data[i] = processItem(data[i]); } public void processAllData () throws Exception { try { processData(getPrimaryDataSet()); processData(getSecondaryDataSet()); } catch(Exception e) { resetDataSets(); throw e; } public static void main(String [] args) { try { processAllData(); } catch(Exception e) { System.out.println(e); }

Exam

The Good News Three hour exam – so lots of time – held in one of the University lab rooms – done on a PC using the tools you are used to Open Book – you can take in textbooks and notes – you can access the web (e.g. look at help pages and/or the Java API)

The Bad News But it is still an Exam – No communication allowed (e.g. IM, Facebook, file sharing) – No pre-prepared solutions allowed – No de-compilers allowed Invigilators will be present to enforce the rules and make sure the machines and software are working properly – They cannot answer questions about your code!

The Questions There are three questions, you must try and answer all of them Question 1 (20%) – Is the easiest question – Explores your ability to read code and understand programming terms Question 2 (50%) – Is the main question – Explores your ability to write code and solve programming problems Question 3 (30%) – Is the advanced question – Explores your ability to understand a program design, write more advanced code and think creatively

Some advice Most people will not finish the whole exam – Do not worry – Stay calm – Start at the beginning – Complete as much as you can Be defensive – Read each question thoroughly before you start it – Save often – Submit your solutions as you go (via handin machine) Check out the past exam papers (under comp1004): –

Feedback

How was it for you? An online questionnaire will allow you to give anonymous feedback – We read and take notice of what you say! But are their any comments you want to make on: – lectures – courseworks – labs – space cadets or ground controllers – dojo What the best and worst things about the course?

Some Last Words

A Dirty Secret No matter how we teach you will mainly learn through practice! Programming is the single most important skill for a computer scientist or software engineer – Systematic thinking and problem solving – Abstraction and data modeling Did we mention that you need to practice?

PRACTICE! “I've often thought that sucking less every year is how humble programmers improve. You should be unhappy with code you wrote a year ago.” - Jeff Atwood, “I have no talent. What I do have is a lot of practice. And I am not talking about occasionally dabbling in Ruby on the weekends. I am talking about the kind of practice where I beat code that isn’t working into submission (though often times the code wins).” - John Nunemaker,

Best of Luck and Have Fun!