Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
<?xml version="1.0" encoding="UTF-8"?>
<section version="5.0" xml:id="sd1_exam_2024_summer" xml:lang="en"
xmlns="http://docbook.org/ns/docbook"
xmlns:xlink="http://www.w3.org/1999/xlink"
xmlns:xila="http://www.w3.org/2001/XInclude/local-attributes"
xmlns:xi="http://www.w3.org/2001/XInclude"
xmlns:trans="http://docbook.org/ns/transclusion"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns:m="http://www.w3.org/1998/Math/MathML"
xmlns:html="http://www.w3.org/1999/xhtml"
xmlns:db="http://docbook.org/ns/docbook">
<title>SD1 examination summer 2024</title>
<section xml:id="sd1_exam_2024_summer_task1">
<title>Implementing tasks</title>
<section xml:id="sd1_exam_2024_summer_task1_preparation">
<title>Preparation</title>
<orderedlist>
<listitem>
<para>Download and unzip the above file
<filename>exam.zip</filename>. You should see a directory
»<filename>Exam</filename>« containing a
<filename>pom.xml</filename> file.</para>
</listitem>
<listitem>
<para>Open this project in your <productname>IDEA</productname> IDE
by selecting the <filename>Exam/pom.xml</filename> file.</para>
</listitem>
</orderedlist>
</section>
<section xml:id="sd1_exam_2024_summer_task1_task">
<title>Task</title>
<qandaset defaultlabel="qanda" xml:id="sd1_exam_2024_summer_task1Qanda">
<qandadiv>
<qandaentry>
<question>
<para>Open the <filename>Readme.md</filename> file in your
project's root. It contains all necessary instructions for
solving the implementation tasks.</para>
</question>
<answer>
<para>Solution see <link
xlink:href="https://gitlab.mi.hdm-stuttgart.de/goik/GoikLectures/-/tree/master/Klausuren/Sd1/2023winter/Solve">winter
2022 exam</link>.</para>
</answer>
</qandaentry>
</qandadiv>
</qandaset>
</section>
<section xml:id="sd1_exam_2024_summer_task1Caveats">
<title>Caveats</title>
<itemizedlist>
<listitem>
<para>When approaching end of examination check your input for
completeness prior to being automatically logged out by the system.
Remember: There is 120 minutes for the examination and another 5
minutes to check for completeness.</para>
</listitem>
<listitem>
<para>Projects residing just on your local workstation's file system
cannot be recovered after finishing the exam.</para>
</listitem>
</itemizedlist>
</section>
</section>
<section xml:id="sd1_exam_2024_summer_task2">
<title>Executing main(...)</title>
<qandaset defaultlabel="qanda" xml:id="sd1_exam_2024_summer_task3Qanda">
<qandadiv>
<qandaentry>
<question>
<para>Executing the following program</para>
<programlisting language="none"><emphasis role="red">01</emphasis> public class LackingInit {
<emphasis role="red">02</emphasis> ...
<emphasis role="red">03</emphasis> public static void main(String[] args) {
<emphasis role="red">04</emphasis> main(args);
<emphasis role="red">05</emphasis> }
<emphasis role="red">06</emphasis> ...</programlisting>
<para>yields:</para>
<screen>Exception in thread "main" java.lang.<link
xlink:href="https://freedocs.mi.hdm-stuttgart.de/doc/openjdk-17-doc/api/java.base/java/lang/StackOverflowError.html">StackOverflowError</link>
at de.hdm_stuttgart.mi.sd1.extra.LackingInit.main(LackingInit.java:4)
at de.hdm_stuttgart.mi.sd1.extra.LackingInit.main(LackingInit.java:4)
<emphasis role="red">... 1020 more identical lines omitted for brevity ...</emphasis>
at de.hdm_stuttgart.mi.sd1.extra.LackingInit.main(LackingInit.java:4)
at de.hdm_stuttgart.mi.sd1.extra.LackingInit.main(LackingInit.java:4)
Process finished with exit code 1</screen>
<para>What's happening here? Why is execution being terminated by
an exception?</para>
</question>
<answer>
<para>Our <methodname>main(...)</methodname> method calls itself
recursively until breaching the JVM's limit resulting in the
observed <link
xlink:href="https://freedocs.mi.hdm-stuttgart.de/doc/openjdk-17-doc/api/java.base/java/lang/StackOverflowError.html">StackOverflowError</link>
exception.</para>
</answer>
</qandaentry>
</qandadiv>
</qandaset>
</section>
<section xml:id="sd1_exam_2024_summer_task3">
<title>Strange arithmetics</title>
<qandaset defaultlabel="qanda" xml:id="sd1_exam_2024_summer_task2Qanda">
<qandadiv>
<qandaentry>
<question>
<para>From ordinary arithmetics we expect a + b - c = a - c + b.
But executing the subsequent code yields:</para>
<informaltable border="1">
<tr>
<th>Code</th>
<th>Output</th>
</tr>
<tr>
<td valign="top"><programlisting language="java">System.out.println(1000000000 + 0.000000001 - 1000000000);
System.out.println(1000000000 - 1000000000 + 0.000000001);</programlisting></td>
<td valign="top"><screen>0.0
1.0E-9</screen></td>
</tr>
</informaltable>
<para>Explain these two different results.</para>
</question>
<answer>
<para>Short answer: The two values 1000000000 or <inlineequation>
<m:math display="inline">
<m:msup>
<m:mi>10</m:mi>
<m:mi>9</m:mi>
</m:msup>
</m:math>
</inlineequation>and 0.000000001 or <inlineequation>
<m:math display="inline">
<m:msup>
<m:mi>10</m:mi>
<m:mi>-9</m:mi>
</m:msup>
</m:math>
</inlineequation> differ by 18 orders of magnitude. An eight
byte <code language="java">double</code> cannot express enough
digits for expressing this.</para>
<para>Longer answer: For summing up the int literal <code
language="java">1000000000</code> gets being converted into a
<code language="java">double</code> value being represented as 8
byte IEEE 754. Due to its inherently limited precision the above
sums gets truncated. We consider:</para>
<informaltable border="1">
<tr>
<th>Code</th>
<th>Output</th>
</tr>
<tr>
<td valign="top"><programlisting language="java">System.out.println(1000000000 == 1000000000 + 0.000000001);</programlisting></td>
<td valign="top"><screen>true</screen></td>
</tr>
<tr>
<td valign="top"><programlisting language="java">System.out.println(1000000000.0 == 1000000000 + 0.000000001);</programlisting></td>
<td valign="top"><screen>true</screen></td>
</tr>
</informaltable>
<para>Thus in 8 byte IEEE 754 representation both <code
language="java">1000000000.0</code> and the expression <code
language="java">1000000000 + 0.000000001</code> amount to the
exact same value. Evaluating from left to right we thus
have:</para>
<itemizedlist>
<listitem>
<para><code language="java">1000000000 + 0.000000001 -
1000000000</code> = <code language="java">1000000000.0 -
1000000000</code> = <code language="java">0.0</code>.</para>
</listitem>
<listitem>
<para>Since <code language="java">1000000000</code> is an
<code language="java">int</code> literal we have <code
language="java">1000000000 - 1000000000 == 0</code> and
thus:</para>
<para><code language="java">1000000000 - 1000000000 +
0.000000001</code> = <code language="java">0 +
0.000000001</code> = <code
language="java">1.0E-9</code>.</para>
</listitem>
</itemizedlist>
</answer>
</qandaentry>
</qandadiv>
</qandaset>
</section>
</section>