12-CRS-0106 REVISED 8 FEB 2013 Java Collection. 12-CRS-0106 REVISED 8 FEB 2013 Java Collection.

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 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.
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.
CS 225 Java Review. Java Applications A java application consists of one or more classes –Each class is in a separate file –Use the main class to start.
Java Review Nelson Padua-Perez Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
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 ->
Java I/O Input: information brought to program from an external source
By: Blake Peters.  OODB- Object Oriented Database  An OODB is a database management system in which information is represented in the form of objects.
5-Oct-15 Air Force Institute of Technology Electrical and Computer Engineering Object-Oriented Programming Design Topic : Streams and Files Maj Joel Young.
12-CRS-0106 REVISED 8 FEB 2013 CSG2H3 Object Oriented Programming.
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.
Prepared by : A.Alzubair Hassan Kassala university Dept. Computer Science Lecture 2 I/O Streams 1.
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.
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.
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.
©SoftMoore ConsultingSlide 1 Serialization. ©SoftMoore ConsultingSlide 2 Serialization Allows objects to be written to a stream Can be used for persistence.
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.
 Learn about computer files  Use the Path class  Learn about  Streams  Buffers  file organization  Use Java’s IO classes to write to and read from.
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.
GENERICS AND FILE HANDLING Saumya Srivastava (977934) Divyangana Pandey (977790) Shubhi Saxena (978108) Arka Das (962969) AHD05/15-16 AJA 21.
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.
12-CRS-0106 REVISED 8 FEB 2013 CSG2H3 Object Oriented Programming.
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
CSC1351 Class 6 Classes & Inheritance.
Keerthi Nelaturu Url: site.uottawa.ca/~knela006
Fundamental of Java Programming
IO in java.
Lecture 8: I/O Streams types of I/O streams Chaining Streams
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.
Ch14 Files and Streams OBJECTIVES
12: The Java I/O System stream model.
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
OBJECT ORIENTED PROGRAMMING II LECTURE 20 GEORGE KOUTSOGIANNAKIS
Files and Streams in Java
Java Basics Introduction to Streams.
CS 240 – Advanced Programming Concepts
David Davenport Spring 2005
Presentation transcript:

12-CRS-0106 REVISED 8 FEB 2013 Java Collection

12-CRS-0106 REVISED 8 FEB 2013 Java Collection

12-CRS-0106 REVISED 8 FEB 2013 Java Collection add( item ) remove( item ) addAll( collection ) removeAll( collection ) retainAll( collection ) contains( item )

12-CRS-0106 REVISED 8 FEB 2013 Java Collection Collection cl = new HashSet(); // Loop using iterator Iterator itr = cl.iterator(); while (itr.hasNext()) { Object o = itr.next(); } // loop using for-element for (Object o : cl) { }

12-CRS-0106 REVISED 8 FEB 2013 Generic Collection Collection str = new HashSet (); List arr_i = new List (); ArrayList emp = new ArrayList ();

12-CRS-0106 REVISED 8 FEB 2013 Sorting Collection Collection.sort( list ) –Element of List must be comparable (implement comparable) Collection.sort( list, comparator ) –Create a comparator class to compare the element –public interface Comparator { int compare(T object1, T object2); }

12-CRS-0106 REVISED 8 FEB 2013 Sorting Collection Example public class Employee implements Comparable { private String name; private double salary; public Employee(String name, double salary) { this.name = name; this.salary = salary; } public String getName() { return name; } public double getSalary() { return salary; public String toString() { return "name=" + name + ", salary=" + salary; public int compareTo(Employee t) { return (this.name).compareTo(t.name); }

12-CRS-0106 REVISED 8 FEB 2013 Sorting Collection Example import java.util.Comparator; public class MyComparator implements Comparator { public int compare(Employee emp1, Employee emp2){ return emp1.getSalary() - emp2.getSalary(); }

12-CRS-0106 REVISED 8 FEB 2013 Sorting Collection Example public static void main(String[] args){ List listEmp = new ArrayList(); listEmp.add(new Employee("bobby", 5)); listEmp.add(new Employee("erick", 56)); listEmp.add(new Employee("anna", 15)); listEmp.add(new Employee("rey", 25)); Collections.sort(listEmp); for (Employee listEmp1 : listEmp) { System.out.println(listEmp1); } Comparator comparator = new MyComparator(); Collections.sort(listEmp, comparator); for (Employee listEmp1 : listEmp) { System.out.println(listEmp1);} name=anna, salary=15.0 name=bobby, salary=5.0 name=erick, salary=56.0 name=rey, salary=25.0 name=bobby, salary=5.0 name=anna, salary=15.0 name=rey, salary=25.0 name=erick, salary=56.0

12-CRS-0106 REVISED 8 FEB 2013 CSG2H3 Object Oriented Programming

12-CRS-0106 REVISED 8 FEB 2013 Computer and Me

12-CRS-0106 REVISED 8 FEB 2013 Input / Output Input : –Keyboard –File Output –Screen –file

12-CRS-0106 REVISED 8 FEB 2013 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

12-CRS-0106 REVISED 8 FEB 2013 Java Stream A Java stream is composed of discrete bytes (characters) of data –Byte streams –Character streams

12-CRS-0106 REVISED 8 FEB 2013 Byte Streams Object InputStream OutputStream FileInputStream FilterInputStream FileOutputStream FilterOutputStream BufferedInputStream DataInputStream BufferedOutputStream DataOutputStream PrintStream

12-CRS-0106 REVISED 8 FEB 2013 Character Streams Object Reader writer BufferedReader InputStreamReader FileReader BufferedWriter OutputStreamWriter PrintWriter FileWriter

12-CRS-0106 REVISED 8 FEB 2013 Snippet Code : Write String

12-CRS-0106 REVISED 8 FEB 2013 Snippet Code : Read String

12-CRS-0106 REVISED 8 FEB 2013 CSG2H3 Object Oriented Programming

12-CRS-0106 REVISED 8 FEB 2013 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).

12-CRS-0106 REVISED 8 FEB 2013 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 Object Persistence

12-CRS-0106 REVISED 8 FEB 2013 Live-time Object Illustration Instantiation Object used in program Some-time Object Saved//Resurect into/from Storage Object destroyed

12-CRS-0106 REVISED 8 FEB 2013 Object Oriented Live as an Object constructor Save as an Object serializing Read as an Object De-serializing

12-CRS-0106 REVISED 8 FEB 2013 Persistence Object To File Object Must be able to transform to binary (implements java.io.Serializa ble) BinaryStream Using io.stream mechanism FileOutputStrea m Write Object to File Using method writeObject() in ObjectOutputSt ream Object in File Open file with FileInputStream class ReadObject in File Using method readObject() in ObjectInputStre am Object Object ready to use

12-CRS-0106 REVISED 8 FEB 2013 Snippet Code : Write Object

12-CRS-0106 REVISED 8 FEB 2013 Snippet Code : Read Object

12-CRS-0106 REVISED 8 FEB 2013 Object Relational Mapping

12-CRS-0106 REVISED 8 FEB 2013 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

12-CRS-0106 REVISED 8 FEB 2013 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

12-CRS-0106 REVISED 8 FEB 2013 Java Hibernate

12-CRS-0106 REVISED 8 FEB 2013 Java Persistence API (JPA)

12-CRS-0106 REVISED 8 FEB 2013 Question?

12-CRS-0106 REVISED 8 FEB 2013 THANK YOU Credits M usic : Yonezawa Madoka - Oui! Ai Kotoba (Instrumental)