Fundamentals of Programming - PowerPoint PPT Presentation

1 / 15
About This Presentation
Title:

Fundamentals of Programming

Description:

Overview of OO concepts and related questions in the model paper ... Discuss briefly some strategies for answering ... It is unblocked after I/O is completed. ... – PowerPoint PPT presentation

Number of Views:28
Avg rating:3.0/5.0
Slides: 16
Provided by: ewiscu
Category:

less

Transcript and Presenter's Notes

Title: Fundamentals of Programming


1
Fundamentals of Programming
  • QA

2
Last Week...
  • Identified question types
  • Answered questions based on fundamentals
  • Overview of OO concepts and related questions in
    the model paper
  • Gave contact information fp_at_ict.cmb.ac.lk

3
This Week...
  • Discuss briefly some strategies for answering
    questions
  • Look at more model questions selected from other
    (more advanced) areas of the syllabus

4
Strategies for Answering
  • Fill-in-the-blank Usually 1 answer
  • Expression evaluation Usually 1 answer
  • Identifying correct/incorrect statements
  • Note if correct or incorrect choices are required
  • When combinations are given, there may still be
    more than one answer (try by elimination)
  • When multiple answers are possible, at least mark
    those you are sure of (dont skip)
  • This is NOT an exhaustive list of strategies!

5
  • There are some sections in the syllabus relating
    to more advanced features of Java
  • One of these relates to threads and
    multi-threading
  • Java threads have six states ready, running,
    waiting, sleeping, blocked and dead
  • The init() method gives birth to a thread that
    becomes ready to be run. The run() method then
    takes the thread into running state.
  • The sleep() method can stop a thread for a
    period, while the wait method makes a thread wait
    till it is woken using an explicit notify()
    method.
  • Once a thread completes execution it dies.

6
  • The final event that can occur to a running
    thread is that it can be blocked for accessing
    input or output. It is unblocked after I/O is
    completed.
  • Threads can be assigned pre-defined priorities,
    MIN, NORM and MAX or a customised priority level
    (1-10)
  • Priority is implemented by higher priority
    threads pre-empting (taking the processor from)
    lower priority ones as soon as they become ready.
  • While any thread can explicitly yield to another,
    by definition higher priority threads cannot do
    this to lower ones.

7
  • Since platforms are different, the exact way in
    which multi-threading is implemented on each may
    be slightly different

8
  • 49) Identify the correct statements related to
    threads?
  • (a) A thread is not executable if it is dead.
  • (b) In Java, a higher priority executable thread
    will pre-empt threads of lower priority.
  • (c) Threads may yield to threads of lower
    priority.
  • (d) Java multithreading is platform dependent.
    Thus, a multithreaded application could behave
    differently on different Java implementations.
    (e) Threads in the waiting state for a monitor
    object must eventually be awakened explicitly
    with a notify (or interrupt ) or the tread will
    wait forever
  • ANSWER (a), (b), (d) and (e)

9
  • 17) Following are some descriptions about
    threads. Identify the correct statement(s).
  • (a) Java is a multithreaded language that allows
    a program to have in-built processes where more
    than one process can be executed concurrently
    within a single program
  • (b) Multithreading is similar to
    multiprocessing however with multithreading all
    execution context do not share the same memory.
  • (c) The benefits of multithreading is most
    apparent in Graphical User Interfaces and in
    applets
  • (d) In Java thread class is defined in java.lang
    as a subclass of the Object class
  • (e) A thread is a non-independent sequential
    flow of control within a process.

10
  • This is another question regarding threads
  • Multithreading is a technique of running more
    than a single independent thread of instruction
    within a single program
  • In Java this support is available as part of the
    core language
  • Multiprocessing is where each such process also
    has its own memory, but a Java program is one
    such process.
  • Multithreading is essential for windows-based and
    internet/ web programming where more than one
    thing can be done at a time
  • ANSWER (a), (c) and (d)

11
  • 37) The following descriptions are related to
    Input/Output in java. Identify the correct ones.
  • a) Streams provide communication channels
    between files and programs.
  • b) Random access file is useful for transaction
    processing applications such as airline
    reservation systems
  • c) DataInputStream class supports seeking a
    specific byte position in the file with method
    seek.
  • d) An existing file is opened for output the
    contents of the file are discarded after issuing
    a warning message.
  • e) Not opening a file before attempting to
    reference it in a program will not give an error
    in java

12
  • This is a question regarding another of the more
    advanced features of Java - INPUT and OUTPUT
  • Streams are an abstraction of all forms of
    information input and output - be it to/from a
    file, a device or a network
  • There are various extensions of the basic Stream
    to handle different requirements
  • e.g. RandomAccessFile is a file that can be
    searched non-sequentially (using the method seek)
    - an essential feature of any on-line system
  • Unlike in some languages, opening an existing
    file for output does not discard its contents,
    but attempting to reference a file without
    opening it will result in an error
  • ANSWER (a) and (b)

13
  • 50) The following descriptions are related to
    Javas Files and Streams. Identify the correct
    ones.
  • (i) Java views each file as a sequential stream
    of bytes
  • (ii) The InputStream class is an abstract class
    that serves as the base class for all other input
    stream classes.
  • (iii) The PrintStream class is derived from
    OutputStream and is designed primarily for
    printing output data as text
  • (iv) The DataInputStream class is useful for
    reading abstract Java data types from an input
    stream
  • (a) all correct (b) (i), (ii) and (iii) (c) (i)
    and (iii)
  • (d) (ii), (iii) (e) (i) ,(iv)

14
  • This is another question relating to Streams
  • As discussed in the previous question a stream
    can be viewed as a channel for sending and
    receiving information
  • The abstract classes InputStream and OutputStream
    are the basic classes for inputting and
    outputting information respectively using this
    channel concept
  • These basic classes are extended for more
    functionality such as in DataInputStream and
    PrintStream respectively
  • DataInputStream supports reading basic Java data
    types from streams, but it needs to be extended
    to handle abstract data types
  • ANSWER (b) - i.e. all except the last is correct

15
  • Exam Dates 31st March and 1st April
  • Wish you all success!
Write a Comment
User Comments (0)
About PowerShow.com