Best web design - 248 Methods Chapter 6 programmers need. The Java

248 Methods Chapter 6 programmers need. The Java API methods are provided as part of the Java 2 Software Development Kit (J2SDK). Good Programming Practice 6.1 Familiarize yourself with the rich collection of classes and methods in the Java API and with the rich collections of classes available in various class libraries. Software Engineering Observation 6.1 Avoid reinventing the wheel. When possible, use Java API classes and methods instead of writing new classes and methods. This reduces program development time and avoids intro ducing programming errors. Performance Tip 6.1 Do not try to rewrite existing Java API classes and methods to make them more efficient. You usually will not be able to increase the performance of these classes and methods. The programmer can write methods to define specific tasks that a program may use many times during its execution. These are sometimes referred to as programmer-defined methods. The actual statements defining the methods are written only once and are hidden from other methods. A method is invoked (i.e., made to perform its designated task) by a method call. The method call specifies the name of the method and provides information (as arguments) that the called method requires to perform its task. When the method call completes, the method either returns a result to the calling method (or caller) or simply returns control to the calling method. A common analogy for this program structure is the hierarchical form of management. A boss (the calling method, or caller) asks a worker (the called method) to perform a task and report back (i.e., return) the results after completing the task. The boss method does not know how the worker method performs its designated tasks. The worker may also call other worker methods, and the boss will be unaware of this occurrence. We will soon see how this hiding of implementation details promotes good software engineering. Figure 6.1 shows the bossmethod communicating with several worker methods in a hierarchical manner. Note that worker1 acts as a boss method to worker4 and worker5. Relationships among methods may also be different than the hierarchical structure shown in this figure. main worker1 worker2 worker3 worker4 worker5 Fig. 6.1Hierarchical boss-method/worker-method relationship. Fig. Copyright 1992 2002 by Deitel & Associates, Inc. All Rights Reserved. 7/3/01

Leave a Reply