ch06_1 - Best way to develop and maintain a large program...

Info iconThis preview shows pages 1–11. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Best way to develop and maintain a large program is to construct it from small, simple pieces, or modules . divide and conquer . Topics in this chapter static methods Declare a method with more than one parameter Method-call stack Simulation techniques with random-number generation. How to declare values that cannot change (i.e., constants) in your programs. Method overloading. Java programs combine new methods and classes that you write with predefined methods and classes available in the Java Application Programming Interface and in other class libraries. Related classes are typically grouped into packages so that they can be imported into programs and reused. You’ll learn how to group your own classes into packages in Chapter 8. Methods help you modularize a program by separating its tasks into self-contained units. Divide-and-conquer approach Constructing programs from small, simple pieces Software reusability Use existing methods as building blocks to create new programs. Every method should be limited to performing a single, well-defined task The name of a method should characterize it’s task A method that performs one task is easier to test and debug than one that performs many tasks Dividing a program into meaningful methods makes the program easier to debug and maintain. Hierarchical form of management (Fig. 6.1). A boss (the caller) asks a worker (the called method) to perform a task and report back (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, unbeknown to the boss. “Hiding” of implementation details promotes good software engineering. Sometimes a method performs a task that does not depend on the contents of any object. Applies to the class in which it’s declared as a whole Known as a static method or a class method It’s common for classes to contain convenient static methods to perform common tasks. To declare a method as static , place the keyword static before the return type in the method’s declaration. Calling a static method e ClassName . methodName ( arguments ) Class Math provides a collection of static methods that enable you to perform common mathematical calculations. Method arguments may be constants, variables or expressions. Math fields for common mathematical constants Math.PI (3.141592653589793) Math.E (2.718281828459045) Declared in class Math with the modifiers public , final and static public allows you to use these fields in your own classes. allows you to use these fields in your own classes....
View Full Document

This note was uploaded on 11/06/2010 for the course CS 2050 taught by Professor Uhlmann during the Fall '09 term at Missouri (Mizzou).

Page1 / 42

ch06_1 - Best way to develop and maintain a large program...

This preview shows document pages 1 - 11. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online