Basic Java IO Decorator pattern Advanced Java IO. Java IO - part 2 BIU OOP. BIU OOP Java IO - part 2
|
|
- Claribel Walker
- 6 years ago
- Views:
Transcription
1 Java IO - part 2 BIU OOP
2 Table of contents 1 Basic Java IO What do we know so far? What s next? 2 Example Overview General structure 3 Stream Decorators Serialization
3 What do we know so far? What s next? What do we know so far? Everything is based on the concept of streams. The basic Java streams work with chunks of type byte. We have separate classes for input and output stream.
4 What do we know so far? What s next? What do we know so far? (2) Java doesn t force us to work in binary, we can use wrappers for extended functionality: We can wrap the streams to get more useful chunks. InputStreamReader & OutputStreamWriter to work with characters instead of bytes.
5 What do we know so far? What s next? What do we know so far? (2) Java doesn t force us to work in binary, we can use wrappers for extended functionality: We can wrap the streams to get more useful chunks. InputStreamReader & OutputStreamWriter to work with characters instead of bytes. We can wrap the streams to get more useful methods. BufferedReader & PrintWriter to get readline() & printf(...)
6 What do we know so far? What s next? What do we know so far? (3) What basic Java streams have we seen? Input streams: FileInputStream - a stream that reads data from a file. System.in - holds a stream object (of unknown class) connected to the Standard Input.
7 What do we know so far? What s next? What do we know so far? (3) What basic Java streams have we seen? Input streams: FileInputStream - a stream that reads data from a file. System.in - holds a stream object (of unknown class) connected to the Standard Input. Output streams: FileOutputStream - a stream that writes data to a file. System.out/System.err - holds a PrintStream object connected to the Standard Output/Error.
8 What do we know so far? What s next? What do we know so far? (3) What basic Java streams have we seen? Input streams: FileInputStream - a stream that reads data from a file. System.in - holds a stream object (of unknown class) connected to the Standard Input. Output streams: FileOutputStream - a stream that writes data to a file. System.out/System.err - holds a PrintStream object connected to the Standard Output/Error. Note Although System.out/System.err hold streams that are already wrapped, they still have the original write() methods to write bytes if we desire.
9 What do we know so far? What s next? What s next? We re still missing some details. To understand these details we need to learn a new design pattern first!
10 Example Overview General structure Decorator Design pattern
11 Example Overview General structure Example - Requirements What do we want to implement? We want the ability to draw/interact with circles. Every circle can have any subset of following behaviours: Have a filling of some color. Have the center point drawn. Have the coordinates drawn near the center. Easily moved in four directions (up, down, left, right). Return from the other direction if it exits the screen. Let s see the final outcome: decorators/main.java
12 Example Overview General structure Example - Possible solutions How can we implement the requirements?
13 Example Overview General structure Example - Possible solutions How can we implement the requirements? Single class?
14 Example Overview General structure Example - Possible solution (Single class) 1 public class Circle { 2 3 // drawing 4 public void drawon ( DrawSurface ds) {...} 5 6 // moving 7 public void moveleft () {...} 8 public void moveup () {...} 9 public void movedown () {...} 10 public void moveright () {...} // configuration 13 public void drawfill ( boolean value ) {...} 14 public void drawcenter ( boolean value ) {...} 15 public void drawcoordinates ( boolean value ) {...} 16 public void shouldreturn ( boolean value ) {...} 17 }
15 Example Overview General structure Example - Possible solution (Single class) 1 public class Circle { 2 3 // drawing 4 public void drawon ( DrawSurface ds) {...} 5 6 // moving 7 public void moveleft () {...} 8 public void moveup () {...} 9 public void movedown () {...} 10 public void moveright () {...} // configuration 13 public void drawfill ( boolean value ) {...} 14 public void drawcenter ( boolean value ) {...} 15 public void drawcoordinates ( boolean value ) {...} 16 public void shouldreturn ( boolean value ) {...} 17 } Drawbacks: Many lines of code in a single class - will be hard to maintain/debug. Violates the single responsibility design principle.
16 Example Overview General structure Example - Possible solutions How can we implement the requirements? Single class Inheritance with many classes?
17 Example Overview General structure Example - Possible solution (Inheritance)
18 Example Overview General structure Example - Possible solution (Inheritance) Drawbacks: How do we even decide who inherits from whom? No clear is a kind of relationship exists. We will end up with 2 5 number of classes. How will we name our classes?
19 Example Overview General structure Example - Possible solutions How can we implement the requirements? Single class Inheritance with many classes to the rescue!
20 Example Overview General structure - Overview Features Provide a flexible alternative to subclassing for extending behaviour. Extend class behaviour at run time, as opposed to inheritance that extends behaviour at compile time. Linear number of classes to the number of behaviours. Allows different combinations of behaviours.
21 Example Overview General structure - Class diagram Things to notice Decorator holds a reference to the decorated object Each decorator exposes the same interface as the object it decorates Abstract decorator implements the default behaviour of passing the message to the decorated object
22 Example Overview General structure - Class diagram Things to notice Decorator holds a reference to the decorated object Each decorator exposes the same interface as the object it decorates Abstract decorator implements the default behaviour of passing the message to the decorated object What we gain from this? We can call the implementation of the decorated object from the decorators implemenation We can decorate an already decorated object and add an additional behaviour (multiple times) No need to implement what the decorators does not wish to extend
23 Example Overview General structure Example - Solution (Decorator Pattern Class Diagram)
24 Example Overview General structure Example - Solution (Combination of Behaviours)
25 Example Overview General structure Example - Implementation See full code example under package decorators
26 Example Overview General structure - Summary We had an implementation problem, involving circles that needed many different behaviour combinations. We saw that inheritance was not a good fit to solve our problem. We solved the problem with the, a very flexible and elegant alternative to inheritance. The core mechanism of the pattern is to wrap around an interface, add behaviour, and expose the same interface.
27 Stream Decorators Serialization Java IO Stream Decorators
28 Stream Decorators Serialization Stream Decorators - Overview InputStream and OutputStream are the base classes. FileInputStream and FileOutputStream are just one example of the concrete implementations that exist. We can add behaviour to the streams with the help of Decorators.
29 Stream Decorators Serialization OutputStream - Class diagram
30 Stream Decorators Serialization OutputStream compression example Writing bytes to a file (and compressing at the same time): 1 OutputStream os = null ; 2 try { 3 os = new GZipOutputStream (new FileOutputStream (" somefile.bin.gz")); 4 5 for ( int i = 0; i < 100; i+= 1) { 6 os. write (i); 7 } 8 } catch ( IOException e) { 9 System.out. println (" Something went wrong while writing!"); 10 } finally { 11 if(os!= null ){ // Exception might have happened at constructor 12 try { 13 os. close (); 14 } catch ( IOException e) { 15 System.out. println (" Failed closing the file!"); 16 } 17 } 18 } Note Decorate the stream to write with compression (How easy is that?)
31 Stream Decorators Serialization OutputStream compression example (with text) Writing text to a file (and compressing at the same time): 1 OutputStreamWriter os = null ; 2 try { 3 os = new OutputStreamWriter ( 4 new GZipOutputStream ( 5 new FileOutputStream (" somefile.txt.gz"))); 6 7 os. write (" Hello World "); 8 9 } catch ( IOException e) { 10 System.out. println (" Something went wrong while writing!"); 11 } finally { 12 if(os!= null ){ // Exception might have happened at constructor 13 try { 14 os. close (); 15 } catch ( IOException e) { 16 System.out. println (" Failed closing the file!"); 17 } 18 } 19 } Note GZipOutputStream is also a type of OutputStream
32 Stream Decorators Serialization InputStream - Class diagram
33 Stream Decorators Serialization InputStream compression example Reading bytes from a compressed file: 1 InputStream is = null ; 2 try { 3 is = new GZipInputStream (new FileInputStream (" somefile.bin.gz")); 4 5 int readbyte ; 6 while (( readbyte = is.read ())!= -1){ // -1 -> no more data in the stream 7 System.out. print ( readbyte ); 8 } 9 } catch ( IOException e) { 10 System.out. println (" Something went wrong while reading!"); 11 } finally { 12 if(is!= null ){ // Exception might have happened at constructor 13 try { 14 is. close (); 15 } catch ( IOException e) { 16 System.out. println (" Failed closing the file!"); 17 } 18 } 19 } Note Decorate the stream to read compression (How easy is that?).
34 Stream Decorators Serialization InputStream compression example Reading text from a compressed file: 1 BufferedReader is = null ; 2 try { 3 is = new BufferedReader ( 4 new InputStreamReader ( 5 new GZipInputStream ( 6 new FileInputStream (" somefile.txt.gz")))); 7 8 System.out. print (is. readline ()); 9 10 } catch ( IOException e) { 11 System.out. println (" Something went wrong while reading!"); 12 } finally { 13 if(is!= null ){ // Exception might have happened at constructor 14 try { 15 is. close (); 16 } catch ( IOException e) { 17 System.out. println (" Failed closing the file!"); 18 } 19 } 20 } Note GZipInputStream is a type of InputStream
35 Stream Decorators Serialization Stream Decorators - Summary We ve seen another example of the Decorator Pattern Java IO extracts common concerns such as compression and encryption into appropriate Decorators. Each concern has two symmetric implementations, one for input and one for output. We saw how we can compress any stream with the GZipOutputStream Because GZipOutputStream is still an OutputStream, we were able to wrap it again with OutputStreamWriter, extending the stream with the ability to write characters.
36 Stream Decorators Serialization Java IO Serialization
37 Stream Decorators Serialization Serialization Overview We ve seen how the basic streams work with byte chunks. We ve seen how we can convert the streams to use character chunks with the use of Reader/Writer wrappers. We will now see that we can also convert the streams to use Object chunks with new types of wrappers.
38 Stream Decorators Serialization Preparing classes for serialization We would like to be able to serialize an object of type Person. Serialization refers to encoding all the data in Person (not the code). Part of Person data is inside two inner objects: Address & CreditCardInfo. Can we just serialize it? No.
39 Stream Decorators Serialization Preparing classes for serialization (2) Serialization works on primitive data types. If the type is not primitive, it must implement the Serializable interface. Serializable interface has no methods, it s just a way to mark a class that it s safe to serialize. So can we now serialize Person? Still No.
40 Stream Decorators Serialization Preparing classes for serialization (3) Serialization is a recursive process, while trying to serialize Person it will need to serialize the Address. What about String? Lucky for us most basic classes in Java already implement Serializable. So can we now serialize Person? Yes.
41 Stream Decorators Serialization Controlling what will be serialized Sometimes we want to not serialize specific field members: The data may be too sensitive (credit card number). We may contain a class that is not Serializable (and we can t change it) but we still want to be serialized without it. We can use a new keyword: transient on field members to achieve this.
42 Stream Decorators Serialization Controlling what will be serialized - example 8 public class CreditCardInfo implements Serializable { 9 10 // regular information 11 private String lastfourdigits ; 12 private String cardholdername ; // sensitive information 15 private transient String cardnumber ; 16 private transient String cardsecuritycode ; } We mark the class as Serializable. We omit the sensitive information field members for security. Only lastfourdigits & cardholderinfo will be serialized.
43 Stream Decorators Serialization Serializing objects into/from streams Similar to InputStreamReader & OutputStremWriter wrappers, we will use: ObjectInputStream - adds the method readobject() ObjectOutputStream - adds the method writeobject(...) A binary data format is used to encode the data in the objects. It s common practice to use the file extension of.ser for files that contain Java serialized objects.
44 Stream Decorators Serialization Example - Implementation See full code example under package io.serialization
45 Stream Decorators Serialization Summary 1 Basic Java IO What do we know so far? What s next? 2 Example Overview General structure 3 Stream Decorators Serialization
Input, Output and Exceptions. COMS W1007 Introduction to Computer Science. Christopher Conway 24 June 2003
Input, Output and Exceptions COMS W1007 Introduction to Computer Science Christopher Conway 24 June 2003 Input vs. Output We define input and output from the perspective of the programmer. Input is data
More informationCS 251 Intermediate Programming Java I/O Streams
CS 251 Intermediate Programming Java I/O Streams Brooke Chenoweth University of New Mexico Spring 2018 Basic Input/Output I/O Streams mostly in java.io package File I/O mostly in java.nio.file package
More informationPIC 20A Streams and I/O
PIC 20A Streams and I/O Ernest Ryu UCLA Mathematics Last edited: December 7, 2017 Why streams? Often, you want to do I/O without paying attention to where you are reading from or writing to. You can read
More informationI/O in Java I/O streams vs. Reader/Writer. HW#3 due today Reading Assignment: Java tutorial on Basic I/O
I/O 10-7-2013 I/O in Java I/O streams vs. Reader/Writer HW#3 due today Reading Assignment: Java tutorial on Basic I/O public class Swimmer implements Cloneable { public Date geteventdate() { return (Date)
More informationLecture 11.1 I/O Streams
21/04/2014 Ebtsam AbdelHakam 1 OBJECT ORIENTED PROGRAMMING Lecture 11.1 I/O Streams 21/04/2014 Ebtsam AbdelHakam 2 Outline I/O Basics Streams Reading characters and string 21/04/2014 Ebtsam AbdelHakam
More information09-1. CSE 143 Java GREAT IDEAS IN COMPUTER SCIENCE. Overview. Data Representation. Representation of Primitive Java Types. Input and Output.
CSE 143 Java Streams Reading: 19.1, Appendix A.2 GREAT IDEAS IN COMPUTER SCIENCE REPRESENTATION VS. RENDERING 4/28/2002 (c) University of Washington 09-1 4/28/2002 (c) University of Washington 09-2 Topics
More informationSimple Java Input/Output
Simple Java Input/Output Prologue They say you can hold seven plus or minus two pieces of information in your mind. I can t remember how to open files in Java. I ve written chapters on it. I ve done it
More informationSoftware 1 with Java. Recitation No. 7 (Java IO) May 29,
Software 1 with Java Recitation No. 7 (Java IO) May 29, 2007 1 The java.io package The java.io package provides: Classes for reading input Classes for writing output Classes for manipulating files Classes
More informationBasic I/O - Stream. Java.io (stream based IO) Java.nio(Buffer and channel-based IO)
I/O and Scannar Sisoft Technologies Pvt Ltd SRC E7, Shipra Riviera Bazar, Gyan Khand-3, Indirapuram, Ghaziabad Website: www.sisoft.in Email:info@sisoft.in Phone: +91-9999-283-283 I/O operations Three steps:
More informationSoftware 1 with Java. Recitation No. 9 (Java IO) December 10,
Software 1 with Java Recitation No. 9 (Java IO) December 10, 2006 1 The java.io package The java.io package provides: Classes for reading input Classes for writing output Classes for manipulating files
More informationChapter 10. File I/O. Copyright 2016 Pearson Inc. All rights reserved.
Chapter 10 File I/O Copyright 2016 Pearson Inc. All rights reserved. Streams A stream is an object that enables the flow of data between a program and some I/O device or file If the data flows into a program,
More informationSoftware 1. Java I/O
Software 1 Java I/O 1 The java.io package The java.io package provides: Classes for reading input Classes for writing output Classes for manipulating files Classes for serializing objects 2 Streams A stream
More informationFiles and Streams
Files and Streams 4-18-2006 1 Opening Discussion Do you have any questions about the quiz? What did we talk about last class? Do you have any questions about the assignment? What are files and why are
More informationExample: Copying the contents of a file
Administrivia Assignment #4 is due imminently Due Thursday April 8, 10:00pm no late assignments will be accepted Sign up in the front office for a demo time Dining Philosophers code is online www.cs.ubc.ca/~norm/211/2009w2/index.html
More informationCOMP 213. Advanced Object-oriented Programming. Lecture 19. Input/Output
COMP 213 Advanced Object-oriented Programming Lecture 19 Input/Output Input and Output A program that read no input and produced no output would be a very uninteresting and useless thing. Forms of input/output
More informationFile IO. Computer Science and Engineering College of Engineering The Ohio State University. Lecture 20
File IO Computer Science and Engineering College of Engineering The Ohio State University Lecture 20 I/O Package Overview Package java.io Core concept: streams Ordered sequences of data that have a source
More informationJava How to Program, 9/e. Copyright by Pearson Education, Inc. All Rights Reserved.
Java How to Program, 9/e Copyright 1992-2012 by Pearson Education, Inc. All Rights Reserved. Data stored in variables and arrays is temporary It s lost when a local variable goes out of scope or when
More informationCS193j, Stanford Handout #26. Files and Streams
CS193j, Stanford Handout #26 Summer, 2003 Manu Kumar Files and Streams File The File class represents a file or directory in the file system. It provides platform independent ways to test file attributes,
More informationLab 2: File Input and Output
Lab 2: File Input and Output This lab introduces how to handle files as both input and output. We re coming back to Tracery (which you implemented in Lab 1) with this assignment but instead of always reading
More informationToday. Book-keeping. File I/O. Subscribe to sipb-iap-java-students. Inner classes. Debugging tools
Today Book-keeping File I/O Subscribe to sipb-iap-java-students Inner classes http://sipb.mit.edu/iap/java/ Debugging tools Problem set 1 questions? Problem set 2 released tomorrow 1 2 So far... Reading
More informationOverview CSE 143. Data Representation GREAT IDEAS IN COMPUTER SCIENCE
CSE 143 Overview Topics Data representation bits and bytes Streams communicating with the outside world Basic Java files Other stream classes Streams Reading: Ch. 16 10/20/2004 (c) 2001-4, University of
More informationChapter 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
Chapter 4 Java I/O X i a n g Z h a n g j a v a c o s e @ q q. c o m Content 2 Java I/O Introduction File and Directory Byte-stream and Character-stream Bridge between b-s and c-s Random Access File Standard
More informationObject-Oriented Programming in the Java language
Object-Oriented Programming in the Java language Part 5. Exceptions. I/O in Java Yevhen Berkunskyi, NUoS eugeny.berkunsky@gmail.com http://www.berkut.mk.ua Exceptions Exceptions in Java are objects. All
More informationJava Input / Output. CSE 413, Autumn 2002 Programming Languages.
Java Input / Output CSE 413, Autumn 2002 Programming Languages http://www.cs.washington.edu/education/courses/413/02au/ 18-November-2002 cse413-18-javaio 2002 University of Washington 1 Reading Readings
More informationOverview CSE 143. Input and Output. Streams. Other Possible Kinds of Stream Converters. Stream after Stream... CSE143 Wi
CSE 143 Overview Topics Streams communicating with the outside world Basic Java files Other stream classes Streams Reading: Ch. 16 2/3/2005 (c) 2001-5, University of Washington 12-1 2/3/2005 (c) 2001-5,
More informationOverview CSE 143. Data Representation GREAT IDEAS IN COMPUTER SCIENCE. Representation of Primitive Java Types. CSE143 Au
Overview CSE 143 Topics Data representation bits and bytes Streams communicating with the outside world Basic Java files Other stream classes Streams Reading: Sec. 19.1, Appendix A2 11/2/2003 (c) 2001-3,
More informationOverview CSE 143. Data Representation GREAT IDEAS IN COMPUTER SCIENCE
Overview CSE 143 Topics Data representation bits and bytes Streams communicating with the outside world Basic Java files Other stream classes Streams Reading: Sec. 19.1, Appendix A2 11/2/2003 (c) 2001-3,
More informationOverview CSE 143. Data Representation GREAT IDEAS IN COMPUTER SCIENCE. Representation of Primitive Java Types. CSE143 Sp
Overview CSE 143 Topics Data representation bits and bytes Streams communicating with the outside world Basic Java files Other stream classes Streams Reading: Ch. 16 4/27/2004 (c) 2001-4, University of
More informationObjec&ves. Review. Standard Error Streams
Objec&ves Standard Error Streams Ø Byte Streams Ø Text Streams Oct 5, 2016 Sprenkle - CSCI209 1 Review What are benefits of excep&ons What principle of Java do files break if we re not careful? What class
More informationByte and Character Streams. Reading and Writing Console input and output
Byte and Character Streams Reading and Writing Console input and output 1 I/O basics The io package supports Java s basic I/O (input/output) Java does provide strong, flexible support for I/O as it relates
More informationObject Oriented Design with UML and Java. PART VIII: Java IO
Object Oriented Design with UML and Java PART VIII: Java IO Copyright David Leberknight and Ron LeMaster. Version 2011 java.io.* & java.net.* Java provides numerous classes for input/output: java.io.inputstream
More informationSpecial error return Constructors do not have a return value What if method uses the full range of the return type?
23 Error Handling Exit program (System.exit()) usually a bad idea Output an error message does not help to recover from the error Special error return Constructors do not have a return value What if method
More informationTechniques of Java Programming: Streams in Java
Techniques of Java Programming: Streams in Java Manuel Oriol May 8, 2006 1 Introduction Streams are a way of transferring and filtering information. Streams are directed pipes that transfer information
More informationCPS122 Lecture: Input-Output
CPS122 Lecture: Input-Output Objectives: Last Revised April 3, 2017 1. To discuss IO to System.in/out/err 2. To introduce the abstract notion of a stream 3. To introduce the java File, Input/OutputStream,
More informationProgramming Languages and Techniques (CIS120)
Programming Languages and Techniques (CIS120) Lecture 30 April 4, 2018 I/O & Histogram Demo Chapters 28 HW7: Chat Server Announcements No penalty for late submission by tomorrow (which is a HARD deadline!)
More informationI/O Streams. Object-oriented programming
I/O Streams Object-oriented programming Outline Concepts of Data Streams Streams and Files File class Text file Binary file (primitive data, object) Readings: GT, Ch. 12 I/O Streams 2 Data streams Ultimately,
More informationExceptions and Working with Files
Exceptions and Working with Files Creating your own Exceptions. You have a Party class that creates parties. It contains two fields, the name of the host and the number of guests. But you don t want to
More informationSri Vidya College of Engineering & Technology Question Bank
1. What is exception? UNIT III EXCEPTION HANDLING AND I/O Part A Question Bank An exception is an event, which occurs during the execution of a program, that disrupts the normal flow of the program s instructions.
More information1.00 Lecture 30. Sending information to a Java program
1.00 Lecture 30 Input/Output Introduction to Streams Reading for next time: Big Java 15.5-15.7 Sending information to a Java program So far: use a GUI limited to specific interaction with user sometimes
More informationObjec&ves STANDARD ERROR. Standard Error Streams. Ø Byte Streams Ø Text Streams 10/5/16. Oct 5, 2016 Sprenkle - CSCI209 1
Objec&ves Standard Error Streams Ø Byte Streams Ø Text Streams Oct 5, 2016 Sprenkle - CSCI209 1 STANDARD ERROR Oct 5, 2016 Sprenkle - CSCI209 2 1 Standard Streams Preconnected streams Ø Standard Out: stdout
More informationSoftware Practice 1 - File I/O
Software Practice 1 - File I/O Stream I/O Buffered I/O File I/O with exceptions CSV format Practice#6 Prof. Joonwon Lee T.A. Jaehyun Song Jongseok Kim (42) T.A. Sujin Oh Junseong Lee 1 (43) / 38 2 / 38
More informationCourse Content. Objectives of Lecture 22 File Input/Output. Outline of Lecture 22. CMPUT 102: File Input/Output Dr. Osmar R.
Structural Programming and Data Structures Winter 2000 CMPUT 102: Input/Output Dr. Osmar R. Zaïane Course Content Introduction Objects Methods Tracing Programs Object State Sharing resources Selection
More informationFile. Long term storage of large amounts of data Persistent data exists after termination of program Files stored on secondary storage devices
Java I/O File Long term storage of large amounts of data Persistent data exists after termination of program Files stored on secondary storage devices Magnetic disks Optical disks Magnetic tapes Sequential
More informationStreams and File I/O
Chapter 9 Streams and File I/O Overview of Streams and File I/O Text File I/O Binary File I/O File Objects and File Names Chapter 9 Java: an Introduction to Computer Science & Programming - Walter Savitch
More informationChapter 10. IO Streams
Chapter 10 IO Streams Java I/O The Basics Java I/O is based around the concept of a stream Ordered sequence of information (bytes) coming from a source, or going to a sink Simplest stream reads/writes
More informationCSB541 Network Programming 網路程式設計. Ch.2 Streams 吳俊興國立高雄大學資訊工程學系
CSB541 Network Programming 網路程式設計 Ch.2 Streams 吳俊興國立高雄大學資訊工程學系 Outline 2.1 Output Streams 2.2 Input Streams 2.3 Filter Streams 2.4 Readers and Writers 2 Java I/O Built on streams I/O in Java is organized
More informationChapter 17 Binary I/O. Liang, Introduction to Java Programming, Eleventh Edition, (c) 2017 Pearson Education, Inc. All rights reserved.
Chapter 17 Binary I/O 1 Motivations Data stored in a text file is represented in human-readable form. Data stored in a binary file is represented in binary form. You cannot read binary files. They are
More informationJava Programming Lecture 9
Java Programming Lecture 9 Alice E. Fischer February 16, 2012 Alice E. Fischer () Java Programming - L9... 1/14 February 16, 2012 1 / 14 Outline 1 Object Files Using an Object File Alice E. Fischer ()
More informationWhat is Serialization?
Serialization 1 Topics What is Serialization? What is preserved when an object is serialized? Transient keyword Process of serialization Process of deserialization Version control Changing the default
More informationJOSE LUIS JUAREZ VIVEROS com) has a. non-transferable license to use this Student Guide
Module 10 I/O Fundamentals Objectives Upon completion of this module, you should be able to: Write a program that uses command-line arguments and system properties Examine the Properties class Construct
More informationFiles and IO, Streams. JAVA Standard Edition
Files and IO, Streams JAVA Standard Edition Java - Files and I/O 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
More information输 入输出相关类图. DataInput. DataOutput. java.lang.object. FileInputStream. FilterInputStream. FilterInputStream. FileOutputStream
输 入 / 输出 杨亮 流的分类 输 入输出相关类图 OutputStream FileOutputStream DataInputStream ObjectOutputStream FilterInputStream PipedOutputStream DataOutput InputStream DataInputStream PrintStream ObjectInputStream PipedInputStream
More informationDarshan Institute of Engineering & Technology for Diploma Studies
Streams A stream is a sequence of data. In Java a stream is composed of bytes. In java, 3 streams are created for us automatically. 1. System.out : standard output stream 2. System.in : standard input
More informationFile Input/Output. Introduction to Computer Science I. Overview (1): Overview (2): CSE 1020 Summer Bill Kapralos. Bill Kapralos.
File Input/Output Tuesday, July 25 2006 CSE 1020, Summer 2006, Overview (1): Before We Begin Some administrative details Some questions to consider The Class Object What is the Object class? File Input
More information27 Trying it 28 Trying it 29 Coursework: A check sum program 30 Section 3: Example:Counting characters from standard input 31 Aim 32 Counting characte
List of Slides 1 Title 2 Chapter 18: Files 3 Chapter aims 4 Section 2: Example:Counting bytes from standard input 5 Aim 6 Counting bytes from standard input 7 File IO API: IOException 9 Counting bytes
More informationpre-emptive non pre-emptive
start() run() class SumThread extends Thread { int end; int sum; SumThread( int end ) { this.end = end; } public void run() { // sum integers 1, 2,..., end // and set the sum } } SumThread t = new SumThread(
More informationIntroduction Unit 4: Input, output and exceptions
Faculty of Computer Science Programming Language 2 Object oriented design using JAVA Dr. Ayman Ezzat Email: ayman@fcih.net Web: www.fcih.net/ayman Introduction Unit 4: Input, output and exceptions 1 1.
More informationThe Java I/O System. Binary I/O streams (ASCII, 8 bits) The decorator design pattern Character I/O streams (Unicode, 16 bits)
The Java I/O System Binary I/O streams (ASCII, 8 bits) InputStream OutputStream The decorator design pattern Character I/O streams (Unicode, 16 bits) Reader Writer Comparing binary I/O to character I/O
More informationDining philosophers (cont)
Administrivia Assignment #4 is out Due Thursday April 8, 10:00pm no late assignments will be accepted Sign up in labs this week for a demo time Office hour today will be cut short (11:30) Another faculty
More informationHST 952. Computing for Biomedical Scientists Lecture 8
Harvard-MIT Division of Health Sciences and Technology HST.952: Computing for Biomedical Scientists HST 952 Computing for Biomedical Scientists Lecture 8 Outline Vectors Streams, Input, and Output in Java
More informationSoftware 1. תרגול 9 Java I/O
Software 1 תרגול 9 Java I/O 1 The java.io package The java.io package provides: Classes for reading input Classes for writing output Classes for manipulating files Classes for serializing objects 2 Streams
More informationF1 A Java program. Ch 1 in PPIJ. Introduction to the course. The computer and its workings The algorithm concept
F1 A Java program Ch 1 in PPIJ Introduction to the course The computer and its workings The algorithm concept The structure of a Java program Classes and methods Variables Program statements Comments Naming
More informationWeek 12. Streams and File I/O. Overview of Streams and File I/O Text File I/O
Week 12 Streams and File I/O Overview of Streams and File I/O Text File I/O 1 I/O Overview I/O = Input/Output In this context it is input to and output from programs Input can be from keyboard or a file
More informationתוכנה 1 תרגול 8 קלט/פלט רובי בוים ומתי שמרת
תוכנה 1 תרגול 8 קלט/פלט רובי בוים ומתי שמרת A Typical Program Most applications need to process some input and produce some output based on that input The Java IO package (java.io) is to make that possible
More informationCPS122 Lecture: Input-Output
CPS122 Lecture: Input-Output Objectives: Last Revised January 19, 2010 1. To discuss IO to System.in/out/err 2. To introduce the abstract notion of a stream 3. To introduce the java File, Input/OutputStream,
More informationCS 2113 Software Engineering
CS 2113 Software Engineering Java 6: File and Network IO https://github.com/cs2113f18/template-j-6-io.git Professor Tim Wood - The George Washington University Project 2 Zombies Basic GUI interactions
More informationCS112 Lecture: Streams
CS112 Lecture: Streams Objectives: Last Revised March 30, 2006 1. To introduce the abstract notion of a stream 2. To introduce the java File, Input/OutputStream, and Reader/Writer abstractions 3. To show
More informationI/O streams. Byte Streams Character Streams InputStream ByteArrayInputStream FileInputStream FilterInputStream
Course Name: Advanced Java Lecture 9 Topics to be covered I/O streams Byte Streams Character Streams InputStream ByteArrayInputStream FileInputStream FilterInputStream Introduction A Stream is a sequence
More informationProgramming Languages and Techniques (CIS120)
Programming Languages and Techniques (CIS120) Lecture 31 November 17, 2017 I/O & Histogram Demo Chapters 28 Announcements HW8: SpellChecker Available on the website and Codio Due next Tuesday, November
More informationInternet Technology 2/7/2013
Sample Client-Server Program Internet Technology 02r. Programming with Sockets Paul Krzyzanowski Rutgers University Spring 2013 To illustrate programming with TCP/IP sockets, we ll write a small client-server
More informationData Structures. 03 Streams & File I/O
David Drohan Data Structures 03 Streams & File I/O JAVA: An Introduction to Problem Solving & Programming, 6 th Ed. By Walter Savitch ISBN 0132162709 2012 Pearson Education, Inc., Upper Saddle River, NJ.
More informationPrinciples of Software Construction: Objects, Design and Concurrency. Design Case Study: Stream I/O. toad
Principles of Software Construction: Objects, Design and Concurrency Design Case Study: Stream I/O 15-214 toad Christian Kästner Charlie Garrod School of Computer Science 2014 C Kästner, C Garrod, J Aldrich,
More informationCN208 Introduction to Computer Programming
CN208 Introduction to Computer Programming Lecture #11 Streams (Continued) Pimarn Apipattanamontre Email: pimarn@pimarn.com 1 The Object Class The Object class is the direct or indirect superclass of every
More information7 Streams and files. Overview. Binary data vs text. Binary data vs text. Readers, writers, byte streams. input-output
Overview 7 Streams and files import java.io.*; Binary data vs textual data Simple file processing - examples The stream model Bytes and characters Buffering Byte streams Character streams Binary streams
More informationCISC 323 (Week 9) Design of a Weather Program & Java File I/O
CISC 323 (Week 9) Design of a Weather Program & Java File I/O Jeremy Bradbury Teaching Assistant March 8 & 10, 2004 bradbury@cs.queensu.ca Programming Project The next three assignments form a programming
More informationITI Introduction to Computer Science II
ITI 1121. Introduction to Computer Science II Laboratory 8 Winter 2015 [ PDF ] Objectives Introduction to Java I/O (input/output) Further understanding of exceptions Introduction This laboratory has two
More informationCore Java Contents. Duration: 25 Hours (1 Month)
Duration: 25 Hours (1 Month) Core Java Contents Java Introduction Java Versions Java Features Downloading and Installing Java Setup Java Environment Developing a Java Application at command prompt Java
More informationActive Learning: Streams
Lecture 29 Active Learning: Streams The Logger Application 2 1 Goals Using the framework of the Logger application, we are going to explore three ways to read and write data using Java streams: 1. as text
More informationProgramming Languages and Techniques (CIS120)
Programming Languages and Techniques (CIS120) Lecture 30 April 2, 2012 Streams & IO HW 09 will be available today Announcements Covers Java libraries: colleclons & IO Last automalcally graded HW assignment
More informationFILE I/O IN JAVA. Prof. Chris Jermaine
FILE I/O IN JAVA Prof. Chris Jermaine cmj4@cs.rice.edu 1 Our Simple Java Programs So Far Aside from screen I/O......when they are done, they are gone They have no lasting effect on the world When the program
More informationC17: I/O Streams and File I/O
CISC 3120 C17: I/O Streams and File I/O Hui Chen Department of Computer & Information Science CUNY Brooklyn College 4/9/2018 CUNY Brooklyn College 1 Outline Recap and issues Review your progress Assignments:
More informationProgramming Languages and Techniques (CIS120)
Programming Languages and Techniques (CIS120) Lecture 31 April 6 th, 2016 I/O Chapter 28 Poll Did you finish HW 07 PennPals? 1. Yes! 2. I turned it in on time, but there are a few things I couldn't figure
More informationCertification In Java Language Course Course Content
Introduction Of Java * What Is Java? * How To Get Java * A First Java Program * Compiling And Interpreting Applications * The JDK Directory Structure Certification In Java Language Course Course Content
More informationSoftware 1 with Java. The java.io package. Streams. Streams. Streams. InputStreams
The java.io package Software with Java Java I/O Mati Shomrat and Rubi Boim The java.io package provides: Classes for reading input Classes for writing output Classes for manipulating files Classes for
More informationIT101. File Input and Output
IT101 File Input and Output IO Streams A stream is a communication channel that a program has with the outside world. It is used to transfer data items in succession. An Input/Output (I/O) Stream represents
More informationJava Input/Output. 11 April 2013 OSU CSE 1
Java Input/Output 11 April 2013 OSU CSE 1 Overview The Java I/O (Input/Output) package java.io contains a group of interfaces and classes similar to the OSU CSE components SimpleReader and SimpleWriter
More informationTirgul 1. Course Guidelines. Packages. Special requests. Inner classes. Inner classes - Example & Syntax
Tirgul 1 Today s topics: Course s details and guidelines. Java reminders and additions: Packages Inner classes Command Line rguments Primitive and Reference Data Types Guidelines and overview of exercise
More informationMore on Objects in JAVA TM
More on Objects in JAVA TM Inheritance : Definition: A subclass is a class that extends another class. A subclass inherits state and behavior from all of its ancestors. The term superclass refers to a
More informationCSCI 200 Lab 2 Inheritance, Polymorphism & Data Streams
CSCI 200 Lab 2 Inheritance, Polymorphism & Data Streams In this lab you will write a set of simple Java interfaces and classes that use inheritance and polymorphism. You will also write code that uses
More informationObject-Oriented Programming Design. Topic : Streams and Files
Electrical and Computer Engineering Object-Oriented Topic : Streams and Files Maj Joel Young Joel Young@afit.edu. 18-Sep-03 Maj Joel Young Java Input/Output Java implements input/output in terms of streams
More informationCSC 1214: Object-Oriented Programming
CSC 1214: Object-Oriented Programming J. Kizito Makerere University e-mail: www: materials: e-learning environment: office: alt. office: jkizito@cis.mak.ac.ug http://serval.ug/~jona http://serval.ug/~jona/materials/csc1214
More informationChapter 12. File Input and Output. CS180-Recitation
Chapter 12 File Input and Output CS180-Recitation Reminders Exam2 Wed Nov 5th. 6:30 pm. Project6 Wed Nov 5th. 10:00 pm. Multitasking: The concurrent operation by one central processing unit of two or more
More informationStarting Out with Java: From Control Structures Through Objects Sixth Edition
Starting Out with Java: From Control Structures Through Objects Sixth Edition Chapter 11 I/O File Input and Output Reentering data all the time could get tedious for the user. The data can be saved to
More informationProgramming Languages and Techniques (CIS120)
Programming Languages and Techniques (CIS120) Lecture 30 November 13, 2015 ExcepEons / IO Chapter 27 HW7: PennPals Chat Due: Tuesday, November 17 th Announcements Start today if you haven't already! Poll
More informationStreams and File I/O
Walter Savitch Frank M. Carrano Streams and File I/O Chapter 10 Objectives Describe the concept of an I/O stream Explain the difference between text and binary files Save data, including objects, in a
More informationCOMP-202: Foundations of Programming. Lecture 12: Linked List, and File I/O Sandeep Manjanna, Summer 2015
COMP-202: Foundations of Programming Lecture 12: Linked List, and File I/O Sandeep Manjanna, Summer 2015 Announcements Assignment 4 is posted and Due on 29 th of June at 11:30 pm. Course Evaluations due
More informationEvents and Exceptions
Events and Exceptions Analysis and Design of Embedded Systems and OO* Object-oriented programming Jan Bendtsen Automation and Control Lecture Outline Exceptions Throwing and catching Exceptions creating
More informationCS1092: Tutorial Sheet: No 3 Exceptions and Files. Tutor s Guide
CS1092: Tutorial Sheet: No 3 Exceptions and Files Tutor s Guide Preliminary This tutorial sheet requires that you ve read Chapter 15 on Exceptions (CS1081 lectured material), and followed the recent CS1092
More informationPROGRAMACIÓN ORIENTADA A OBJETOS
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
More informationExperiment No: Group B_4
Experiment No: Group B_4 R (2) N (5) Oral (3) Total (10) Dated Sign Problem Definition: Write a web application using Scala/ Python/ Java /HTML5 to check the plagiarism in the given text paragraph written/
More information