Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
84 changes: 84 additions & 0 deletions source/ch2_firstjavaprogram.ptx
Original file line number Diff line number Diff line change
Expand Up @@ -526,4 +526,88 @@ Hello World!

</reading-questions>
</section>

<section xml:id="naming-conventions">
<title>Naming Conventions</title>
<p>
It is worth pointing out that Java has some very handy naming conventions. It is advisable to both use meaningful names and to follow these naming conventions while developing software in Java for good maintenance and readability of code.
</p>

<p>
<ul>
<li>
<p>
Class names should be nouns that are written in UpperCamelCase, namely with the first letter of each word capitalized including the first.
For example, <c>ArrayList</c>, <c>Scanner</c>, <c>StringBuilder</c>, <c>System</c>, etc.
</p>
</li>

<li>
<p>
Method names use lowerCamelCase which start with a verb that describes the action they perform. This means that method names start with a lower case letter, and use upper case for each internal-word method names. For example, <c>isInt()</c>, <c>nextLine()</c>, <c>getDenominator()</c>, <c>setNumerator()</c>, etc.
</p>
</li>

<li>
<p>
Instance variables of a class start with a lower case letter and use lowerCamelCase like method names. For example, <c>count</c>, <c>totalAmount</c>, etc.
</p>
</li>

<li>
<p>
Constants are in all upper case letters or in upper snake case, which also known as screaming snake case, and which is a naming convention in which each word is written in uppercase letters, separated by underscores.
For example, <c>Math.MAXINT</c> or <c>MAX_INT</c>.
</p>
</li>
</ul>
</p>

<exercise label="mcq-java-vs-python-variable-names">
<statement>
<p>
Which of the following is a valid variable name according to the core syntax rules of Java, but causes a syntax error in Python?
</p>
</statement>
<choices>
<choice>
<statement><c>_variableName</c></statement>
<feedback>
<p>
Incorrect. Leading underscores are valid in both Java and Python (commonly used in Python for private/protected attributes).
</p>
</feedback>
</choice>

<choice>
<statement><c>variable_name</c></statement>
<feedback>
<p>
Incorrect. Snake_case names with underscores are valid in both languages (and are actually standard convention in Python).
</p>
</feedback>
</choice>

<choice correct="yes">
<statement><c>$variableName</c></statement>
<feedback>
<p>
Correct! Java allows the dollar sign (<c>$</c>) in variable names, but Python generates a <c>SyntaxError</c> because <c>$</c> is not a permitted identifier character in Python.
</p>
</feedback>
</choice>

<choice>
<statement><c>variableName2</c></statement>
<feedback>
<p>
Incorrect. Numbers at the end of variable names are valid syntax in both Java and Python.
</p>
</feedback>
</choice>
</choices>
</exercise>

</section>

</chapter>
81 changes: 0 additions & 81 deletions source/ch3_javadatatypes.ptx
Original file line number Diff line number Diff line change
Expand Up @@ -1126,88 +1126,7 @@ public class HistoMap {

</section>

<section xml:id="naming-conventions">
<title>Naming Conventions</title>
<p>
It is worth pointing out that Java has some very handy naming conventions. It is advisable to both use meaningful names and to follow these naming conventions while developing software in Java for good maintenance and readability of code.
</p>

<p>
<ul>
<li>
<p>
Class names should be nouns that are written in UpperCamelCase, namely with the first letter of each word capitalized including the first.
For example, <c>ArrayList</c>, <c>Scanner</c>, <c>StringBuilder</c>, <c>System</c>, etc.
</p>
</li>

<li>
<p>
Method names use lowerCamelCase which start with a verb that describes the action they perform. This means that method names start with a lower case letter, and use upper case for each internal-word method names. For example, <c>isInt()</c>, <c>nextLine()</c>, <c>getDenominator()</c>, <c>setNumerator()</c>, etc.
</p>
</li>

<li>
<p>
Instance variables of a class start with a lower case letter and use lowerCamelCase like method names. For example, <c>count</c>, <c>totalAmount</c>, etc.
</p>
</li>

<li>
<p>
Constants are in all upper case letters or in upper snake case, which also known as screaming snake case, and which is a naming convention in which each word is written in uppercase letters, separated by underscores.
For example, <c>Math.MAXINT</c> or <c>MAX_INT</c>.
</p>
</li>
</ul>
</p>

<exercise label="mcq-java-vs-python-variable-names">
<statement>
<p>
Which of the following is a valid variable name according to the core syntax rules of Java, but causes a syntax error in Python?
</p>
</statement>
<choices>
<choice>
<statement><c>_variableName</c></statement>
<feedback>
<p>
Incorrect. Leading underscores are valid in both Java and Python (commonly used in Python for private/protected attributes).
</p>
</feedback>
</choice>

<choice>
<statement><c>variable_name</c></statement>
<feedback>
<p>
Incorrect. Snake_case names with underscores are valid in both languages (and are actually standard convention in Python).
</p>
</feedback>
</choice>

<choice correct="yes">
<statement><c>$variableName</c></statement>
<feedback>
<p>
Correct! Java allows the dollar sign (<c>$</c>) in variable names, but Python generates a <c>SyntaxError</c> because <c>$</c> is not a permitted identifier character in Python.
</p>
</feedback>
</choice>

<choice>
<statement><c>variableName2</c></statement>
<feedback>
<p>
Incorrect. Numbers at the end of variable names are valid syntax in both Java and Python.
</p>
</feedback>
</choice>
</choices>
</exercise>

</section>

<section xml:id="chapter3_summary">
<title>Summary &amp; Reading Questions</title>
Expand Down