Introduction to Input and Output - PowerPoint PPT Presentation

1 / 16
About This Presentation
Title:

Introduction to Input and Output

Description:

Introduction to Input and Output – PowerPoint PPT presentation

Number of Views:82
Avg rating:3.0/5.0
Slides: 17
Provided by: PORe150
Category:

less

Transcript and Presenter's Notes

Title: Introduction to Input and Output


1
Introduction to Input and Output
2
Layers (or Tiers) of an Application
  • Software in the real world normally takes the
    form of a number of independent classes, like
    lego blocks, that can be stuck together in
    whatever form the designer wishes.
  • Programmers thus write sections or components of
    a solution and put them together as they go along.

3
Layers (or Tiers) of an Application
  • The structure, where a solution is made out of
    connected classes, is called a layered or tiered
    approach.
  • Distinct parts of a solution are organized into
    distinct groups and these are then put together
    to form layers.
  • There are usually 3 distinct layers
  • The user interface
  • The logic layer
  • The data layer

4
Layer/ Tiers
  • There are usually three distinct layers
  • The user interface layer is intended to contain
    all the statements necessary to supply
    information to and obtain information from the
    user. The user interface layer may not
    necessarily process the information or store that
    information, for these functions it can pass the
    information to an application layer.
  • The application layer, sometimes called the
    business logic or logic layer, is usually
    responsible for managing the information and
    performing operations on it, for example
    retrieving information, computing results,
    applying rules.
  • The data layers responsibility is to store or
    retrieve the data on disk, in memory or in a
    database.

5
Tier Example - Bank
  • For example imagine that you were asked to write
    an Information System for a bank.
  • The structure for a bank you meet the teller
    when you go in the door, they take your
    particular request and then defer to a manager.
    The manager then looks up your file to see if you
    can be granted your request, passes their
    decision to the teller who will notify you.

6
Tier Example - Bank
  • To computerise this would require a User
    Interface to the system that the tellers could
    use to create new accounts and to lodge and
    withdraw money from accounts. This User Interface
    would use another part of the program which would
    manage accounts. The layer which manages accounts
    would effectively replace the manager and
    therefore carries out business logic. Account
    information could be stored as objects in the
    data layer.
  • Therefore we have three distinct sections for our
    problem, a Graphical User Interface layer, a
    Business Logic layer and a Data layer.

7
Bank
8
Developing Layers
  • Each layer must be debugged before use
  • Layers should be as independent as possible

9
Layers
GUI
Enter Data
Login User
Handle data input
Logic
Data
DataBase
Account Manager
Account Object
Account Object
10
Scenario
  • We want to write a file to maintain an array of
    person objects.
  • The user can add to, delete from or modify Person
    objects in the array.
  • To make this practical, we must save data to a
    file
  • If data was saved to a file then the program can
    read them back from the file and rebuild the array

11
File I/O
  • The most basic of Input/Output with Java is done
    with streams.
  • Think of a stream as a flow of data, which can be
    an input stream or an output steam
  • The stream commands enable you to write to a disk
    or to the output screen.

12
File I/O
  • A common term in programming is persistence.
  • How can you make data persist, or still be
    available, from one run of a program to the next?
  • You have 2 main choices-
  • Write/Read from files
  • Write/Read from database

13
File I/O
  • No matter where the data is coming from or going
    to and no matter what type its type, the
    mechanism for sequentially reading and writing
    data are basically the same.

READING WRITING
open a stream open a stream
while more information while more information
read information write information
close the stream close the stream
14
File and FileDialog Objects
  • Suppose we want to read the contents of a file
    sample.data. Before we begin the actual operation
    of reading data from this file, we must create a
    File object (from the java.io package) and
    associate it to the file.
  • We call the File constructor
  • File inFile new File (sample.data)
  • File inFile new File (c\\JavaProjects,
    xyz.data)

15
File and FileDialog
  • A file MUST be opened before performing any file
    access operation.
  • Since the user can select a file from a directory
    different from the current directory, we should
    use directoryPath in creating a file object
  • File inFile new File (directoryPath, filename)

16
Streams
  • A Stream is simply a sequence of data items,
    usually eight-bit bytes.
  • Java has 2 types of streams
  • An input stream
  • An output stream
  • An input stream has a source from where the data
    items come and an output stream has a destination
    to where the data items are going.
  • To read/write data items from/to a file, we
    attach one of the Java input/output stream
    objects to the file.
  • The basic classes for Java I/0 are
    FileInputStream and FileOutputStream
Write a Comment
User Comments (0)
About PowerShow.com