Senin, 25 Mei 2015

Transfornation - Dari Sampah Menjadi Berkah

Pendahuluan

Banyaknya sampah di Indonesia merupakan masalah yang serius. Sampah non-organik seperti plastik, botol, lampu bekas tidak bisa diuraikan secara biologis. Salah satu cara untuk mengurangi sampah non organik adalah dengan mendaur  ulang sampah tersebut menjadi barang lain yang mempunyai nilai guna.

Hari 1 - Workshop

Dalam acara charity TRANSFORNATION yang diselenggarakan oleh Binus Square dan Binus Square Student Community (BSSC) bekerja sama dengan Komunitas LUMINTU untuk memberikan training pada mahasiswa Binus bagaimana cara mendaur ulang sampah. Workshop diadakan pada tanggal 15 May 2015 di Binus Square. Pada workshop ini saya membuat robot dari sampah






Peralatan yang digunakan antara lain: gunting baja, lem tembak, cat pilox, gergaji besi
Bahan yang digunakan: lampu bekas, botol bekas, pena bekas, CD tak terpakai, bola plastic dan PCB elektronik bekas

Setelah robot di rangkai, robot pun kemudian di cat menggunakan pilox.
Tantangan paling besar adalah kreativitas dan imaginasi untuk membuat robot. Selain itu perlu extra hati-hati saat menggunakan lem tembak karena panas. Tapi overall workshopnya sangat seru dang a nyangka banget sampah bisa dibuat menjadi robot-robot yang keren. Salut buat komunitas lumintu #lumintu

Hari 2 - Buat Robot di Yayasan Hati Suci

Pada hari kedua acara TRANSFORNATION teman-teman dari LUMINTU bersama mahasiswa Binus pergi mngunjungi yayasan Hati Suci. Tujuan kami adalah untuk berbagi pengetahuan tentang mendaur ulang sampah.

Di yayasan Hati Suci ada 43 anak, masing-masing anak mendapat mentor 1-2 orang mahasiswa. Saya dan +Vena Sushmita mementori Wiken. Dia berumur 10 tahun. Kami membuat robot yang kayak tank.





Hari 3 - Buat Skenario Cerita

Pada hari ketiga (Minggu, 17 May 2015) kami dibagi dalam kelompok-kelompok. Setiap kelompok harus menyiapkan satu scenario cerita yang berhubungan dengan robot-robotnya.

Kelompok kami membuat cerita tentang showroom robot. Showroomnya berisi robot-robot hebat yang dijual untuk menjaga umat manusia dari kejahatan.

Pembuatan showroom memanfaatkan kardus bekas untuk bentuk bangunannya. Untuk aksesoris lainnya menggunakan sampah-sampah bekas sepeti sendok, pena, kertas, tutup botol, botol plastic dll. Karena keterbatasan waktu pembuatan showroom robot di lanjutkan oleh anak-anak yayasan Hati Suci.






Hari 4 - Presentasi

Pada hari keempat (24 May 2015), tepatnya 1 minggu setelah hari ketiga saya sangat terkejut melihat hasil kerja anak-anak di yayasan Hati Suci. Mereka melakukan finishing yang sangat detail. Mereka menambahkan orang-orangan dari kertas, kaca mika sebagai tangga dll.

Sembelum acara resmi ditutup panitia meminta setiap kelompok untuk mempresentasikan hasil karyanya. Kami pun menceritakan showroom buatan kami dengan senang dan bangga. 






Dari acara ini saya belajar banyak hal. Saya belajar bahwa sampah tidak sekedar barang sisa tapi sampah adalah bahan baku untuk membuat sebuah kreasi. Sekian terima kasih


Kamis, 27 Juni 2013

Chap 15 - Review Question and Problem Set - Concepts of Programming Languages, Sebesta

CONCEPTS OF
PROGRAMMING LANGUAGES
TENTH EDITION
Robert W. Sebesta
Chapter 15-Functional Programming Languages


Review Question

5. Explain why QUOTE is needed for a parameter that is a data list.
Answer: To avoid evaluating a parameter, it is first given as a parameter to the primitive function QUOTE, which simply returns it without change.

