Level 90 Level 92
116 words 0 ignored
Ready to learn Ready to review
Check the boxes below to ignore/unignore words, then click save at the bottom. Ignored words will never appear in any learning session.
What are overloaded methods?
methods within the same class that have the same name but different numbers or types of parameters
How many overloaded versions can a method have?
based on the types of the parameters passed to it
How does the compiler know which one of the overloaded methods to call?
true, only the types of the parameters matter
T/F: Names of the formal parameters in the method definition do not distinguish overloaded methods.
may get confusing and cause bugs
Problems with having too many overloaded versions of a method?
they are overloaded by definition
All constructors in a class have the same name, so...
non-static and static
What are the two kinds of fields a Java class may define?
Variables declared outside of any method definitions and are not modified by the "static" keyword
What is another name for static fields?
class variables (shared by all objects of the class)
Why are static fields called "static"?
their memory is not dynamically allocated: is reserved before any objects of the class are created
Reasons for static fields (3)
to define "universal" public constant (ex. Color.BLUE), to have all objects of the class share same constants or settings (ex. craps table), to collect stats or accumulate totals for all objects of the class …
What are static methods?
do not access/ manipulate any instance variables: only work with static fields or do not access any fields at all (attributed to the whole class)
methods that cant use the "this" keyword :
Reasons for defining static methods (2)
may provide "public service" that has nothing to do with any particular object (ex. find GCF), may work with static fields of the class (ex. accessor or modifier for a static field)
such a call implies this-dot
Why is a static method is not allowed to access/ modify instance fields or call instance methods without an object-dot prefix?
main is always static
Why can't main call a non-static method without a reference to a particular object?
Where are instance variables initialized?
instance (non-static) methods
Where are instance variables used?
Why doesn't it make sense to have a constructor set static fields?
normally you don't want to affect all class objects while constructing just one of them
they would all be identical
Why does Math never create objects?
Indicates that a variable or method belongs to a class, rather than to any object created from the class.
java.lang (built into Java)
String class belongs to what package?
+ and += (for concatenation)
What are 2 operators in the String class?
objects of the String class; text in double quotes
false (they are "just there")
T/F: Literal strings have to be constructed.
\n stands for:
What is the term for: once created, a string can not be changed (even by its methods)
Why are immutable objects convenient?
several references can point to the same object safely (no danger of changing one without the others being aware)
have no characters; length zero
int length ()
returns the k-th character (positions numbered from zero)
String s2 = s.substring(i,k);
returns the substring of chars in positions from i to k-1
String s2 = s.substring(i)
returns the substring from the i-th char to the end
concatenates s1 and s2
String result = s1 + s2
result += s3
concatenates s3 to result
result += num
converts num to string and concatenates it to result
A value that is a number.
11 (starts searching at position 9)
String date = "July 5, 2012 1:28:19 PM";
-1 (not found)
String date = "July 5, 2012 1:28:19 PM"
if s1 is equal to s2
boolean b = s1.equals(s2) returns true when?
if s1 matches s2, case blind
boolean b = s1.equalsIgnoreCase(s2) returns true when?
returns the "difference": s1-s2
int diff = s1.compareTo(s2)
int diff = s1.compareToIgnoreCase(s2)
returns the "difference": s1-s2, case blind
String s2 = s1.trim()
returns a new string formed from s1 by removing white space at both ends
String s2 = s1.replace (oldCh, newCh)
returns a new string formed from s1 by replacing all occurrences of oldCh with newCh
String s2 = s1.toUpperCase(); or String s2 = s1.toLowerCase();
returns a new string formed from s1 by converting its characters to upper or lower case
s1 = s1.toUpperCase();
How do you convert s1 to uppercase?
converts numbers to string
String s = "" + num
converts integer to string
String s = Integer.toString(i)
converts double to string
String s = Double.toString(d)
returns number from a string
String s1 = "-123"; s2 = "123.45";
Number Format Exception
Which exception is thrown if s does not represent a valid number when trying to get a number from a string?
if(Character.isDigit(ch)).../ .isLetter.../ .isWhiteSpace...
return true if ch belongs to the corresponding category
char ch2 = Character.toUpperCase(ch1);
if ch1 is a letter, returns its upper case, otherwise returns ch1
int d = Character.digit (ch, radix);
returns the int value of the digit ch in the given int radix
char ch = Character.forDigit (d, radix);
returns a char that represents int d in a given int radix
represents a string of characters as a mutable object
empty StringBuffer of the default capacity
empty StringBuffer of a given capacity
converts str into a StringBuffer
Which method converts StringBuffer into a string?
How is the pow method used in Java?
In Java a function is known as _______
How is the random method used in Java?
modifier returnType name(parameters)
What is the structure of a method?
Math.ceil() and Math.floor() do?
Takes a double argument and returns the rounded up/down value respectively to the nearest integer.
Math.max() and Math.min() do?
Takes 2 int, long, float, or double arguments and returns the max/min between the 2
Takes an int, long, float, or double argument and returns the absolute value of it.
int  series;
How is an array variable created? How is it given a size? How about initializing it in one line?
What is the method to get the size of the array?
public static void doIt(int array)
How is an array passed to a method?
public static double doStuff(double series)
How is an array returned from a method?
must have: import java.lang.System
How is the arraycopy method used?
for(double x: arrayName)
What is the enhanced for-loop for arrays?
Variable length argument?
public static void (int...numbers);
What is the sort method from the Arrays class?
What is the binary search method from the Arrays class?
responsible for declaring & defining how some module works
somebody that makes use of an existing module (user)
classes & interfaces
can contain fields (data variables) & methods (member functions)
if you are going to be using many classes from the same package, you can tell the compiler to import all classes from a single package with *
gives all the information you need to be able to syntactically use it correctly.
section that lists data fields that you might want to use (often constants)
section that lists the constructor methods that are available for this class
lists methods that are available for this class
static variable format
static method format
has two variables- e & PI
the format to call upon fields/methods with dot-operators for instance members, once you've declared 1 > objects
a pseudo-random generator with a seed used as the input to an algorithm for a number
A software object's behavior is exposed through a
The types that are part of the Java platform are members of various packages that bundle classes by _______
when used in a loop, this statement causes the current loop iteration to end, but the loop then moves on to the next step
while loop process
the rest of the loop body is skipped, and execution moves on to the test condition
for loop process
the rest of the loop body is skipped, and execution moves on to the iterative statement
for (initialCondition; booleanExpression; iterativeStatement)
format for FOR loop
the loop body is executed first
while loop format
incrementing is done after the value of x is used in the rest of the expression
v = v+e
Returns the character at Index in this string. Index numbers begin at 0.
Compares this string with A_String to see which string comes first in the lexicographic ordering. Returns negative integer if this string is first, zero if the two strings are equal, and a positive integer if A_String is first.
Returns a new string having the same characters as this string concatenated with the characters in A_String. You can use the + operator instead of concat.
Returns true if this string and Other_String are equal. Otherwise, returns false.
Behaves like method equals, but considers uppercase and lowercase versions of a letter to be the same.
Returns the index of the first occurrence of the substring A_String within this string. Returns a -1 if A_String is not found. Index numbers begin with 0.
Returns the index of the last occurrence of the substring A_String within this string. Returns a -1 if A_String is not found. Index numbers begin with 0.
returns how long a string is
returns string in all lowercase letters
returns string in all uppercase letters
replace(OldChar , NewChar)
Returns a new string having the same characters as this string, but with each occurrence of OldChar replaced by NewChar.
Returns a new string having the same characters as the substring that begins at the index Start of this string through the end of the string. Index numbers begin at 0.
substring(Start , End)
Returns a new string having the same characters as the substring that begins at the index Start of this string through, but not including, index End of the string. Index numbers begin at 0.
returns a copy of the string without spaces