PROGRAMACIÓN ORIENTADA A OBJETOS

Similar documents
CS 251 Intermediate Programming Java I/O Streams

Files and IO, Streams. JAVA Standard Edition

Object-Oriented Programming in the Java language

Input, Output and Exceptions. COMS W1007 Introduction to Computer Science. Christopher Conway 24 June 2003

IT101. File Input and Output

Sri Vidya College of Engineering & Technology Question Bank

File Operations in Java. File handling in java enables to read data from and write data to files

Simple Java Input/Output

Introduction Unit 4: Input, output and exceptions

Darshan Institute of Engineering & Technology for Diploma Studies

Object-Oriented Programming Design. Topic : Streams and Files

Lecture 11.1 I/O Streams

Chapter 4 Java I/O. X i a n g Z h a n g j a v a c o s q q. c o m

Java Input/Output. 11 April 2013 OSU CSE 1

C17: File I/O and Exception Handling

09-1. CSE 143 Java GREAT IDEAS IN COMPUTER SCIENCE. Overview. Data Representation. Representation of Primitive Java Types. Input and Output.

Java How to Program, 9/e. Copyright by Pearson Education, Inc. All Rights Reserved.

Core Java Contents. Duration: 25 Hours (1 Month)

Software 1 with Java. Recitation No. 9 (Java IO) December 10,

I/O in Java I/O streams vs. Reader/Writer. HW#3 due today Reading Assignment: Java tutorial on Basic I/O

תוכנה 1 תרגול 8 קלט/פלט רובי בוים ומתי שמרת

Objec&ves. Review. Standard Error Streams

Lecture 19 Programming Exceptions CSE11 Fall 2013

Chapter 10. File I/O. Copyright 2016 Pearson Inc. All rights reserved.

PIC 20A Streams and I/O

WOSO Source Code (Java)

Software 1 with Java. Recitation No. 7 (Java IO) May 29,

Basic Java IO Decorator pattern Advanced Java IO. Java IO - part 2 BIU OOP. BIU OOP Java IO - part 2

Example: Copying the contents of a file

Software 1. Java I/O

Lecture 22. Java Input/Output (I/O) Streams. Dr. Martin O Connor CA166

Object Oriented Design with UML and Java. PART VIII: Java IO

File IO. Computer Science and Engineering College of Engineering The Ohio State University. Lecture 20

Special error return Constructors do not have a return value What if method uses the full range of the return type?

COMP-202: Foundations of Programming. Lecture 22: File I/O Jackie Cheung, Winter 2015

COMP-202: Foundations of Programming. Lecture 12: Linked List, and File I/O Sandeep Manjanna, Summer 2015

Objec&ves STANDARD ERROR. Standard Error Streams. Ø Byte Streams Ø Text Streams 10/5/16. Oct 5, 2016 Sprenkle - CSCI209 1

Programming Languages and Techniques (CIS120)

Experiment No: Group B_4

Overview CSE 143. Input and Output. Streams. Other Possible Kinds of Stream Converters. Stream after Stream... CSE143 Wi

1.00 Lecture 30. Sending information to a Java program

HST 952. Computing for Biomedical Scientists Lecture 8

Agenda & Reading. Python Vs Java. COMPSCI 230 S Software Construction

Exceptions and Working with Files

Java Basics: Part 3 - Exceptions. Manuel Oriol

Streams and File I/O

Basic I/O - Stream. Java.io (stream based IO) Java.nio(Buffer and channel-based IO)

Character Stream : It provides a convenient means for handling input and output of characters.

Byte and Character Streams. Reading and Writing Console input and output

Exceptions Chapter 10. Instructor: Scott Kristjanson CMPT 125/125 SFU Burnaby, Fall 2013

C17: I/O Streams and File I/O

Overview CSE 143. Data Representation GREAT IDEAS IN COMPUTER SCIENCE. Representation of Primitive Java Types. CSE143 Au

Overview CSE 143. Data Representation GREAT IDEAS IN COMPUTER SCIENCE

COMP 213. Advanced Object-oriented Programming. Lecture 19. Input/Output