6. What is a simple list?
Answer: A list which membership of a given atom in a given list that does not include sublists.

7. What does the abbreviation REPL stand for?
Answer: REPL stand for read-evaluate-print loop

8. What are the three parameters to IF?
Answer:
The Scheme two-way selector function, named IF, has three parameters: a predicate expression, a then expression, and an else expression. A call to IF has the form (IF predicate then_expression else_expression)

11. What are the two forms of DEFINE?
Answer:
DEFINE takes two lists as parameters. The first parameter is the prototype of a function call, with the function name followed by the formal parameters, together in a list. The second list contains an expression to which the name is to be bound.

18. What is tail recursion? Why is it important to define functions that use recursion to specify repetition to be tail recursive?
Answer:
A function is tail recursive if its recursive call is the last operation in the function. This means that the return value of the recursive call is the return value of the nonrecursive call to the function. It is important to specify repetition to be tail recursive because it is more efficient(increase the efficiency).

27. What is the use of the fn reserved word in ML?
Answer: T
he predicate function is often given as a lambda expression, which in ML is defined exactly like a function, except with the fn reserved word, instead of fun, and of course the lambda expression is nameless.

29. What is a curried function?
Answer:
Curried functions are interesting and useful because new functions can be constructed from them by partial evaluation.

30. What does partial evaluation mean?
Answer:
Partial evaluation means that the function is evaluated with actual parameters for one or more of the leftmost formal parameters.

31. Define reader macros.
Answer:
Reader macros or read macros, that are expanded during the reader phase of a LISP language processor. A reader macro expands a specific character into a string of LISP code. For example, the apostrophe in LISP is a read macro that expands to a call to QUOTE. Users can define their own reader macros to create other shorthand constructs.

32.What is the use of evaluation environment table?
Answer:
A table called the evaluation environment stores the names of all implicitly and explicitly declared identifiers in a program, along with their types. This is like a run-time symbol table. When an identifier is declared, either implicitly or explicitly, it is placed in the evaluation environment.

33. Explain the process of currying.
Answer:
The process of currying replaces a function with more than one parameter with a function with one parameter that returns a function that takes the other parameters of the initial function.


Problem Set

6. Refer to a book on Haskell programming and discuss the features of Haskell
Answer:
Haskell features lazy evaluation, pattern matching, list comprehension, type classes, and type polymorphism.Lazy evaluation or call-by-need is an evaluation strategy which delays the evaluation of an expression until its value is needed (non-strict evaluation) and which also avoids repeated evaluations (sharing). The sharing can reduce the running time of certain functions by an exponential factor over other non-strict evaluation strategies, such as call-by-name.Pattern matching is the act of checking a perceived sequence of tokens for the presence of the constituents of some pattern. In contrast to pattern recognition, the match usually has to be exact. The patterns generally have the form of either sequences or tree structures. Uses of pattern matching include outputting the locations (if any) of a pattern within a token sequence, to output some component of the matched pattern, and to substitute the matching pattern with some other token sequence.List comprehension is a syntactic construct available in some programming languages for creating a list based on existing lists. It follows the form of the mathematical set-builder notation (set comprehension) as distinct from the use of map and filter functions.Type class is a type system construct that supports ad-hoc polymorphism. This is achieved by adding constraints to type variables in parametrically polymorphic types. Such a constraint typically involves a type class T and a type variable a, and means that a can only be instantiated to a type whose members support the overloaded operations associated with T.Polymorphism is a programming language feature that allows values of different data types to be handled using a uniform interface.

7. What features make F# unique when compared to other languages?
Answer:
F# has a full-featured IDE, an extensive library of utilities that supports imperative, object-oriented, and functional programming, and has interoperability with a collection of nonfunctional languages. F# includes a variety of data types. Among these are tuples, like those of Python and the functional languages ML and Haskell, lists, discriminated unions, an expansion of ML’s unions, and records, like those of ML, which are like tuples except the components are named. F# has both mutable and immutable arrays.

8.How is the functional operator pipeline(|>)used in F#?
Answer:
The pipeline operator is a binary operator that sends the value of its left operand, which is an expression, to the last parameter of the function call, which is the right operand. It is used to chain together function calls while flowing the data being processed to each call. Consider the following example code, which uses the high-order functions filter and map:

