Java Reference
In-Depth Information
Method
Description
COBOL Equivalent
String toUpperCase ()
Return a new String with all the
MOVE STRING1 TO
characters in String converted to
NEW-STRING INSPECT
uppercase.
CONVERTING NEW-STRING
String trim ()
Return a new String with the
STRING STRING1 INTO
characters in String, except leading
STRING2 DELIMITED BY
and trailing spaces.
SPACES
String valueOf
Return a String representation of arg.
MOVE NUMBER TO
(datatype arg)
NUMBER-AS-Z9 3
1. COBOL automatically adds spaces to the end of strings of unequal length. Java String s have an implied length
(including all spaces) and are not equal unless their sizes are also equal.
2. Multilanguage case conversion is not possible with this approach. Library packages are recommended.
3. There is no COBOL analogy for a string representation of true or false, but numeric types can be converted into
characters.
N UMERIC W RAPPER C LASSES
In the same way that numeric items can be converted into String s, String s some-
times need to be turned into numbers. However, since primitive data types are not
objects, they do not have methods and members. Where can the Java language de-
signers place the necessary methods?
To provide a mechanism to represent primitive types as objects, Java defines
special classes that wrap the basic numeric data types into objects. These classes are
very useful when objects (rather than intrinsic data types) are required. These classes
have familiar names ( Integer , Long , Float , Double , Byte ), and all are inherited from
the parent Number class. All sorts of useful methods are contained in these classes.
One example is the parseInt() method, which the developer can use to convert
a String into a numeric item. This method accepts a String input parameter and
returns a numeric item of type int .
This method implements the Java construct called exception processing. This means
that a program can call the method, but some exception may occur before the method
completes. The calling program can use the try and catch code blocks to properly
handle possible exceptions. Exceptions are discussed in more detail in Chapter 9.
 
Search WWH ::




Custom Search