CIS 3020 Part 4
Jump to navigation
Jump to search
Variables
Variable: An identifier that can be given a value
- Associated with primitive types
Reference Variable: A variable whose value is a reference
- Associated with instances of a class
- Most programmers refer to both as variables
- There is a fundamental difference in how they are used internally
String Methods
Method | Return Value | Arguments | Definition |
---|---|---|---|
toUpperCase | Reference to String Object | None | Shifts all alpha-characters to uppercase |
toLowerCase | Reference to String Object | None | Shifts all alpha-characters to lowercase |
length | int | None | Returns number of characters in string |
trim | Reference to String Object | None | Removes white space from end of string object |
concat | Reference to String Object | Reference to String Object | Concatenates string object in argument to original string object |
substring | Reference to String Object | int | Returns substring of original string from position given to end |
substring | Reference to String Object | int,int | Returns substring of original string from position given to second position given |
Bound Variables
Given two methods:
public int test (int x) { body1 } |
public int square (int x) { body2 } |
are the two x's the same?
No! These are formal parameters of their respective methods. The method definitions bind them.