let myNums = [1; 2; 3; 4; 5]

let evensTimesFive = myNums

|> List.filter (fun n −> n % 2 = 0)

|> List.map (fun n −> 5 * n)



Special thanks to Mr. Tri Djoko Wahjono, Ir., M.Sc.

Chap 14 - Review Question and Problem Set - Concepts of Programming Languages, Sebesta

CONCEPTS OF
PROGRAMMING LANGUAGES
TENTH EDITION
Robert W. Sebesta
Chapter 14-Exception Handling and Event Handling


Review question

1. Define exception, exception handler, raising an exception, disabling an exception, continuation, finalization, and built-in exception.
Answer: An exception is an unusual event that is detectable by either hardware or software and that may require special processing. The special processing that may be required when an exception is detected is called exception handling. The processing is done by a code unit or segment called an exception handler. An exception is raised when its associated event occurs. In some situations, it may be desirable to ignore certain hardware-detectable exceptions—for example, division by zero—for a time. This action would be done by disabling the exception. After an exception handler executes, either control can transfer to somewhere in the program outside of the handler code or program execution can simply terminate. We term this the question of control continuation after handler execution, or simply continuation. In some situations, it is necessary to complete some computation regardless of how subprogram execution terminates. The ability to specify such a computation is called finalization. Built-in exceptions have a built-in meaning, it is generally inadvisable to use these to signal program-specific error conditions.  Instead we introduce a new exception using an exception declaration, and signal it using a raise expression when a run-time violation occurs.  That way we can associate specific exceptions with specific pieces of code, easing the process of tracking down the source of the error.

2. When is an exception thrown or raised?
Answer: The exception thrown or raised when there is throw clause of a method lists that have checked exception which could throw and does not handle.

10. What are the four exceptions defined in the Standard package of Ada?
Answer: The four exception defined in the standard package of Ada are Constraint_Error, Program_Error, Storage_Error, Tasking_Error

11. What is the use of suppress pragma in Ada?
Answer: An Ada pragma is a directive to the compiler. Certain run-time checks that are parts of the built-in exceptions can be disabled in Ada programs by use of the Suppress pragma, the simple form of which is pragma Suppress(check_name) where check_name is the name of a particular exception check. The Suppress pragma can appear only in declaration sections. When it appears, the specified check may be suspended in the associated block or program unit of which the declaration section is a part. Explicit raises are not affected by Suppress. Although it is not required, most Ada compilers implement the Suppress pragma.

13. Describe three problems with Ada’s exception handling.
Answer: There are several problems with Ada’s exception handling. One problem is the propagation model, which allows exceptions to be propagated to an outer scope in which the exception is not visible. Also, it is not always possible to determine the origin of propagated exceptions. Another problem is the inadequacy of exception handling for tasks. For example, a task that raises an exception but does not handle it simply dies. Finally, when support for object-oriented programming was added in Ada 95, its exception handling was not extended to deal with the new constructs. For example, when several objects of a class are created and used in a block and one of them propagates an exception, it is impossible to determine which one raised the exception.

14. What is the name of all C++ exception handlers?
Answer: Each catch function is an exception handler. A catch function can have only a single formal parameter, which is similar to a formal parameter in a function definition in C++, including the possibility of it being an ellipsis (. . .). A handler with an ellipsis formal parameter is the catch-all handler; it is enacted for any raised exception if no appropriate handler was found. The formal parameter also can be a naked type specifier, such as float, as in a function prototype. In such a case, the only purpose of the formal parameter is to make the handler uniquely identifiable. When information about the exception is to be passed to the handler, the formal parameter includes a variable name that is used for that purpose. Because the class of the parameter can be any user-defined class, the parameter can include as many data members as are necessary.

15. Which standard libraries define and throw the exception out_of_range in C++?
Answer: The exception out_of_range in C++ thrown by library container classes

16. Which standard libraries define and throw the exception overflow_error in C++?
Answer: the exception overflow_error in C++ thrown by math library functions

19. State the similarity between the exception handling mechanism in C++ and Ada
Answer: In some ways, the C++ exception-handling mechanism is similar to that of Ada. For example, unhandled exceptions in functions are propagated to the function’s caller.

