GENERICS AND FILE HANDLING Saumya Srivastava (977934) Divyangana Pandey (977790) Shubhi Saxena (978108) Arka Das (962969) AHD05/15-16 AJA 21.

Slides:



Advertisements
Similar presentations
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.
Advertisements

Introduction to Java 2 Programming Lecture 7 IO, Files, and URLs.
Lecture 15: I/O and Parsing
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.
Java File I/O. File I/O is important! Being able to write and read from files is necessary and is also one common practice of a programmer. Examples include.
Slides prepared by Rose Williams, Binghamton University ICS201 Lecture 23 : Generics King Fahd University of Petroleum & Minerals College of Computer Science.
10-1 Writing to a Text File When a text file is opened in this way, a FileNotFoundException can be thrown – In this context it actually means that the.
Text File I/O. Text Files and Binary Files Files that are designed to be read by human beings, and that can be read or written with an editor are called.
© 2000 Scott S Albert Structured Programming 256 Chapter 7 Streams and File I/O.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter N - 1 Chapter 12 File Input and Output.
CS 206 Introduction to Computer Science II 09 / 14 / 2009 Instructor: Michael Eckmann.
©TheMcGraw-Hill Companies, Inc. Permission required for reproduction or display. Chapter 12  File Input and Output Stream Classes Text Input and Output.
1 File Output. 2 So far… So far, all of our output has been to System.out  using print(), println(), or printf() All input has been from System.in 
Slides prepared by Rose Williams, Binghamton University Chapter 14 Generics and the ArrayList Class.
HST 952 Computing for Biomedical Scientists Lecture 8.
Files and Streams CS 21a. 10/02/05 L18: Files Slide 2 Copyright 2005, by the authors of these slides, and Ateneo de Manila University. All rights reserved.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter N - 1 Chapter 12 File Input and Output.
1 Text File I/O Overview l I/O streams l Opening a text file for reading l Reading a text file l Closing a stream l Reading numbers from a text file l.
Slides prepared by Rose Williams, Binghamton University Chapter 10 File I/O.
1 Streams Overview l I/O streams l Opening a text file for reading l Reading a text file l Closing a stream l Reading numbers from a text file l Writing.
CS102--Object Oriented Programming Lecture 14: – File I/O BufferedReader The File class Write to /read from Binary files Copyright © 2008 Xiaoyan Li.
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 ->
7/2/2015CS2621 OO Design and Programming II I/O: Reading and Writing.
Slides prepared by Rose Williams, Binghamton University Chapter 10 File I/O.
Lecture 30 Streams and File I/O COMP1681 / SE15 Introduction to Programming.
CS 206 Introduction to Computer Science II 01 / 23 / 2009 Instructor: Michael Eckmann.
Chapter 12 File Input and Output. Topics Stream Classes Files Text Input and Output JFileChooser for GUI programs Binary files.
Exceptions and IO Dr. Andrew Wallace PhD BEng(hons) EurIng
Streams and File I/O Chapter 14. I/O Overview I/O = Input/Output In this context it is input to and output from programs Input can be from keyboard or.
Stream: an object that either delivers data to its destination (screen, file, etc.) or that takes data from a source (keyboard, file, etc.) –it acts as.
Very Brief Introduction to Java I/O with Buffered Reader and Buffered Writer.
Prepared by : A.Alzubair Hassan Kassala university Dept. Computer Science Lecture 2 I/O Streams 1.
Chapter 9 1 Chapter 9 – Part 1 l Overview of Streams and File I/O l Text File I/O l Binary File I/O l File Objects and File Names Streams and File I/O.
JAVA: An Introduction to Problem Solving & Programming, 5 th Ed. By Walter Savitch and Frank Carrano. ISBN © 2008 Pearson Education, Inc., Upper.
SE-1020 Dr. Mark L. Hornick 1 File Input and Output.
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.
Chapter 9Java: an Introduction to Computer Science & Programming - Walter Savitch 1 Chapter 9 l Streams and Simple File I/O l Exception Handling with File.
1 Week 12 l Overview of Streams and File I/O l Text File I/O Streams and File I/O.
By Rachel Thompson and Michael Deck.  Java.io- a package for input and output  File I/O  Reads data into and out of the console  Writes and reads.
Introduction to Generics
CS 206 Introduction to Computer Science II 09 / 11 / 2009 Instructor: Michael Eckmann.
CMSC 202 Text File I/O. Aug 8, Text Files and Binary Files Files that are designed to be read by human beings, and that can be read or written with.
CIS Intro to JAVA Lecture Notes Set 6 2-June-05.
Fall 2002CS 150: Intro. to Computing1 Streams and File I/O (That is, Input/Output) OR How you read data from files and write data to files.
CS 116 OBJECT ORIENTED PROGRAMMING II LECTURE 11 GEORGE KOUTSOGIANNAKIS Copyright: 2015 / Illinois Institute of Technology/George Koutsogiannakis 1.
CSI 3125, Preliminaries, page 1 Java I/O. CSI 3125, Preliminaries, page 2 Java I/O Java I/O (Input and Output) is used to process the input and produce.
I/O Basics 26 January Aside from print( ) and println( ), none of the I/O methods have been used significantly. The reason is simple: most real.
I/O Basics Java does provide strong, flexible support for I/O related to files and networks. Java’s console based interaction is limited since in real.
File Input and Output Appendix E © 2015 Pearson Education, Inc., Hoboken, NJ. All rights reserved.
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 Generics. Lecture Objectives To understand the objective of generic programming To be able to implement generic classes and methods To know the limitations.
Generics and file handling Presented by: Abha Kumari Neha Pradip Vhanmane Raj Visa Rashmi Kewlani Suvrat Dixit.
CHAPTER 3 File Output.
Keerthi Nelaturu Url: site.uottawa.ca/~knela006
OO Design and Programming II I/O: Reading and Writing
Lesson 8: More File I/O February 5, 2008
Streams and File I/O.
I/O Basics.
Streams and File I/O Chapter 9 Chapter 9.
Streams and File I/O Chapter 14.
JAVA IO.
CSS 161: Fundamentals of Computing
Computer Programming with JAVA
Input and Output Stream
OBJECT ORIENTED PROGRAMMING II LECTURE 20 GEORGE KOUTSOGIANNAKIS
I/O and Applet from Chapter 12
ECE 122 April 14, 2005.
David Davenport Spring 2005
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, then the stream.
Presentation transcript:

