Computer Science 201 _csc 201

Embed Size (px)

Citation preview

  • 7/28/2019 Computer Science 201 _csc 201

    1/16

    Compare Primitive to

    Reference Data Types

    Primitive data types can

    perform simple arithmetic.

    Reference data types require

    methods to be manipulated.

    Components (Specifications)

    of a Problem

    Initial conditions => Problem

    => Result

    input => Plan of Action =>

    Outcome

    Control Structure

    A group of individual instructions

    in a program that takes control of

    the program. The control structure

    should have only one entry and one

    exit point.

    Define Algorithm as it Relates

    to Computer Programs

    An algorithm is a

    programming recipe.

    Define Algorithm as it Relates

    to Problem Theory

    Algorithms can be defined as

    a refinement of a plan of

    action.

  • 7/28/2019 Computer Science 201 _csc 201

    2/16

    Define Real and Artificial

    Formal Problems

    Real - The making of a

    product

    Artificial - Simulated problem

    (playing games/AI).

    Demonstrate two ways to

    declare the string msg = "foo"

    String msg = new String

    ("foo"); //with instantiation

    String msg = "foo"; //without

    instantiation

    Describe a left-decision tree

    nested control structure

    In a left-decision tree nested control structure the "IF"s are nested

    in the "IF" structures not in the else block structure. They are not

    commonly used. The syntax is as follows:

    IF (cond1)

    IF (cond2)

    Statement 1

    ELSE

    Statement 2

    ELSE

    Statement 3

    Describe a nested control

    structure. What are the two

    form of nestes control

    structure

    Multiple number of "IF" statements

    are nested during a process. There

    are two forms of nested control

    structure, left-decision tree and

    right-decision tree

    Describe a one way selection

    control structure

    The conditional path is selected if

    the condition is true. If false, the

    corresponding statement(s) will be

    passed and the lines of code

    following the block are executed.

  • 7/28/2019 Computer Science 201 _csc 201

    3/16

    Describe a right-decision tree

    nested control structure

    In a right-decision tree nested control structure, the statements are tested

    until a true statement is found. This is the most common nested control

    structure. The syntax follows:

    IF (cond1)

    Statement 1

    ELSE

    IF (cond2)

    Statement 2

    ELSE

    IF (cond3)

    Statement 3

    ELSE

    Statement 4

    Describe a Switch Control

    Structure

    The switch statement allows you to choose from a

    fixed set of alternatives. It is used in a narrow

    collection of situations.

    Switches should not be used with real numbers.

    only Integers and integer compatibles (characters)

    Switches must use "breaks" to avoid code "fall

    through"

    Describe a two-way selection

    control structure

    Regardless of conditions, one

    of two paths will always be

    taken

    Describe Encapsulation

    The mechanism that binds together codes

    and data and prevents unauthorized

    acces to the heart of the class which is

    private. A class is designed such that the

    implementation is protected from the

    action of external code except through

    form interface.

    Describe Inheritance

    Each object is related to one or

    more objects. One class of objects

    inherits data behavior from another

    object. In other words, sub classes

    share characteristics of the class

    they are derived from.

  • 7/28/2019 Computer Science 201 _csc 201

    4/16

    Describe Multi-way Selection

    Control

    Selection control that

    involves more than two

    structures.

    Describe Polymorphism

    The capability of an object to assume different

    forms. Messages can lead to different operations

    depending on the object receiving it. Example:

    Context based right clicking

    Formal definition: The mechanism by which one

    general interface can be used to access different

    specific implementations.

    Describe the AND operator.

    Give an example of how it can

    be used with bit sequences

    True when all conditions are true. The java syntax

    is &&. Used for filtering/masking a bit pattern.

    Allow only the 1st and 2nd bits through:

    10101101

    00000011

    00000001

    Describe the Bottom Up

    design structure and give

    advantages and

    disadvantages

    Modules are designed first, then put

    together to form the main program.

    Advantages: Less expensive and

    faster to build

    Disadvantages: The pieces don't

    always work well together.

    Describe the NOT operator.The NOT operator is used to

    reverse a condition. Java

    Syntax is !.

  • 7/28/2019 Computer Science 201 _csc 201

    5/16

    Describe the OR operator.

    Give an example of how it can

    be used with bit sequences

    True when any input is true. The java

    syntax is ||

    Used for bit setting (sets any or all bits to

    1) in a sequence.

    Set the 2nd bit: 10101101

    00000010

    10101111

    Describe the XOR operator.

    Give an example of how it can

    be used with bit sequencing

    Also ca lled the equivalence operator. Returns FALSE when both

    statements are the same. The Java syntax is a compound statemen

    (!ab + a!b). Used for testing bit sequence errors (unexpected state

    change) and also for flipping:

    10101101

    11111111

    01010010

    Describe Top Down design

    structure and give

    advantages and

    disadvantages

    The overall structure of the program is

    already known and modules are

    integrated as design progresses.

    Disadvantage: Expensive and time

    consuming

    Advantage: Highly customized.

    Fields of Computer Science

    Switching Theory

    Software Engineering

    Automation and Control

    Robotics

    Biotechnology

    Hardware Design

    Give a General Definition of

    Algorithm

    Algorithm is a set of defined

    instructions which result into

    a solution

  • 7/28/2019 Computer Science 201 _csc 201

    6/16

    How are Problems of

    Analysis and Synthesis

    Linked

    Generally speaking software

    engineers convert problems of

    analysis to problems of

    synthesis which can then be

    solved by computers.

    How does Java handle

    dangling pointers caused by

    string literals declared

    without instantiation?

    Java periodically runs a

    GarbageCollection method to

    eliminate objects with zero

    reference.

    Identifier vs Method Syntax Identifier - xyz

    Method - xyz()

    List the Logical Operators

    OR NOR

    XOR XNOR

    AND NAND

    NOT

    Relational Operators

    An operator which determines the

    relationship of a one value to

    another and returns a true or false

    result. They are binary operators

    != >= < ==

  • 7/28/2019 Computer Science 201 _csc 201

    7/16

    Selection Control Structure

    Allows the program to execute one

    of the alternative paths. The

    selection is governed by the

    outcome of a conditional test that

    evaluates if a statement is true or

    false.

    Six Recommendations on the

    Selection of Algorithms

    1. Avoid algorithms which cause informal problems.

    2. Avoid algorithms with undetermined solutions

    3. Avoid algorithms which require excessive amounts

    of time.

    4. Select algorithms that closely fit the specifications

    5. Select algorithms which allow for assumptions

    6. Select algorithms which don't generate multiple

    problems

    6.1 Examine the algorithm's efficiency

    String Tokenization

    Using ReadLine(), it is possible to

    convert a string of multiple items

    into individual values (tokens).

    String Tokenization generally

    requires wrapper classes to convert

    between different integer types

    Suggestions for Program

    Appearance

    1. Format the program in a way that

    enhances its readability

    2. Use spaces between segments

    3. All composite sequences must be

    separated

    4. Use appropriate (and well named)

    identifiers

    The Four Stages of

    Programming Development

    1. Program Planning

    2. Program Coding

    3. Testing and Debugging

    4. Maintenance/Refactoring

  • 7/28/2019 Computer Science 201 _csc 201

    8/16

    Three Common Principles of

    Programming Style

    1. Program structure and

    design

    2. Program Documentation

    3. Program Overall

    Appearance and Style

    What are conditions for a

    Switch Control Structure?

    1. When a comparison (equality) is

    performed

    2. When the same expression is being

    compared in each condition

    3. When the type of value to which the

    expression being compared is integer

    compatible

    What are Formal Problems

    Characterized by complete

    specification of a problem:

    initial conditions, plan of

    action, and expected

    outcome.

    What are Informal Problems

    Informal problems have no satisfactory

    solution. The result of the problem

    cannot be achieved knowing the

    specifications of the problem (initial

    conditions and the plan of action). There

    is no satisfactory solution.

    What are Logical Operators

    Used for in Programming

    1. For Supporting multiple or

    complex conditions

    2. For setting or clearing bit

    sequences

  • 7/28/2019 Computer Science 201 _csc 201

    9/16

    What are Object Oriented

    Programs

    Complex software programs

    requiring proper abstraction

    and separating the internal

    implementation from external

    behavior of the object.

    What are the elements of

    program Documentation?

    1. Explanation of components

    2. Functioning of each unit

    3. Summary of the problem specification

    4. Special algorithms (if used)

    5. Assumptions made

    6. Formulation

    7. Name of program

    8. Date

    9. Date of last modification

    10. Project Name

    11. Division/Dpt

    12. References used for program development

    What are the Four Stage of

    Program Design?

    1. Input Phase

    2. Output Phase

    3. Formulation of

    Assumptions

    4. Constraints

    What are the three primary

    characteristics of Objects in

    OOP

    Polymorphism

    Inheritance

    Encapsulation

    What are the three types of

    selection control structures?

    One-way selection control

    structure, two-way selection

    control structure, and multi-

    way selection control

    structure.

  • 7/28/2019 Computer Science 201 _csc 201

    10/16

    What are the Two Categories

    of Formal Problems

    Problems of analysis and

    problems of synthesis

    What are the two forms of

    multi-way selection control

    Nested selection control and

    switch control structure

    What are the two method

    types found in Java?

    Strict (Instance) methods

    Static methods

    What are the two program

    design structures that are

    commonly used?

    Top Down and Bottom Up

    What are the two types of

    control structures

    Selection Control Structure

    and Loop Control Structure

  • 7/28/2019 Computer Science 201 _csc 201

    11/16

    What are Wrapper Classes

    Wrapper classes allow us to

    convert between different

    variable types: strings,

    integers, doubles, booleans,

    etc

    What happens when a

    Primitive Data Type is

    declared?

    1. A space is reserved for an int

    data type

    2. The variable name gets

    associated with the first byte

    of allocated storage

    What happens when a

    Reference Data Type is

    declared?

    1. A list of all variable objects and their associated

    data types are generated for compiling.

    2. Sufficient memory is allocated for the declared

    type as referenced by the address.

    3. The first byte of the address is assigned to the

    reference name, only after the object is instantiated.

    The allocation is not done until the object is

    instantiated. Therefore string msg; does nothing.

    What is a class in OOP?Consists of a Data Structure and

    methods that can be applied to that

    structure. A class is a module unit.

    Class = operations + data structure

    What is a Computer

    Program?

    A computer program is the statement of

    an algorithm in a computer

    programming language. It is a collection

    of instructions that a computer can

    understand, process and accomplish. It is

    an exacting task.

  • 7/28/2019 Computer Science 201 _csc 201

    12/16

    What is a method in OOP?

    A unit of a program module

    that contains a sequence of

    operations and statements. In

    Java, methods can ONLY exist

    within a class.

    What is a module in OOP?

    A structure consisting of

    interrelated segments arranged in

    logical order to form an integrated

    unit. It is constructed basically from

    classes.

    What is a Plan of Action

    A general outline of the major

    steps we need to accomplish

    our goal, starting at

    predefined initial conditions.

    What is a Problem of Analysis

    A formal problem where the initial

    condition (input) and the result (output)

    are known. The goal is to identify the plan

    of action.

    Problems of Analysis are generally solved

    by a programmer or software engineer

    What is a Problem of

    Synthesis

    A formal problem where the initial

    condition (input) and the plan of action

    are known. The goal is to identify the

    result (output).

    Problems of Synthesis are generally

    solved by a computer.

  • 7/28/2019 Computer Science 201 _csc 201

    13/16

    What is a Problem?

    A goal or a task. The

    difference between actual

    conditions and those that are

    required or desired.

    What is a Shift operator

    Used to shift bit patterns to the

    right or to the left.

    Logical shifts multiply or divide the

    pattern by the pattern's base.

    (LogicalShiftLeft x)

    (LogicalShiftRight /)

    What is a Static method in

    Java?

    Static methods are called by

    prefixing them with the class name.

    No instance variables of any object

    of the class are defined in the

    method. Example: Math.pow(2,3)

    calls the exponent method pow.

    What is a Strict method in

    Java?

    The method is associated with an object

    and use the instance variables of that

    object. Instance methods are called by

    prefixing it with an object. Example:

    System.out.println("")

    Strict methods are also known as

    instance methods

    What is a String?

    A string is a REFERENCE data type

    where the variable references the

    location in memory where the

    actual value is stored. The actual

    stored value is the object.

  • 7/28/2019 Computer Science 201 _csc 201

    14/16

    What is an abstract data

    type?

    Refers to a data type together

    with a set of operations that

    can be performed on that

    data structure.

    What is an Object

    All objects have:

    1. Name

    2. Behavior

    3. Receives input (receives message)

    Example: Remote Control

    name - remote control

    behavior - changes channels on a television

    receives input - from user using the number/keypad

    What is Automatic

    Dereferencing?

    The process of obtaining the

    address from a reference variable

    and going to the address to retrieve

    the correct number of bytes for the

    object.

    What is Computer Science?The study of how computers

    can be applied effectively and

    efficiently to solve problems.

    What is InstantiationThe process of allocation that

    creates a SPECIFIC instance

    of an object

  • 7/28/2019 Computer Science 201 _csc 201

    15/16

    What is Parsing Parsing is the process of

    tokenization

    What is Problem Theory?

    The study of characteristics of problems.

    Most problems have certain

    characteristics that are independent of

    the details of any particular problem or

    may have a relation to other problems in

    general.

    What is the input phase of

    Program Design?

    Identify where input comes

    from and what they are.

    User? Storage?

    What is the output phase of

    Program Design?

    Identify the outputs of the

    computer program. Does

    something get displayed on

    the screen? On a printer?

    What is the Purpose of Object

    Oriented Programming

    To provide software developers with:

    Reliability

    Cost effectiveness

    Adaptability

    Understandability

    Reusable

  • 7/28/2019 Computer Science 201 _csc 201

    16/16

    What kind of method is

    Decimalformat("format

    string")

    DecimalFormat is a static

    method because it is called

    simply from it's class name.

    No object name is used.

    What two reference data

    types don't require

    instantiation?

    Strings and arrays