20. State the differences between the exception handling mechanism in C++ and Ada
Answer: There are no predefined hardware-detectable exceptions that can be handled by the user, and exceptions are not named. Exceptions are connected to handlers through a parameter type in which the formal parameter may be omitted. The type of the formal parameter of a handler determines the condition under which it is called but may have nothing whatsoever to do with the nature of the raised exception.

24. What is the difference between checked and unchecked exceptions in Java?
Answer: Exceptions of class Error and RuntimeException and their descendants are called unchecked exceptions. All other exceptions are called checked exceptions. Unchecked exceptions are never a concern of the compiler. However, the compiler ensures that all checked exceptions a method can throw are either listed in its throws clause or handled in the method. Note that checking this at compile time differs from C++, in which it is done at run time. The reason why exceptions of the classes Error and RuntimeException and their descendants are unchecked is that any method could throw them. A program can catch unchecked exceptions, but it is not required.

26. How can an exception handler be written in Java so that it handles any exception?
Answer: The exception handlers of Java have the same form as those of C++, except that every catch must have a parameter and the class of the parameter must be a descendant of the predefined class Throw-able. The syntax of the try construct in Java is exactly as that of C++, except for the finally clause.

28. What is the purpose of Java finally clause?
Answer: A finally clause is placed at the end of the list of handlers just after a complete try construct. The semantics of this construct is as follows: If the try clause throws no exceptions, the finally clause is executed before execution continues after the try construct. If the try clause throws an exception and it is caught by a following handler, the finally clause is executed after the handler completes its execution. If the try clause throws an exception but it is not caught by a handler following the try construct, the finally clause is executed before the exception is propagated


Problem Set

1 . What mechanism did early programming languages provide to detect or attempt to deal with errors?
Answer:
Early programming languages were designed and implemented in such a way that the user program could neither detect nor attempt to deal with such errors. In these languages, the occurrence of such an error simply causes the program to be terminated and control to be transferred to the operating system. The typical operating system reaction to a run-time error is to display a diagnostic message, which may be meaningful and therefore useful, or highly cryptic. After displaying the message, the program is terminated.

2. Describe the approach for the detection of subscript range errors used in C and Java.
Answer:
Java compilers usually generate code to check the correctness of every subscript expression (they do not generate such code when it can be determined at compile time that a subscript expression cannot have an out-of-range value, for example, if the subscript is a literal). In C, subscript ranges are not checked because the cost of such checking was (and still is) not believed to be worth the benefit of detecting such errors. In some compilers for some languages, subscript range checking can be selected (if not turned on by default) or turned off (if it is on by default) as desired in the program or in the command that executes the compiler.

5. From a textbook on FORTRAN, determine how exception handling is done in FORTRAN programs.
Answer:
For example, a Fortran “Read” statement can intercept input errors and end-of-file conditions, both of which are detected by the input device hardware. In both cases, the Read statement can specify the label of some statement in the user program that deals with the condition. In the case of the end-of-file, it is clear that the condition is not always considered an error. In most cases, it is nothing more than a signal that one kind of processing is completed and another kind must begin. In spite of the obvious difference between end-of-file and events that are always errors, such as a failed input process, Fortran handles both situations with the same mechanism.

6. In languages without exception-handling facilities, it is common to have most subprograms include an “error” parameter, which can be set to some value representing “OK” or some other value representing “error in procedure”. What advantage does a linguistic exception-handling facility like that of Ada have over this method?
Answer:
There are several advantages of a linguistic mechanism for handling exceptions, such as that found in Ada, over simply using a flag error parameter in all subprograms. One advantage is that the code to test the flag after every call is eliminated. Such testing makes programs longer and harder to read. Another advantage is that exceptions can be propagated farther than one level of control in a uniform and implicit way. Finally, there is the advantage that all programs use a uniform method for dealing with unusual circumstances, leading to enhanced readability.

7. In a language without exception handling facilities, we could send an error-handling procedure as a parameter to each procedure that can detect errors that must be handled. What disadvantages are there to this method?
Answer:
There are several disadvantages of sending error handling subprograms to other subprograms. One is that it may be necessary to send several error handlers to some subprograms, greatly complicating both the writing and execution of calls. Another is that there is no method of propagating exceptions, meaning that they must all be handled locally. This complicates exception handling, because it requires more attention to handling in more places.