GENERICS AND FILE HANDLING Saumya Srivastava (977934) Divyangana Pandey (977790) Shubhi Saxena (978108) Arka Das (962969) AHD05/15-16 AJA 21

February 3, 2011 CONTENTS - * - 111FC GENERICS-INTRODUCTION A Class Definition with a Type Parameter A Generic Constructor Name Has No Type Parameter INTRODUCTION TO FILE HANDLING Java Streams Classes For File Operations Limitations of generics

February 3, 2011 GENERICS-INTRODUCTION  New feature in JDK1.5.  Generics allow us to abstract over types.  Generics make the code clearer and safer.  Reduces the runtime cast exceptions.  Increase readability and robustness.

February 3, 2011 A Class Definition with a Type Parameter  The T in the angle Bracket is the formal parameter.  This T gets replaced with the respective actual parameter in the invocation of the method.  The generic type declaration complied only once and turned into single class file.  Note on naming convention :Recommended to use single characters and avoid lower case.

February 3, 2011 A Generic Constructor Name Has No Type Parameter!!!  Although the class name in a parameterized class definition has a type parameter attached, the type parameter is not used in the heading of the constructor definition: public Pair ()  A constructor can use the type parameter as the type for a parameter of the constructor, but in this case, the angular brackets are not used: public Pair(T first, T second)  However, when a generic class is instantiated, the angular brackets are used: Pair pair = new Pair ("Happy", "Day");

February 3, 2011 Limitations of Generics: Arrays such as the following are illegal: Pair [] a = new Pair [10]; Although this is a reasonable thing to do, it is not allowed given the way that Java implements generic classes. Other limitations are as follows: Cannot Create, Catch or Throw objects of parametrized types Cannot instantiate generic types with primitive types. Cannot declare static fields whose types are type parameters. Cannot overload a method where the formal parameter types of each overload erase to the same raw type.

February 3, 2011 Types of files: Text files contain strings of printable characters; they look intelligible to humans when opened in a text editor. Binary files contain numbers or data in non-printable codes; they look unintelligible to humans when opened in a text editor. Java can process both binary and text files, but binary files are more common while doing file I/O. INTRODUCTION TO FILE HANDLING

February 3, 2011 JAVA Streams: Definition: an object that either delivers data to its destination (screen, file, etc.) or takes data from a source (keyboard, file, etc.). It acts as a buffer between the data source and destination. Types: Input stream: a stream that provides input to a program. Eg: System.in Output stream: a stream that accepts output from a program. Eg: System.out

February 3, 2011 Classes For File Operations Output: PrintWriter FileOutputStream or FileWriter Input: BufferedReader FileInputStream and FileReader InputStream and OutputStream are designed for byte streams. Reader and Writer are designed for character streams. The byte stream classes and the character stream classes form separate hierarchies. In general, you should use the character stream classes when working with characters or strings, and use the byte stream classes when working with bytes or other binary objects.

February 3, 2011 To use these we need to import java.io.*; Opening an output file creates a new file if it does not already exist Opening an output file that already exists eliminates the old file and creates a new, empty one. Data in the original file is lost To add/append to a file instead of replacing it, add ‘true’ as second parameter to open file in append mode. EXCEPTIONS FileNotFoundException : Input file not found IOException EOFException: Attempt to read a character after EOF has been reached. To avoid this Always check for the end of the file when reading from a file.

February 3, 2011 CODE FOR FILE INPUT

February 3, 2011 CODE FOR FILE OUTPUT

February 3, 2011 REFERENCES: [1] [2] TCS iON [3] [4] tutorials.jenkov.com [5] Patrick Naughton, Herbert Schildt, “Java 2: The Complete Reference”, Osborne/McGraw-Hill Publication, [6]

Thank you AHD05/15-16 AJA 21