Java Reference
In-Depth Information
Each attribute of an object is denoted as a field in the class. Each behavior of
an object becomes a method in the class.
Procedural Programming
In the early days of programming, programs were designed using flowcharts
and a sort of top-down design. With this type of design, a large problem is
solved by breaking it down into smaller tasks. For each of the smaller tasks, a
procedure is written. One main procedure was written to start the process and
subsequently flow through to the solution, invoking the desired procedures
along the way.
This type of programming is referred to as procedural programming . There are
many procedural programming languages widely used today, most notably
COBOL and C.
Procedural programming involves writing a procedure that performs a spe-
cific task. Any data that the procedure needs to use is passed in to the procedure
via its parameters . The procedure can view and alter the data passed in and
optionally return a value back to whoever called the procedure.
To demonstrate procedural programming, let's look at an example. Suppose
that you want to write a program to weekly pay the employees of a company
(a realistic problem to solve). Paying employees involves computing their pay
based on hours worked or a portion of an annual salary. In addition, you have
to compute Social Security and Medicare taxes, as well as any federal income
taxes to be withheld.
Each of these computations has to be repeated for each employee in the
company. Because these tasks are repeated, you can write a procedure for each
one. For example, you might write a procedure called computePay() that
inputs an employee's payment data and returns his or her pay. You may also
have procedures called computeMedicareTax(),computeSSTax(), and so forth.
In the example of writing the program to pay the employees of a
company, many procedures will be written, and each of these procedures
needs to have the employee's data passed in to it. For example, if you
want to invoke the computePay() procedure, you will need to pass in the
employee's payment information such as hours worked or hourly pay.
This is a common occurrence in procedural programming, in which data
is passed around between procedures. The procedures modify the data
passed in and/or return data back to whoever called the procedure. As
you will soon see, object-oriented programming uses a different
approach.
Search WWH ::




Custom Search