Special thanks to Mr. Tri Djoko Wahjono, Ir., M.Sc.

Chap 13 - Review Question and Problem Set - Concepts of Programming Languages, Sebesta

CONCEPTS OF
PROGRAMMING LANGUAGES
TENTH EDITION
Robert W. Sebesta
Chapter 13-Concurrency


Review question

1. What are the three possible levels of concurrency in programs?
Answer:
- Instruction level (executing two or more machine instructions simultaneously)
- Statement level (executing two or more high-level language statements simultaneously)
- Unit level (executing two or more subprogram units simultaneously)

2. Describe the logical architecture of an SIMD computer.
Answer:
SIMD computer has some processor. One processor is used to control and coordinate the other processor. ecause all of the processors, except the controller, execute the same instruction at the same time, no synchronization is required in the software. Perhaps the most widely used
SIMD machines are a category of machines called vector processors. They 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. Originally, the kinds of programs that could most benefit from this architecture were in scientific computation, an area of computing that is often the target of multiprocessor machines. However, SIMD processors are now used for a variety of application areas, among them graphics and video processing. Until recently, most supercomputers were vector processors.

4. What level of program concurrency is best supported by SIMD computers?
Answer: Statement-level concurrency

5. What level of program concurrency is best supported by SIMD computers?
Answer: Unit-level concurrency

7. What is the difference between physical and logical concurrency?
Answer: Physical concurrency is several program units from the same program that literally execute simultaneously.Logical concurrency is multiple processors providing actual concurrency, when in fact the actual execution of programs is taking place in interleaved fashion on a single processor.

8. what is the work of a scheduler?
Answer: A run-time system program called a scheduler manages the sharing of processors among the tasks.

16. What is a task descriptor?
Answer: Task descriptor is a data structure that stores all of the relevant information about the execution state of a task.

21. What is a binary semaphore? What is a counting semaphore?
Answer: Binary semaphore is a semaphore that requires only a binary-valued counter, like the one used to provide competition synchronization. A counting semaphore is a synchronization object that can have an arbitrarily large number of states.

30. What is purpose of an Ada terminate clause?
Answer: The purpose of an Ada terminate clause is to mark that the task is finished with its job but is not yet terminated.

34. What does the Java sleep method do?
Answer: It blocks the tread by using a single parameter that contains of integer of millisecond

35. What does the Java yield method do?
Answer: Yield method surrenders the processor voluntarily as a request from the running thread.

36. What does the Java join method do?
Answer: Java forces a method to delay its execution until the run method of another thread has completed its execution.

42. What kind of Java object is a monitor?
Answer: In Java, a monitor can be implemented in a class designed as an abstract data type, with the shared data being the type. Accesses to objects of the class are controlled by adding the synchronized modifier to the access methods.

55. What is Concurrent ML?
Answer: Concurrent ML is an extension to ML that includes a fform of threads and a form of synchronous message passing to support concurrency.

56. What is the use of the spawn primitive of CML?
Answer: The use of Spawn primitive of CML is to create a thread.



57. What is the use of subprograms BeginInvoke and EndInvoke in F#?
Answer: The use of subprograms BeginInvoke and Endinvoke in F# is to call threads asynchronously.



58. What is the use of the DISTRIBUTE and ALIGN specification of HPC?
Answer: The use of DISTRIBUTE and ALIGN specification of HPC is to provide information to the compiler on machines that do not share memory, that is, each processor has its own memory.


Problem set

1 . Explain why a race condition can create problems for a system.
Answer:
Race condition is a condition when two or more task is racing to use the shared resource. This condition may create a problem for the system because when there is no "winner" so the system have choose which task can may use the resource. But as long as there is a task arrives first the system will allow it to use the resource.

2. What are the different ways to handle deadlock?
Answer:
To handle a deadlock the system should terminated one or more program units, the others may continue without being terminated. In other case of deadlock, the system can pending one or more program units and let the other 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?
Answer:
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 woud be the result of this error on execution of the system?
Answer:
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.


