Introduction to Input and Output - PowerPoint PPT Presentation


PPT – Introduction to Input and Output PowerPoint presentation | free to download - id: 73040c-YzQ5Y


The Adobe Flash plugin is needed to view this content

Get the plugin now

View by Category
About This Presentation

Introduction to Input and Output


Introduction to Input and Output – PowerPoint PPT presentation

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


Write a Comment
User Comments (0)
Transcript and Presenter's Notes

Title: Introduction to Input and Output

Introduction to Input and Output
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.

Layers (or Tiers) of an Application
  • The structure, where a solution is made out of
    connected classes, is called a layered or tiered
  • 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

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

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.

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.

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

Enter Data
Login User
Handle data input
Account Manager
Account Object
Account Object
  • 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
  • If data was saved to a file then the program can
    read them back from the file and rebuild the array

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.

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

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.

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

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)

  • 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