Writing usable APIs in practice

Size: px
Start display at page:

Download "Writing usable APIs in practice"

Transcription

1 Writing usable APIs in practice NDC Oslo linkedin: Asprotunity Ltd

2 API Any well-defined interface that defines the service that one component, module, or application provides to other software elements From: Sometimes You Need to See Through Walls A Field Study of Application Programming Interfaces, Cleidson R. B. de Souza et al., cdesouza/pub/p390-desouza.pdf

3 Example: java.io package (Java 7) Interfaces: Closeable, DataInput, DataOutput, Externalizable, FileFilter, FilenameFilter, Flushable, ObjectInput, ObjectInputValidation, ObjectOutput, ObjectStreamConstants, Serializable Classes: BufferedInputStream, BufferedOutputStream, BufferedReader, BufferedWriter, ByteArrayInputStream, ByteArrayOutputStream, CharArrayReader, CharArrayWriter, Console, DataInputStream, DataOutputStream, File, FileDescriptor, FileInputStream, FileOutputStream, FilePermission, FileReader, FileWriter, FilterInputStream, FilterOutputStream, FilterReader, FilterWriter, InputStream, InputStreamReader, LineNumberInputStream, LineNumberReader, ObjectInputStream, ObjectInputStream.GetField, ObjectOutputStream, ObjectOutputStream.PutField, ObjectStreamClass, ObjectStreamField, OutputStream, OutputStreamWriter, PipedInputStream, PipedOutputStream, PipedReader, PipedWriter, PrintStream, PrintWriter, PushbackInputStream, PushbackReader, RandomAccessFile, Reader, SequenceInputStream, SerializablePermission, StreamTokenizer, StringBufferInputStream, StringReader, StringWriter, Writer Exceptions: CharConversionException, EOFException, FileNotFoundException, InterruptedIOException, InvalidClassException, InvalidObjectException, IOException, NotActiveException, NotSerializableException, ObjectStreamException, OptionalDataException, StreamCorruptedException, SyncFailedException, UnsupportedEncodingException, UTFDataFormatException, WriteAbortedException Errors: IOError

4 Usability Efficiency Effectiveness Error prevention Ease of learning

5 Giovanni s usability equation u = O(1/b) u = usability b = brain power necessary to achieve your goals

6 The equation is... Made up Totally arbitrary

7 Why bother (company s perspective) APIs can be among a company's greatest assets Can also be among company's greatest liabilities Adapted from: How to Design a Good API and Why it Matters, Joshua Bloch, keynote.pdf

8 Why bother (programmer s perspective) Fewer bugs to take care of Code of higher quality More productivity

9 Public and private APIs Public APIs Given to third parties Private APIs For internal use

10 Any non trivial software application involves writing one or more APIs

11 When we talk about good code we always mean usable code as well

12 Some usability concepts

13 Affordances An affordance is a quality of an object, or an environment, that allows an individual to perform an action. From:

