CHAPTER 4 SUMMARY
MATHEMATICAL FUNCTIONS, CHARACTERS, AND STRINGS
Java provides the mathematical methods sin, cos, tan, asin, acos, atan, toRadians,
toDegree, exp, log, log10, pow, sqrt, ceil, floor, rint, round, min, max, abs, and
random in the Math class for performing mathematical functions.
The character type char represents a single character.
An escape sequence consists of a backslash (\) followed by a character or a combination of
digits.
The character \ is called the escape character.
The characters ' ', \t, \f, \r, and \n are known as the whitespace characters.
Characters can be compared based on their Unicode using the relational operators.
The Character class contains the methods isDigit, isLetter, isLetterOrDigit, isLowerCase,
and isUpperCase for testing whether a character is a digit, letter, lowercase, or uppercase. It
also contains the toLowerCase and toUpperCase methods for returning a lowercase or
uppercase letter.
A string is a sequence of characters. A string value is enclosed in matching double quotes ("). A
character value is enclosed in matching single quotes (').
Strings are objects in Java. A method that can only be invoked from a specific object is called an
instance method. A non-instance method is called a static method, which can be invoked
without using an object.
You can get the length of a string by invoking its length() method, retrieve a character at the
specified index in the string using the charAt(index) method, and use the indexOf and
lastIndexOf methods to find a character or a substring in a string.
You can use the concat method to concatenate two strings, or the plus (+) operator to
concatenate two or more strings.
You can use the substring method to obtain a substring from the string.
You can use the equals and compareTo methods to compare strings. The equals method
returns true if two strings are equal, and false if they are not equal. The compareTo method
returns 0, a positive integer, or a negative integer, depending on whether one string is equal to,
greater than, or less than the other string.
The printf method can be used to display a formatted output using format specifiers.