Java Reference
In-Depth Information
A red squiggly line is placed under the text sample in line 9 and if you display the error message, you will see that
RAD suggests entering a semicolon. RAD does not do as good a job identifying this error. While technically it is true
that placing a semicolon after sample would make a valid statement, this is not the real source of the problem. Rather,
this shows that RAD often identifies/highlights the token before or after the real problem and error messages will
often suggest incorrect solutions .
Be careful. Because of the widespread use of word processing software, most people assume that whatever text
is “red squiggled” is the problem. For instance, a novice programmer might think that the text sample is the problem
and try changing it or delete it entirely (since it appears to be the problem).
Avoid compounding a mistake by thoroughly reading the error message and looking for the problem in the
statement(s) or token(s) preceding or following the “red squiggled” text.
26.
Replace the deleted equal sign on line 9 and run the application to verify it is correct.
27.
On line 9, change the “s” in sample to a capital “S.” This changes the variable name to
“Sample.”
Notice that line 10 is flagged as an error. There are two lessons to be learned. First, Java is case sensitive. Line
10 refers to sample but there is no variable sample, however, there is a variable Sample. For beginner programmers,
incorrect capitalization is a source of countless errors. Second, sometimes RAD's first solution is correct. Click on the
light bulb icon to display solutions. Notice that RAD suggests changing the variable name to Sample. This is a viable
solution to remove the error indicators.
28.
Copy the println statement from line 10 and paste it on line 12.
RAD flags the statements on both lines 10 and 12 as errors. If you display the solutions, RAD will once again
suggest changing the variables from sample to Sample. In this case, this is not the best solution. Instead, you should
change the variable definition on line 9 not the two statements on lines 10 and 12.
29.
On line 9, change Sample to sample.
Notice that RAD removes both errors icons. This is an example of a cascading error. A cascading error is a single
error that results in many error messages being generated. This is why you shouldn't panic if many lines of source
code are flagged as incorrect. Often solving one error will clean up many error messages. This is also why you should
solve errors within the source code from top to bottom .
30.
Delete the println statement from line 12 and save the source code for EmployeeApp. The
code should look like Figure 1-19 .
Results of the Tutorial
Here's what we now have:
1.
A new project called MyFirstProject.
2.
In MyFirstProject/src, a new package called myFirstPackage.
3.
In myFirstPackage, one file called EmployeeApp.java.
4.
The source code in EmployeeApp should look like Figure 1-19 .
 
Search WWH ::




Custom Search