ProgUseJava SampleExam-----PTJ_(07-07)_(reference answer参考答案)

 

INTERNATIONAL DIPLOMA IN COMPUTER STUDIES

                                   

PROGRAMMING TECHNIQUES USING JAVA

 

 

 

Registration No:

 

 

 

 

 

 

 

-

 

 

 

 

 

 

 

-

 

 

 

 

 

 

   Student No:

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

                                         DURATION: 3 Hours and 10 Minutes Reading Time

 

 

INSTRUCTIONS:

 

ü     Students are reminded to write their own Registration and Student Number clearly on Question Paper and All Pages of Answer Scripts.

 

ü          Students are reminded to read the questions carefully.

 

ü          No reference material of any kind may be taken in the examination.

 

ü     Students must attempt ALL questions.

           

ü          There are 4 pages altogether.

 

 

 

QUESTION NO

MAXIMUM MARKS

MARKS OBTAINED

Part – I ( 1 to 10 )

10 x 2 = 20

 

Part – II ( 1 to 4 )

4 x 20 = 80

 

Total

100

 


Part – I (20 Marks)

 

1)                  _____________ language is also refers to as one-for-one language.

 

A)    Machine            B)  Assembly            C)  C++                     D)  Pascal

 

2)                  The program that translates programming language into machine code is called _____________ .

 

A)    Compiler            B)  Assembler          C)  Interpreter            D)  None of the above

 

3)                  Which of the following errors refer to as bugs in the program?

 

A)    Logic errors        B)  Syntax errors      C)  Source errors      D)  Compiler errors

 

4)                  This language has become one of the most popular because of the ability to quickly create user-friendly event-driven programs.

 

A)    Java                   B)  C++                   C)  VB                       D)  ASP

 

5)                  Program written in the assembly language is called _____________.

 

A)    Macro                B)  Source Program  C)  Object Program    D)  None of the above

 

6)                  In the _____________ algorithms, the smallest value moves up to the top of the array while the largest value moves to the bottom.

 

A)    Bubble Sort        B)  Quick Sort          C)  Selection Sort       D)  Merge Sort

 

7)                  _____________ is invoked via HTTP on the Web server computer in responds to requests from browsers.

 

A)    Java applet         B)  Java servlet         C)  Java application    D)  None of the above

 

8)                  A Java bytecode program that runs on the application user's computer is called a(n):

 

A)    Java virtual machine                              B)  Servlet

C)    Byte code interpreter                            D)  Applet

 

9)                  Which of the following terms means that an object is complete in itself?

 

A)    Inheritance继承      B)  Encapsulation封装     C)  Polymorphism 多态     D)  None of the above

 

10)              Instances of objects may be referred to as:

 

A)    Object classes                                      B)  Persistent objects

C)    Object class libraries                             D)  None of the above

Part – II (80 Marks)

Question 1 (20 Marks)

a)                  What do you understand by the term “Compiler”?                                                [6 Marks]

Reference: 参见书p4

Compiler is the program that translates source code programs into computer language. it do the following jobs:

 First the source code is read into the computer's memory ,then it will be translated into a kind of in between code: OBJECT CODE, a program will have many different objects and libraries that need to be linked together into one (large) executable By compiling a program into computer language, the execution speed is very fast because the processor read instructions in the program directly.

 

b)                  Distinguish between Local and Global variables. Give examples.                           [4 Marks]

Reference: 参见书p39

Local variables usually are defined in a function body, the use scope is limited in the function body, outside the function body ,the local variables can’t be used. But  global variables usually are defined in the beginning of the program and ouside all functions in the program. we can use the global variables at any function in the program. In the following examples, variable x,n, array ndigits  are  global variables, variable i is local variable and only be used in the for loop block.

 

c)                  Define the following terms related to a decision table:

 

i)                    Action Stub

ii)                   Action Entry                                                                                           [4 Marks]

Reference: 参见书p8

A  decision table as following:

1        candies>=20packets

Y

N

N

N

2   candies>=10packets

N

Y

N

N

3   candies<=10packets

N

N

Y

N

 

 

 

 

 

10% discount is given

X

 

 

 

7% discount is given

 

X

 

 

5% discount is given

 

 

X

X

Action Stub refer to the statements: 10% discount is given, 7% discount is given, 5% discount is given.

Action Entry refer to the corresponding action ,in the above example, the symbole ‘X’ is the action entry.

 

d)                  Explain what you understand by Abstract Classes.                                              [6 Marks]

Reference: 参见书p62

An abstract class is one that is not used to construct objects, but only as a basis for making subclasses. An abstract class exists only to express the common properties of all its subclasses. In Java, every class has a superclass. If we don't specify a superclass, then the superclass is automatically taken to be Object, a predefined class that is part of the package java.lang.      

Question 2 (20 Marks)

 

a)                  Describe each of the following approaches to program design checking:

 

i)                    Catalytic Checking

ii)                   Independent Inspection                                                                      [2 x 5 Marks]

Reference: 参见书p11

Catalytic Checking  is a much less formal approach to design checking: the designer tries to describe in detail to a single colleague exactly how the program works.  The colleague appears in a purely passive role, occasionally asking "why?" or "how?".  The designer has to describe every part of the program carefully, and be able to justify every step.

Independent Inspection nvolves the designer handing work to a colleague to go through alone.  The colleague may walk through or dry run the design, or simply study it: the point that a separate view may bring to light unrecognized problems.  This technique is often adopted by a senior programmer, who will "inspect" a junior's work before discussing it.

 

