CSC1351 Class 6 Classes & Inheritance.

Slides:



Advertisements
Similar presentations
A Guide to Advanced Java Faculty:Nguyen Ngoc Tu. 2 Operating System Application #1 Application #2 Java Virtual Machine #1 Local Memory Shared Memory Threads.
Advertisements

1 Streams and Input/Output Files Part 2. 2 Files and Exceptions When creating files and performing I/O operations on them, the systems generates errors.
1 Streams and Input/Output Files Part 3. 2 Handling Primitive Data Types The basic input and output streams provide read/write methods that can be used.
1 Streams and Input/Output Files Part I. 2 Introduction So far we have used variables and arrays for storing data inside the programs. This approach poses.
Jan Java I/O Yangjun Chen Dept. Business Computing University of Winnipeg.
Lecture 15: I/O and Parsing
The Package Statement Group related interfaces and classes together Purpose: encapsulation and reduces name conflicts –private package classes not visible.
MOD III. Input / Output Streams Byte streams Programs use byte streams to perform input and output of 8-bit bytes. This Stream handles the 8-bit.
Streams Dwight Deugo Nesa Matic Portions of the notes for this lecture include excerpts from.
CSC1351 9/6/2011 Where are we?. Polymorphism // Use dynamic lookup to allow different data types to be manipulated // with a uniform interface. public.
COMP201 Java Programming Topic 5: Input and Output Reading: Chapter 12.
Streams and Files The objectives of this chapter are: To understand the principles of I/O streams and where to use them To understand the options and limitations.
Java I/O and Java Networking (Client Side) Yoshi.
Algorithm Programming I/O via Java Streams Bar-Ilan University תשס"ח by Moshe Fresko.
Java I/O – what does it include? Command line user interface –Initial arguments to main program –System.in and System.out GUI Hardware –Disk drives ->
Exceptions and IO Dr. Andrew Wallace PhD BEng(hons) EurIng
Java I/O Input: information brought to program from an external source
Java Programming: I/O1 Java I/O Reference: java.sun.com/docs/books/tutorial/essential/io/
CS203 Programming with Data Structures Input and Output California State University, Los Angeles.
Streams and Files CMPS Overview Stream classes File objects File operations with streams Examples in C++ and Java 2.
5-Oct-15 Air Force Institute of Technology Electrical and Computer Engineering Object-Oriented Programming Design Topic : Streams and Files Maj Joel Young.
Streams Reading: 2 nd Ed: , rd Ed: 11.1, 19.1, 19.4
Java How to Program, 8/e © by Pearson Education, Inc. All Rights Reserved.
Based on OOP with Java, by David J. Barnes Input-Output1 The java.io Package 4 Text files Reader and Writer classes 4 Byte stream files InputStream, FileInputStream,
JAVA I/O © EnhanceEdu, IIIT Hyderabad. Contents 3/29/2010EnhanceEdu, IIIT - H 2  Command Line I/O  File Class  Streams  Byte Streams [Low level and.
I / O in java. java.io BufferedInputStream BufferedOutputStream BufferedReader BufferedWriter ByteArrayInputStream ByteArrayOutputStream CharArrayReader.
CSC 1351 Semester Summary. CSC 1351 Summary A study aid Not an exclusive set of study materials Please check:
Java Programming: Advanced Topics 1 Input/Output and Serialization Chapter 3.
Java Input/Output CSE301 University of Sunderland Harry Erwin, PhD Half Lecture.
The Java I/O Classes and Interfaces cont’d
File IO Basics By Dan Fleck Coming up: Data Streams.
Input/output Input in java is stream based.A stream represents sequence of bytes or characters. Stream provides an abstract view of I/O. Stream can be.
L5: Input & Output COMP206, Geoff Holmes and Bernhard Pfahringer.
Two Ways to Store Data in a File  Text format  Binary format.
Java Input/Output. Reading standard input Surprisingly complicated (GUI focus) Old-fashioned way: BufferedReader r = new BufferedReader(new InputStreamReader(System.in));
1 Software 1 Java I/O. 2 The java.io package The java.io package provides: Classes for reading input Classes for writing output Classes for manipulating.
Read and Write Files  By the end of this lab you will be able to:  Write a file in internal storage  Read a file from internal storage  Write a file.
Copyright(c) Systems and Computer Engineering, Carleton Univeristy, * Object-Oriented Software Development Unit 13 I/O Stream Hierarchy Case.
Exception Handling, Reading and Writing in Files, Serialization, Exceptions, Files, Streams, File Readers and Writers, Serializable SoftUni Team Technical.
1 Putting Streams to use. 2 Stream Zoo C++ gives you istream, ostream, iostream, ifstream, ofstream, fstream, wistream, wifstream, istrsteam… (18) Java.
Java Input / Output l a modular approach to input/output: - different stream objects are connected/wrapped to handle I/O l a data stream object: a flow.
Java Programming: Advanced Topics 1 Input/Output and Serialization.
Java Programming Language (3) - Input/Output Stream –
CS202 Java Object Oriented Programming Input and Output Chengyu Sun California State University, Los Angeles.
Java IO Exploring the java.io package and living to talk about it.
java.io supports console and file I/O
The Java IO System Different kinds of IO Different kinds of operations
IO in java.
CSG2H3 Object Oriented Programming
Java Text I/O CS140 Dick Steflik. Reader Abstract super class for character based input Subclasses: – BufferedReader – CharArrayReader – FilterReader.
IO in java.
Chapter 17 Input and Output
Exception Handling, Reading and Writing in Files, Serialization,
Chapter 8: Input and Output
Object Writing in files
12: The Java I/O System stream model.
I/O Basics.
תרגול מס' 5: IO (קלט-פלט) זרמי קלט וזרמי פלט ((Input & Output Streams,
File I/O & collection frame work
JAVA IO.
תרגול מס' 5: IO (קלט-פלט) זרמי קלט וזרמי פלט ((Input & Output Streams,
Stream Oriented I/O Computer Programming II Dr. Tim Margush
Adapter Pattern Context:
CSC 143 Java Streams.
OBJECT ORIENTED PROGRAMMING II LECTURE 20 GEORGE KOUTSOGIANNAKIS
Files and Streams in Java
Web Design & Development Lecture 8
Java Basics Introduction to Streams.
David Davenport Spring 2005
Presentation transcript:

CSC1351 Class 6 Classes & Inheritance

Patterns Singleton - The Sound class. Has just one static instance. Model View Controller Model is Board, Piece, Player, Pos View is in Ball and BallViewer Listener classes provide control

Polymorphism // Use dynamic lookup to allow different data types to be manipulated // with a uniform interface. public class FlameThrower implements Weapon { public void inflict(Target t) { t.fireDamage(6); } public class Sword implements Weapon { t.cuttingDamage(3); ... Weapon w = new Sword(); w.inflict(target); // Dynamic lookup of Sword's inflict method w = new FlameThrower(); w.inflict(target); // Method comes from object type, not variable type

Events Mouse addMouseListener() MouseListener - interface MouseAdapter - class with methods that do nothing MouseEvent Keyboard addKeyListener() KeyListener - interface KeyAdapter - class with methods that do nothing KeyEvent

Input Reader - based on chars BufferedReader - wraps a reader String readLine() FileReader - opens files for reading StringReader - reads from a string InputStreamReader - wraps in input stream InputStream - based on bytes BufferedInputStream - wraps an input stream FileInputStream - opens files for reading ObjectInputStream - read whole objects ByteArrayInputStream - read from a byte array

Output Writer FileWriter - create / append to files StringWriter - create strings BufferedWriter - wrapper for a writer PrintWriter - provides println() OutputStreamWriter - write to a stream OutputStream FileOutputStream - create / append to files ByteArrayOutputStream - create a byte array BufferedOutputStream - wraper for a stream PrintStream - provides println() ObjectOutputStream - write whole objects

Making your own javap java.io.Reader | grep abstract int read(char[], int, int); void close(); javap java.io.InputStream | grep abstract int read(); javap java.io.Writer | grep abstract void write(char[], int, int) void flush(); javap javai.io.OutputStream | grep abstract void write(int);

NullOutputStream import java.io.OutputStream; import java.io.PrintStream; public class NullOutputStream extends OutputStream { public void write(int a) {} public static void main(String[] args) { NullOutputStream nout = new NullOutputStream(); PrintStream ps = new PrintStream(nout); ps.println("Hello, world."); }

CapOutputStream import java.io.OutputStream; import java.io.PrintStream; public class CapOutputStream extends OutputStream { public void write(int a) { char c = (char)a; System.out.write(Character.toUpperCase(c)); } public static void main(String[] args) { CapOutputStream cout = new CapOutputStream(); PrintStream ps = new PrintStream(cout); ps.println("Hello, world.");