From 89d974a95e8e40d67f34c4b603e94f80a2235b1d Mon Sep 17 00:00:00 2001 From: Martin Goik <goik@hdm-stuttgart.de> Date: Tue, 2 Apr 2024 08:01:08 +0200 Subject: [PATCH] Cosmetics --- .../languageFundamentals.xml | 95 +++++++++---------- 1 file changed, 46 insertions(+), 49 deletions(-) diff --git a/Doc/Sd1/LanguageFundamentals/languageFundamentals.xml b/Doc/Sd1/LanguageFundamentals/languageFundamentals.xml index ba277f0ba..ba0ef4974 100644 --- a/Doc/Sd1/LanguageFundamentals/languageFundamentals.xml +++ b/Doc/Sd1/LanguageFundamentals/languageFundamentals.xml @@ -3499,48 +3499,40 @@ System.out.println("Maximum short value:" + MAXIMUM);</programlisting> </itemizedlist> <tip> - <para>Which integer literal types do exist according to the - <xref linkend="glo_Java"/> <link + <para>Which integer literals are being defined by the <xref + linkend="glo_Java"/> <link xlink:href="https://docs.oracle.com/javase/specs/jls/se8/html/jls-3.html#jls-3.10.1">standard</link>?</para> </tip> </question> <answer> - <para>Since variables of type <code language="java" + <para>Variables of type <code language="java" xlink:href="https://docs.oracle.com/javase/specs/jls/se7/html/jls-4.html#jls-4.2.1-100-B">short</code> - use signed two-byte two-complement representation their - corresponding range is <inlineequation> + use signed two-byte two-complement representation ranging from + <inlineequation> <m:math display="inline"> <m:mrow> - <m:mo>[</m:mo> - - <m:mrow> - <m:mrow> - <m:mo>-</m:mo> - - <m:msup> - <m:mi>2</m:mi> - - <m:mi>15</m:mi> - </m:msup> - </m:mrow> - - <m:mo>,</m:mo> + <m:mo>-</m:mo> - <m:mrow> - <m:msup> - <m:mi>2</m:mi> + <m:msup> + <m:mi>2</m:mi> - <m:mi>15</m:mi> - </m:msup> + <m:mi>15</m:mi> + </m:msup> + </m:mrow> + </m:math> + </inlineequation> to <inlineequation> + <m:math display="inline"> + <m:mrow> + <m:msup> + <m:mi>2</m:mi> - <m:mo>-</m:mo> + <m:mi>15</m:mi> + </m:msup> - <m:mi>1</m:mi> - </m:mrow> - </m:mrow> + <m:mo>-</m:mo> - <m:mo>]</m:mo> + <m:mi>1</m:mi> </m:mrow> </m:math> </inlineequation>. Thus intensity values ranging from 0 to 255 @@ -3613,12 +3605,16 @@ System.out.println("Maximum short value:" + MAXIMUM);</programlisting> <para>The second question is more difficult to answer: The <xref linkend="glo_Java"/> standard only defines <code language="java" - xlink:href="https://docs.oracle.com/javase/specs/jls/se7/html/jls-4.html#jls-4.2.1-100-C">int</code> + xlink:href="https://docs.oracle.com/javase/specs/jls/se7/html/jls-4.html#jls-4.2.1-100-C">int</code>, + <code language="java" + xlink:href="https://docs.oracle.com/javase/specs/jls/se7/html/jls-4.html#jls-4.2.1-100-D">long</code> + and <code language="java" + xlink:href="https://docs.oracle.com/javase/specs/jls/se7/html/jls-4.html#jls-4.2.1-100-E">char</code> but no <code language="java" xlink:href="https://docs.oracle.com/javase/specs/jls/se7/html/jls-4.html#jls-4.2.1-100-B">short</code> or <code language="java" xlink:href="https://docs.oracle.com/javase/specs/jls/se7/html/jls-4.html#jls-4.2.1-100-A">byte</code> - literals. The given example code is thus equivalent to:</para> + integer literals. The given example is thus equivalent to:</para> <programlisting language="java">final short MINIMUM = 0B00000000_00000000_10000000_00000000, MAXIMUM = 0B00000000_00000000_01111111_11111111;</programlisting> @@ -3642,8 +3638,8 @@ System.out.println("Maximum short value:" + MAXIMUM);</programlisting> <m:mi>15</m:mi> </m:msup> </m:math> - </inlineequation> or 32768. This is one step above - <inlineequation> + </inlineequation> or 32768. This is one step above a <code + language="java">short</code>'s range <inlineequation> <m:math display="inline"> <m:mrow> <m:mo>[</m:mo> @@ -3680,7 +3676,7 @@ System.out.println("Maximum short value:" + MAXIMUM);</programlisting> </inlineequation> and thus cannot be assigned to a <code language="java">short</code> variable.</para> - <para>The cast cuts off the two leading bytes of + <para>Using a cast cuts off the two leading bytes of <code>00000000_00000000_10000000_00000000</code> forcing the remaining two lower bytes into a <code language="java">short</code> variable @@ -3785,20 +3781,22 @@ System.out.println(11 + 22 + " is our result");</programlisting></td> problem:</para> <programlisting language="java">... -System.out.println("Decimal:" + (512 + +System.out.println("Decimal:" + <emphasis role="red">(</emphasis>512 + 256 + 128 + 32 + - 4)); ...</programlisting> + 4<emphasis role="red">)</emphasis>); ...</programlisting> <para>Why are the <quote>inner</quote> braces grouping - <code>(512 + 256 + 128 + 4)</code> being required?</para> + <code><emphasis role="red">(</emphasis>512 + 256 + 128 + + 4<emphasis role="red">)</emphasis></code> being + required?</para> </listitem> </orderedlist> <tip> - <para>Execute the above code omitting these <quote>inner</quote> - braces.</para> + <para>Execute the above code omitting the <quote>inner</quote> + braces pair.</para> </tip> </question> @@ -3827,8 +3825,8 @@ System.out.println("Decimal:" + (512 + </listitem> <listitem> - <para>We start by omitting the <quote>inner</quote> braces. - This results in:</para> + <para>Omitting the <quote>inner</quote> braces results + in:</para> <informaltable border="1"> <tr> @@ -3850,11 +3848,10 @@ System.out.println("Decimal:" + (512 + </tr> </informaltable> - <para>We inspect the first expression <code>"Decimal:" + - <emphasis role="red">512</emphasis></code>. <xref - linkend="glo_Java"/> implicitly converts the int literal 512 - into a String "512". Then the two + operator concatenates both - Strings into <code>"Decimal:<emphasis + <para>For the leftmost expression <code>part "Decimal:" + + <emphasis role="red">512</emphasis></code> the int literal 512 + is being implicitly converted into a String "512" prior to + being concatenated into <code>"Decimal:<emphasis role="red">512</emphasis>"</code>. Evaluating the whole expression from left to right this pattern keeps repeating. Like in this exercises first example the above code is thus @@ -3905,9 +3902,9 @@ System.out.println("Decimal:" + "512" + <para><quote>+</quote> operators computing the integer sum of 512, 256, 128, 32 and 4 yielding a value of 932. This value subsequently gets transformed into the String <code - language="java">"932"</code> in order to be concatenated - with the preceding <code language="java">"Decimal:"</code> - string.</para> + language="java">"932"</code> and then again being + concatenated into <code + language="java">Decimal:932</code>.</para> </callout> </calloutlist> </listitem> -- GitLab