uni

Published on March 2017 | Categories: Documents | Downloads: 57 | Comments: 0 | Views: 677
of 12
Download PDF   Embed   Report

Comments

Content

04IN1011: Programming techniques and technologies (6 ECTS) INJE02: Programming (8 ECTS)

Final—SS 2013
Universit¨ at Koblenz-Landau, FB4 Prof. Dr. Ralf L¨ ammel, Dr. Manfred Jackel 16 July 2013

Name, Vorname Matrikel-Nr. Email Studiengang ECTS Pr¨ ufungsversuch

[email protected] 2 BSc Inf 2 BSc CV 2 ........................ 26 28 21 22 23

Hiermit best¨ atige ich, dass ich zur Klausur angemeldet und zugelassen bin. Eine falsche Angabe wird als T¨ auschungsversuch gewertet.

Unterschrift:
————————————————————————————— Aufgabe Punkte (0-2)

Korrekturabschnitt
In der 8 ECTS-Version werden 20 Punkte als 100 % angesetzt. Es werden also die Antworten zu allen 10 Fragen gez¨ ahlt. In der 6 ECTS-Version werden 16 Punkte als 100 % angesetzt. Es werden die Antworten zu 8 Fragen gez¨ ahlt bei Maximierung der Gesamtpunktzahl.

1 2 3 4 5 6 7 8 9 10 Total
1

Exam Manual
1. If you have any questions regarding the following items, please ask them ahead of the final. You can ask them during the final or the re-sit as well, but this may be less helpful to you. 2. There are 10 exam assignments with 0-2 points each. 0 means ‘missing’ or ‘wrong’; 1 means ‘arguably appropriate, but significantly incomplete or incorrect’; 2 means ‘appropriate and essentially complete and correct’. You might get an extra point for each exam assignment, if you manage to come up with an exceptionally insightful solution. The exam lasts 1 hour. Thus, one can spend more than 5 min per exam assignment. 3. All exam assignments focus on ‘program comprehension’. That is, you need to understand and comment on some given code fragment. A 140 chars limit applies to each answer if text is required. Longer answers will receive a reduced score (≥ 0). In some cases, if any, you may need to write down some piece of code, grammar, XML, schema, SQL, or alike. 4. The overall topics for the exam are defined with the dry-run; see the section headers and the per-section footnotes for extra explanations. These topics are maintained for the actual final and the re-sit of the given course edition. The topics may be different in the next edition of this course. 5. One should be prepared—systematically—that the text of the exam assignments relates to the (software) concepts that are listed on the wiki pages for the individual lectures. Definitions of the concepts are never inquired, but basic understanding of the concepts is assumed and crucial for passing the exam. 6. The code fragments of the exam assignments may be drawn from the illustrations given for all concepts on the wiki pages, the contributions (i.e., implementations of the 101system ) practiced in the lectures, and the overall scenarios of the homework assignments. 7. Detailed knowledge of libraries, technologies, and language extensions (such as specific details of java.lang.reflect, Hibernate mapping files, or AspectJ language constructs) is never assumed. As the exam assignments require understanding of code, one needs to remember a fair amount of details though. 2

1

“The Expression problem”1

