From 069212e8c33b60e9f213626af808187f964364d6 Mon Sep 17 00:00:00 2001 From: "Dr. Martin Goik" <goik@hdm-stuttgart.de> Date: Thu, 5 Apr 2018 20:09:11 +0200 Subject: [PATCH] static range check example --- Doc/Sd1/appendix.xml | 39 ++------------------------ Doc/Sd1/languageFundamentals.xml | 48 ++++++++++++++++++++++++++------ 2 files changed, 42 insertions(+), 45 deletions(-) diff --git a/Doc/Sd1/appendix.xml b/Doc/Sd1/appendix.xml index 80577407a..fe829bffc 100644 --- a/Doc/Sd1/appendix.xml +++ b/Doc/Sd1/appendix.xml @@ -371,43 +371,8 @@ public void test_400() { <figure xml:id="sd1_fig_projectEvalCriteria"> <title>Marking criteria</title> - <informaltable border="1"> - <colgroup width="30%"/> - - <colgroup width="10%"/> - - <tr> - <td>Code quality</td> - - <td>25%</td> - </tr> - - <tr> - <td>Code documentation</td> - - <td>25%</td> - </tr> - - <tr> - <td>(Unit) Tests</td> - - <td>25%</td> - </tr> - - <tr> - <td>Deployment</td> - - <td>15%</td> - </tr> - - <tr> - <td>Using <link - xlink:href="https://gitlab.mi.hdm-stuttgart.de">Source code - management (Git)</link></td> - - <td>10%</td> - </tr> - </informaltable> + <para>Project marking criteria vary, different rules apply: Ask your + tutor when starting your project.</para> </figure> <para>The following sections contain both the current and archived project diff --git a/Doc/Sd1/languageFundamentals.xml b/Doc/Sd1/languageFundamentals.xml index 27e831b27..64cbed9e2 100644 --- a/Doc/Sd1/languageFundamentals.xml +++ b/Doc/Sd1/languageFundamentals.xml @@ -866,6 +866,30 @@ i = 4.3345 // Error: Cannot assign double to int i = "Hello"; // Even worse: Assigning a String to an int</programlisting> </figure> + <figure xml:id="sd1_fig_narrowingStaticAnalysis"> + <title>Compile time analysis</title> + + <informaltable border="1"> + <colgroup width="40%"/> + + <colgroup width="60%"/> + + <tr> + <td valign="top"><programlisting language="java">byte b120 = 120; // o.K., static check +byte b128 = 130; // Wrong: Exceeding 127 </programlisting></td> + + <td valign="top"><para>Performing static range check</para></td> + </tr> + + <tr> + <td valign="top"><programlisting language="java">int a = 120; +byte b120 = a;</programlisting></td> + + <td valign="top"><para>No static check on variable value</para></td> + </tr> + </informaltable> + </figure> + <figure xml:id="sd1_fig_forcedConversion"> <title>Forcing conversions</title> @@ -873,11 +897,11 @@ i = "Hello"; // Even worse: Assigning a String to an int</programlisting> <tr> <td valign="top"><programlisting language="java">long l = 4345; -int i = (int) l; +int i = (int) l; // Casting long to int <emphasis role="bold">System.out.println("i carrying long: " + i)</emphasis>; double d = 44.2323; -i = (int) d; +i = (int) d; // Casting double to int <emphasis role="bold">System.out.println("i carrying double: " + i)</emphasis>; </programlisting></td> <td valign="top"><screen>i carrying long: 4345 @@ -4440,10 +4464,10 @@ System.out.println(<link System.out.println("sum = " + sum); } catch (<link xlink:href="https://docs.oracle.com/javase/9/docs/api/java/lang/ArithmeticException.html">ArithmeticException</link> ex) { - System.err.println("Problem:" + ex.getMessage()); + System.err.println("Problem: " + ex.getMessage()); }</programlisting> - <screen>Problem:integer overflow</screen> + <screen>Problem: integer overflow</screen> </figure> <figure xml:id="sd1_fig_divideByZero"> @@ -4556,7 +4580,15 @@ System.out.println("Difference: " + difference);</programlisting><screen>Differe <td><code language="java">int</code></td> - <td rowspan="5"><code language="java">+, -, *, /, %</code></td> + <td rowspan="6"><code language="java">+, -, *, /, %</code></td> + </tr> + + <tr> + <td><code language="java">int</code></td> + + <td><code language="java">long</code></td> + + <td><code language="java">long</code></td> </tr> <tr> @@ -4564,7 +4596,7 @@ System.out.println("Difference: " + difference);</programlisting><screen>Differe <td><code language="java">short</code></td> - <td><code language="java">short</code></td> + <td><code language="java">int</code></td> </tr> <tr> @@ -4588,7 +4620,7 @@ System.out.println("Difference: " + difference);</programlisting><screen>Differe <td><code language="java">byte</code></td> - <td><code language="java">char</code></td> + <td><code language="java">int</code></td> </tr> </informaltable> </figure> @@ -5175,7 +5207,7 @@ i += b; i = i + b; i %= 3; i = i % 3; // boolean -b != b; b = !b; // true <--> false</programlisting> +b = !b; // true <--> false</programlisting> </figure> <qandaset defaultlabel="qanda" xml:id="sd1_qanda_GuessingResults"> -- GitLab