diff --git a/Doc/Sd1/Ref/LangFundament/dualSigned3bit.multi.svg b/Doc/Sd1/Ref/LangFundament/dualSigned3bit.multi.svg index d6c028fa1a132998c1798d7d89da6ec315b1ca58..7a262f9645bd2d1a0fa634babd2abe224a1d750e 100644 --- a/Doc/Sd1/Ref/LangFundament/dualSigned3bit.multi.svg +++ b/Doc/Sd1/Ref/LangFundament/dualSigned3bit.multi.svg @@ -32,7 +32,7 @@ inkscape:current-layer="layer1" showgrid="true" inkscape:window-width="1533" - inkscape:window-height="1046" + inkscape:window-height="1044" inkscape:window-x="67" inkscape:window-y="27" inkscape:window-maximized="1"> @@ -48,7 +48,7 @@ <dc:format>image/svg+xml</dc:format> <dc:type rdf:resource="http://purl.org/dc/dcmitype/StillImage" /> - <dc:title></dc:title> + <dc:title /> </cc:Work> </rdf:RDF> </metadata> @@ -1117,7 +1117,7 @@ id="tspan7531" x="29.104166" y="228.20833" - style="stroke-width:0.26458332">Converting decimal to <tspan + style="stroke-width:0.26458332">Converting decimal -4 to <tspan style="fill:#ff0000" id="tspan7549">3- bit</tspan> two-complement rule:</tspan></text> <text @@ -1158,7 +1158,12 @@ style="stroke-width:0.26458332" id="tspan7547">In <tspan style="fill:#ff0000" - id="tspan7551">8-bit</tspan> two-complement we have --> 11111100</tspan></text> + id="tspan7551">8-bit</tspan> two-complement -4 is being</tspan><tspan + sodipodi:role="line" + x="29.104166" + y="278.47919" + style="stroke-width:0.26458332" + id="tspan467">represented by 11111100</tspan></text> </g> <g style="display:none" diff --git a/Doc/Sd1/Ref/LangFundament/longCastInt.multi.svg b/Doc/Sd1/Ref/LangFundament/longCastInt.multi.svg index 237ba85abb96d0b1b57f8142b4522990bdce619f..4b5dc39d701b21fb4ab6dc8b16e627a0a7f0dfd1 100644 --- a/Doc/Sd1/Ref/LangFundament/longCastInt.multi.svg +++ b/Doc/Sd1/Ref/LangFundament/longCastInt.multi.svg @@ -47,7 +47,7 @@ inkscape:current-layer="layer1" showgrid="true" inkscape:window-width="1533" - inkscape:window-height="1046" + inkscape:window-height="1044" inkscape:window-x="67" inkscape:window-y="27" inkscape:window-maximized="1"> @@ -1832,7 +1832,7 @@ id="tspan3160" x="66.145836" y="210.78719" - style="stroke-width:0.26458332"></tspan></text> + style="stroke-width:0.26458332" /></text> <text xml:space="preserve" style="font-style:normal;font-variant:normal;font-weight:bold;font-stretch:normal;font-size:4.23333311px;line-height:1.25;font-family:luci;-inkscape-font-specification:'luci Bold';letter-spacing:0px;word-spacing:0px;fill:#000000;fill-opacity:1;stroke:none;stroke-width:0.26458332" @@ -1844,6 +1844,19 @@ x="66.145836" y="210.78719" style="stroke-width:0.26458332" /></text> + <text + xml:space="preserve" + style="font-style:normal;font-variant:normal;font-weight:bold;font-stretch:normal;font-size:4.23333311px;line-height:1.25;font-family:'DejaVu Sans';-inkscape-font-specification:'DejaVu Sans Bold';letter-spacing:0px;word-spacing:0px;fill:#ff0000;fill-opacity:1;stroke:none;stroke-width:0.26458332" + x="116.03368" + y="260.02835" + id="text4085"><tspan + sodipodi:role="line" + id="tspan4083" + x="116.03368" + y="260.02835" + style="fill:#ff0000;stroke-width:0.26458332"><tspan + style="fill:#000000" + id="tspan4087">Value:</tspan> -296517632</tspan></text> </g> <g style="display:none" @@ -3604,7 +3617,7 @@ y="210.78719" x="66.145836" id="tspan3806" - sodipodi:role="line"></tspan></text> + sodipodi:role="line" /></text> <text id="text3812" y="207.04167" @@ -4861,7 +4874,7 @@ id="tspan4452" x="66.145836" y="210.78719" - style="stroke-width:0.26458332"></tspan></text> + style="stroke-width:0.26458332" /></text> <text xml:space="preserve" style="font-style:normal;font-variant:normal;font-weight:bold;font-stretch:normal;font-size:4.23333311px;line-height:1.25;font-family:luci;-inkscape-font-specification:'luci Bold';letter-spacing:0px;word-spacing:0px;fill:#000000;fill-opacity:1;stroke:none;stroke-width:0.26458332" @@ -6064,7 +6077,7 @@ y="210.78719" x="66.145836" id="tspan6609" - sodipodi:role="line"></tspan></text> + sodipodi:role="line" /></text> <text id="text6615" y="207.04167" @@ -6182,7 +6195,7 @@ id="tspan7043" x="66.145836" y="210.78719" - style="stroke-width:0.26458332"></tspan></text> + style="stroke-width:0.26458332" /></text> <text xml:space="preserve" style="font-style:normal;font-variant:normal;font-weight:bold;font-stretch:normal;font-size:4.23333311px;line-height:1.25;font-family:luci;-inkscape-font-specification:'luci Bold';letter-spacing:0px;word-spacing:0px;fill:#000000;fill-opacity:1;stroke:none;stroke-width:0.26458332" diff --git a/Doc/Sd1/Ref/LangFundament/variableToMemory.multi.svg b/Doc/Sd1/Ref/LangFundament/variableToMemory.multi.svg index a93be8c52718d3f77028240908155eb8e329d77e..cec8303700b57152ca99b66bc5d131fbe67a9262 100644 --- a/Doc/Sd1/Ref/LangFundament/variableToMemory.multi.svg +++ b/Doc/Sd1/Ref/LangFundament/variableToMemory.multi.svg @@ -31,7 +31,7 @@ inkscape:current-layer="layer1" showgrid="true" inkscape:window-width="1533" - inkscape:window-height="1046" + inkscape:window-height="1044" inkscape:window-x="67" inkscape:window-y="27" inkscape:window-maximized="1" @@ -699,7 +699,7 @@ <dc:format>image/svg+xml</dc:format> <dc:type rdf:resource="http://purl.org/dc/dcmitype/StillImage" /> - <dc:title></dc:title> + <dc:title /> </cc:Work> </rdf:RDF> </metadata> @@ -1743,7 +1743,7 @@ height="230" x="-30" y="23.464569" /></flowRegion><flowPara - id="flowPara2132"></flowPara></flowRoot> <path + id="flowPara2132" /></flowRoot> <path style="fill:none;stroke:#000000;stroke-width:2.00000048;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" d="m 400,972.51973 v 44.99997" id="path5344-4-2-9-3-4" @@ -1820,7 +1820,7 @@ sodipodi:role="line" id="tspan3000" x="590" - y="1076.676"></tspan></text> + y="1076.676" /></text> </g> <g transform="translate(0,-839.05516)" @@ -2709,7 +2709,7 @@ height="230" width="280" id="rect3376" /></flowRegion><flowPara - id="flowPara3380"></flowPara></flowRoot> <path + id="flowPara3380" /></flowRoot> <path sodipodi:nodetypes="cc" inkscape:connector-curvature="0" id="path3384" @@ -2774,7 +2774,7 @@ y="1076.676" x="590" id="tspan3408" - sodipodi:role="line"></tspan></text> + sodipodi:role="line" /></text> </g> <g inkscape:label="Layer 70" @@ -3383,7 +3383,7 @@ height="230" x="-30" y="23.464569" /></flowRegion><flowPara - id="flowPara3738"></flowPara></flowRoot> <path + id="flowPara3738" /></flowRoot> <path style="fill:none;stroke:#000000;stroke-width:2.00000048;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" d="m 400,972.51973 v 44.99997" id="path3742" @@ -3426,7 +3426,7 @@ sodipodi:role="line" id="tspan3762" x="590" - y="1076.676"></tspan></text> + y="1076.676" /></text> </g> <g transform="translate(0,-839.05516)" @@ -3495,7 +3495,7 @@ height="230" width="280" id="rect3986" /></flowRegion><flowPara - id="flowPara3990"></flowPara></flowRoot> <text + id="flowPara3990" /></flowRoot> <text id="text4008" y="1062.5198" x="590" @@ -3504,7 +3504,7 @@ y="1076.676" x="590" id="tspan4006" - sodipodi:role="line"></tspan></text> + sodipodi:role="line" /></text> </g> <g inkscape:label="Layer 50" @@ -3562,7 +3562,7 @@ height="230" x="-30" y="23.464569" /></flowRegion><flowPara - id="flowPara4034"></flowPara></flowRoot> <text + id="flowPara4034" /></flowRoot> <text xml:space="preserve" style="font-style:normal;font-variant:normal;font-weight:bold;font-stretch:normal;font-size:16px;line-height:1.25;font-family:'DejaVu Sans';-inkscape-font-specification:'DejaVu Sans Bold';letter-spacing:0px;word-spacing:0px;fill:#000000;fill-opacity:1;stroke:none" x="590" @@ -3571,7 +3571,7 @@ sodipodi:role="line" id="tspan4038" x="590" - y="1076.676"></tspan></text> + y="1076.676" /></text> </g> <script ns1:version="14.10-05142318" diff --git a/Doc/Sd1/languageFundamentals.xml b/Doc/Sd1/languageFundamentals.xml index d5b8956e7ba73f746b666a68087adba6620fcd74..01ffd0caaef49003caef0af505e6f3bda8599bdc 100644 --- a/Doc/Sd1/languageFundamentals.xml +++ b/Doc/Sd1/languageFundamentals.xml @@ -413,7 +413,7 @@ representation</screen></td> <figure xml:id="sd1_fig_varDeclareAndUse"> <title>Declare and use</title> - <programlisting language="java">double pi; // Variable seclaration + <programlisting language="java">double pi; // Variable declaration ... pi = 3.1415926; // Assigning value to variable @@ -945,10 +945,10 @@ double f;</programlisting> <title>Type safety</title> <programlisting language="java">int i = 2; -int j = i; // o.K.: Assigning int to int -long l = i // o.K.: Widening conversion +int j = i; // o.K.: Assigning int to int +long l = i; // o.K.: Widening conversion -i = l; // Wrong: Narrowing +i = l; // Wrong: Narrowing boolean b = true; i = b; // Error: int and boolean are incompatible types @@ -965,7 +965,7 @@ i = "Hello"; // Even worse: Assigning a String to an int</programlisting> <colgroup width="60%"/> <tr> - <td valign="top"><programlisting language="java">byte b120 = 120; // o.K., static check + <td valign="top"><programlisting language="java">byte b120 = 127; // o.K., static check byte b128 = 128; // Wrong: Exceeding 127</programlisting></td> <td valign="top"><para>Performing static range check</para></td> @@ -973,13 +973,76 @@ byte b128 = 128; // Wrong: Exceeding 127</programlisting></td> <tr> <td valign="top"><programlisting language="java">int a = 120; -byte b120 = a;</programlisting></td> + +byte b120 = a; // Error Incompatible types + // Required: byte + // Found:int</programlisting></td> <td valign="top"><para>No static check on variable value</para></td> </tr> </informaltable> </figure> + <qandaset defaultlabel="qanda" xml:id="sd1_qanda_staticFinalCheck"> + <title>Benefits of <code language="java">final</code></title> + + <qandadiv> + <qandaentry> + <question> + <para>We reconsider our code from <xref + linkend="sd1_fig_narrowingStaticAnalysis"/>:</para> + + <programlisting language="java">int a = 120; + +byte b120 = a; // Error Incompatible types + // Required: byte + // Found:int</programlisting> + + <para>Adding <code language="java">final</code> solves the + issue:</para> + + <programlisting language="java">final int a = 120; + +byte b120 = a; // o.K.</programlisting> + + <para>Why does introducing a <code language="java">final</code> + modifier solves the fatal compile time error issue?</para> + + <tip> + <para>Read <link + xlink:href="https://en.wikipedia.org/wiki/Static_program_analysis">Static + program analysis</link>. Why does <code + language="java">final</code> help the compiler in code + analysis?</para> + </tip> + </question> + + <answer> + <para>Modifying variable <code language="java">a</code> to become + <code language="java">final</code> assures its initial value will + never change. Thus from a <link + xlink:href="https://en.wikipedia.org/wiki/Data-flow_analysis">Data-flow + analysis</link> point of view the two snippets are + equivalent:</para> + + <informaltable border="1"> + <tr> + <td valign="top"><programlisting language="java">final int a = 120; + +byte b120 = a;</programlisting></td> + + <td valign="top"><programlisting language="java">byte b120 = 120;</programlisting></td> + </tr> + </informaltable> + + <para>Thus the compiler is able to perform a <emphasis + role="red">compile time</emphasis> range check assuring the value + of 120 to be within the interval [-128, 127].</para> + </answer> + </qandaentry> + </qandadiv> + </qandaset> + <figure xml:id="sd1_fig_forcedConversion"> <title>Forcing conversions</title> @@ -1036,7 +1099,7 @@ i carrying double:2147483647</screen></td> <informaltable border="1"> <tr> - <td valign="top"><programlisting language="java">#include <stdio.h> + <td valign="top"><programlisting language="c">#include <stdio.h> void main(void) { double measure = 65234.5435; @@ -1951,41 +2014,42 @@ Different</screen></td> </informaltable> </figure> + <figure xml:id="sd1_fig_perlDynamicTyping2"> + <title>Dynamic typing in PERL, part 2</title> + + <informaltable border="1"> + <tr> + <td valign="top"><programlisting language="perl">$a = 2; # An integer +$b = 3; # Another integer + +print '$a + $b = ', $a + $b, "\n"; + +$jim = "Jim"; # A string +print '$jim + $a = ' , $jim + $a, "\n";</programlisting></td> + + <td valign="top"><screen>$a + $b = 5 +$jim + $a = 2</screen></td> + </tr> + </informaltable> + </figure> + <figure xml:id="sd1_fig_final"> <title>Using final</title> - <glosslist> - <glossentry> - <glossterm>Bad:</glossterm> - - <glossdef> - <programlisting language="java">double pi = 3.141592653589793; - ... + <programlisting language="java">//Bad! +double pi = 3.141592653589793; +... pi = -4; // Woops, accidential and erroneous redefinition</programlisting> - </glossdef> - </glossentry> - - <glossentry> - <glossterm>Good:</glossterm> - <glossdef> - <para><programlisting language="java">final double pi = 3.141592653589793; + <programlisting language="java">//Good +final double pi = 3.141592653589793; ... pi = -4; // Compile time error: - // Cannot assign a value to final variable 'pi'</programlisting></para> - </glossdef> - </glossentry> + // Cannot assign a value to final variable 'pi'</programlisting> - <glossentry> - <glossterm>Even better:</glossterm> - - <glossdef> - <para><programlisting language="java">final double PI = 3.141592653589793; // Coding style (Best practices): - // Using capital letters for - // constant variable.</programlisting></para> - </glossdef> - </glossentry> - </glosslist> + <programlisting language="java">// Even better +final double PI // Coding style (Best practices): Using + = 3.141592653589793; // capital letters for constant variable.</programlisting> </figure> <figure xml:id="sd1_fig_variableCategories"> @@ -2309,7 +2373,7 @@ Value 4: 29</screen> <tr> <td valign="top">29</td> - <td valign="top"><para>Default:</para><para>base <emphasis + <td valign="top"><para>base <emphasis role="red">10</emphasis></para></td> <td valign="top">Decimal</td> @@ -2518,8 +2582,8 @@ Value 4: 29</screen> </informaltable> </figure> - <figure xml:id="sd1_fig_javaLiterals"> - <title><xref linkend="glo_Java"/> literals</title> + <figure xml:id="sd1_fig_javaLiteralsPrimitive"> + <title><xref linkend="glo_Java"/> primitive literals</title> <informaltable border="1"> <colgroup width="24%"/> @@ -2586,15 +2650,6 @@ Value 4: 29</screen> -23</code>, <code language="java">-17.</code></td> </tr> - <tr> - <td><code language="java" - xlink:href="https://docs.oracle.com/javase/tutorial/java/data/strings.html">String</code></td> - - <td><code language="java">"Hello"</code>, <code - language="java">"Greek Δ"</code>, <code language="java">"Greek <link - xlink:href="https://www.fileformat.info/info/unicode/char/0394/index.htm">\u0394</link>"</code></td> - </tr> - <tr> <td><code language="java" xlink:href="https://docs.oracle.com/javase/specs/jls/se7/html/jls-4.html#jls-4.2.5-100">boolean</code></td> @@ -2604,6 +2659,27 @@ Value 4: 29</screen> <code language="java" xlink:href="https://docs.oracle.com/javase/specs/jls/se7/html/jls-4.html#jls-4.2.5-100">false</code></td> </tr> + </informaltable> + </figure> + + <figure xml:id="sd1_fig_javaLiteralsClass"> + <title><xref linkend="glo_Java"/> <classname + xlink:href="https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/lang/String.html">String</classname> + and <code language="java">null</code> literals</title> + + <informaltable border="1"> + <colgroup width="24%"/> + + <colgroup width="76%"/> + + <tr> + <td><code language="java" + xlink:href="https://docs.oracle.com/javase/tutorial/java/data/strings.html">String</code></td> + + <td><code language="java">"Hello"</code>, <code + language="java">"Greek Δ"</code>, <code language="java">"Greek <link + xlink:href="https://www.fileformat.info/info/unicode/char/0394/index.htm">\u0394</link>"</code></td> + </tr> <tr> <td/> @@ -2623,11 +2699,11 @@ Value 4: 29</screen> <para>We want to construct a list of <link xlink:href="https://www.rapidtables.com/code/text/ascii-table.html#print">printable ASCII characters</link>. Write a <xref linkend="glo_Java"/> - application by starting just from from the character literals - <code language="java">' '</code>, <code - language="java">'!'</code>, <code language="java">'"'</code>, - <code language="java">'#'</code>, '$', '%', '&' to show their - corresponding <xref linkend="glo_ASCII"/> decimal values. The + application printing the character literals <code + language="java">' '</code>, <code language="java">'!'</code>, + <code language="java">'"'</code>, <code + language="java">'#'</code>, '$', '%', '&' among with their + respective decimal <xref linkend="glo_ASCII"/> values. The intended output is:</para> <screen> : 32 @@ -2656,7 +2732,7 @@ $: 36 xlink:href="https://docs.oracle.com/javase/specs/jls/se7/html/jls-4.html#jls-4.2.1-100-E">char</code> values may be assigned to <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> - variables we may code:</para> + variables we code:</para> <programlisting language="java">{ char c = ' '; // space @@ -3159,7 +3235,7 @@ System.out.println("Maximum short value:" + MAXIMUM</programlisting> </qandaset> <qandaset defaultlabel="qanda" xml:id="sd1QandaBracesInPrintln"> - <title>Why using braces inside <code + <title>Why using braces in <code language="java">System.out.println(...)</code> ?</title> <qandadiv> @@ -4928,7 +5004,9 @@ System.out.println("Difference: " + difference);</programlisting><screen>Differe <td><code language="java">int</code></td> - <td rowspan="6"><code language="java">+, -, *, /, %</code></td> + <td rowspan="6"><para>+, -, *, /, % <link + linkend="sd1_explainNoByteByteOperator">(read + here!)</link></para></td> </tr> <tr> @@ -4971,32 +5049,31 @@ System.out.println("Difference: " + difference);</programlisting><screen>Differe <td><code language="java">int</code></td> </tr> </informaltable> - - <para>The careful reader may stumble upon the absence of e.g. a »+« - operator turning two byte values <code language="java">a</code> and - <code language="java">b</code> into an expression <code - language="java">a + b</code> of type <code language="java">byte</code> - rather than <code language="java">int</code>. This is due to a Java - Virtual Machine <link - xlink:href="https://docs.oracle.com/javase/specs/jvms/se10/html/jvms-2.html#jvms-2.11.1-120">design - decision</link> leading to a <link - xlink:href="https://docs.oracle.com/javase/specs/jvms/se10/html/jvms-2.html#jvms-2.11.1-320">limited - set of computational types</link>:</para> - - <blockquote> - <para>Given the Java Virtual Machine's one-byte opcode size, encoding - types into opcodes places pressure on the design of its instruction - set. If each typed instruction supported all of the Java Virtual - Machine's run-time data types, there would be more instructions than - could be represented in a byte. Instead, the instruction set of the - Java Virtual Machine provides a reduced level of type support for - certain operations. In other words, the instruction set is - intentionally not orthogonal. Separate instructions can be used to - convert between unsupported and supported data types as - necessary.</para> - </blockquote> </figure> + <para xml:id="sd1_explainNoByteByteOperator">The careful reader may + stumble upon the absence of e.g. a »+« operator turning two byte values + <code language="java">a</code> and <code language="java">b</code> into an + expression <code language="java">a + b</code> of type <code + language="java">byte</code> rather than <code language="java">int</code>. + This is due to a Java Virtual Machine <link + xlink:href="https://docs.oracle.com/javase/specs/jvms/se10/html/jvms-2.html#jvms-2.11.1-120">design + decision</link> leading to a <link + xlink:href="https://docs.oracle.com/javase/specs/jvms/se10/html/jvms-2.html#jvms-2.11.1-320">limited + set of computational types</link>:</para> + + <blockquote> + <para>Given the Java Virtual Machine's one-byte opcode size, encoding + types into opcodes places pressure on the design of its instruction set. + If each typed instruction supported all of the Java Virtual Machine's + run-time data types, there would be more instructions than could be + represented in a byte. Instead, the instruction set of the Java Virtual + Machine provides a reduced level of type support for certain operations. + In other words, the instruction set is intentionally not orthogonal. + Separate instructions can be used to convert between unsupported and + supported data types as necessary.</para> + </blockquote> + <qandaset defaultlabel="qanda" xml:id="sw1QandaCircleArea"> <title>Calculating a circle's area</title> @@ -5749,13 +5826,14 @@ char resultChar= s + c; // Incompatible types Required: char found: int</prog <figure xml:id="sd1_fig_OperatorExamples"> <title>Operator examples</title> - <programlisting language="java">i++; i = i + 1; -i--; i = i - 1; -i += b; i = i + b; -i %= 3; i = i % 3; + <programlisting language="java">//Integer +i++; i = i + 1; // Increment by one +i--; i = i - 1; // Decrement by one +i += b; i = i + b; // Raise by b's value +i %= 3; i = i % 3; // Modulus of 3 // boolean -b = !b; // true <--> false</programlisting> + b = !b; // Switching true <--> false</programlisting> </figure> <qandaset defaultlabel="qanda" xml:id="sd1_qanda_GuessingResults"> @@ -6017,7 +6095,7 @@ public class Rectangle { // There is more to come soon ... }</programlisting> - <calloutlist> + <calloutlist role="slideExclude"> <callout arearefs="sd1_fig_javadocComment-1-co" xml:id="sd1_fig_javadocComment-1"> <para>A <xref linkend="glo_Javadoc"/> describing class diff --git a/Doc/Sd1/objectsClasses.xml b/Doc/Sd1/objectsClasses.xml index ca171bc571a4b05addd507c1a4c52e582850d1d8..1e7e0957d25daea7749c861b0dbe02d87acf7a49 100644 --- a/Doc/Sd1/objectsClasses.xml +++ b/Doc/Sd1/objectsClasses.xml @@ -221,7 +221,7 @@ if (null == r) { <title>Packages</title> <figure xml:id="sd1_fig_packages"> - <title>Package benefits</title> + <title>Why packages ?</title> <itemizedlist> <listitem> @@ -462,7 +462,7 @@ public class Q { <imagedata fileref="Ref/ObjectsAndClasses/packageToDirectory.png.marked.svg"/> </imageobject> - <calloutlist> + <calloutlist role="slideExclude"> <callout arearefs="sd1_imagemap_package2directory-2-co" xml:id="sd1_imagemap_package2directory-2.2"> <para>A class Print defined in package @@ -1637,13 +1637,15 @@ public void writeSvg() { </listitem> <listitem> - <para>Use private unless you have a good reason not to.</para> + <para>Use <code language="java">private</code> unless you have a + good reason not to.</para> </listitem> <listitem> - <para>Avoid public fields except for constants. Public fields tend - linking to a particular implementation and limit your flexibility - in changing your code.</para> + <para>Avoid <code language="java">public</code> fields except for + constants. Public fields tend linking to a particular + implementation and limit your flexibility in changing your + code.</para> </listitem> </itemizedlist> </figure> @@ -3763,7 +3765,7 @@ Club's member count:3</screen> </figure> <figure xml:id="sd1_fig_staticNoInstanceNeeded"> - <title>Do we require an instance?</title> + <title>Do we <emphasis>really</emphasis> require an instance?</title> <informaltable border="1"> <tr> diff --git a/Doc/Sd1/statements.xml b/Doc/Sd1/statements.xml index 40f71620bf839574fbe0cd0c0f6459e088336f00..c30af2bb746ec1bf8974f22b31fbc81c3aadc46d 100644 --- a/Doc/Sd1/statements.xml +++ b/Doc/Sd1/statements.xml @@ -38,9 +38,9 @@ <figure xml:id="sd1_fig_StatementEndSemicolon"> <title>General Syntax</title> - <para>Statement body terminated by <quote>;</quote>:</para> + <para>Statement body terminated by <quote>;</quote></para> - <programlisting language="none">{statement} ;</programlisting> + <programlisting language="none">{statement};</programlisting> </figure> <figure xml:id="sd1_fig_StatementDeclareVariable"> @@ -753,7 +753,7 @@ Address: <emphasis role="red">129.35.230.2</emphasis> <co linkends="sd1_fig_getIpToDns-3" xml:id="sd1_fig_getIpToDns-3-co"/></screen> <calloutlist> - <callout arearefs="sd1_fig_getIpToDns-1-co" + <callout arearefs="sd1_fig_getIpToDns-1-co" role="slideExclude" xml:id="sd1_fig_getIpToDns-1"> <para>Choosing a name server to query <xref linkend="glo_DNS"/> names.</para> @@ -1449,13 +1449,13 @@ Decimal value 11 not yet implemented</screen> if (1 == number) { System.out.println("Monday"); } else if (2 == number) { - System.out.println("Tuesday"); + System.out.println("Tuesday"); ... } else if (7 == number) { - System.out.println("Sunday"); + System.out.println("Sunday"); } else { - System.out.println("Invalid number " + number); + System.out.println("Invalid number " + number); } }</programlisting> </figure> @@ -1476,9 +1476,9 @@ switch(number) { case 5: System.out.println("Friday"); break; case 6: System.out.println("Saturday"); break; case 7: System.out.println("Sunday"); break; + default: System.out.println("Invalid number " + number); break; -} -...</programlisting> +} ...</programlisting> <screen>Enter a weekday number (1=Monday, 2=Tuesday,...) : 6 Saturday</screen> @@ -2012,48 +2012,28 @@ scan.close();</programlisting> <figure xml:id="sd1_fig_loopWhy"> <title>Why loops?</title> - <glosslist> - <glossentry> - <glossterm>Objective</glossterm> + <para><emphasis>Objective</emphasis>: Execute the same statement + multiple times.</para> - <glossdef> - <para>Execute the same statement multiple times.</para> - </glossdef> - </glossentry> + <para><emphasis>Solution</emphasis>: Copy / paste the statement in + question:</para> - <glossentry> - <glossterm>Solution</glossterm> - - <glossdef> - <para>Copy / paste the statement in question:</para> - - <programlisting language="java">System.out.println("Do not copy!"); + <programlisting language="java">System.out.println("Do not copy!"); System.out.println("Do not copy!"); System.out.println("Do not copy!"); System.out.println("Do not copy!");</programlisting> - </glossdef> - </glossentry> - - <glossentry> - <glossterm>Problem</glossterm> - - <glossdef> - <para>Only works if number of repetitions is known at compile - time.</para> - </glossdef> - </glossentry> - </glosslist> + + <para><emphasis>Problem</emphasis>: Only works if number of repetitions + is known at compile time.</para> </figure> <figure xml:id="sd1_fig_loopBadParameterization"> <title>Hard to parameterize</title> - <para>Limited workaround for repetition count given at runtime:</para> - - <programlisting language="java">int repetitions; + <para>Limited workaround for runtime supplied repetition count:</para> -repetitions = 3; // Simulated dynamic value - // Runtime, not compile-time + <programlisting language="java">System.out.print("Enter desired number of repetitions: "); +final repetitions = scan.nextInt(); switch(repetitions) { case 5: System.out.println("Do not copy!"); @@ -2074,7 +2054,7 @@ switch(repetitions) { <informaltable border="1"> <tr> - <td valign="top"><programlisting language="java">int repetitions = 3; <co + <td valign="top"><programlisting language="java">final int repetitions = scan.nextInt(); <co linkends="sd1_callout_whileLoop-1" xml:id="sd1_callout_whileLoop-1-co"/> int loopCounter = 1; <co linkends="sd1_callout_whileLoop-2" @@ -2130,7 +2110,7 @@ Do not copy!</screen></td> <figure xml:id="sd1_fig_loopParamSolutionSyntaxSugar"> <title>Combining increment and termination condition</title> - <programlisting language="java">int repetitions = 3; + <programlisting language="java">final int repetitions = scan.nextInt(); int loopCounter = 1; while (loopCounter++ <= repetitions) { @@ -2496,7 +2476,8 @@ while (i < LIMIT) { <tip> <para>Consider renaming <code>i</code> to <code>row</code> and - <code>j</code> to <code>column</code>.</para> + <code>j</code> to <code>column</code> improving code + understandability.</para> </tip> </figure> @@ -3612,7 +3593,7 @@ final int <informaltable border="1"> <tr> - <td><programlisting language="java">int LIMIT = 5; + <td><programlisting language="java">final int LIMIT = 5; int sum = 0; for (int i = 1; i <= LIMIT; i++) {