June 27, 2013

KBP Chapter 13

Rickvian aldi / 1601253441 / 02PCT

Review question

1. What are the three possible levels of concurrency in programs?
-Instruction level, Statement level, and Unit level
2. Describe the logical architecture of an SIMD computer.
-Computers that have multiple processors that execute the same instruction simultaneously
3. Describe the logical architecture of an MIMD computer.
-Computers that have multiple processors that operate independently but whose operations can be synchronized
4. What level of program concurrency is best supported by SIMD computers?
-Instruction concurrency level
5. What level of program concurrency is best supported by MIMD computers?
-Unit concurrency level.
6. Describe the logical architecture of a vector processor.
-Vector processors have groups of registers that store the operands of a vector operation in which the same instruction is executed on the whole group of operands simultaneously
7. What is the difference between physical and logical concurrency?
-Physical concurrency – Multiple independent processors (multiple threads of control)
Logical concurrency – The appearance of physical concurrency is presented by time-sharing one processor (software can be designed as if there were multiple threads of control)
8. What is a thread of control in a program?
-A thread of control in a program is the sequence of program points reached as control flows through the program
12. What is a heavyweight task? What is a lightweight task?
-Heavyweight tasks execute in their own address space. Lightweight tasks all run in the same address space – more efficient
Problem Set
1. Explain clearly why competition synchronization is not a problem in a programming environment that supports coroutines but not concurrency.
answer:
Competition synchronization is not necessary when no actual concurrency takes place simply because there can be no concurrent contention for shared resources.  Two nonconcurrent processes cannot arrive at a resource at the same time.
2. What is the best action a system can take when deadlock is detected?
When deadlock occurs, assuming that only two program units are causing the deadlock, one of the involved program units should be gracefully terminated, thereby allowed the other to continue.
3. Busy waiting is a method whereby a task waits for a given event by continuously checking for that event to occur. What is the main problem with this approach?
The main problem with busy waiting is that machine cycles are wasted in the process.
4. In the producer-consumer example of Section 13.3, suppose that we incorrectly replaced the release(access) in the consumer process with wait(access). What would be the result of this error on execution of the system?
Deadlock would occur if the release(access) were replaced by a wait(access) in the consumer process, because instead of relinquishing access control, the consumer would wait for control that it already had.

KBP chapter 12

Rickvian Aldi / 02PCT / 1601253441
Assignment By Mr. Tri Djoko Wahjono

Review Questions

1. Describe the three characteristic features of object-oriented languages.
-Abstract data types, Inheritance and Polymorphism.

2. What is the difference between a class variable and an instance variable?
-The difference between instance and class variables is. Class variables only have one copy that is shared by all the different objects of a class, whereas every object has it’s own personal copy of an instance variable. So, instance variables across different objects can have different values whereas class variables across different objects can have only one value.

3. What is multiple inheritance?
-the inheritance which allows a new class to inherit from two or more classes

4. What is a polymorphic variable?
-A polymorphic variable can be defined in a class that is able to reference (or point to) objects of the class and objects of any of its descendants

5. What is an overriding method?
-Overriding method is a method that purpose is provide an operation in the subclass that is similar to one in the parent class, but is customized for objects of the subclass.

7. What is a virtual method?
-Virtual method is a function or method whose behavior can be overridden within an inheriting class by a function with the same signature.

8. What is an abstract method? What is an abstract class?
-An abstract method is one that does not include a definition (it only defines a protocol). An abstract class is one that includes at least one virtual method. An abstract class cannot be instantiated

9. Describe briefly the eight design issues used -in this chapter for objectoriented languages.
The Exclusivity of Objects
Are Subclasses Subtypes?
Type Checking and Polymorphism
Single and Multiple Inheritance
Object Allocation and Deallocation
Dynamic and Static Binding
Nested Classes
Initialization of Objects

10. What is a nesting class?
-Nesting class is a class whose definition appears inside the definition of another class, as if it were a member of the other class.

11. What is the message protocol of an object?
-Message protocol of an object is the entire collection of methods of an object


problem set

1.What important part of support for inheritance is missing in java?
java does not support the private and protected derivation of c++.One can surmise that the Java designers believed that subclasses should be subtypes,
which they are not when private and protected derivations are supported. Thus,
they did not include them.

