Computer Science and Engineering

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

The Package Statement Group related interfaces and classes together Purpose: encapsulation and reduces name conflicts –private package classes not visible.
Streams Dwight Deugo Nesa Matic Portions of the notes for this lecture include excerpts from.
Spring/2002 Distributed Software Engineering C:\unocourses\4350\slides\DefiningThreads 1 Serialization Flatten your object for automated storage or network.
Slide 10.1 Advanced Programming 2004, based on LY Stefanus’s Slides Object Serialization Object serialization: the process of converting an object into.
Chapter - 12 File and Streams (continued) This chapter includes -  DataOutputStream  DataInputStream  Object Serialization  Serializing Objects 
12-2 Chapter Topics Chapter 12 discusses the following main topics: Part I: Exceptions Handling Exceptions Throwing Exceptions Part II: More about Input/Output.
King Saud University College of Computer and Information Sciences Department of Computer Science Dr. S. HAMMAMI Chapter 3 File Input/Output Chapter 3 File.
Lecture 31 File I/O -Part 2 COMP1681 / SE15 Introduction to Programming.
©TheMcGraw-Hill Companies, Inc. Permission required for reproduction or display. Chapter 12  File Input and Output Stream Classes Text Input and Output.
Unit 211 File IO Binary Files Reading and Writing Binary Files Writing Objects to files Reading Objects from files.
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved Chapter Trees and B-Trees.
File-based Persistence: Serializability COMP53 Dec 7, 2007.
Unit 201 File IO Binary Files Reading and Writing Binary Files Writing Objects to files Reading Objects from files.
Scott Grissom, copyright 2004Ch 3: Java Features Slide 1 Why Java? It is object-oriented provides many ready to use classes platform independent modern.
Slides prepared by Rose Williams, Binghamton University Chapter 10 File I/O.
Advanced Java Class Serialization. Serialization – what and why? What? –Translating the contents of an Object to a series of bytes that represent it,
Chapter 91 Streams and File I/O Chapter 9. 2 Reminders Project 6 released: due Nov 10:30 pm Project 4 regrades due by midnight tonight Discussion.
CS102--Object Oriented Programming Lecture 14: – File I/O BufferedReader The File class Write to /read from Binary files Copyright © 2008 Xiaoyan Li.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved L08 (Chapter 18) Binary I/O.
Java File I/O (Continued). File I/O in Java Like every other programming language, Java supports the writing to and reading from different files with.
School of Engineering and Computer Science Victoria University of Wellington Copyright: Xiaoying Gao, Peter Andreae, VUW Indexing Large Data COMP
Files and Streams (part 2) 1 -Based on slides from Deitel & Associates, Inc. - Revised by T. A. Yang.
CPSC 335 BTrees Dr. Marina Gavrilova Computer Science University of Calgary Canada.
Nirmalya Roy School of Electrical Engineering and Computer Science Washington State University Cpt S 122 – Data Structures Data Structures Trees.
§6 B+ Trees 【 Definition 】 A B+ tree of order M is a tree with the following structural properties: (1) The root is either a leaf or has between 2 and.
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.
Lecture Objectives  To learn how to use a tree to represent a hierarchical organization of information  To learn how to use recursion to process trees.
Streams Reading: 2 nd Ed: , rd Ed: 11.1, 19.1, 19.4
Java I/O Writing and Reading Objects to File Serialization.
Chapter 14 - Designing Data Access Classes1 Chapter 14 Designing Data Access Classes.
Object Persistence and Object serialization CSNB534 Asma Shakil.
 Pearson Education, Inc. All rights reserved Files and Streams.