b)                  With the help of example(s), describe the following terms:

 

i)                    Inheritance

ii)                   Polymorphism                                                                                   [2 x 5 Marks]

Reference: 参见书p57

Inheritance refers to the fact that one class can inherit part or all of its structure and behavior from another class. (一个类可以继承另一个类的部分或全部结构和行为) If class B is a subclass of class A, we also say that class A is a superclass of class B. A subclass can add to the structure and behavior that it inherits. It can also replace or modify inherited behavior.

A method is polymorphic if the action performed by the method depends on the actual type of the object to which the method is applied. Polymorphism is one of the major distinguishing features of object-oriented programming.

abstract class shape{

       int x,y;

       String color;  

       public shape(){

              x=0;

              y=0;

       }

       public shape(int xx,int yy){

             

              x=xx;

              y=yy;

       }

       void setColor(String str){

              color=str;

       }    

abstract     double getArea();      

       }    

class Rect extends shape{  

       public Rect(int xx,int yy){          

              super(xx,yy);

       }    

       double getArea(){

              return x*y;

              }    

       }

class oval extends shape{   

       public oval(int xx,int yy){           

              super(xx,yy);

       }    

       double getArea(){       

              return 0.5*x*x*y*y;

       }

       }

      

class  aaa{

      

       public static void main(String[] args){

             

       //     shape sh=new shape(10,10);

             

              Rect rc=new Rect(10,10);

              System.out.println(rc.getArea());

             

              oval ov=new oval(20,10);

              System.out.println(ov.getArea());

             

       }

}

Question 3 (20 Marks)

a)                  What do you understand by “Abstract Data Types”?                                           [4 Marks]

Reference: 参见书p65

We call a data type abstract, if we do not reveal its representation to the user. Abstract data types offer great flexibility to the programmer. Abstract data types satisfy the good programming principles of information hiding and divide and conquer. Information such as the representation of data items is given only to the one with a need to know: to the implementer and not to the user. With an abstract data type we cleanly separate the programming tasks of implementation and usage: we are well on our way to decompose a large system into smaller modules.

 

b)                  What is meant by “Recursion”? Use example(s) whenever necessary.                   [6 Marks]

Reference: 参见书p65

A programming technique in which a routine calls itself is refer to as recursion. In the following example, the function factorial uses itself in its function body.

public class Factorial {

   public static int factorial (int n){

    int result = 0;

        

    if (n <= 1){

        result = 1;

    }

    else if (n > 1){

        result = n * factorial (n-1);

    }

    return result;

   }

    

   public static void main (String args[]){

    for (int i=0; i<10; i++)

        System.out.print(factorial (i) +" ");

   }

}

c)                  Distinguish between Linked lists and Arrays.                                                        [4 Marks]

Reference: 参见书p70

A linked list consists of a chain of objects of the same type, linked together by pointers from one object to the next. The elements in a linked list is class object. The address of each elements is pointed to by its prior element. An array consists of elements that are simple data type such as int ,float and so on. The address of each element is orderly in the array.

 

d)                  Compare and contrast between Stacks and Queues.                                            [6 Marks]

Reference: 参见书p76

A stack consists of a sequence of items, which should be thought of piled one on top of the other like a physical stack of boxes or cafeteria trays. Only the top item on the stack is accessible at any given time. LIFO(last in first out)先进后出

Queues are similar to stacks in that a queue consists of a sequence of items, and there are restrictions about how items can be added to and removed from the list. a queue has two ends, called the front and the back of the queue. FIFO(first in first out)先进先出

Question 4 (20 Marks)

a)                  By using proper example, discuss the use of "Constructors" in Java classes.          [6 Marks]

Reference: 参见书p53

Object types(对象类型) in Java are very different from the primitive types(原始). Simply declaring a variable whose type is given as a class does not automatically create an object of that class. Objects must be explicitly constructed(对象必须显式地被构造)by Constructor.

An example is listed in the following:

class Person

{

    private String name;

    private int age;

    Person(String name,int age)

    {

        this.name = name;

        this.age = age;

    }   

  

The name of the Constructor is the same with the class name Person. An object of the class Person  is created by the Constructor Person(String name,int age) There are two parameters in the Constructor function, they are name and age.

 

b)                  What do you understand about the term “garbage collection”?                              [4 Marks]

Reference: 参见书p56

In Java, the destruction of objects takes place automatically, we call it garbage collection. Java uses a procedure called garbage collection to reclaim memory occupied by objects that are no longer accessible to a program. It is the responsibility of the system, not the programmer, to keep track of which objects are "garbage".

 

c)                  Briefly describe the three major types of testing.                                                  [6 Marks]

Reference: 参见书p108

There are three main types of testing:

@      Assertion Testing—Testing at the API level, demonstrating that the code will perform as specified: "For this API, and this input, the following output/error will be returned...."

@      Functional Testing—Testing using a high-level, building-block approach. Taking features that have been tested independently, assembling them into small applications, and confirming that they work together.

@      Stress Testing—Continually running features and methods randomly for as long as they might be running in the real world. Stress testing is particularly effective at manifesting memory leaks, garbage collection problems, and thread execution issues.

 

                                                                                                                                                     

d)                  List the different categories of testing tools.                                                          [4 Marks]

Reference: 参见书p109

There are several different categories of testing tools:

·         Code coverage analyzers

·         API level tools

·         Stress level tools

·         Test harnesses

·         GUI/user-level tools

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值