14 import java.io.bufferedreader; import java.io.file; import java.io.filereader; BufferedReader reader; try { reader = new BufferedReader(new FileReader( filename )); while (true) { String line = reader.readline(); if (line == null) { break; processline(line); catch (Exception exc) { // Do something here... finally { if (reader!= null) { reader.close();

15 import java.nio.file.path; import java.nio.filesystems; import java.nio.charset.charset; try { Path filepath = FileSystems.getDefault().getPath("filename"); Charset charset = Charset.defaultCharset(); for (String line : Files.readAllLines(filePath, charset)) { processline(line); catch (IOException e) { // Do something here

16 import java.io.file; import java.util.scanner; File file = new File("filename"); try { Scanner scanner = new Scanner(file); while (scanner.hasnextline()) { String line = scanner.nextline(); processline(line); scanner.close(); catch (FileNotFoundException e) { e.printstacktrace();

17 with open("filename") as infile: for line in infile.readlines(): processline(line)

18 Some cognitive dimensions Abstraction level. The minimum and maximum levels of abstraction exposed by the API Working framework. The size of the conceptual chunk (developer working set) needed to work effectively Progressive evaluation. To what extent partially completed code can be executed to obtain feedback on code behaviour Penetrability. The extent to which a developer must understand the underlying implementation details of an API Consistency. How much of the rest of an API can be inferred once part of it is learned Adapted from: Measuring API Usability, Steven Clarke,

19 import java.io.bufferedreader; import java.io.file; import java.io.filereader; BufferedReader reader; try { reader = new BufferedReader(new FileReader( filename )); while (true) { String line = reader.readline(); if (line == null) { break; processline(line); catch (Exception exc) { // Do something here... finally { if (reader!= null) { reader.close(); Abstraction level Working framework Progressive evaluation Penetrability Consistency

20 import java.nio.file.path; import java.nio.filesystems; import java.nio.charset.charset; try { Path filepath = FileSystems.getDefault().getPath("filename"); Charset charset = Charset.defaultCharset(); for (String line : Files.readAllLines(filePath, charset)) { processline(line); catch (IOException e) { // Do something here Abstraction level Working framework Progressive evaluation Penetrability Consistency

21 import java.io.file; import java.util.scanner; File file = new File("filename"); try { Scanner scanner = new Scanner(file); while (scanner.hasnextline()) { String line = scanner.nextline(); processline(line); scanner.close(); catch (FileNotFoundException e) { e.printstacktrace(); Abstraction level Working framework Progressive evaluation Penetrability Consistency

22 with open("filename") as infile: for line in infile.readlines(): processline(line) Abstraction level Working framework Progressive evaluation Penetrability Consistency

23 Some techniques

24 None of the ideas presented here are new; they are just forgotten from time to time. Alan J. Perlis, 1966 Turing Award Lecture.

25 User s perspective Naming Explicit context Error reporting Incremental design

26 User s perspective Naming Explicit context Error reporting Incremental design

27 Ask, What Would the User Do? (You Are Not the User) Giles Colborne, 97 Things Every Programmer Should Know

28 Use language constructs to make intent clear

29 maketv(true, false); From: API Design Matters, Michi Henning, id=

30 void maketv(bool iscolor, bool iscrt); From: API Design Matters, Michi Henning, id=

31 enum ColorType { Color, BlackAndWhite enum ScreenType { CRT, FlatScreen ; void maketv(colortype col, ScreenType st); From: API Design Matters, Michi Henning, id=

32 maketv(color, FlatScreen); From: API Design Matters, Michi Henning, id=

33 Give control to the caller

34 What s wrong with these? public interface Startable { Startable start() throws AlreadyStartedException; public interface Stoppable { Stoppable stop() throws AlreadyStoppedException;

35 A better alternative public interface Service { void start() throws AlreadyStartedException; void stop() throws AlreadyStoppedException; boolean isstarted();

36 TDD It puts you in the shoes of an user Outside-in development If writing a test is painful, the design may be wrong Tests will provide up to date documentation and examples of use

37 TDD helps with Abstraction level. It helps to limit the number of abstractions in mainline scenarios Working framework. It helps in keeping it smaller Progressive evaluation. The tests themselves are written in a progressive way Penetrability. It provides examples on how the various components interact with each other Consistency. It is maintained by refactoring the code

38 Back to the first example: potential test with TDD List<String> expectedlines = ; File file = new File( testfile )); assertequals(file.readlines(), expectedlines);

39 More likely outcome File file = new File( filename )); try { for (String line : file.readlines()) { processline(line); finally { file.close()

40 Less likely outcome BufferedReader reader; try { reader = new BufferedReader(new FileReader( filename )); while (true) { String line = reader.readline(); if (line == null) { break; processline(line); catch (Exception exc) { // Do something here... finally { if (reader!= null) { reader.close();

41 User s perspective Naming Explicit context Error reporting Incremental design

42 Naming Reserve the simplest and most intuitive names for the entities used in the most common scenarios Pick one word per concept Use easy to remember conventions Don t be cute!

43 What not to do (1/2) java.io.objectstreamconstants Constants written into the Object Serialization Stream

44

45 User s perspective Naming Explicit context Error reporting Incremental design

46 Explicit context Assumptions about the external environment There are two kinds of context we are interested in Deployment context Runtime context

47 Deployment context Dependencies on other APIs Assumptions on deployment paths User permissions etc.

48 Runtime context Initialization (and finalization) steps Preconditions for calling methods (or functions) or instantiating classes Assumptions about global application state

49 Global state Difficult to use in a concurrent environment Can make test setup extremely hard Can make penetrability really hard by hiding dependencies

50 User s perspective Naming Explicit context Error reporting Incremental design

51 Error reporting Error reporting code is important for usability Users need to know How errors are reported What is reported when What they can do about them

52 Error recovery Make recovery easy to do Error codes Exception classes A mix of the above Text messages are usually not good enough

53 Error management and reporting need careful design from the very beginning

54 What is an error at one level......may not be an error at another one

55 User s perspective Naming Explicit context Error reporting Incremental design

56 I will contend that conceptual integrity is the most important consideration in system design. It is better to have a system omit certain anomalous features and improvements, but to reflect one set of design ideas, than to have one that contains many good but independent and uncoordinated ideas. Fred Brooks, The Mythical Man Month

57 Start specific and small Start with the 80% case first It is easier to remove constraints rather than to add them later YAGNI

58 A caveat Public APIs are more difficult to refactor. In fact, some errors may actually become features Techniques to refactor them usually involve some form of deprecation and versioning

59 Surprising study results

60 Factory pattern A user study comparing the usability of the factory pattern and constructors in API designs found highly significant results indicating that factories are detrimental to API usability in several varied situations. The results showed that users require significantly more time (p = 0.005) to construct an object with a factory than with a constructor while performing both context-sensitive and context free tasks From: The Factory Pattern in API Design: A Usability Evaluation

61 Constructors It was hypothesized that required parameters would create more usable and self documenting APIs by guiding programmers toward the correct use of objects and preventing errors. However, in the study, it was found that, contrary to expectations, programmers strongly preferred and were more effective with APIs that did not require constructor parameters. Participants behavior was analyzed using the cognitive dimensions framework, and revealing that required constructor parameters interfere with common learning strategies, causing undesirable premature commitment. From: Usability Implications of Requiring Parameters in Objects Constructors

62 Links Sometimes You Need to See Through Walls A Field Study of Application Programming Interfaces, Cleidson R. B. de Souza et al., Measuring API Usability, Steven Clarke, API Design Matters, Michi Henning, How to Design a Good API and Why it Matters, Joshua Bloch, What Makes APIs Difficult to Use?, Minhaz Fahim Zibran, Usability Implications of Requiring Parameters in Objects Constructors, Jeffrey Stylos and Steven Clarke, The Factory Pattern in API Design: A Usability Evaluation, Brian Ellis, Jeffrey Stylos, and Brad Myers,

63 Books ptg From the Library of Giovanni Asproni

Writing usable APIs in practice

Writing usable APIs in practice Writing usable APIs in practice SyncConf 2013 Giovanni Asproni gasproni@asprotunity.com @gasproni Summary API definition Two assumptions Why bother with usability Some usability concepts Some techniques

More information

Writing usable APIs in practice. ACCU 2012 Conference, Oxford, UK Giovanni

Writing usable APIs in practice. ACCU 2012 Conference, Oxford, UK Giovanni Writing usable APIs in practice ACCU 2012 Conference, Oxford, UK Giovanni Asproni gasproni@asprotunity.com @gasproni 1 Summary API definition Two assumptions Why bother with usability Some techniques to

More information

7 Streams and files. Overview. Binary data vs text. Binary data vs text. Readers, writers, byte streams. input-output

7 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 information

The 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) 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 information

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

Software 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 information

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

Software 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 information

Exceptions and Working with Files

Exceptions 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 information

Software 1. Java I/O

Software 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 information

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

Java 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 information

CSC 1214: Object-Oriented Programming

CSC 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 information

JOSE LUIS JUAREZ VIVEROS com) has a. non-transferable license to use this Student Guide

JOSE 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 information

The I/O Package. THE Java platform includes a number of packages that are concerned with the CHAPTER20

The I/O Package. THE Java platform includes a number of packages that are concerned with the CHAPTER20 CHAPTER20 The I/O Package From a programmer s point of view, the user is a peripheral that types when you issue a read request. Peter Williams THE Java platform includes a number of packages that are concerned

More information

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

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 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 information

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

Software 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 information

Princeton University COS 333: Advanced Programming Techniques A Subset of Java

Princeton University COS 333: Advanced Programming Techniques A Subset of Java Princeton University COS 333: Advanced Programming Techniques A Subset of Java Program Structure public class Hello public static void main(string[] args) // Print "hello, world" to stdout. System.out.println("hello,

More information

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

输 入输出相关类图. DataInput. DataOutput. java.lang.object. FileInputStream. FilterInputStream. FilterInputStream. FileOutputStream 输 入 / 输出 杨亮 流的分类 输 入输出相关类图 OutputStream FileOutputStream DataInputStream ObjectOutputStream FilterInputStream PipedOutputStream DataOutput InputStream DataInputStream PrintStream ObjectInputStream PipedInputStream

More information

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

Streams. Programação Orientada por Objetos (POO) Centro de Cálculo Instituto Superior de Engenharia de Lisboa Streams Programação Orientada por Objetos (POO) Centro de Cálculo Instituto Superior de Engenharia de Lisboa Pedro Alexandre Pereira (palex@cc.isel.ipl.pt) 4 hieraquias de streams em Java Escrita Leitura

More information

Example: Copying the contents of a file

Example: 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 information

Object-Oriented Programming in the Java language

Object-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 information

PIC 20A Streams and I/O

PIC 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 information

System.out.format("The square root of %d is %f.%n", i, r);

System.out.format(The square root of %d is %f.%n, i, r); 1 Input/Output in Java Vedi anche: http://java.sun.com/docs/books/tutorial/essential/io/index.html 2 Formattazione public class Root2 { public static void main(string[] args) { int i = 2; double r = Math.sqrt(i);

More information

CSD Univ. of Crete Fall Files, Streams, Filters

CSD Univ. of Crete Fall Files, Streams, Filters Files, Streams, Filters 1 CSD Univ. of Crete Fall 2008 Introduction Files are often thought of as permanent data storage (e.g. floppy diskettes) When a file is stored on a floppy or hard disk, the file's

More information

CS 251 Intermediate Programming Java I/O Streams

CS 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 information

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

Software 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 information

How to access your database from the development environment. Marco Ronchetti Università degli Studi di Trento

How to access your database from the development environment. Marco Ronchetti Università degli Studi di Trento 1 How to access your database from the development environment Marco Ronchetti Università degli Studi di Trento App (data) management LONG LONG App management Data management 2 3 Open the DDMS Perspective

More information

Chapter 12. File Input and Output. CS180-Recitation

Chapter 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 information

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

תוכנה 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 information

Pieter van den Hombergh Richard van den Ham. March 13, 2018

Pieter van den Hombergh Richard van den Ham. March 13, 2018 Pieter van den Hombergh Richard van den Ham Fontys Hogeschool voor Techniek en Logistiek March 13, 2018 /FHTenL March 13, 2018 1/23 Topics /FHTenL March 13, 2018 2/23 Figure: Taken from the Oracle/Sun

More information

Software Development & Education Center. Java Platform, Standard Edition 7 (JSE 7)

Software Development & Education Center. Java Platform, Standard Edition 7 (JSE 7) Software Development & Education Center Java Platform, Standard Edition 7 (JSE 7) Detailed Curriculum Getting Started What Is the Java Technology? Primary Goals of the Java Technology The Java Virtual

More information

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

Java 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 information

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, 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 information

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

COMP 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 information

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

09-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 information

COURSE 10 PROGRAMMING III OOP. JAVA LANGUAGE

COURSE 10 PROGRAMMING III OOP. JAVA LANGUAGE COURSE 10 PROGRAMMING III OOP. JAVA LANGUAGE PREVIOUS COURSE CONTENT Graphical User Interfaces Abstract Window Toolkit Swing COUSE CONTENT Input/Output Sreams Text Files Byte Files RandomAcessFile Exceptions

More information

Java IO and C++ Streams

Java IO and C++ Streams Java IO and C++ Streams October 22, 2004 Operator Overloading in C++ - 2004-10-21 p. 1/31 Outline Java IO InputStream/OutputStream FilterInputStream/FilterOutputStream DataInputStream/DataOutputStream

More information

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

Special 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 information

10.1 Overview 162 CHAPTER 10 CHARACTER STREAMS

10.1 Overview 162 CHAPTER 10 CHARACTER STREAMS C H A P T E R 1 0 Character streams 10.1 Overview 162 10.2 Character encoding 164 10.3 Class Writer 167 10.4 Class Reader 169 10.5 Class OutputStreamWriter 171 10.6 Class InputStreamReader 173 10.7 An

More information

Introduction to Java

Introduction to Java Introduction to Java Module 10: Stream I/0 and Files 24/04/2010 Prepared by Chris Panayiotou for EPL 233 1 Introduction to Java IO o The Java library designers attacked the problem by creating lots of

More information

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

Core 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 information

Today. 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.  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 information

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

Overview 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 information

Files and Streams

Files 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 information

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

CSB541 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 information

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

I/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 information

Darshan Institute of Engineering & Technology for Diploma Studies

Darshan 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 information

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

Software 1. The java.io package. Streams. Streams. Streams. InputStreams The java.io package Software 1 תרגול 9 Java I/O The java.io package provides: Classes for reading input Classes for writing output Classes for manipulating files Classes for serializing objects 1 2 Streams

More information

Index. CalculatorEngine class, 40, 44 CalculatorFrame class, 48 CalculatorInterface class, 45

Index. CalculatorEngine class, 40, 44 CalculatorFrame class, 48 CalculatorInterface class, 45 Index A Abstract classes, 57, 83 Abstract methods, 80, 83 Abstract window toolkit components, 204, 205 events, 209 214 frames in, 203 Layout Managers, 206 208 panels, 205 208 Abstraction, concept of, 23,

More information

Chapter 10. IO Streams

Chapter 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 information

I/O Streams. Object-oriented programming

I/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 information

Overview CSE 143. Data Representation GREAT IDEAS IN COMPUTER SCIENCE

Overview 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 information

Chapter 17 Binary I/O. Liang, Introduction to Java Programming, Eleventh Edition, (c) 2017 Pearson Education, Inc. All rights reserved.

Chapter 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 information

C17: I/O Streams and File I/O

C17: 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 information

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. 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 information

Overview CSE 143. Data Representation GREAT IDEAS IN COMPUTER SCIENCE

Overview 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 information

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

Overview 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 information

Java Input/Output. 11 April 2013 OSU CSE 1

Java 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 information

How to access your database from the development environment. Marco Ronchetti Università degli Studi di Trento

How to access your database from the development environment. Marco Ronchetti Università degli Studi di Trento 1 How to access your database from the development environment Marco Ronchetti Università degli Studi di Trento App (data) management LONG LONG App management Data management 2 3 Open the DDMS Perspective

More information

File 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 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 information

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

Basic Java IO Decorator pattern Advanced Java IO. Java IO - part 2 BIU OOP. BIU OOP Java IO - part 2 Java IO - part 2 BIU OOP 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 What do we know so far? What s next?

More information

1.00 Lecture 30. Sending information to a Java program

1.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 information

A Quick Tour p. 1 Getting Started p. 1 Variables p. 3 Comments in Code p. 6 Named Constants p. 6 Unicode Characters p. 8 Flow of Control p.

A Quick Tour p. 1 Getting Started p. 1 Variables p. 3 Comments in Code p. 6 Named Constants p. 6 Unicode Characters p. 8 Flow of Control p. A Quick Tour p. 1 Getting Started p. 1 Variables p. 3 Comments in Code p. 6 Named Constants p. 6 Unicode Characters p. 8 Flow of Control p. 9 Classes and Objects p. 11 Creating Objects p. 12 Static or

More information

IT101. File Input and Output

IT101. 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 information

Exception handling in Java. J. Pöial

Exception handling in Java. J. Pöial Exception handling in Java J. Pöial Errors and exceptions Error handling without dedicated tools: return codes, global error states etc. Problem: it is not reasonable (or even possible) to handle each

More information

Active Learning: Streams

Active 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 information

JAVA V Input/Output Java, winter semester

JAVA V Input/Output Java, winter semester JAVA Input/Output 1 Overview package java.io basic input/output streams bytes since JDK1.1 Reader and Writer chars (Unicode) package java.nio since JDK1.4 channels, buffers increased performance classes

More information

Objec&ves. Review. Standard Error Streams

Objec&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 information

JAVA Input/Output Java, winter semester

JAVA Input/Output Java, winter semester JAVA Input/Output 1 Overview package java.io basic input/output streams bytes since JDK1.1 Reader and Writer chars (Unicode) package java.nio since JDK1.4 channels, buffers increased performance classes

More information

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

Basic 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 information

CS Week 11. Jim Williams, PhD

CS Week 11. Jim Williams, PhD CS 200 - Week 11 Jim Williams, PhD This Week 1. Exam 2 - Thursday 2. Team Lab: Exceptions, Paths, Command Line 3. Review: Muddiest Point 4. Lecture: File Input and Output Objectives 1. Describe a text

More information

J.73 J.74 THE I/O PACKAGE. Java I/O is defined in terms of streams. Streams are ordered sequences of data that have a source and a destination.

J.73 J.74 THE I/O PACKAGE. Java I/O is defined in terms of streams. Streams are ordered sequences of data that have a source and a destination. THE I/O PACKAGE Java I/O is defined in terms of streams. J.73 import java.io.*; class Translate { public static void main(string[] args) { InputStream in = System.in; OutputStream out = System.out; J.74

More information

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

File. 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 information

Lab 5: Java IO 12:00 PM, Feb 21, 2018

Lab 5: Java IO 12:00 PM, Feb 21, 2018 CS18 Integrated Introduction to Computer Science Fisler, Nelson Contents Lab 5: Java IO 12:00 PM, Feb 21, 2018 1 The Java IO Library 1 2 Program Arguments 2 3 Readers, Writers, and Buffers 2 3.1 Buffering

More information

Chapter 10 Input Output Streams

Chapter 10 Input Output Streams Chapter 10 Input Output Streams ICT Academy of Tamil Nadu ELCOT Complex, 2-7 Developed Plots, Industrial Estate, Perungudi, Chennai 600 096. Website : www.ictact.in, Email : contact@ictact.in, Phone :

More information

Performing input and output operations using a Byte Stream

Performing input and output operations using a Byte Stream Performing input and output operations using a Byte Stream public interface DataInput The DataInput interface provides for reading bytes from a binary stream and reconstructing from them data in any of

More information

CS 200 File Input and Output Jim Williams, PhD

CS 200 File Input and Output Jim Williams, PhD CS 200 File Input and Output Jim Williams, PhD This Week 1. WaTor Change Log 2. Monday Appts - may be interrupted. 3. Optional Lab: Create a Personal Webpage a. demonstrate to TA for same credit as other

More information

Programming Languages and Techniques (CIS120)

Programming 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 information

Object-Oriented Programming Design. Topic : Streams and Files

Object-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 information

Java Input/Output Streams

Java Input/Output Streams Java Input/Output Streams Rui Moreira Some useful links: http://java.sun.com/docs/books/tutorial/essential/toc.html#io Input Stream Output Stream Rui Moreira 2 1 JVM creates the streams n System.in (type

More information

Chapter 8: Files and Security

Chapter 8: Files and Security Java by Definition Chapter 8: Files and Security Page 1 of 90 Chapter 8: Files and Security All programs and applets we created up to this point had one feature in common: as soon as the program or applet

More information

CS193j, Stanford Handout #26. Files and Streams

CS193j, 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 information

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

Starting 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 information

Jonathan Aldrich Charlie Garrod

Jonathan Aldrich Charlie Garrod Principles of So3ware Construc9on: Objects, Design, and Concurrency Part 3: Design Case Studies Design Case Study: Java I/O Jonathan Aldrich Charlie Garrod School of Computer Science 1 Administrivia Homework

More information

CN208 Introduction to Computer Programming

CN208 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 information

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

CS5000: Foundations of Programming. Mingon Kang, PhD Computer Science, Kennesaw State University CS5000: Foundations of Programming Mingon Kang, PhD Computer Science, Kennesaw State University Files Two types: Text file and Binary file Text file (ASCII file) The file data contains only ASCII values

More information

5/29/2006. Announcements. Last Time. Today. Text File I/O Sample Programs. The File Class. Without using FileReader. Reviewed method overloading.

5/29/2006. Announcements. Last Time. Today. Text File I/O Sample Programs. The File Class. Without using FileReader. Reviewed method overloading. Last Time Reviewed method overloading. A few useful Java classes: Other handy System class methods Wrapper classes String class StringTokenizer class Assn 3 posted. Announcements Final on June 14 or 15?

More information

ROEVER ENGINEERING COLLEGE Elambalur,Perambalur DEPARTMENT OF CSE

ROEVER ENGINEERING COLLEGE Elambalur,Perambalur DEPARTMENT OF CSE ROEVER ENGINEERING COLLEGE Elambalur,Perambalur-621212 DEPARTMENT OF CSE 2 marks questions with answers CS331-ADVANCED JAVA PROGRAMMING 1. What is Java Streaming? Java streaming is nothing more than a

More information

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

Objec&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 information

Java Object Serialization Specification

Java Object Serialization Specification Java Object Serialization Specification Object serialization in the Java system is the process of creating a serialized representation of objects or a graph of objects. Object values and types are serialized

More information

Data Structures. 03 Streams & File I/O

Data 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 information

ITI Introduction to Computer Science II

ITI 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 information

Learn Java/J2EE Basic to Advance level by Swadeep Mohanty

Learn Java/J2EE Basic to Advance level by Swadeep Mohanty Basics of Java Java - What, Where and Why? History and Features of Java Internals of Java Program Difference between JDK,JRE and JVM Internal Details of JVM Variable and Data Type OOPS Conecpts Advantage

More information

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

Lecture 22. Java Input/Output (I/O) Streams. Dr. Martin O Connor CA166 Lecture 22 Java Input/Output (I/O) Streams Dr. Martin O Connor CA166 www.computing.dcu.ie/~moconnor Topics I/O Streams Writing to a Stream Byte Streams Character Streams Line-Oriented I/O Buffered I/O

More information

pre-emptive non pre-emptive

pre-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 information

WOSO Source Code (Java)

WOSO Source Code (Java) WOSO 2017 - Source Code (Java) Q 1 - Which of the following is false about String? A. String is immutable. B. String can be created using new operator. C. String is a primary data type. D. None of the

More information

CISC 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 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 information

Advanced Object-Oriented Programming Streams and Files

Advanced Object-Oriented Programming Streams and Files Advanced Object-Oriented Programming Streams and Files Dr. Kulwadee Somboonviwat International College, KMITL kskulwad@kmitl.ac.th Streams File I/O Streams and Files Binary I/O Text I/O Object I/O (object

More information

Simple Java Input/Output

Simple 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 information

Complete Java Contents

Complete Java Contents Complete Java Contents Duration: 60 Hours (2.5 Months) Core Java (Duration: 25 Hours (1 Month)) Java Introduction Java Versions Java Features Downloading and Installing Java Setup Java Environment Developing

More information

C17: File I/O and Exception Handling

C17: File I/O and Exception Handling CISC 3120 C17: File I/O and Exception Handling Hui Chen Department of Computer & Information Science CUNY Brooklyn College 10/24/2017 CUNY Brooklyn College 1 Outline Recap and issues Exception Handling

More information

Core Java Syllabus. Overview

Core Java Syllabus. Overview Core Java Syllabus Overview Java programming language was originally developed by Sun Microsystems which was initiated by James Gosling and released in 1995 as core component of Sun Microsystems' Java

More information