Skip to content

Commit 9f0ab25

Browse files
committed
change section title and mention debugging tools
1 parent dea854b commit 9f0ab25

1 file changed

Lines changed: 17 additions & 7 deletions

File tree

source/ch9_commonmistakes.ptx

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,23 @@
77
<introduction>
88
</introduction>
99

10-
<section xml:id="how-to-avoid-mistakes">
11-
<title>How to Avoid Making Mistakes</title>
10+
<section xml:id="mistakes-happen">
11+
<title>Mistakes Happen!</title>
1212
<p>
13-
Making mistakes is a natural part of learning Java—or any programming language. The good news is that most errors happen for just a few common reasons, and once you recognize the patterns, they become much easier to fix. This chapter focuses on those typical mistakes and how to understand and correct them.
13+
Making mistakes is a very natural part of learning Java—or any other programming language. In fact, mistakes are an absolutely essential part of the learning process! So, try not to feel discouraged when you encounter errors in your code. Instead, view each mistake as an opportunity to deepen your understanding. Every programmer, no matter how experienced, encounters errors in their code. The key is to learn how to identify and correct these errors while also learning from them.
1414
</p>
1515
<p>
16-
One of the best ways to avoid these errors is to slow down and test your code in small pieces. Write a few lines, compile, and check the output before moving on. If something goes wrong, read the error message carefully and focus on fixing one problem at a time. Often, solving the first error helps fix others that follow.
16+
The good news is that most errors happen for just a few common reasons, and once you recognize the patterns, they become much easier to fix. This chapter focuses on those typical mistakes and how to understand and correct them.
1717
</p>
1818
<p>
19-
A simple debugging technique is to use <c>System.out.println()</c> to print out variable values and program flow. If you're not sure whether a part of your code is running or what a variable contains, print it out. This helps you check your assumptions and narrow down where something is going wrong.
19+
One of the best ways to correct these errors is to slow down and test your code in small pieces. Write a few lines, compile, and check the output before moving on. If something goes wrong, read the first error message very carefully, and focus on fixing one problem at a time. Often, solving the first error helps fix others that follow.
20+
</p>
21+
<p>
22+
A simple debugging technique is to use <c>System.out.println()</c> to print out variable values. If you're not sure whether a part of your code is running correctly or what a variable contains, you can print it out. This can help you to check your assumptions and narrow down where something is going wrong.
23+
</p>
24+
25+
<p>
26+
Consider the following example where we have a method that multiplies a number by two. We can add print statements to help us debug the code:
2027
</p>
2128
<program language="java" interactive="activecode" line-numbers="yes">
2229
<code>
@@ -39,10 +46,13 @@
3946
</code>
4047
</program>
4148
<p>
42-
In the example above, <c>System.out.println()</c> is used inside both <c>main</c> and <c>multiplyByTwo()</c> to trace what values are being passed and returned. This kind of print-based debugging can quickly reveal logic errors, unexpected behavior, or whether a method is even being called.
49+
In the example above, <c>System.out.println()</c> is used inside both <c>main</c> and <c>multiplyByTwo()</c> to trace what values are being passed and returned. This kind of print-based debugging can quickly reveal logic errors, unexpected behavior, or whether a method is even being called. However, overuse of this technique will often take more time than using the debugging tools that are built into your IDE.
50+
</p>
51+
<p>
52+
Useful tools in the built-in Java debugger can help you step through your code, inspect variables, and evaluate expressions at runtime. Familiarizing yourself with these tools can greatly enhance your debugging efficiency.
4353
</p>
4454
<p>
45-
Above all, be patient with yourself. Every mistake you make is an opportunity to understand Java more deeply.
55+
Above all, when you encounter an error, be patient with yourself. Every mistake you make is an opportunity to learn.
4656
</p>
4757
</section>
4858

0 commit comments

Comments
 (0)