Computer Science Introductory Course MSc - Introduction to Java

Similar documents
Computer Science Introductory Course MSc - Introduction to Java

Lists, Stacks, and Queues (plus Priority Queues)

Introduction to functions

MI-RUB Exceptions Lecture 7

Android Services. Lecture 4. Operating Systems Practical. 26 October 2016

Design Patterns and Refactoring

Voortgezet Programmeren

Compiling Techniques

Introduction to Computing II (ITI1121) FINAL EXAMINATION

Introduction to Computing II (ITI 1121) FINAL EXAMINATION

Stacks. Definitions Operations Implementation (Arrays and Linked Lists) Applications (system stack, expression evaluation) Data Structures 1 Stacks

CS-140 Fall 2017 Test 1 Version Practice Practice for Nov. 20, Name:

Activities, Fragments and Intents

An Exploratory Study of the Design Impact of Language Features for Aspect-oriented Interfaces

Introduction to Computing II (ITI 1121) FINAL EXAMINATION

Outline Resource Introduction Usage Testing Exercises. Linked Lists COMP SCI / SFWR ENG 2S03. Department of Computing and Software McMaster University

Softwaretechnik. Lecture 13: Design by Contract. Peter Thiemann University of Freiburg, Germany

Softwaretechnik. Lecture 13: Design by Contract. Peter Thiemann University of Freiburg, Germany

MURA Office hours Thurs at 12-1pm in CIT 546 Contact for more info.

A Java introduction SDK, FC 15/12/2009 UMR AMAP. SDK, FC (UMR AMAP) A Java introduction 15/12/ / 50

Course Announcements. John Jannotti (cs32) Scope, Collections & Generics Feb 8, / 1

Modern Functional Programming and Actors With Scala and Akka

Techniques of Java Programming

Object Oriented Programming for Python

Extensibility Patterns: Extension Access

