diff --git a/Doc/Sd1/Ref/Fig/packageHierarchy.png b/Doc/Sd1/Ref/Fig/packageHierarchy.png deleted file mode 100644 index 4675aee470467ce619744b226d93640c4702269b..0000000000000000000000000000000000000000 Binary files a/Doc/Sd1/Ref/Fig/packageHierarchy.png and /dev/null differ diff --git a/Doc/Sd1/objectsClasses.xml b/Doc/Sd1/objectsClasses.xml index 7041c332c83442d7bea3e3cff072d6828482af69..ccee9ba2150939523a0c96fa1950d57dfa5f5595 100644 --- a/Doc/Sd1/objectsClasses.xml +++ b/Doc/Sd1/objectsClasses.xml @@ -3306,25 +3306,25 @@ public void print() { <qandadiv> <qandaentry> <question> - <para>In <xref linkend="sd1_qanda_extendEmployee"/> you had two - classes:</para> + <para>The previous exercise featured two classes:</para> <itemizedlist> <listitem> - <para>A class <classname>Employee</classname> defining an - employee's attributes and methods.</para> + <para><classname>Employee</classname> defining an employee's + attributes and methods.</para> </listitem> <listitem> - <para>A class <classname>Driver</classname> containing a - <methodname>main</methodname> method to start the + <para><classname>Driver</classname> containing a + <methodname>main</methodname> method for starting the application.</para> </listitem> </itemizedlist> <para>Currently both classes (hopefully!) reside in the same package <package>company</package>. We will assume the two - attributes age and salary yet have no <code + attributes <property>age</property> and + <property>salary</property> yet have no <code language="java">public</code>, <code language="java">private</code> or <code language="java">protected</code> access modifiers :</para> @@ -3387,7 +3387,7 @@ public class Driver { <answer> <para>Moving the <classname>Employee</classname> class from its <package>company</package> package to <package>model</package> - changes just its <code language="java">package</code> + changes its <code language="java">package</code> declaration:</para> <informaltable border="1"> @@ -3473,8 +3473,8 @@ public class Driver { }</programlisting> <para>This error message is in accordance with Table 4.1 from - the Encapsulation and Access Control section of <xref - linkend="bib_Kurniawan"/>: The attributes + the <quote>Encapsulation and Access Control</quote> section of + <xref linkend="bib_Kurniawan"/>: The attributes <property>age</property> and <property>salary</property> have no access modifiers at all. Hence <quote>default</quote> access prohibits classes belonging to other packages accessing the @@ -3557,7 +3557,7 @@ public class Driver { an employee's salary as with the first approach.</para> <para>There is however one apparent benefit: Developers do have - better bug tracking options on offer:</para> + better control including bug tracking options on offer:</para> <programlisting language="java">public void setSalary(double salary) { if (salary < 0) { @@ -3579,19 +3579,20 @@ public class Driver { <qandadiv> <qandaentry> <question> - <para>In <xref linkend="sd1_qanda_refineAccessEmployee"/> you - moved the <classname>Employee</classname> class to a package - <package>model</package>.</para> - - <para>How are the corresponding <xref linkend="glo_Java"/> files - <filename>Employee.java</filename> and - <filename>Driver.java</filename> being represented? What about - the generated byte code files + <para>In the <link + linkend="sd1_qanda_refineAccessEmployee">Employee + exercise</link> you moved the <classname>Employee</classname> + class to a package <package>model</package>.</para> + + <para>How are the corresponding <xref linkend="glo_Java"/> + source files <filename>Employee.java</filename> and + <filename>Driver.java</filename> being represented in your file + system? What about the generated byte code files <filename>Employee.</filename>class and <filename>Driver.</filename>class?</para> <tip> - <para>Use your OS's file system explorer.</para> + <para>Use your OS file system explorer.</para> </tip> </question> @@ -3618,37 +3619,64 @@ public class Driver { files</glossterm> <glossdef> - <para>Below folder <filename>bin</filename>.</para> + <para>Below folder <filename>target</filename> or + <filename>bin</filename>.</para> </glossdef> </glossentry> </glosslist> <para>Packages give rise to further sub directories both for - source code and their generated byte code - <quote>partners</quote>. The following example is a minor - variation of our employee example. The package - <package>model</package> has been transformed into + source code and compiler generated byte code. The following + example is a minor variation of our employee example. The + <package>model</package> package has been refactored into <package>company.model</package>:</para> <figure xml:id="sd1FigPackageHierarchy"> - <title>Package hierarchy of the employee example</title> - - <screenshot> - <info> - <title>On filesystem level the package - <package>company.model</package> becomes a subdirectory - <filename>model</filename> of sub directory - <filename>company</filename> for both our source - (<filename>src</filename>) and bytecode - (<filename>bin</filename>) file hierarchy.</title> - </info> + <title> <classname>Employee</classname> example package + hierarchy</title> + + <programlisting language="none"> Project root + <emphasis role="red">┣â”â”â”┳</emphasis> src <co + linkends="sd1FigPackageHierarchy-1" + xml:id="sd1FigPackageHierarchy-1-co"/> + <emphasis role="red">┃</emphasis> <emphasis role="red">┣â”â”â”┳</emphasis> company + <emphasis role="red">┃</emphasis> ... <emphasis role="red">┣â”â”â”</emphasis> Driver.java <emphasis + role="red">â”â”â”â”â”â”â”â”┓</emphasis> + <emphasis role="red">┃</emphasis> <emphasis role="red">â”—â”â”â”┳</emphasis> model <emphasis + role="red">┃</emphasis> <emphasis role="red">compile</emphasis> + <emphasis role="red">┃</emphasis> <emphasis role="red">â”—â”â”â”</emphasis> Employee.java <emphasis + role="red">â”â”â•‹â”â”â”┓</emphasis> + <emphasis role="red">┣â”â”â”┳</emphasis> target <emphasis + role="red">┃</emphasis> <emphasis role="red">┃</emphasis> <co + linkends="sd1FigPackageHierarchy-2" + xml:id="sd1FigPackageHierarchy-2-co"/> + <emphasis role="red">┃</emphasis> <emphasis role="red">┣â”â”â”┳</emphasis> company <emphasis + role="red">┃</emphasis> <emphasis role="red">┃</emphasis> + <emphasis role="red">┃</emphasis> ... <emphasis role="red">┣â”â”â”</emphasis> Driver.class <emphasis + role="red">â—€â”â”â”â”â”â”<emphasis role="red">â”›</emphasis></emphasis> <emphasis + role="red">┃</emphasis> + <emphasis role="red">┃</emphasis> <emphasis role="red">â”—â”â”â”┳</emphasis> model <emphasis + role="red">┃</emphasis> + <emphasis role="red">┃</emphasis> <emphasis role="red">â”—â”â”â”</emphasis> Employee.class <emphasis + role="red">â—€â”â”â”â”<emphasis role="red">â”›</emphasis></emphasis> +...</programlisting> - <mediaobject> - <imageobject> - <imagedata fileref="Ref/Fig/packageHierarchy.png"/> - </imageobject> - </mediaobject> - </screenshot> + <calloutlist> + <callout arearefs="sd1FigPackageHierarchy-1-co" + xml:id="sd1FigPackageHierarchy-1"> + <para>Folder <filename>src</filename> hosts source files + <abbrev>e.g.</abbrev> classes like + <filename>Employee.java</filename>.</para> + </callout> + + <callout arearefs="sd1FigPackageHierarchy-2-co" + xml:id="sd1FigPackageHierarchy-2"> + <para>Folder <filename>target</filename> hosts generated + files. As an example <filename>Employee.class</filename> + is being derived from <filename>Employee.java</filename> + by compilation.</para> + </callout> + </calloutlist> </figure> </answer> </qandaentry> @@ -3701,7 +3729,9 @@ public class Driver { <para>Read the section in <xref linkend="bib_Kurniawan"/> about the <quote xlink:href="https://docs.oracle.com/javase/tutorial/java/javaOO/thiskey.html">this</quote> - keyword.</para> + keyword and the <link + linkend="sd1_fig_circleClassDistinctVariableNames">class + <abbrev>vs.</abbrev> method scope slide</link>.</para> </tip> </question> @@ -3721,6 +3751,9 @@ public class Driver { public double <emphasis role="bold">salary</emphasis>; ... }</programlisting> + + <para>Both variables are accessible from within the whole + class including all its methods.</para> </glossdef> </glossentry> @@ -3731,17 +3764,20 @@ public class Driver { <programlisting language="java">public Employee(int <emphasis role="bold">age</emphasis>, double <emphasis role="bold">salary</emphasis>) {.../* Constructor's method body */}</programlisting> + + <para>Definition is being limited to the method's + body.</para> </glossdef> </glossentry> </glosslist> <para>Within the constructor's method body the parameter list - scope will take precedence over class scope. Thus the assignment - <code language="java">age = age</code> will assign the - constructor's argument <code language="java">age</code> to - itself rather than assigning it to the instance variable <code - language="java">age</code> being defined within class - scope.</para> + scope <emphasis>will take precedence over class + scope</emphasis>. Thus the assignment <code language="java">age + = age</code> will assign the constructor's argument <code + language="java">age</code> to itself rather than assigning it to + the instance variable <code language="java">age</code> being + defined at class scope.</para> <para>We may explicitly resolve this scope conflict in our favour by qualifying the instance variables <code @@ -3750,10 +3786,10 @@ public class Driver { represented by the <code language="java">this</code> keyword:</para> - <programlisting language="java">public Employee(int age, double salary) { + <programlisting language="none">public Employee(int age, double salary) { // The "this" keyword refers to class scope - this.age = age; - this.salary = salary; + <emphasis role="red">this</emphasis>.age = age; + <emphasis role="red">this</emphasis>.salary = salary; }</programlisting> </answer> </qandaentry> @@ -3767,10 +3803,14 @@ public class Driver { <qandaentry> <question> <para>This exercise is about using packages for resolving class - name clashes.</para> - - <para>Define your own <classname>String</classname> class having - a suitable constructor and a <methodname>public String + name clashes. Usually you won't actually define a class String + of your own next to <link + xlink:href="https://docs.oracle.com/en/java/javase/14/docs/api/java.base/java/lang/String.html">java.lang.String</link>.</para> + + <para>Define your own <classname>String</classname> class + internally using <link + xlink:href="https://docs.oracle.com/en/java/javase/14/docs/api/java.base/java/lang/String.html">java.lang.String</link>. + Provide a suitable constructor and a <methodname>public String toString()</methodname> method just returning the <quote>internal</quote> <classname>java.lang.String</classname> instance allowing for the following snippet:</para> @@ -3810,8 +3850,8 @@ Hello 'John'</screen> a <methodname>String toString()</methodname> method in a class allows for easy object to String conversion and thus for simply using - <methodname>System.out.println()</methodname> to print an - object's state.</para> + <methodname>System.out.println()</methodname> for printing + an object's state.</para> </listitem> </orderedlist> </tip> diff --git a/ws/Docbook/Preprocess/docbooksupplement.js b/ws/Docbook/Preprocess/docbooksupplement.js index a6014c6c925e45bc986de3e7af2a0fc78e2d275d..fa9b043b5d417b566372901ac998bf6dab1d94e4 100644 --- a/ws/Docbook/Preprocess/docbooksupplement.js +++ b/ws/Docbook/Preprocess/docbooksupplement.js @@ -28,17 +28,22 @@ function initBbPost(index, bbForumElement) { dataType: "json", success: function (data) { var postcount = data.postcount - 1; - var p = bbForumElement.getElementsByTagName("p")[0]; - var a = p.getElementsByTagName("a")[0]; - var text; + + var a = bbForumElement.getElementsByTagName("a")[0]; + var text, style; if (0 == postcount) { - text = "Create comment"; - a.setAttribute("style", "color: red"); + text = "Create first comment in forum!"; + style = "color: red"; } else { - text = "Read comments (" + postcount + ((1 == postcount) ? " posting" : " postings") + ")"; - a.setAttribute("style", "color: green"); + style = "color: green"; + if (1 == postcount){ + text = "Read or add comment in forum"; + } else { + text = "Read " + postcount + " comments or add one"; + } } - a.innerHTML = text; + a.innerHTML = "<img src='common/images/comment.svg' width='40ex' style='vertical-align: middle;' alt=' " + text + "' title = '" + text + "'>" + text; + a.setAttribute("style", style); } }); }