Consider the following Java-based object model for expression forms and an extra class for an evaluator with an incomplete definition of a static evaluation method: public abstract class Expr { } public class Literal extends Expr { public int info; // a constant } public class Add extends Expr { public Expr left, right; // operands of addition } public class Evaluator { public int evaluate(Expr e) { ... // method body omitted } } By placing methods such as evaluate outside the underlying classes for data variants, we seem to be achieving ‘operation extensibility’, i.e., the ability to add operations without the need to revise code for existing data variants. However, what is the drawback of such an approach in Java?

Reference solution
As the evaluate method would need to dispatch on the different expression forms, it would also involve weakly typed casts. Data extensibility may also be limited.

1 This topic concerns the lecture with the same name. One should understand, for example, data and operation extensibility, the relationship to class inheritance, object composition, and the use of static versus instance methods. The problem also resurfaces in the contexts of AOP and the Visitor design pattern.

3

2

“XML data binding”2

Consider the following XSD fragment which models lines as consisting of two points: <xs:element name="line"> <xs:complexType> <xs:sequence> <xs:element ref="point"/> <xs:element ref="point"/> </xs:sequence> </xs:complexType> </xs:element>

Why is it difficult to map this element declaration automatically to a Java class?

Reference solution
We would prefer a Line class with two fields, but reasonable names of those fields are not suggested by the element declaration.

2 This topic concerns the lecture with the same name. One should understand, for example, some basics of XML schemas, the differences between object graphs and XML data, the overall utility of annotations in the mapping processing, the notions of marshaling and unmarshaling, and the implications on OO programming.

4

3

“Object/relational mapping”3

Consider the following Java code which persists a new cat in a Hibernate session: Transaction tx = session.beginTransaction(); Cat princess = new Cat(); princess.setName("Princess"); princess.setSex(’F’); princess.setWeight(7.4f); session.save(princess); tx.commit(); Why is it necessary to explicitly ‘save’ the new cat, if you want Hibernate to persist the cat?

Reference solution
Assuming that Cat is a POJO class, Hibernate would not know about the new instance unless told explicitly, as done with save.

This topic concerns the lecture ‘Database programming’, specifically the part on object/relational mapping. One should understand, for example, the motivation for the use of O/R mapping, basic mapping rules from object models to relational tables, the notion of transactions on the OO program side, the mechanics of persisting objects and retrieving them later again.

3

5

4

“Reflection”4

Consider the following reflection code which performs object construction and method invocation: 01 02 03 04 05 Class clss = Class.forName("mypackage.MyClass"); Constructor cons = clss.getConstructor(); Object obj = cons.newInstance(); Method meth = clss.getMethod("myMethod"); meth.invoke(obj);

Extract a Java class from the code which would be suitable for this reflection code to succeed.

Reference solution
package mypackage public class MyClass { public void myMethod() { } }

4 This topic concerns the lecture ‘Metaprograms and metadata’, specifically the part on Java’s introspection. One should understand, for example, the basics of the reflection API, its fundamental limitations, simple use cases such as object dumping, and the role of exceptions in the use of reflection.

6

5

“Aspect-oriented programming”5

Consider the following aspect that should be applied to a simple Account class with methods for withdrawal, deposit, etc. before(Account a, double value): call(void Account.withdraw(double)) && target(a) && args(value) { assert value >= 0 && a.getBalance() >= value; }

Explain the aspect.

Reference solution
The poincut identifies the withdraw method and binds receiver and argument; the advice asserts that there is sufficient balance.

5 This topic concerns the lecture with the same name. One should understand, for example, the key notions of crosscutting, join point, pointcut, before/after/around advice, and inter-type declarations as well as basic application scenarios such as logging, contract checking, and update handling.

7

6

“Functors in OO programs”6

Consider the following functor interface: interface Function<X,Y,Z> { Z apply(X x, Y y); } Write down a Java expression which instantiates an anonymous class that implements the Function interface such that apply implements string concatenation.

Reference solution
new Function<String,String,String> { String apply(String x, String y) { return x+y; }; }

This topic concerns the lecture ‘Functional OO programming’. The lecture dealt with parsing and traversal combinators, but these relatively advanced scenarios are not exercised in the exam. Instead, one should understand the notion of functors as such and manage simple scenarios such as list processing, as exercised by the homework assignment on FOOP.

6

8

7

“Multithreading”7

Consider the following code that could be part of an application for searching and booking flight connections: final Date date = ...; // the date for the flight final Airport from = ...; // aiport for departure final Airport to = ...; // airport for arrival Callable<List<BookingOption>> searchCallable = new Callable<List<BookingOption>>() { public List<BookingOption> call() { List<BookingOption> options = new LinkedList<BookingOption>(); ... // actual search omitted return options; } }; Future<List<BookingOption>> searchFuture = pool.submit(searchCallable); That is, a ‘callable’ for seaching booking options is instantiated and ‘submitted’ to a ‘thread pool’ to receive a ‘future’ in return so that the determined booking options could be retrieved eventually. What is the advantage of delegating the search to a thread?

Reference solution
The main thread of the application remains responsive. The future could be checked later for the availability of the result.

7 This topic concerns the lecture with the same name. One should understand, for example, the use of ‘callables’, ‘runnables’, functors, and thread pools in scenarios of programming with threads as well as simple means of synchronization for use of shared resources.

9

8

“Remote method invocation”8

Consider the following server-side RMI code which binds a product catalog so that a client may access the catalog: ProductCatalog amazon = ...; // InetAddress addr = InetAddress.getLocalHost(); hostname = addr.getHostName(); Naming.rebind("//" + hostname + "/Amazon", amazon); Why is it sufficient to bind only the catalog as such, but not the individual sections, entries, and other components of the catalog?

Reference solution
All the catalog’s components can be retrieved on the client side via regular getters; only the root object, i.e., the catalog, must be looked up.

This topic concerns the lecture with the same name. One should understand, for example, the role of interfaces for services, the need for client-side stubs (proxies) and server-side skeletons, and the use of a name-binding service.

8

10

9

“Recursive descent parsing”9

Consider the following grammar production: company : ’company’ STRING ’{’ ceo department* ’}’

Please sketch the code that would implement the production in a recursive descent parser.

Reference solution
private final void company() { match("company"); match(STRING); match("{"); ceo(); while (test("department")) department(); match("}"); }

This topic concerns the lecture ‘Language processing patterns’, specifically the Acceptor and Parser patterns. One should understand, for example, the correspondence between grammars and ‘procedures’ (methods) that perform recursive descent parsing.

9

11

10

“Parser generation”10

Consider the following ANTLR grammar fragment which is concerned with totaling salaries of employees. employee : STRING ’{’ ’address’ STRING ’salary’ FLOAT { total += Double.parseDouble($FLOAT.text); } ’}’; The semantic action accesses a variable total. What is the declaring scope of the variable?

Reference solution
The variable total is an instance field of the class that is generated from the ANTLR grammar.

This topic concerns the lecture ‘Generative programming’, specifically the Parser Generation and Text-to-object patterns. One should understand, for example, the representation of context-free grammars with ANTLR, the overall mechanics of generating, building, and running an ANTLR-based parser, the role and expressiveness of semantic actions in ANTLR, and the possibility to parse text into ANTLR-unaware objects, in fact, POJOs.

10

12

Sponsor Documents

Or use your account on DocShare.tips

Hide

Forgot your password?

Or register your new account on DocShare.tips

Hide

Lost your password? Please enter your email address. You will receive a link to create a new password.

Back to log-in

Close