Beruflich Dokumente
Kultur Dokumente
Lang
Class
The Math Class
Math Class
Provides predefined constants and methods for
performing different mathematical operations.
Math Methods
public static void double abs(double e)
Returns the positive value of the parameter. Can also take in a float, or an integer or a
long integer as a parameter, in which case the return type is either a float or an integer
or a long integer, respectively.
2
The Math Class (cont…)
4
The Math Class (cont…)
6
The Math Class (cont…)
7
The Math Class (cont…)
8
The String Class
String Class
Represents combination of character literals
Using Java, strings can be represented using:
- Array of characters
Note: A String object is different from an array of characters!
String constructor
- 11 constructors
9
The String Class (cont…)
10
The String Class (cont…)
11
The String Class (cont…)
String Methods
public char charAt(int index)
Returns the character located in the specified index.
public int compareTo(String anotherString)
Compares this String with the specified parameter. Returns a negative value if this
String comes lexicographically before other String, 0 if both of the Strings have the
same value and a positive value if this String comes after the other String
lexicographically.
12
The String Class (cont…)
13
The String Class (cont…)
public void getChars(int srcBegin, int srcEnd, char[ ] dst, int dstBegin)
Gets the characters from this String starting at the srcBegin index up to the srcEnd
index and copies these characters to the dst array starting at the dstBegin index.
public int length()
Returns the length of this String.
public String replace(char oldChar, char newChar)
Returns the String wherein all occurences of the oldChar in this String is replaced with
newChar.
14
The String Class (cont…)
15
The String Class (cont…)
16
The String Class (cont…)
17
The String Class (cont…)
18
The String Class (cont…)
19
The Wrapper Classes
Wrapper Classes
Some Facts:
- Primitive data types are not Objects
- Cannot access methods of the Object Class
- Only actual Objects can access methods of the
Object Class
20
The Wrapper Classes (cont…)
Wrapper Classes
Some Facts:
- Why wrapper classes?
- Need an object representation for the primitive type
variables to use Java built-in methods.
Definition:
- Object representations of simple non-object
variables. 21
The Wrapper Classes (cont…)
Primitive Data Type Corresponding Wrapper Classes
boolean Boolean
char Character
byte Byte
short Short
int Integer
long Long
float Float
double Double
22
The Wrapper Classes (cont…)
23
The Wrapper Classes (cont…)
24