Special thanks to Mr. Tri Djoko Wahjono, Ir., M.Sc.

Rabu, 26 Juni 2013

Chap 12 - Review Question and Problem Set - Concepts of Programming Languages, Sebesta

CONCEPTS OF
PROGRAMMING LANGUAGES
TENTH EDITION
Robert W. Sebesta
Chapter 12-Support for Object-Oriented Programming
Review Question

2. What are the problems associated with programming using abstract data types?
Answer:
-In nearly all cases, the features and capabilities of the existing type are not quite right for the new use.
-The type definitions are all independent and are at the same level.

4. What is message protocol?
Answer: Message protocol is the entire collection of methods of an object.

5. What is an overriding method?
Answer: Overriding method is method that overrides the inherited method.

7. What is dynamic dispatch?
Answer: Dynamic dispatch is the third characteristic (after abstract data types and inheritance) of object-oriented programming language which is a kind of polymorhphism provided by the dynamic binding of messages to method definitions.

8. What is an abstract method ? What is an abstract class ?
Answer: a method which all descendant classes should have. An abstract class is a class which implement abstract method.

12. From where are Smalltalk objects allocated?
Answer: Smalltalk objects are allocated from the heap and are referenced through reference variables, which are implicitly dereferenced.

15. What kind of inheritance, single or multiple, does Smalltalk support?
Answer: Smalltalk supports single inheritance; it does not allow multiple inheritance.

19. How are C++ heap-allocated objects deallocated?
Answer: C++ heap-allocated objects are deallocated using destructor.

25. What is mixins in objective-C?
Answer: Mixins are sometimes used to add certain functionalities to different classes. And, of course, the class still has a normal superclass from which it inherits members. So, mixins provide some of the benefits of multiple inheritance, without the naming collisions that could occur if modules did not require module names on their functions.

29. Does Objective-C support multiple inheritance?
Answer: No Objective-C doesn’t support it. (It supports only single inheritance).

33. What is the purpose of an Objective-C category?
Answer: The purpose of an Objective-C category is to add certain functionalities to different classes and also to provide some of the benefits of multiple inheritance, without the naming collisions that could occur if modules did not require module names on their functions.

38. What is boxing?
Answer: Boxing is primitive values in Java 5.0+ which is implicitly coerced when they are put in object context. This coercion converts the primitive value to an object of the wrapper class of the primitive value’s type.

39. How are Java objects deallocated?
Answer: By implicitly calling a finalizemethod when the garbage collector is about to reclaim the storage occupied by the object.


Problem Set

1 . What important part of support for inheritance is missing in Java?
Answer: Java does not support the private and protected access control, unlike in C++ user can determine which data member can be inherit by using protected access control.

3. Compare the inheritance of C++ and Java.
Answer:
-In Java, all objects are Inherited, either directly or indirectly. While in C++ a class can be defined to stand on its own without an ancestor.
-In Java, methods are virtual by default. In C++, we explicitly use virtual keyword.
-Java uses a separate keyword interface for interfaces, and abstract keyword for abstract classes and abstract functions.
-In Java, there’s no access level specifier of inheritance, while C++ has private public and protected.
-Unlike C++, Java doesn’t support multiple inheritance. A class cannot inherit from more than one class. A class can implement multiple interfaces though.

7. What is one programming situation where multiple inheritance has a significant disadvantage over interfaces ?
Answer:
When two or more parent classes are derived from one grandparent class and they have one same child. (diamond problem)

9. Given an example of inheritance in C++, where a subclass overrides the superclass methods.
Answer:

class car{

public :
void engine()
{std::cout<<”120 hp”;}
}
class sportcar : public car{
public :
void enginge()
{std::cout<<”580 hp”;}
}


10. Explain one advantage of inheritance
Answer:
One advantage of inheritance is more easier for update of a program. Because child classes are inherited from the parent to if there are any update the programmer can only focus on the parent.
The attitude or function in the parent will automatically inherited to the children.

12. Compare inheritance and nested classes in C++. Which of these supports an is-a relationship?
Answer:
Inheritance is where one class (child class) inherits the members of another class (parent class).Nested class is a class declared entirely within the body of another class or interface.

