java basics part 3 exceptions
play

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


  1. Java Basics: Part 3 - Exceptions Manuel Oriol

  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

  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

  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

  5. Error • Meant to represent an unrecoverable error • Can be recovered still... • Example: AnnotationFormatError, AssertionError, AWTError, CoderMalfunctionError, FactoryConfigurationError, LinkageError, ThreadDeath, TransformerFactoryConfigurationError, VirtualMachineError 87

  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

  7. try...catch... finally 89

  8. Java Basics: Part 4 - Streams Manuel Oriol

  9. data Stream Input Output • 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 outer part of the communication 91

  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

  11. Output Stream • regroup all objects that can send information • can build filters around them • OutputStream API 93

  12. Example: PrintStream • System.out • overloaded print/println/printf methods • PrintStream API note: printf is a variable arguments method... 94

  13. Variable Argument Methods • Arguments are automatically boxed into an array (http://java.sun.com/developer/ JDCTechTips/2005/tt1018.html) • Similar to C 95

  14. Variable Arguments Methods Example 96

  15. Example: FileInputStream • Reads from an file • FileInputStream API 97

  16. Reader • For reading character streams... • BufferedReader • Reader API String readline() 98

  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

  18. System.in • By default reads on the terminal/console • Can be changed • easier to build a BufferReader on it 100

  19. Using Streams for Keyboard Interactions 101

  20. Other Example: NoteTaker 102

  21. Basic Serialization • ObjectOutputStream • ObjectInputStream 103

  22. Example OOS/OIS 104

  23. Socket streams • SocketInputStream • SocketOutputStream 105

  24. Example Socket Streams 106

  25. Java Basics: Part 5 - Basic Swing

  26. Model/View/Controller? http://heim.ifi.uio.no/~trygver/themes/mvc/mvc- 108

  27. Model • The model contains the application logic • The model is typically an independent component 109

  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

  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

  30. Example of Model Your application code (e.g. calculator component or model of whales travels) 112

  31. Examples of View Components (1/3) • JFrame: • creates a windows including a panel (getContentPane()) • has to be shown (setVisible(true)) 113

  32. Examples of View Components (2/3) • JTable: • A table of panels • takes an AbstractTableModel (Model component) 114

  33. Examples of View Components (3/3) • JButton • JTextField • JLabel 115

  34. Controller • ActionListener 116

  35. Java Basics: Part 6 - open questions

  36. Green Cards Results • Networking • DB + Java • J2ME • Threads and • Web Services, • Test Suites Synchro XML • J2EE + JMS • New in 5.0 and 6.0? • Ant and Eclipse • Eiffel vs Java • Secure Engineering • NetBeans • JavaBeans in Java • GUI • Patterns in Java 118

  37. Green Cards Results • J2ME • Networking • DB + Java • Threads and • Test Suites • Web Services, Synchro • J2EE + JMS XML • New in 5.0 and 6.0? • Eiffel vs Java • Ant and Eclipse • Secure Engineering in • JavaBeans • NetBeans Java • GUI • Patterns in Java 119

  38. Green Cards Results • Networking • DB + Java • J2ME • Threads and • Web Services, • Test Suites Synchro • XML J2EE & JMS • New in 5.0 and 6.0? • • Ant and Eclipse Eiffel vs Java • Secure Engineering in • JavaBeans • NetBeans Java • GUI • Patterns in Java 120

Recommend


More recommend