Overview CSE 143. Data Representation GREAT IDEAS IN COMPUTER SCIENCE. Representation of Primitive Java Types. CSE143 Sp

Streams and File I/O

File. Long term storage of large amounts of data Persistent data exists after termination of program Files stored on secondary storage devices

Overview CSE 143. Data Representation GREAT IDEAS IN COMPUTER SCIENCE

I/O Streams. Object-oriented programming

Here is a hierarchy of classes to deal with Input and Output streams.

Java Input/Output Streams


Active Learning: Streams

Lab 2: File Input and Output

Programming Languages and Techniques (CIS120)

F1 A Java program. Ch 1 in PPIJ. Introduction to the course. The computer and its workings The algorithm concept

CS5000: Foundations of Programming. Mingon Kang, PhD Computer Science, Kennesaw State University

CSCI 200 Lab 2 Inheritance, Polymorphism & Data Streams

pre-emptive non pre-emptive

Software 1. תרגול 9 Java I/O

Tirgul 1. Course Guidelines. Packages. Special requests. Inner classes. Inner classes - Example & Syntax

Java Input / Output. CSE 413, Autumn 2002 Programming Languages.

What is the purpose of exceptions and exception handling? Vocabulary: throw/raise and catch/handle Exception propagation Java checked and unchecked

Training topic: OCPJP (Oracle certified professional Java programmer) or SCJP (Sun certified Java programmer) Content and Objectives

CSC 1214: Object-Oriented Programming

Week 12. Streams and File I/O. Overview of Streams and File I/O Text File I/O

Course Content. Objectives of Lecture 22 File Input/Output. Outline of Lecture 22. CMPUT 102: File Input/Output Dr. Osmar R.

ITI Introduction to Computer Science II

File Input/Output. Introduction to Computer Science I. Overview (1): Overview (2): CSE 1020 Summer Bill Kapralos. Bill Kapralos.

Streams. Programação Orientada por Objetos (POO) Centro de Cálculo Instituto Superior de Engenharia de Lisboa

Programming Languages and Techniques (CIS120)

Programming Languages and Techniques (CIS120)

Data Structures. 03 Streams & File I/O

Starting Out with Java: From Control Structures Through Objects Sixth Edition

I/O STREAM (REQUIRED IN THE FINAL)

Chapter 10. IO Streams

Fundamentals of Object Oriented Programming

Algorithms. Produced by. Eamonn de Leastar

CSB541 Network Programming 網路程式設計. Ch.2 Streams 吳俊興國立高雄大學資訊工程學系

Programming Languages and Techniques (CIS120)

Dining philosophers (cont)

Compile error. 2. A run time error occurs when the program runs and is caused by a number of reasons, such as dividing by zero.

The Java I/O System. Binary I/O streams (ASCII, 8 bits) The decorator design pattern Character I/O streams (Unicode, 16 bits)