17. What are the different options for object destruction in Java?
Answer:
Finalize is related to C++ destructor. A finalize method is implicitly called when the garbage collector is about to reclaim the storage occupied by the object. The problem with finalize is that the time it will run cannot be forced or even predicted. The alternative to using finalize to reclaim resources held by an object about to be garbage collected is to include a method that does the reclamation. The only problem with this is that all clients of the objects must be aware of this method and remember to call it.

21. Compare the support for polymorphism in C# with that of in Objective-C.
Answer:
In Objective-C, polymorphism is implemented in a way that differs from the way it is done in most other common programming languages. A polymorphic variable is created by declaring it to be of type id. Such a variable can reference any object. The run-time system keeps track of the class of the object to which
an id type variable refers. If a call to a method is made through such a variable, the call is dynamically bound to the correct method, assuming one exists.
To allow dynamic binding of method calls to methods in C#, both the base method and its corresponding methods in derived classes must be specially marked. The base class method must be marked with virtual, as in C++. To make clear the intent of a method in a subclass that has the same name and protocol as a virtual method in an ancestor class, C# requires that such methods be marked override if they are to override the parent class virtual method.

25. Study and explain private and public modifiers in C++. How do those modifiers differ in C#?
Answer:
C++ includes both classes and structs, which are nearly identical constructs. The only difference is that the default access modifier for class is private, whereas for structs it is public. C# also has structs, but they are very different from those of C++. In C#, structs are, in a sense, lightweight classes. They can have constructors, properties, methods, and data fields and can implement interfaces but do not support

Special thanks to Mr. Tri Djoko Wahjono, Ir., M.Sc.

Chap 11 - Review Question and Problem Set - Concepts of Programming Languages, Sebesta

CONCEPTS OF
PROGRAMMING LANGUAGES
TENTH EDITION
Robert W. Sebesta
Chapter 11-Abstract Data Type and Encapsulation
Review Question

1. What are the two kinds of abstraction in programming languages?
Answer: The two kinds of abstraction in programming languages are process abstraction and data abstraction.

2. Define abstract data type.
Answer: Abstract data type is a data structure that include its data member and also member function that process its data.

6 . Explain how information hiding is provided in Ada package.
Answer: Data type representations can appear in the package specification but be hidden from clients by putting them in the private clause of the package. The abstract type itself is defined to be private in the public part of the package specification. Private types have built-in operations for assignment and comparison for equality and inequality.

10. What is the use of the Ada with clause ?
Answer: To make the names defined in external packages visible

15. What is the purpose of a C++ destructor?
Answer: Destructor in C++ can be used to print a value of some or all of the object's data members dan it can deallocate an object from a class.

16. What are the legal return types of a destructor?
Answer: there are no legal return from a destructor and constructor. It is like void function that has no return value.

20. What is the use of limited private types?
Answer: An alternative to private types is a more restricted form: limited private types. Nonpointer limited private types are described in the private section of a package specification, as are nonpointer private types. The only syntactic difference is that limited private types are declared to be limited private in the visible part of the package specification. The semantic difference is that objects of a type that is declared limited private have no built-in operations. Such a type is useful when the usual predefined operations of assignment and comparison are not meaningful or useful. For example, assignment and comparison are rarely used for stacks.

21. What are initializers in Objective-C?
Answer: The initializers in Objective-C are constructors.

22. What is the use of @private and @public directives?
Answer: The use is to specify the access levels of the instance variables in a class definition.

27. Where are all Java methods defined?
Answer: All Java methods are defined in a class.

37. What is the name of all Ruby constructors?
Answer: Constructors in Ruby are named initialize.

43. What is a C++ namespace, what is its purpose?
Answer: In general, a namespace is a container for a set of identifiers and allows the disambiguation of homonym identifiers residing in different namespaces. The purpose is to help programs manage the problem of global namespace.

Problem Set:

4. What are the advantages of the nonpointer concept in Java?
Answer:
Advantages:
-It reduce the chance of memory leak
-No nameless variable
Disadvantage:
-Not allowed to declare pointer variable
-Increase the complexity of task related to data structer like array, structure ect.

