CSG2H3 Object Oriented Programming

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 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.
Introduction to Java 2 Programming Lecture 7 IO, Files, and URLs.
Exceptions. Definition Exception: something unexpected that can occur in the execution of a program e.g., divide by zero or attempt to open a file that.
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.
COMP201 Java Programming Topic 5: Input and Output Reading: Chapter 12.
Standard input, output and error. Lecture Under Construction.
Geoff Holmes Overview IO Zoo Stream I/O File I/O Buffering Random-Access Text Streams Examples Serialization Java IO – programs that start with import.
©TheMcGraw-Hill Companies, Inc. Permission required for reproduction or display. Chapter 12  File Input and Output Stream Classes Text Input and Output.
File-based Persistence: Serializability COMP53 Dec 7, 2007.
File I/O in Java CS 311, Winter File Basics Recall that a file is block structured. What does this mean? What happens when an application opens.
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
CS203 Programming with Data Structures Input and Output California State University, Los Angeles.
Java How to Program, 9/e © Copyright by Pearson Education, Inc. All Rights Reserved.
Working with files By the end of this lecture you should be able to: explain the principles of input and output and identify a number of different input.
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.
Program data (instance variables, local variables, and parameters) is transient, because its lifetime ends with the program...if not, before. Sometimes.
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.
12-CRS-0106 REVISED 8 FEB 2013 Java Collection. 12-CRS-0106 REVISED 8 FEB 2013 Java Collection.
Object Persistence and Object serialization CSNB534 Asma Shakil.
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
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.
Two Ways to Store Data in a File  Text format  Binary format.
CIS 270—App Dev II Big Java Chapter 19 Files and Streams.
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.
 Pearson Education, Inc. All rights reserved Files and Streams.
Streams & Files. Java I/O Classes Saving data to / Loading data from files Two Choices: Binary-Formatted or Text-Formatted Data – int x = 1234; – Binary.
DEPARTMENT OF COMPUTER SCIENCE N.HARIKA. Contents Overview of I/O Streams Character Streams Byte Streams Using the Streams 2.
Exception Handling, Reading and Writing in Files, Serialization, Exceptions, Files, Streams, File Readers and Writers, Serializable SoftUni Team Technical.
UMass Lowell Computer Science Java and Distributed Computing Prof. Karen Daniels Fall, 2000 Lecture 13 Java Fundamentals File I/O Serializing an.
1 Putting Streams to use. 2 Stream Zoo C++ gives you istream, ostream, iostream, ifstream, ofstream, fstream, wistream, wifstream, istrsteam… (18) Java.
Simple Java I/O Part I General Principles. Streams All modern I/O is stream-based A stream is a connection to a source of data or to a destination for.
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.
CS202 Java Object Oriented Programming Input and Output Chengyu Sun California State University, Los Angeles.
java.io supports console and file I/O
The Java IO System Different kinds of IO Different kinds of operations
CSC1351 Class 6 Classes & Inheritance.
Keerthi Nelaturu Url: site.uottawa.ca/~knela006
IO in java.
Lecture 8: I/O Streams types of I/O streams Chaining Streams
Java Text I/O CS140 Dick Steflik. Reader Abstract super class for character based input Subclasses: – BufferedReader – CharArrayReader – FilterReader.
IO in java.
Ch14 Files and Streams OBJECTIVES
I/O Basics.
תרגול מס' 5: IO (קלט-פלט) זרמי קלט וזרמי פלט ((Input & Output Streams,
File I/O & collection frame work
Java Programming Course
Chapter 17 Binary I/O Dr. Clincy - Lecture.
JAVA IO.
תרגול מס' 5: IO (קלט-פלט) זרמי קלט וזרמי פלט ((Input & Output Streams,
MSIS 670: Object-Oriented Software Engineering
Stream Oriented I/O Computer Programming II Dr. Tim Margush
Files and Streams in Java
Web Design & Development Lecture 8
Java Basics Introduction to Streams.
14 Files and Streams.
CS 240 – Advanced Programming Concepts
Chapter 8: Exceptions and I/O Streams
David Davenport Spring 2005
Presentation transcript:

CSG2H3 Object Oriented Programming Java I/O

Computer and Me

Input / Output Input : Keyboard File Output Screen file

Java Stream Sequence of data of undetermined length Input streams move data into a Java program usually from an external source System.in Output streams move data from a Java program to an external target. System.out

Java Stream A Java stream is composed of discrete bytes (characters) of data Byte streams Character streams

Byte Streams FileInputStream BufferedInputStream InputStream FilterInputStream DataInputStream Object FileOutputStream BufferedOutputStream OutputStream FilterOutputStream DataOutputStream PrintStream

Character Streams BufferedReader Reader InputStreamReader FileReader Object BufferedWriter writer OutputStreamWriter FileWriter PrintWriter

Snippet Code : Write String

Snippet Code : Read String

CSG2H3 Object Oriented Programming Object Persistence

Object Persistence Persistence is the property of an object through which its existence transcends time (i.e. the object continues to exist after its creator ceases to exist) and/or space (i. e. the objects location moves from the address space in which it was created).

Object Persistence the ability of an object to survive the lifetime of the OS process in which it resides relevant for objects with an internal state The state needs to be retained between object deactivation and object activation

Live-time Object Illustration Instantiation Object used in program Some-time Object Saved//Resurect into/from Storage Object destroyed

Object Oriented Live as an Object constructor Save as an Object serializing Read as an Object De-serializing

Persistence Object To File Must be able to transform to binary (implements java.io.Serializable) BinaryStream Using io.stream mechanism FileOutputStream Write Object to File Using method writeObject() in ObjectOutputStream Object in File Open file with FileInputStream class ReadObject in File Using method readObject() in ObjectInputStream Object Object ready to use

Snippet Code : Write Object

Snippet Code : Read Object

Object Relational Mapping

Object Relational Mapping a programming technique for converting data between incompatible type systems in object- oriented programming languages object-oriented (OO) objects are almost always non-scalar values However, many popular database products such as structured query language database management systems (SQL DBMS) can only store and manipulate scalar values

Object Relational Mapping The programmer must either convert the object values into groups of simpler values for storage in the database (and convert them back upon retrieval), or only use simple scalar values within the program. Object-relational mapping is used to implement the first approach

Java Hibernate

Java Persistence API (JPA)

Question?

Credits Music : Yonezawa Madoka - Oui! Ai Kotoba (Instrumental)