Java Reference
In-Depth Information
To develop a program to solve a problem, you start by analyzing the problem, then
outlining the problem and the options for a solution. You then design the algorithm;
write the program instructions in a high-level language, or code the program; and enter
the program into a computer system.
Analyzing the problem is the first, and most important, step in the process. This step
requires that you do the following:
￿ Thoroughly understand the problem.
￿ Understand the problem requirements. Requirements can include whether the
program requires interaction with the user, whether it manipulates data,
whether it produces output, and what the output looks like. If the program
manipulates data, the programmer must know what the data are and how they
arerepresented.Todothis,youneedtolookatsampledata.
￿ If the program produces output, you should know how the results should
be generated and formatted.
￿ If the problem is complex, divide the problem into subproblems and
repeat Steps 1 and 2 by analyzing each subproblem and understanding
each subproblem's requirements. You also need to know how the sub-
problems relate to each other.
After you carefully analyze the problem, the next step is to design an algorithm to solve it. If
you broke the problem into subproblems, you need to design an algorithm for each subpro-
blem. Once you design an algorithm, you must check it for correctness. You can sometimes do
this using sample data; other times, you might need to perform some mathematical analysis to
test the algorithm's correctness. You also need to integrate the subproblem solutions.
Once you have designed the algorithm and verified its correctness, the next step is to
convert the algorithm into a high-level language. You use a text editor to enter the
program into a computer, making sure that the program follows the language's syntax. To
verify the correctness of the syntax, you run the code through a compiler. If the compiler
generates error messages, you must identify the errors in the code, resolve them, and then
run the code through the compiler again. When all syntax errors are removed, the
compiler generates the machine code (bytecode in Java).
The final step is to execute the program. The compiler guarantees only that the program
follows the language's syntax; it does not guarantee that the program will run correctly.
During execution, the program might terminate abnormally due to logical errors, such as
division by zero. Even if the program terminates normally, it may still generate erroneous
results. Under these circumstances, you may have to reexamine the code, the algorithm,
or even your analysis of the problem.
Your overall programming experience will benefit if you spend enough time to thor-
oughly complete the problem analysis before attempting to write the programming
instructions. Usually, you do this work on paper using a pen or pencil. Taking this
careful approach to programming has a number of advantages. It is much easier to
discover errors in a program that is well analyzed and well designed. Furthermore, a
1
 
Search WWH ::




Custom Search