9. What happens if the constructor is absent in Java and C++?
Answer:
If there is no constructor in jave and C++ so the compiler will set a default constructor.

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 the 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.

13. Compare and contrast the data abstraction of Java and C++.
Java support for abstract data types is similar to that of C++. There are, however, a few important differences. All objects are allocated from the heap and accessed through reference variables. Methods in Java must be defined completely in a class. A method body must appear with its corresponding method
header. Therefore, a Java abstract data type is both declared and defined in a single syntactic unit. A Java compiler can inline any method that is not overridden. Definitions are hidden from clients by declaring them to be private. Rather than having private and public clauses in its class definitions, in Java access modifiers can be attached to method and variable definitions. If an instance variable or method does not have an access modifier, it has package access.

Special thanks to Mr. Tri Djoko Wahjono, Ir., M.Sc.

Chap 10 - Review Question and Problem Set - Concepts of Programming Languages, Sebesta

CONCEPTS OF
PROGRAMMING LANGUAGES
TENTH EDITION
Robert W. Sebesta
Chapter 10-Implementing Subprogram

Review Question


1. What is the definition used in this chapter for “simple” subprograms ?
Answer: Simple subprograms are not nasted and all variables in it are static

2. Which of the caller of callee saves execution status information ?
Answer: Either can save the execution status

4. What is the task of a linker?
Answer: 
-find the files that contain the translated subprograms referenced in that program 
-load the files that contains translated subprograminto memory.
-set the target addresses of all calls to those subprograms in the main program to the entry addresses of those subprograms.

8. What kind of machines often use registers to pass parameters ?
Answer: RISC Machines

10. Define static chain, static_depth, nesting_depth,and chain_offset.
Answer: 
static chain : a chain of static links that connect certain activation record instances in the stack.
static_depth : integer associated with a static scope that indicates how deeply it is nested in the outermost scope.
nesting_depth : difference between static_depth of a subprogram containing reference to x and the static_depth of a subprogram containing the declaration of x.
chain_offset : number of links to the correct activation record instance

12. How are references to variables represented in the static-chain method ?
Answer: It is represented by static_depth.


17. Describe the shallow-access method of implementing dynamic scoping.
Answer: 
Shallow access is an alternative implementation method. The semantic of shallow and deep access are indentical.
In the shallow-access method, variables declared in subprograms are not stored in the activation records of those subprograms.


Problem Set

7. It is stated in this chapter that when nonlocal variables are accessed in a dynamic-scoped language using the dynamic chain, variable names must be stored in the activation records with the values. If this were actually done, every nonlocal access would require a sequence of costly string comparisons on names. Design an alternative to these string comparisons that would be faster.
Answer: 
One very simple alternative is to assign integer values to all variable names used in the program. Then the integer values could be used in the activation records, and the comparisons would be between integer values, which are much faster than string comparisons.

8. Pascal allows gotos with nonlocal targets. How could such statements be handled if static chains were used for nonlocal variable access?
Answer: 
Finding the correct activation record instance of a nonlocal variable using static links is relatively straightforward. When a reference is made to nonlocal variable, the activation record instance containing the variable can be found by searching the static chain until a static ancestor activation record instance is found that contains the variable.

9. The static-chain method could be expanded slightly by using two static links in each activation record instance where the second points to the static grandparent activation record instance. How would this approach affect the time required for subprogram linkage and nonlocal references?
Answer: 
The nesting of scopes is known at compile time, the compiler can determine not only that a reference is nonlocal but also the length of the static chain that must be followed to reach the activation records instance that contains the nonlocal object.

11. If a compiler uses the static chain approach to implementing blocks, which of the entries in the activation records for subprograms are needed in the activation records for blocks?
Answer: 
A static chain is a chain of static links that connect certain activation record instances in the stack. During the execution of a subprogram P, the static link of its activation record instance points to an activation record instance of P’s static parent program unit. That instance’s static link points in turn to P’s static grandparent program unit’s activation record instance, if there is one. So, the static chain connects all the static ancestors of an executing subprogram, in order of static parent first. This chain can obviously be used to implement the accesses to nonlocal variables in static-scoped languages.



Special thanks to Mr. Tri Djoko Wahjono, Ir., M.Sc.