Skip to content
Snippets Groups Projects
Commit eb68bfa7 authored by Goik Martin's avatar Goik Martin
Browse files

Merge branch 'master' of gitlab.mi.hdm-stuttgart.de:goik/GoikLectures

parents a4a23590 ab72ff1d
No related branches found
No related tags found
No related merge requests found
...@@ -115,7 +115,7 @@ ...@@ -115,7 +115,7 @@
<orderedlist> <orderedlist>
<listitem> <listitem>
<para>Is this implementation correct regarding the <link <para>Is this implementation correct regarding the <link
xlink:href="https://freedocs.mi.hdm-stuttgart.de/doc/openjdk-17-doc/api/java.base/java/lang/Object.html#hashCode()">contract xlink:href="https://freedocs.mi.hdm-stuttgart.de/doc/openjdk-21-doc/api/java.base/java/lang/Object.html#hashCode()">contract
between <methodname>equals()</methodname> and between <methodname>equals()</methodname> and
<methodname>hashCode()</methodname></link>? Correct if <methodname>hashCode()</methodname></link>? Correct if
necessary.</para> necessary.</para>
...@@ -242,7 +242,7 @@ public static byte getAverage(byte a, final byte b, final byte c) { ...@@ -242,7 +242,7 @@ public static byte getAverage(byte a, final byte b, final byte c) {
<tip> <tip>
<para><methodname <para><methodname
xlink:href="https://freedocs.mi.hdm-stuttgart.de/lib/openjdk-17-doc/api/java.base/java/lang/Math.html#round(double)">Math.round(double)</methodname> xlink:href="https://freedocs.mi.hdm-stuttgart.de/lib/openjdk-21-doc/api/java.base/java/lang/Math.html#round(double)">Math.round(double)</methodname>
might be your friend.</para> might be your friend.</para>
</tip> </tip>
</question> </question>
...@@ -254,9 +254,9 @@ public static byte getAverage(byte a, final byte b, final byte c) { ...@@ -254,9 +254,9 @@ public static byte getAverage(byte a, final byte b, final byte c) {
language="java">+=</code>'s way of cycling through a <code language="java">+=</code>'s way of cycling through a <code
language="java">byte</code>'s range when exceeding <code language="java">byte</code>'s range when exceeding <code
language="java" language="java"
xlink:href="https://freedocs.mi.hdm-stuttgart.de/lib/openjdk-17-doc/api/java.base/java/lang/Byte.html#MAX_VALUE">Byte.MAX_VALUE</code> xlink:href="https://freedocs.mi.hdm-stuttgart.de/lib/openjdk-21-doc/api/java.base/java/lang/Byte.html#MAX_VALUE">Byte.MAX_VALUE</code>
or <code language="java" or <code language="java"
xlink:href="https://freedocs.mi.hdm-stuttgart.de/lib/openjdk-17-doc/api/java.base/java/lang/Byte.html#MIN_VALUE">Byte.MIN_VALUE</code> xlink:href="https://freedocs.mi.hdm-stuttgart.de/lib/openjdk-21-doc/api/java.base/java/lang/Byte.html#MIN_VALUE">Byte.MIN_VALUE</code>
boundaries. Consider:</para> boundaries. Consider:</para>
<informaltable border="1"> <informaltable border="1">
...@@ -366,17 +366,17 @@ System.out.println("Result: " + ...@@ -366,17 +366,17 @@ System.out.println("Result: " +
of overflow errors with respect to the given context of summing up of overflow errors with respect to the given context of summing up
three byte values. Choosing <code>short</code> is sufficient for three byte values. Choosing <code>short</code> is sufficient for
adding either <code language="java" adding either <code language="java"
xlink:href="https://freedocs.mi.hdm-stuttgart.de/lib/openjdk-17-doc/api/java.base/java/lang/Byte.html#MAX_VALUE">Byte.MAX_VALUE</code> xlink:href="https://freedocs.mi.hdm-stuttgart.de/lib/openjdk-21-doc/api/java.base/java/lang/Byte.html#MAX_VALUE">Byte.MAX_VALUE</code>
or <code language="java" or <code language="java"
xlink:href="https://freedocs.mi.hdm-stuttgart.de/lib/openjdk-17-doc/api/java.base/java/lang/Byte.html#MIN_VALUE">Byte.MIN_VALUE</code> xlink:href="https://freedocs.mi.hdm-stuttgart.de/lib/openjdk-21-doc/api/java.base/java/lang/Byte.html#MIN_VALUE">Byte.MIN_VALUE</code>
even three times in a row.</para> even three times in a row.</para>
<para>Dividing by 3 should be a floating point rather than an <para>Dividing by 3 should be a floating point rather than an
integer operation to avoid cutting off fractional values. On top integer operation to avoid cutting off fractional values. On top
we finally use the <classname we finally use the <classname
xlink:href="https://freedocs.mi.hdm-stuttgart.de/lib/openjdk-17-doc/api/java.base/java/lang/Math.html">Math</classname><code xlink:href="https://freedocs.mi.hdm-stuttgart.de/lib/openjdk-21-doc/api/java.base/java/lang/Math.html">Math</classname><code
language="java">.</code><methodname language="java">.</code><methodname
xlink:href="https://freedocs.mi.hdm-stuttgart.de/lib/openjdk-17-doc/api/java.base/java/lang/Math.html#round(double)">round(double)</methodname> xlink:href="https://freedocs.mi.hdm-stuttgart.de/lib/openjdk-21-doc/api/java.base/java/lang/Math.html#round(double)">round(double)</methodname>
method avoiding rounding errors like the one shown method avoiding rounding errors like the one shown
previously.</para> previously.</para>
......
...@@ -206,7 +206,7 @@ ...@@ -206,7 +206,7 @@
<para>This way both implementations are in complete sync. (At <para>This way both implementations are in complete sync. (At
least despite runtime efficiency and possible <link least despite runtime efficiency and possible <link
xlink:href="https://freedocs.mi.hdm-stuttgart.de/doc/openjdk-17-doc/api/java.base/java/lang/OutOfMemoryError.html">OutOfMemoryError</link>s)</para> xlink:href="https://freedocs.mi.hdm-stuttgart.de/doc/openjdk-21-doc/api/java.base/java/lang/OutOfMemoryError.html">OutOfMemoryError</link>s)</para>
</answer> </answer>
</qandaentry> </qandaentry>
</qandadiv> </qandadiv>
...@@ -227,12 +227,12 @@ int a = ...; ...@@ -227,12 +227,12 @@ int a = ...;
... ...
try { try {
String s = (String) o; // May throw a <link String s = (String) o; // May throw a <link
xlink:href="https://freedocs.mi.hdm-stuttgart.de/doc/openjdk-17-doc/api/java.base/java/lang/ClassCastException.html">ClassCastException</link> xlink:href="https://freedocs.mi.hdm-stuttgart.de/doc/openjdk-21-doc/api/java.base/java/lang/ClassCastException.html">ClassCastException</link>
int c = 4 / a; // May throw an <link int c = 4 / a; // May throw an <link
xlink:href="https://freedocs.mi.hdm-stuttgart.de/doc/openjdk-17-doc/api/java.base/java/lang/ArithmeticException.html">ArithmeticException</link> xlink:href="https://freedocs.mi.hdm-stuttgart.de/doc/openjdk-21-doc/api/java.base/java/lang/ArithmeticException.html">ArithmeticException</link>
} catch (<link xlink:href="https://freedocs.mi.hdm-stuttgart.de/doc/openjdk-17-doc/api/java.base/java/lang/ClassCastException.html">ClassCastException</link> e) { } catch (<link xlink:href="https://freedocs.mi.hdm-stuttgart.de/doc/openjdk-21-doc/api/java.base/java/lang/ClassCastException.html">ClassCastException</link> e) {
System.err.println(e.getMessage()); System.err.println(e.getMessage());
} catch (<link xlink:href="https://freedocs.mi.hdm-stuttgart.de/doc/openjdk-17-doc/api/java.base/java/lang/ArithmeticException.html">ArithmeticException</link> e) { } catch (<link xlink:href="https://freedocs.mi.hdm-stuttgart.de/doc/openjdk-21-doc/api/java.base/java/lang/ArithmeticException.html">ArithmeticException</link> e) {
System.err.println(e.getMessage()); System.err.println(e.getMessage());
}</programlisting> }</programlisting>
...@@ -259,14 +259,14 @@ try { ...@@ -259,14 +259,14 @@ try {
<answer> <answer>
<para>Both <link <para>Both <link
xlink:href="https://freedocs.mi.hdm-stuttgart.de/doc/openjdk-17-doc/api/java.base/java/lang/ClassCastException.html">ClassCastException</link> xlink:href="https://freedocs.mi.hdm-stuttgart.de/doc/openjdk-21-doc/api/java.base/java/lang/ClassCastException.html">ClassCastException</link>
and <link and <link
xlink:href="https://freedocs.mi.hdm-stuttgart.de/doc/openjdk-17-doc/api/java.base/java/lang/ArithmeticException.html">ArithmeticException</link> xlink:href="https://freedocs.mi.hdm-stuttgart.de/doc/openjdk-21-doc/api/java.base/java/lang/ArithmeticException.html">ArithmeticException</link>
are being derived from their common parent <link are being derived from their common parent <link
xlink:href="https://freedocs.mi.hdm-stuttgart.de/doc/openjdk-17-doc/api/java.base/java/lang/RuntimeException.html">RuntimeException</link>. xlink:href="https://freedocs.mi.hdm-stuttgart.de/doc/openjdk-21-doc/api/java.base/java/lang/RuntimeException.html">RuntimeException</link>.
All three classes share the common <link All three classes share the common <link
xlink:href="https://freedocs.mi.hdm-stuttgart.de/doc/openjdk-17-doc/api/java.base/java/lang/Throwable.html">Throwable</link>#<link xlink:href="https://freedocs.mi.hdm-stuttgart.de/doc/openjdk-21-doc/api/java.base/java/lang/Throwable.html">Throwable</link>#<link
xlink:href="https://freedocs.mi.hdm-stuttgart.de/doc/openjdk-17-doc/api/java.base/java/lang/Throwable.html#getMessage()">getMessage()</link> xlink:href="https://freedocs.mi.hdm-stuttgart.de/doc/openjdk-21-doc/api/java.base/java/lang/Throwable.html#getMessage()">getMessage()</link>
method by inheritance without redefining it.</para> method by inheritance without redefining it.</para>
<para>Our two <code>catch</code> clauses may thus be combined into <para>Our two <code>catch</code> clauses may thus be combined into
...@@ -275,17 +275,17 @@ try { ...@@ -275,17 +275,17 @@ try {
<programlisting language="java">... <programlisting language="java">...
try { try {
String s = (String) o; // May throw a <link String s = (String) o; // May throw a <link
xlink:href="https://freedocs.mi.hdm-stuttgart.de/doc/openjdk-17-doc/api/java.base/java/lang/ClassCastException.html">ClassCastException</link> xlink:href="https://freedocs.mi.hdm-stuttgart.de/doc/openjdk-21-doc/api/java.base/java/lang/ClassCastException.html">ClassCastException</link>
int c = 4 / a; // May throw an <link int c = 4 / a; // May throw an <link
xlink:href="https://freedocs.mi.hdm-stuttgart.de/doc/openjdk-17-doc/api/java.base/java/lang/ArithmeticException.html">ArithmeticException</link> xlink:href="https://freedocs.mi.hdm-stuttgart.de/doc/openjdk-21-doc/api/java.base/java/lang/ArithmeticException.html">ArithmeticException</link>
} catch (<link xlink:href="https://freedocs.mi.hdm-stuttgart.de/doc/openjdk-17-doc/api/java.base/java/lang/RuntimeException.html">RuntimeException</link> e) { // Common parent class } catch (<link xlink:href="https://freedocs.mi.hdm-stuttgart.de/doc/openjdk-21-doc/api/java.base/java/lang/RuntimeException.html">RuntimeException</link> e) { // Common parent class
System.err.println(e.getMessage()); System.err.println(e.getMessage());
}</programlisting> }</programlisting>
<para>Caveat: There is a <link <para>Caveat: There is a <link
xlink:href="https://freedocs.mi.hdm-stuttgart.de/doc/openjdk-17-doc/api/java.base/java/lang/RuntimeException.html#class-description">whole xlink:href="https://freedocs.mi.hdm-stuttgart.de/doc/openjdk-21-doc/api/java.base/java/lang/RuntimeException.html#class-description">whole
bunch of other child classes</link> of <link bunch of other child classes</link> of <link
xlink:href="https://freedocs.mi.hdm-stuttgart.de/doc/openjdk-17-doc/api/java.base/java/lang/RuntimeException.html">RuntimeException</link>. xlink:href="https://freedocs.mi.hdm-stuttgart.de/doc/openjdk-21-doc/api/java.base/java/lang/RuntimeException.html">RuntimeException</link>.
The simplified version thus potentially catches additional The simplified version thus potentially catches additional
exceptions we might not be aware of. On the other hand the <code exceptions we might not be aware of. On the other hand the <code
language="java">try {...}</code> block does not contain an language="java">try {...}</code> block does not contain an
......
...@@ -208,7 +208,7 @@ package de.hdm_stuttgart.mi.sd1.task2; ...@@ -208,7 +208,7 @@ package de.hdm_stuttgart.mi.sd1.task2;
* satisfying the corresponding unit tests.</li> * satisfying the corresponding unit tests.</li>
* *
* <li><a href= * <li><a href=
* "https://freedocs.mi.hdm-stuttgart.de/lib/openjdk-17-doc/api/java.base/java/lang/Math.html#sqrt(double)" * "https://freedocs.mi.hdm-stuttgart.de/lib/openjdk-21-doc/api/java.base/java/lang/Math.html#sqrt(double)"
* >Math.sqrt(...)</a> * >Math.sqrt(...)</a>
* </li> * </li>
* *
......
...@@ -193,12 +193,12 @@ int a = ...; ...@@ -193,12 +193,12 @@ int a = ...;
... ...
try { try {
String s = (String) o; // May throw a <link String s = (String) o; // May throw a <link
xlink:href="https://freedocs.mi.hdm-stuttgart.de/doc/openjdk-17-doc/api/java.base/java/lang/ClassCastException.html">ClassCastException</link> xlink:href="https://freedocs.mi.hdm-stuttgart.de/doc/openjdk-21-doc/api/java.base/java/lang/ClassCastException.html">ClassCastException</link>
int c = 4 / a; // May throw an <link int c = 4 / a; // May throw an <link
xlink:href="https://freedocs.mi.hdm-stuttgart.de/doc/openjdk-17-doc/api/java.base/java/lang/ArithmeticException.html">ArithmeticException</link> xlink:href="https://freedocs.mi.hdm-stuttgart.de/doc/openjdk-21-doc/api/java.base/java/lang/ArithmeticException.html">ArithmeticException</link>
} catch (<link xlink:href="https://freedocs.mi.hdm-stuttgart.de/doc/openjdk-17-doc/api/java.base/java/lang/ClassCastException.html">ClassCastException</link> e) { } catch (<link xlink:href="https://freedocs.mi.hdm-stuttgart.de/doc/openjdk-21-doc/api/java.base/java/lang/ClassCastException.html">ClassCastException</link> e) {
System.err.println(e.getMessage()); System.err.println(e.getMessage());
} catch (<link xlink:href="https://freedocs.mi.hdm-stuttgart.de/doc/openjdk-17-doc/api/java.base/java/lang/ArithmeticException.html">ArithmeticException</link> e) { } catch (<link xlink:href="https://freedocs.mi.hdm-stuttgart.de/doc/openjdk-21-doc/api/java.base/java/lang/ArithmeticException.html">ArithmeticException</link> e) {
System.err.println(e.getMessage()); System.err.println(e.getMessage());
}</programlisting> }</programlisting>
...@@ -225,14 +225,14 @@ try { ...@@ -225,14 +225,14 @@ try {
<answer> <answer>
<para>Both <link <para>Both <link
xlink:href="https://freedocs.mi.hdm-stuttgart.de/doc/openjdk-17-doc/api/java.base/java/lang/ClassCastException.html">ClassCastException</link> xlink:href="https://freedocs.mi.hdm-stuttgart.de/doc/openjdk-21-doc/api/java.base/java/lang/ClassCastException.html">ClassCastException</link>
and <link and <link
xlink:href="https://freedocs.mi.hdm-stuttgart.de/doc/openjdk-17-doc/api/java.base/java/lang/ArithmeticException.html">ArithmeticException</link> xlink:href="https://freedocs.mi.hdm-stuttgart.de/doc/openjdk-21-doc/api/java.base/java/lang/ArithmeticException.html">ArithmeticException</link>
are being derived from their common parent <link are being derived from their common parent <link
xlink:href="https://freedocs.mi.hdm-stuttgart.de/doc/openjdk-17-doc/api/java.base/java/lang/RuntimeException.html">RuntimeException</link>. xlink:href="https://freedocs.mi.hdm-stuttgart.de/doc/openjdk-21-doc/api/java.base/java/lang/RuntimeException.html">RuntimeException</link>.
All three classes share the common <link All three classes share the common <link
xlink:href="https://freedocs.mi.hdm-stuttgart.de/doc/openjdk-17-doc/api/java.base/java/lang/Throwable.html">Throwable</link>#<link xlink:href="https://freedocs.mi.hdm-stuttgart.de/doc/openjdk-21-doc/api/java.base/java/lang/Throwable.html">Throwable</link>#<link
xlink:href="https://freedocs.mi.hdm-stuttgart.de/doc/openjdk-17-doc/api/java.base/java/lang/Throwable.html#getMessage()">getMessage()</link> xlink:href="https://freedocs.mi.hdm-stuttgart.de/doc/openjdk-21-doc/api/java.base/java/lang/Throwable.html#getMessage()">getMessage()</link>
method by inheritance without redefining it.</para> method by inheritance without redefining it.</para>
<para>Our two <code>catch</code> clauses may thus be combined into <para>Our two <code>catch</code> clauses may thus be combined into
...@@ -241,10 +241,10 @@ try { ...@@ -241,10 +241,10 @@ try {
<programlisting language="java">... <programlisting language="java">...
try { try {
String s = (String) o; // May throw a <link String s = (String) o; // May throw a <link
xlink:href="https://freedocs.mi.hdm-stuttgart.de/doc/openjdk-17-doc/api/java.base/java/lang/ClassCastException.html">ClassCastException</link> xlink:href="https://freedocs.mi.hdm-stuttgart.de/doc/openjdk-21-doc/api/java.base/java/lang/ClassCastException.html">ClassCastException</link>
int c = 4 / a; // May throw an <link int c = 4 / a; // May throw an <link
xlink:href="https://freedocs.mi.hdm-stuttgart.de/doc/openjdk-17-doc/api/java.base/java/lang/ArithmeticException.html">ArithmeticException</link> xlink:href="https://freedocs.mi.hdm-stuttgart.de/doc/openjdk-21-doc/api/java.base/java/lang/ArithmeticException.html">ArithmeticException</link>
} catch (<link xlink:href="https://freedocs.mi.hdm-stuttgart.de/doc/openjdk-17-doc/api/java.base/java/lang/RuntimeException.html">RuntimeException</link> e) { // Common parent class } catch (<link xlink:href="https://freedocs.mi.hdm-stuttgart.de/doc/openjdk-21-doc/api/java.base/java/lang/RuntimeException.html">RuntimeException</link> e) { // Common parent class
System.err.println(e.getMessage()); System.err.println(e.getMessage());
}</programlisting> }</programlisting>
</answer> </answer>
......
...@@ -18,7 +18,7 @@ ...@@ -18,7 +18,7 @@
<maven.compiler.source>17</maven.compiler.source> <maven.compiler.source>17</maven.compiler.source>
<freedocs.url>https://freedocs.mi.hdm-stuttgart.de</freedocs.url> <freedocs.url>https://freedocs.mi.hdm-stuttgart.de</freedocs.url>
<jdk.api_17.url>${freedocs.url}/doc/openjdk-17-doc/api/</jdk.api_17.url> <jdk.api_17.url>${freedocs.url}/doc/openjdk-21-doc/api/</jdk.api_17.url>
<mathjax.url>${freedocs.url}/lib/MathJax/es5/tex-chtml.js</mathjax.url> <mathjax.url>${freedocs.url}/lib/MathJax/es5/tex-chtml.js</mathjax.url>
<libhighlight.url>${freedocs.url}/lib/highlight.js</libhighlight.url> <libhighlight.url>${freedocs.url}/lib/highlight.js</libhighlight.url>
</properties> </properties>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment