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)