Virtualians.ning.pk. 2 - Java program code is compiled into form called 1. Machine code 2. native Code 3. Byte Code (From Lectuer # 2) 4.

PIC 20A Exceptions. Ernest Ryu UCLA Mathematics. Last edited: November 27, 2017

Software 1 with Java. The java.io package. Streams. Streams. Streams. InputStreams

Java file manipulations

Exceptions and I/O: sections Introductory Programming. Errors in programs. Exceptions

Introductory Programming Exceptions and I/O: sections

输 入输出相关类图. DataInput. DataOutput. java.lang.object. FileInputStream. FilterInputStream. FilterInputStream. FileOutputStream

Transcription:

PROGRAMACIÓN ORIENTADA A OBJETOS TEMA8: Excepciones y Entrada/Salida Manel Guerrero

Tipos de Excepciones Checked Exception: The classes that extend Throwable class except RuntimeException and Error are known as checked exceptions e.g.ioexception, SQLException etc. Checked exceptions are checked at compile-time. Unchecked Exception: The classes that extend RuntimeException are known as unchecked exceptions e.g. ArithmeticException, NullPointerException, ArrayIndexOutOfBoundsException etc. Unchecked exceptions are not checked at compile-time rather they are checked at runtime. Error: Error is irrecoverable e.g. OutOfMemoryError, VirtualMachineError, AssertionError etc. http://www.javatpoint.com/exception-handling-in-java

https://www3.ntu.edu.sg/home/ehchua/programming/java/j5a_exceptionassert.html

https://newcircle.com/bookshelf/java_fundamentals_tutorial/exceptions

Try-with-resources Try-with-resources closes the resources: Resource implements public interface AutoCloseable {...} and the catch invokes its only method: void close() throws Exception;

Entrada/Salida The java.io package contains nearly every class you might ever need to perform input and output (I/O) in Java. All these streams represent an input source and an output destination. The stream in the java.io package supports many data such as primitives, object, localized characters, etc. Stream: A stream can be defined as a sequence of data. InPutStream: The InputStream is used to read data from a source. OutPutStream: The OutputStream is used for writing data to a destination. https://www.tutorialspoint.com/java/java_files_io.htm

Byte Streams Java byte streams are used to perform input and output of 8-bit bytes. Though there are many classes related to byte streams but the most frequently used classes are, FileInputStream and FileOutputStream. Veure StreamBytesCopyFile.java i StreamBytesCopyFileV2.java

Byte Streams

Character Streams Java Byte streams are used to perform input and output of 8-bit bytes, whereas Java Character streams are used to perform input and output for 16-bit unicode. Though there are many classes related to character streams but the most frequently used classes are, FileReader and FileWriter. Though internally FileReader uses FileInputStream and FileWriter uses FileOutputStream but here the major difference is that FileReader reads two bytes at a time and FileWriter writes two bytes at a time. Veure StreamCharsCopyFile.java

Character Streams

Standard Streams Standard Input This is used to feed the data to user's program and usually a keyboard is used as standard input stream and represented as System.in. [STDIN in C] Standard Output This is used to output the data produced by the user's program and usually a computer screen is used for standard output stream and represented as System.out. [STDOUT in C] Standard Error This is used to output the error data produced by the user's program and usually a computer screen is used for standard error stream and represented as System.err. [STDERR in C] Veure StreamConsole.java

BufferedReader En la asignatura usamos BufferedReader (que se construye con un InputStreamReader) y que permite leer líneas de texto enteras. Aunque la clase Scanner (también se construye con un InputStreamReader) es más potente. http://beginnersbook.com/2014/01/how-to-readfile-in-java-using-bufferedreader/ Veure WithBufferedReader.java

PrintWriter En la asignatura usamos PrintWriter (que se construye con un FileOutputStreamr) para escribir en un fichero tipos primitivos y Strings. FileOutputStream fos = new FileOutputStream(nomFitxer); PrintWriter pw = new PrintWriter(fos); Luego podemos escribir en él con print() y println() o con write(). http://beginnersbook.com/2014/01/how-to-append-to-a-file-in-java/ http://stackoverflow.com/questions/32797719/printwriter-andfileoutputstream-in-java Veure WithPrintWriter.java (similar pero amb File(nomF)).

ObjectInputStream ObjectOutputStream Sirven para gravar objetos directamente (serializar/des-serializar). Se graba una copia profunda (versus copia superficial ): Los objetos referenciados por el objeto o por objetos referenciados por él también se graban. Esto lo veremos en el próximo tema.

Referencias https://www.tutorialspoint.com/java/java_exceptions.htm http://tutorials.jenkov.com/java-exception-handling/fail-safe-exceptionhandling.html http://www.javatpoint.com/exception-handling-in-java https://www.tutorialspoint.com/java/java_files_io.htm http://www3.ntu.edu.sg/home/ehchua/programming/java/j5b_io.html http://beginnersbook.com/2014/01/how-to-read-file-in-java-usingbufferedreader/ http://beginnersbook.com/2014/01/how-to-append-to-a-file-in-java/ http://stackoverflow.com/questions/32797719/printwriter-andfileoutputstream-in-java

PROGRAMACIÓN ORIENTADA A OBJETOS Pasemos a ver los códigos de W8.

PROGRAMACIÓN ORIENTADA A OBJETOS Preguntas