Java Reference
In-Depth Information
// Create an instance of ErrorMsg.
ErrorMsg myErrorMsg = new ErrorMsg ();
// Create an instance of a String variable and put some text in it.
String inputMsg = "Some input Text";
// Call the function setErrorMsg.
myErrorMsg.setErrorMsg (inputMsg);
// Evaluate the size of this instance of ErrorMsg using the constant
// NO_TEXT_FOUND.
if (myErrorMsg.msgSize == myErrorMsg.NO_TEXT_FOUND) {
...
// Some logic
...
}
// Evaluate the number of times ErrorMsg has been called.
if (myErrorMsg.total_counter == 100) {
...
// Some logic
...
}
// A static class variable can also be identified using only the class
// name.
// Static variables are not associated with any instance of a class.
if (ErrorMsg.total_counter == 100) {
...
// Some logic
...
}
L OCAL V ARIABLES
Java supports a concept of local variables, an idea without a traditional COBOL
equivalent. A Java program can define a variable when it is needed, rather than right
up front as part of the class definition.
Imagine that COBOL allowed you to insert variable definitions (e.g., 01 MY-
ITEM PIC X) right in the middle of the PROCEDURE DIVISION. Furthermore,
suppose that variables defined this way were only associated with the paragraph in
which they were defined. When the paragraph completed, the variable would go
away. Finally, suppose that another MY-ITEM variable could be defined in the
same program but in a different paragraph. This instance of MY-ITEM would re-
ally be a separate variable, having nothing to do with the original MY-ITEM. You
might wonder what kind of confused code that could lead to!
Search WWH ::




Custom Search