1 Trees. Listing 1: Node with two child reference. public class ptwochildnode { protected Object data ; protected ptwochildnode l e f t, r i g h t ;

CS 6110 Lecture 28 Subtype Polymorphism 3 April 2013 Lecturer: Andrew Myers

Design of Mutant Operators for the AspectJ Language. Fabiano Cutigi Ferrari. Awais Rashid. José Carlos Maldonado

Java Programming. Final Examination on December 13, 2015 Fall 2015

Algebraic Dynamic Programming

13 Concurrent Programming using Tasks and Services

Outline. PeerSim: Informal introduction. Resources. What is PeerSim? Alberto Montresor Gianluca Ciccarelli

Speculative Parallelism in Cilk++

COMP 204. Exceptions continued. Yue Li based on material from Mathieu Blanchette, Carlos Oliver Gonzalez and Christopher Cameron

SFWR ENG 3S03: Software Testing

Go Tutorial. Ian Lance Taylor. Introduction. Why? Language. Go Tutorial. Ian Lance Taylor. GCC Summit, October 27, 2010

Basic Java OOP 10/12/2015. Department of Computer Science & Information Engineering. National Taiwan University

Solving Linear Equations - Absolute Value

Cryptographical Security in the Quantum Random Oracle Model

Typed MSR: Syntax and Examples

INF Models of concurrency

Information System Design IT60105

Parallelization of the QC-lib Quantum Computer Simulator Library

Outline Resource Introduction Usage Testing Exercises. Linked Lists COMP SCI / SFWR ENG 2S03. Department of Computing and Software McMaster University

Standard(s): 2.5 TA: Independence Level: % Assistance, coaching, prompting:

Comp 11 Lectures. Dr. Mike Shah. August 9, Tufts University. Dr. Mike Shah (Tufts University) Comp 11 Lectures August 9, / 34

SideNail. Martín Schonaker, Santiago Martínez

Compiling Techniques

MSR by Examples. Iliano Cervesato. ITT Industries, NRL Washington DC.

CMSC 132, Object-Oriented Programming II Summer Lecture 11:

Tou has been released!

Abstract Specification of Crypto- Protocols and their Attack Models in MSR

Programming Languages Fall 2013

MODELING IN XCOS USING MODELICA

ITI Introduction to Computing II

Choosing among models

Android Security Mechanisms

MSR by Examples. Iliano Cervesato. ITT Industries, NRL Washington DC.

N-CN Complex Cube and Fourth Roots of 1

Project # Embedded System Engineering

Analytical Modeling of Parallel Programs. S. Oliveira

Lecture Overview SSA Maximal SSA Semipruned SSA o Placing -functions o Renaming Translation out of SSA Using SSA: Sparse Simple Constant Propagation

Factory method - Increasing the reusability at the cost of understandability

Sharing Objects. Pieter van den Hombergh. Fontys Hogeschool voor Techniek en Logistiek. February 15, 2017

Current and Resistance

Introduction to Algorithmic Complexity. D. Thiebaut CSC212 Fall 2014

1 import java. u t i l. ArrayList ; 2 import java. u t i l. L i s t ; 4 /

Software Engineering

Agile modeling for INF5150

CS Exam 3 Study Guide and Practice Exam

ITI Introduction to Computing II

Usability Extensions for the Worklet Service

CMSC 313 Lecture 16 Announcement: no office hours today. Good-bye Assembly Language Programming Overview of second half on Digital Logic DigSim Demo

Testability. Shaahin Hessabi. Sharif University of Technology. Adapted from the presentation prepared by book authors.

Vectors. Representations: Vectors. Instructor s Guide. Table of Contents

AlgAE (Algorithm Animation Engine) Reference Manual Version 3.0. Steven J. Zeil Old Dominion University Dept. of Computer Science

Python. chrysn

SDS developer guide. Develop distributed and parallel applications in Java. Nathanaël Cottin. version

Projectile Motion Slide 1/16. Projectile Motion. Fall Semester. Parallel Computing

Vectors. Representations: Vectors. Instructor s Guide. Table of Contents

Introduction to ASM - ByteCode Manipulating Tool

Microcontroller VU

Project 3: Hadoop Blast Cloud Computing Spring 2017

From rest, a rock is dropped and falls for 3.0 seconds before hitting the ground. What is its velocity right before it hits the ground?

Systems of Equations - Addition/Elimination

Class versus Instance (Section 5.1)

CS-140 Fall 2018 Test 2 Version Practice Nov. 12, Name:

Scheduling of Concurrent Reactive Objects for Embedded Real-Time Systems

Tools for Feature Extraction: Exploring essentia

Programming Languages and Types

Examples of Dynamic Binding in.net

An Introduction to Z3

Solution suggestions for examination of Logic, Algorithms and Data Structures,

Lecture VII Part 2: Syntactic Analysis Bottom-up Parsing: LR Parsing. Prof. Bodik CS Berkley University 1

Today s Lecture. Lecture 4: Formal SE. Some Important Points. Formal Software Engineering. Introduction to Formal Software Engineering

Comp 11 Lectures. Mike Shah. July 26, Tufts University. Mike Shah (Tufts University) Comp 11 Lectures July 26, / 40

Parallel Lines, Transversals, and Angle Relationships

Introduction to Programming (Java) 3/12

JSCL: a Middleware for Service Coordination

GlobalExistenceandUniquenessoftheWeakSolutioninKellerSegelModel

Transcription:

Computer Science Introductory Course MSc - Introduction to Java Lecture 3:,, Pablo Oliveira <pablo@sifflez.org> ENST Outline 1 2 3

Definition An exception is an event that indicates an abnormal condition disrupting the normal flow of the program. Exception is a subclass of java.lang.throwable. When an exception is thrown the program is interrupted, the exception is propagated rewinding the call stack until an appropriate exception handler is found. Creating and throwing an Exception c l a s s MyException extends E x c e p t i o n { MyException ( ) { MyException ( S t r i n g message ) { throw new MyException ( ) ;

Catching an Exception t r y { // code that can throw an e x c e p t i o n catch ( MyException1 e ) { // treatment i n c a s e o f Exception1 catch ( MyException2 e ) { // treatment i n c a s e o f Exception2 f i n a l l y { // always execute at the end o f the t r y block finally is optional. Exception rules If a method is thrown inside a method, one these two must be true : the exception is catched inside a try/catch block. the method is declared to throw the exception (using keyword throws) One can throw an exception inside a catch block. One can catch a group of exceptions using an Exception superclass.

Example c l a s s Example { void f o o ( ) throws MyException { t r y { throw new MyException ( ) ; catch ( MyException e ) { throw e ; void bar ( ) { t r y { f o o ( ) ; catch ( E x c e p t i o n e ) { System. out. p r i n t l n ( Problem! ) ; Outline 1 2 3

Definition are a way of instantiating classes or calling methods with a variable type paramater. This allows to remove unnecessary casts and make safer code, because the compiler knows which type he is supposed to work with and thus can generate the appropriate checks. List without generics Q : We want to implement a list of objects? c l a s s L i s t { p r i v a t e s t a t i c f i n a l i n t maxsize = 1 0 0 ; p r i v a t e i n t l a s t = 0 ; p r i v a t e Object l i s t [ ] ; L i s t ( ) { l i s t = new Object [ maxsize ] ; void add ( Object o ) throws E x c e p t i o n { i f ( l a s t >= maxsize ) throw new E x c e p t i o n ( no p l a c e l e f t ) ; l i s t [ l a s t ++] = o ; Object g e t ( i n t i n d e x ) { r e t u r n l i s t [ i n d e x ] ; L i s t l = new L i s t ( ) ; l. add ( H e l l o ) ; S t r i n g s = ( S t r i n g ) l. g e t ( 0 ) ; I n t e g e r i = ( I n t e g e r ) l. g e t ( 0 ) ; // e r r o r at runtime!

List with generics c l a s s L i s t <T> { p r i v a t e s t a t i c f i n a l maxsize = 1 0 0 ; p r i v a t e i n t l a s t = 0 ; p r i v a t e T l i s t [ ] ; L i s t ( ) { l i s t = (T [ ] ) new Object [ maxsize ] ; void add (T o ) throws E x c e p t i o n { i f ( l a s t >= maxsize ) throw new E x c e p t i o n ( no p l a c e l e f t ) ; l i s t [ l a s t ++] = o ; T g e t ( i n t i n d e x ) { r e t u r n l i s t [ i n d e x ] ; L i s t <S t r i n g > l = new L i s t <S t r i n g >(); l. add ( H e l l o ) ; S t r i n g s = l. g e t ( 0 ) ; I n t e g e r i = l. g e t ( 0 ) ; // d e t e c t e d at compile time! Generic methods and constructors c l a s s Example { <T> Example (T something ) { <T> void f o o (T something ) { Example e = new Example ( H e l l o ) ; // type i n f e r e n c e, e. f o o (new I n t e g e r ( 3 ) ) ; //no need to pass <>

Outline 1 2 3 Definition framework is a group of classes in java libraries which eases the manipulation of group of objects. All the classes in the collection framework implement the Collection interface. The collection framework provides List, Set, Queue, Map, etc... The collection classes can be provided with a generic type!

Example L i s t <S t r i n g > mylist = new A r r a y L i s t <S t r i n g >(); mylist. add ( H e l l o ) ; mylist. add ( Bye ) ; mylist. g e t ( 1 ) ; j a v a. u t i l. C o l l e c t i o n. s o r t ( mylist ) ; The for-each control construct L i s t <S t r i n g > mylist = new A r r a y L i s t <S t r i n g >(); f o r ( S t r i n g s : mylist ) { System. out. p r i n t l n ( s ) ;

This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License.