Java Basics: Part 3 - Exceptions Manuel Oriol Throwable The - - PowerPoint PPT Presentation

java basics part 3 exceptions
SMART_READER_LITE
LIVE PREVIEW

Java Basics: Part 3 - Exceptions Manuel Oriol Throwable The - - PowerPoint PPT Presentation

Java Basics: Part 3 - Exceptions Manuel Oriol Throwable The Throwable interface is meant to represent computational events that can interrupt the current computation Computation can occur after the event is handled 84 Exception


slide-1
SLIDE 1

Java Basics: Part 3 - Exceptions

Manuel Oriol

slide-2
SLIDE 2

Throwable

  • The Throwable interface is meant to

represent computational events that can interrupt the current computation

  • Computation can occur after the event is

handled

84

slide-3
SLIDE 3

Exception

  • Exceptions represent events that are meant

to be treated.

  • Whenever a method may trigger an

exception, it is required that it declares so (modulo conformance). Except for RuntimeExceptions.

85

slide-4
SLIDE 4

Runtime Exceptions

AnnotationTypeMismatchException, ArithmeticException, ArrayStoreException, BufferOverflowException, BufferUnderflowException, CannotRedoException, CannotUndoException, ClassCastException, CMMException, ConcurrentModificationException, DOMException, EmptyStackException, EnumConstantNotPresentException, EventException, IllegalArgumentException, IllegalMonitorStateException, IllegalPathStateException, IllegalStateException, ImagingOpException, IncompleteAnnotationException, IndexOutOfBoundsException, JMRuntimeException, LSException, MalformedParameterizedTypeException, MissingResourceException, NegativeArraySizeException, NoSuchElementException, NullPointerException, ProfileDataException, ProviderException, RasterFormatException, RejectedExecutionException, SecurityException, SystemException, TypeNotPresentException, UndeclaredThrowableException, UnmodifiableSetException, UnsupportedOperationException ...

86

slide-5
SLIDE 5

Error

  • Meant to represent an unrecoverable error
  • Can be recovered still...
  • Example: AnnotationFormatError, AssertionError,

AWTError, CoderMalfunctionError, FactoryConfigurationError, LinkageError, ThreadDeath, TransformerFactoryConfigurationError, VirtualMachineError

87

slide-6
SLIDE 6

Throw, throws

  • it is possible to throw an exception manually

by using:

  • methods that may fail due to an exception

(non-runtime) have to indicate it:

88

slide-7
SLIDE 7

try...catch... finally

89

slide-8
SLIDE 8

Java Basics: Part 4 - Streams

Manuel Oriol

slide-9
SLIDE 9
  • Streams are useful to apply to different

inputs and outputs a single treatment with different results

  • Basically, receive and send bytes
  • Streams are responsible for handling the
  • uter part of the communication

91

Input Output data Stream

slide-10
SLIDE 10

Input Streams

  • InputStream regroup all objects that can

receive information

  • Can build readers on top of them, to handle

the inner part of the communication

  • InputStream API

92

slide-11
SLIDE 11

Output Stream

  • regroup all objects that can send information
  • can build filters around them
  • OutputStream API

93

slide-12
SLIDE 12

Example: PrintStream

  • System.out
  • overloaded print/println/printf methods
  • PrintStream API

note: printf is a variable arguments method...

94

slide-13
SLIDE 13

Variable Argument Methods

  • Arguments are automatically boxed into an

array (http://java.sun.com/developer/ JDCTechTips/2005/tt1018.html)

  • Similar to C

95

slide-14
SLIDE 14

Variable Arguments Methods Example

96

slide-15
SLIDE 15

Example: FileInputStream

  • Reads from an file
  • FileInputStream API

97

slide-16
SLIDE 16

Reader

  • For reading character streams...
  • BufferedReader
  • Reader API

String readline()

98

slide-17
SLIDE 17

System.out

  • is a PrintStream
  • can be changed (e.g. output in a file,

socket...)

  • by default is set to terminal/console output

99

slide-18
SLIDE 18

System.in

  • By default reads on the terminal/console
  • Can be changed
  • easier to build a BufferReader on it

100

slide-19
SLIDE 19

Using Streams for Keyboard Interactions

101

slide-20
SLIDE 20

Other Example: NoteTaker

102

slide-21
SLIDE 21

Basic Serialization

  • ObjectOutputStream
  • ObjectInputStream

103

slide-22
SLIDE 22

Example OOS/OIS

104

slide-23
SLIDE 23

Socket streams

  • SocketInputStream
  • SocketOutputStream

105

slide-24
SLIDE 24

Example Socket Streams

106

slide-25
SLIDE 25

Java Basics: Part 5 - Basic Swing

slide-26
SLIDE 26

Model/View/Controller?

http://heim.ifi.uio.no/~trygver/themes/mvc/mvc-

108

slide-27
SLIDE 27

Model

  • The model contains the application logic
  • The model is typically an independent

component

109

slide-28
SLIDE 28

View

  • This is the GUI itself
  • An element of the GUI is a widget (e.g.

menus, buttons, text fields...)

  • Show the information

110

slide-29
SLIDE 29

Controller

  • This is the part that treats users interactions
  • Controls the GUI to make it change when

needed

  • Controls the Model and changes it

111

slide-30
SLIDE 30

Example of Model

112

Your application code (e.g. calculator component or model

  • f whales travels)
slide-31
SLIDE 31

Examples of View Components (1/3)

  • JFrame:
  • creates a windows including a panel

(getContentPane())

  • has to be shown (setVisible(true))

113

slide-32
SLIDE 32

Examples of View Components (2/3)

  • JTable:
  • A table of panels
  • takes an AbstractTableModel (Model

component)

114

slide-33
SLIDE 33

Examples of View Components (3/3)

  • JButton
  • JTextField
  • JLabel

115

slide-34
SLIDE 34

Controller

  • ActionListener

116

slide-35
SLIDE 35

Java Basics: Part 6 - open questions

slide-36
SLIDE 36

Green Cards Results

  • DB + Java
  • Web Services,

XML

  • Ant and Eclipse
  • NetBeans
  • GUI

118

  • Networking
  • Threads and

Synchro

  • New in 5.0 and 6.0?
  • Secure Engineering

in Java

  • Patterns in Java
  • J2ME
  • Test Suites
  • J2EE + JMS
  • Eiffel vs Java
  • JavaBeans
slide-37
SLIDE 37

Green Cards Results

  • DB + Java
  • Web Services,

XML

  • Ant and Eclipse
  • NetBeans
  • GUI

119

  • Networking
  • Threads and

Synchro

  • New in 5.0 and 6.0?
  • Secure Engineering in

Java

  • Patterns in Java
  • J2ME
  • Test Suites
  • J2EE + JMS
  • Eiffel vs Java
  • JavaBeans
slide-38
SLIDE 38

Green Cards Results

  • DB + Java
  • Web Services,

XML

  • Ant and Eclipse
  • NetBeans
  • GUI

120

  • Networking
  • Threads and

Synchro

  • New in 5.0 and 6.0?
  • Secure Engineering in

Java

  • Patterns in Java
  • J2ME
  • Test Suites
  • J2EE & JMS
  • Eiffel vs Java
  • JavaBeans