5. Compare the class entity access controls of C++ and Ada 95.
C++ has extensive access controls to its class entities. Individual entities can be marked public, private, or protected, and the derivation process itself can impose further access controls by being private. Ada, on the other hand, has no way to restrict inheritance of entities (other than through child libraries, which this book does not describe), and no access controls for the derivation process.

10.explain one advantage of inheritance.
-The advantage is able to reuse the declared class in other name, an inheritance class will inherit all method , attribute inside the class without declaring the same class again. It also reduce the code length.

11.Compare inheritance and nested classes in C++. Which of these supports an is-a relationship?
-clearly inheritance that support is-a relationship. Inheritance offer a solution to both the modification problem posed by abstract data type can inherit the data and functionality of some existing type
nested classes are only used for data hiding, it does not inherit.

KBP chapter 11

Rickvian Aldi / 02PCT / 1601253441
Assignment By Mr. Tri Djoko Wahjono

Review Questions 1. What are the two kinds of abstractions in programming languages?
- Process abstraction and Data abstraction.

2. Define abstract data type.
-An abstract data type is a data structure, in
the form of a record, but which includes subprograms that manipulate its data.

3. What are the advantages of the two parts of the definition of abstract data
type?
-It is a weapon against complexity; a means of making large and/or complicated programs more manageable.

4. What are the language design requirements for a language that supports
abstract data types?

-The representation of objects of the type is hidden from the program units
that use the type, so the only direct operations possible on those objects are
those provided in the type’s definition.
-The declarations of the type and the protocols of the operations on objects
of the type, which provide the type’s interface, are contained in a single
syntactic unit. The type’s interface does not depend on the representation
of the objects or the implementation of the operations. Also, other program
units are allowed to create variables of the defined type.

5. What are the language design issues for abstract data types?
-The first design issue for abstract data types is the form of the container for the interface to the type.
-The second design issue is whether abstract data types can be parameterized.
-The third design issue is what access controls are
provided and how such controls are specified.

15. What is the purpose of a C++ constructor?
-constructors are used to initialize the data members of newly created objects. A constructor
may also allocate the heap-dynamic data that are referenced by the pointer
members of the new object.

17. Where are all Java methods defined?
-Methods in Java must be defined completely in a class.

26. Why does Java not have destructor?
-destructor are obviated by Java’s implicit garbage collection

27. Where are all Java methods defined?
-Methods in Java must be defined completely
in a class.

28. Where are Java classes allocated?
-from the heap and
accessed through reference variables.


30. What is a friend function? What is a friend class?
-Friend functions have access to the private entities of the class where they are declared to be friends.Friend class is a class that can access the private entities of the class which has friend function in it.
37. What is the name of all Ruby constructors?
-Constructors in Ruby are named initialize.

Problem Set
4. What are the advantages of the nonpointer concept in Java?
answer: 
-Any task that would require arrays, structures, and pointers in C can be more easily and reliably performed by declaring objects and arrays of objects. Instead of complex pointer manipulation on array pointers, you access arrays by their arithmetic indices. The Java run-time system checks all array indexing to ensure indices are within the bounds of the array. You no longer have dangling pointers and trashing of memory because of incorrect pointers, because there are no pointers in Java.


10.Which two conditions make data type “abstract”?
answer :
-The representation of objects of the type is hidden from the program units that use the type, so the only direct operations possible on those objects are those provided in the type’s definition.
-The declarations of the type and the protocols of the operations on objects of the type, which provide the type’s interface, are contained in a single syntactic unit. The type’s interface does not depend on the representation of the objects or the implementation of the operations. Also, other program units are allowed to create variables of the defined type.

11. Why is destructor of C# rarely used?
answer:
-Although C# allows destructors to be defined, because it uses garbage collection
for most of its heap objects, destructors are rarely used.

12.How are classes in Ruby are made dynamic?
answer:
-Classes in Ruby are dynamic in the sense that members can be added at
any time. This is done by simply including additional class definitions that
specify the new members. Moreover, even predefined classes of the language,


15. Give one capability that Java 5.0 provides which C# 2005 does not.
answer:
-One capability that Java 5.0 provides that C# 2005 does not is wildcard classes.