• Keine Ergebnisse gefunden

Advanced Aspects of Object-Oriented Programming (SS 2013) Practice Sheet 9

N/A
N/A
Protected

Academic year: 2022

Aktie "Advanced Aspects of Object-Oriented Programming (SS 2013) Practice Sheet 9"

Copied!
1
0
0

Wird geladen.... (Jetzt Volltext ansehen)

Volltext

(1)

Prof. Dr. A. Poetzsch-Heffter Mathias Weber, M.Sc.

University of Kaiserslautern Department of Computer Science Software Technology Group

Advanced Aspects of Object-Oriented Programming (SS 2013) Practice Sheet 9

Date of Issue: 11.06.13

Deadline: 18.06.13 (before the lecture as PDF via E-Mail)

Exercise 1 Behavioral Subtyping

In this exericse we look at theReaderexample found at the end of slide set 5 (specification and checking).

a) Give a detailed explanation why the execution of methodBuffReader.getChar()cannot lead to an

ArrayIndexOutOfBoundsException.

b) Implement aStringReader. First add an interface equivalent to theBlankReaderincluding the specification of the behavior. Second add an implementation ofStringReaderthat fulfills the specification.

c) Add a method void unread(int c) toBuffReader. The method pushes back a single character by copying it to the front of the buffer. After the method returns, the next character to be read is c. Add a specification and an implementation of the method inBuffReader. Is it easily possible to move the method to theReaderinterface instead?

Exercise 2 Concurrent Access to Shared State

Read and write operations on fields are atomic except for fields of typelonganddouble(§17.7). Analize the following code (taken and adapted from the book “Effective Java Second Edition” by Joshua Bloch):

package concurrency . mt ;

import java . util . concurrent . TimeUnit ; public class StopThread {

private static boolean stopRequested ;

public static void main ( String [] args ) throws InterruptedException { Thread backgroundThread = new Thread (new Runnable () {

public void run () { int i = 0;

while(! stopRequested ) { i ++;

}

System . out . println (" Thread terminated ." );

} });

backgroundThread . start ();

TimeUnit . SECONDS . sleep (1);

stopRequested = true;

System . out . println (" Program sould terminate now ... " );

} }

The expected behavior is that the program terminates after one second by telling the background thread to stop work- ing. On some machines, this program does not terminate. Explain this unintended behavior. How can the program be fixed?

Referenzen

ÄHNLICHE DOKUMENTE

a) Write a generic static method flip which takes an object of class Pair (see the slides of the lecture) and flips the elements of the given Pair object. Hint: In order to flip

a) Write a generic static method flip which takes an object of class Pair (see the slides of the lecture) and flips the elements of the given Pair object.. The method has the

• Guarantees of the type system cannot be used anymore.. b) If the set of types/roles can be given at compile time and it will not change for an object during its lifecycle, it

Advanced Aspects of Object-Oriented Programming (SS 2011) Practice Sheet 8 (Hints and Comments).. Exercise

a) Extend the syntax as well as the semantics (static & dynamic) of StoJas to support a " for (...) { ... } " statement and give a detailed explanation for the

Advanced Aspects of Object-Oriented Programming (SS 2010) Practice Sheet 9 Date of Issue: 10.06.10. Deadline: 17.06.10 (until

Examine the code, available with this practice sheet on the web, with respect to confinedness. The classes ProofTreeNodeIt und ProofContainer should provide the externally

Advanced Aspects of Object-Oriented Programming (SS 2009) Practice Sheet 9 Date of Issue: 23.06.09. Deadline: 29.06.09 (until