|
Java, Java, Java(c) Object-Orienting Problem Solving Authors: Morelli R., Walde R. Published year: 2005 Pages: 226-229/275 |
Executable StatementsSimple statements, such as assignment statements, should be written one per line and should be aligned with the other statements in the block. Compound statements are those that contain other statements. Examples would include if statements, for statements, while statements, and do-while statements. Compound statements should use braces and appropriate indentation to highlight the statement's structure. Here are some examples of how to code several kinds of compound statements:
if (condition) { // A simple if statement statement1; statement2; } // if if (condition1) { // An if-else statement statement1; } else if (condition2) { statement2; statement3; } else { statement4; statement5; } // if/else for (initializer; entry-condition; updater) { // For loop statement1; statement2; } // for while (condition) { // While statement statement1; statement2; } // while do { // Do-while statement statement1; statement2; } while (condition); |
Preconditions and PostconditionsA good way to design and document loops and methods is to specify their preconditions and postconditions. A precondition is a condition that must be true before the method (or loop) starts. A postcondition is a condition that must be true after the method (or loop) completes. Although the conditions can be represented formallyusing boolean expressionsthis is not necessary. It suffices to give a clear and concise statement of the essential facts before and after the method (or loop). Chapter 6 introduces the use of preconditions and postconditions, and Chapters 6 through 8 provide numerous examples of how to use them. It may be helpful to reread some of those examples and model your documentation after them. |
Sample ProgramsFor specific examples of well-documented programs used in the text, see the online source code that is available on the accompanying Web site at http://www.prenhall.com/morelli |
Appendix B. The Java Development KitThe Java Development Kit (JDK) for Java 2 Platform Standard Edition is a set of command line tools for developing Java programs. It is available for free in versions for recent editions of Microsoft Windows, Linus, Macintosh OS X, and Solaris (Sun Microsystems). Download information and documentation are available for the entire range of products associated with the Java 2 Platform, Standard Edition (J2SE) at: http://java.sun.com/j2se/ This appendix summarizes some of the primary tools available in the JDK. For more detailed information, consult Sun's Web site. Table B.1 provides a summary of some of the JDK tools. Table B.1. Tools included in the Java Development Kit
Sun Microsystems provides detailed instructions on how to install JDK for J2SE on computers running any of the above operating systems, including how to set the system's PATH and CLASSPATH variables . Installation instructions can be located using the above link to downloading information. |
|
Java, Java, Java(c) Object-Orienting Problem Solving Authors: Morelli R., Walde R. Published year: 2005 Pages: 226-229/275 |