diff --git a/Doc/Sd1/Ref/LangFundament/floatConverter.png b/Doc/Sd1/Ref/LangFundament/floatConverter.png new file mode 100644 index 0000000000000000000000000000000000000000..7ddbe77f9b57abe0e6b70f34908c05fc8e1e8bc7 Binary files /dev/null and b/Doc/Sd1/Ref/LangFundament/floatConverter.png differ diff --git a/Doc/Sd1/languageFundamentals.xml b/Doc/Sd1/languageFundamentals.xml index 931a3c99e460e99247510fb3f333acbe75a52ba9..935496e374efca86add969c7af56217ffd47dd60 100644 --- a/Doc/Sd1/languageFundamentals.xml +++ b/Doc/Sd1/languageFundamentals.xml @@ -1,5 +1,5 @@ <?xml version="1.0" encoding="UTF-8"?> -<chapter annotations="slide" version="5.0" xml:id="sw1LanguageFundamental" +<chapter annotations="slide" version="5.1" xml:id="sw1LanguageFundamental" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xila="http://www.w3.org/2001/XInclude/local-attributes" @@ -768,11 +768,81 @@ Octal 35</programlisting></td> </tr> </informaltable> </figure> - </section> - </section> - <section xml:id="sd1_sect_langFundamental_exercises"> - <title>Exercises</title> + <figure xml:id="sd1_fig_intLiteralLimitExcess"> + <title>Know your limits!</title> + + <programlisting language="java">System.out.println(10000000000<emphasis + role="bold">L</emphasis>); // o.K. +System.out.println(10000000000 ); // Compile time error: Integer number too large</programlisting> + </figure> + + <figure xml:id="sd1_fig_javaLiterals"> + <title><xref linkend="glo_Java"/> literals</title> + + <informaltable border="1"> + <tr> + <td><code>byte</code>, <code>short</code></td> + + <td>-</td> + </tr> + + <tr> + <td><code>char</code></td> + + <td><code>'A'</code>, <code>'\u0041'</code></td> + </tr> + + <tr> + <td><code>int</code></td> + + <td><code>29</code>, <code>0b1_1101</code>, <code>0x1D</code>, + <code>035</code>, <code>-29</code>,</td> + </tr> + + <tr> + <td><code>long</code></td> + + <td><code>35L</code>, <code>0b10_0011L</code>, <code>0x23L</code>, + <code>043L</code>, <code>-35L</code>,...</td> + </tr> + + <tr> + <td><code>float</code></td> + + <td><code>55.43F</code>, <code>1.7E-23F</code>, <code>-17.F, + 100_342.334_113</code></td> + </tr> + + <tr> + <td><code>double</code></td> + + <td><code>55.43</code>, <code>1.7 E -23</code>, + <code>-17.</code></td> + </tr> + + <tr> + <td><code>String</code></td> + + <td><code>"Hello"</code>, <code>"Greek Δ"</code>, <code>"Greek + <link + xlink:href="https://www.fileformat.info/info/unicode/char/0394/index.htm">\u0394</link>"</code></td> + </tr> + + <tr> + <td><code>boolean</code></td> + + <td><code>true</code>, <code>false</code></td> + </tr> + + <tr> + <td/> + + <td><code>null</code></td> + </tr> + </informaltable> + </figure> + </section> <section xml:id="sd1_sect_arithmeticLimitations"> <title>Arithmetic limitations</title> @@ -789,7 +859,7 @@ byte points = 130; // Compile error: Incompatible types </figure> <figure xml:id="sd1_fig_byteOverflow"> - <title>Funny things</title> + <title>Overflow</title> <programlisting language="java">int count = 2147483647; int points = 2147483647; @@ -828,10 +898,24 @@ System.out.println("Expected value: " + Long.MAX_VALUE);</programlisting> <para>Result:</para> <programlisting language="none"> Float value: 9223372036854776000.000000 -Expected value: 9223372036854775807 -</programlisting> +Expected value: 9223372036854775807</programlisting> + </figure> + + <figure xml:id="sd1_fig_floatConverter"> + <title><uri + xlink:href="https://www.h-schmidt.net/FloatConverter">https://www.h-schmidt.net/FloatConverter</uri></title> + + <mediaobject> + <imageobject> + <imagedata fileref="Ref/LangFundament/floatConverter.png"/> + </imageobject> + </mediaobject> </figure> </section> + </section> + + <section xml:id="sd1_sect_langFundamental_exercises"> + <title>Exercises</title> <section xml:id="sw1LegalVariableName"> <title>Legal variable names</title> @@ -1920,6 +2004,38 @@ System.out.println("Character: " + arabicChar);</programlisting> </qandadiv> </qandaset> </section> + + <section xml:id="sd1_sect_literalProblem"> + <title>Literal problem</title> + + <qandaset defaultlabel="qanda" xml:id="sd1_qanda_literalProblem"> + <qandadiv> + <qandaentry> + <question> + <para>Consider:</para> + + <programlisting language="java">System.out.println(048);</programlisting> + + <para>This yields a compile time error <quote>Integer number + too large</quote>. On contrary the following code will compile + and run perfectly well:</para> + + <programlisting language="java">System.out.println(047);</programlisting> + + <para>Explain the underlying problem.</para> + </question> + + <answer> + <para>The literal <quote>048</quote> is meant to be octal + representation. Unfortunately the only digits in octal + representations range from 0 to 7. So <quote>047</quote> is + fine but <quote>048</quote> simply is no valid literal in + <xref linkend="glo_Java"/>.</para> + </answer> + </qandaentry> + </qandadiv> + </qandaset> + </section> </section> <section xml:id="sw1SectSimpleExpressions">