5.3 Documentation and Comments
Enduring Understanding
Programmers use code to represent a physical object or nonphysical concept, real or imagined, by defining a class based on the attributes and/or behaviors of the object or concept.
Learning Objective
Describe the functionality and use of program code through comments.
Essential Understanding
Comments are ignored by the compiler and are not executed when the program is run.
Three types of comments in Java include /* /, which generates a block of comments, //, which generates a comment on one line, and /* */, which are Javadoc comments and are used to create API documentation.
A precondition is a condition that must be true just prior to the execution of a section of program code in order for the method to behave as expected. There is no expectation that the method will check to ensure preconditions are satisfied.
A postcondition is a condition that must always be true after the execution of a section of program code. Postconditions describe the outcome of the execution in terms of what is being returned or the state of an object.
Programmers write method code to satisfy the postconditions when preconditions are met.
Last updated
Was this helpful?