Object Serialization.  When the data was output to disk, certain information was lost, such as the type of each value.  If the value "3" is read from.
©SoftMoore ConsultingSlide 1 Serialization. ©SoftMoore ConsultingSlide 2 Serialization Allows objects to be written to a stream Can be used for persistence.
1 Lecture 21: Binary Search Tree delete etc. operations Lecturer: Santokh Singh CompSci 105 SS 2005 Principles of Computer Science.
CS 116 OBJECT ORIENTED PROGRAMMING II LECTURE 12 GEORGE KOUTSOGIANNAKIS Copyright: 2015 Illinois Institute of Technology/ George Koutsogiannakis 1.
Introduction to Collections. Collections Collections provide a way of organizing related data in a model Different types of collections have different.
Spring 2008 Mark Fontenot CSE Honors Principles of Computer Science I Note Set 20.
UMass Lowell Computer Science Java and Distributed Computing Prof. Karen Daniels Fall, 2000 Lecture 13 Java Fundamentals File I/O Serializing an.
1 Copyright © 2011 Tata Consultancy Services Limited TCS Internal.
Files and Serialization. Files Used to transfer data to and from secondary storage.
File Input & Output1 Streams & File I/O. Introduction (1) The Java platform includes a number of packages that are concerned with the movement of data.
XSLT in Practice. Exercises  download Apache Xalan - install it - try the example in Xalan-Java Overview  ZVON XSLT Tutorial.
1 CSE 331 Memento Pattern and Serialization slides created by Marty Stepp based on materials by M. Ernst, S. Reges, D. Notkin, R. Mercer, Wikipedia
CSG2H3 Object Oriented Programming
OBJECT ORIENTED PROGRAMMING II LECTURE 21 GEORGE KOUTSOGIANNAKIS
CS-0401 INTERMEDIATE PROGRAMMING USING JAVA
University Of Karachi Department Of Computer Science
Recursive Objects (Part 4)
Object Writing in files
Applets In Java Visit for more Learning Resources 1.
Accessing Files in Java
Java Serialization B.Ramamurthy 11/8/2018 B.Ramamurthy.
CS 116 Object Oriented Programming II
Java Serialization B.Ramamurthy 11/14/2018 B.Ramamurthy.
MSIS 670: Object-Oriented Software Engineering
Exceptions Complicate Code
Exceptions Complicate Code
Serialization and Deserialization Bullet points from Head First Java, Ch Dec-18 serialization.ppt.
CSE 331 Memento Pattern slides created by Marty Stepp based on materials by M. Ernst, S. Reges, D. Notkin, R. Mercer, Wikipedia
OBJECT ORIENTED PROGRAMMING II LECTURE 22 GEORGE KOUTSOGIANNAKIS
Binary Search Trees Chapter 9 2/22/2019 B.Ramamurthy.
Computer Science and Engineering
Copyright ©2012 by Pearson Education, Inc. All rights reserved
Binary Search Trees Chapter 9 2/24/2019 B.Ramamurthy.
Exceptions Complicate Code
Podcast Ch23f Title: Serialization
Sorting And Searching CSE116A,B 4/7/2019 B.Ramamurthy.
System Models Bina Ramamurthy 9/7/2019 B.Ramamurthy.
Presentation transcript:

Computer Science and Engineering Binary Decision Tree Computer Science and Engineering 1/13/2019 B.Ramamurthy

Introduction Binary Search Tree: Key value at the root partitions the set of data represented in the tree into three disjoint sets: A set with key value at the root A set of keys in the left subtree < key value of the root A set of keys in the right subtree > key value of the root We considered only numerical values, > and < operators. In a decision tree the criteria for partition is stored in the internal node and the data in the leaf nodes. When the partition is two-way we get a binary decision tree. Example: Tree for the popular animal guessing game The criteria “mammal” could split the zoo animals into two sets, such other criteria could split the two sets further, until the splitting process results in a single animal kind. 1/13/2019 B.Ramamurthy

(Zoo) Animal Tree Is it a mammal? no yes Is it an amphibian? Is it a wild animal? no yes yes no Frog Parrot Does it have a long neck? Cow yes no Questions with “yes” or “no” answers at the internal nodes; Answers at the leaf nodes. Giraffe Tiger 1/13/2019 B.Ramamurthy

Simple Guesser: no load/save 1/13/2019 B.Ramamurthy

Builder/Guesser with save/no load AnimalDBBuilder java.io.Serializable BTreeInterface ObjectOutputStream BTree Visitor OutputFile LearnVisitor PlayVisitor 1/13/2019 B.Ramamurthy

Guesser with simple load/save GuesserSimpleLoadSave java.io.Serializable BTreeInterface ObjectOutputStream ObjectInputStream BTree Visitor OutputFile InputFile LearnVisitor PlayVisitor 1/13/2019 B.Ramamurthy

Guesser with Load/Save Visitors OtherApplications GuesserLoadSave java.io.Serializable BTreeInterface ObjectOutputStream ObjectInputStream Visitor BTree OutputFile InputFile LearnVisitor PlayVisitor LoadVisitor SaveVisitor 1/13/2019 B.Ramamurthy

Load/Save (using Object Streaming) The capability to store and retrieve Java objects is essential to building persistence and streaming into application. Writing to an Object Stream Reading from an Object Stream Exception Handling Example: See the code in the BTree example 1/13/2019 B.Ramamurthy

Persistence The values of the data structures in a program are lost when the program terminates. If you want the data to exist after program termination you need to store it in a file or in a database. This capability of data is known as persistence. 1/13/2019 B.Ramamurthy

How to use Serialization? 1. import java.io.*; 2. Specify the class whose instances need to be stored/loaded as implementing java.io.Serializable interface. 3. Use writeObject and readObject methods whose header are as given below: void writeObject (Object obj) throws IOException; Object readObject() throws ClassNotFoundException, IOException; 1/13/2019 B.Ramamurthy

Writing to an Object Stream // serialize various objects into a file FileOutputStream f = new FileOutputStream(“tmp”); ObjectOutputStream s = new ObjectOutputStream(f); s.writeObject(“Today”); s.writeObject(new Date()); BTree t = new BTree(“MyName”, null, null); s.writeObject(t); 1/13/2019 B.Ramamurthy

Reading from an Object Stream // Deserialize a objects from a file FileInputStream inf = new FileInputStream(“tmp”); ObjectInputStream s1 = new ObjectInputStream(inf); //read the Object and cast to retrieve the // actual object String = (String)s1.readObject(); Data date = (Date)s1.readObject(); BTree animalDB = (BTree)s1.readObject(); 1/13/2019 B.Ramamurthy