Java Reference
In-Depth Information
c. s1.insert( 2 , "is fun" );
d . s1.insert( 1 , s2);
e . s1.charAt( 2 );
f . s1.length();
g . s1.deleteCharAt( 3 );
h . s1.delete( 1 , 3 );
i . s1.reverse();
j. s1.replace( 1 , 3 , "Computer" );
k. s1.substring( 1 , 3 );
l. s1.substring( 2 );
10.32
Show the output of the following program:
public class Test {
public static void main(String[] args) {
String s = "Java" ;
StringBuilder builder = new StringBuilder(s);
change(s, builder);
System.out.println(s);
System.out.println(builder);
}
private static void change(String s, StringBuilder builder) {
s = s + " and HTML" ;
builder.append( " and HTML" );
}
}
K EY T ERMS
abstract data type (ADT)
366
composition 374
has-a relationship
aggregation
374
374
boxing 383
class abstraction 366
class encapsulation
multiplicity
373
stack 378
unboxing
366
383
class's contract
366
C HAPTER S UMMARY
1.
The procedural paradigm focuses on designing methods. The object-oriented paradigm
couples data and methods together into objects. Software design using the object-
oriented paradigm focuses on objects and operations on objects. The object-oriented
approach combines the power of the procedural paradigm with an added dimension that
integrates data with operations into objects.
2.
Many Java methods require the use of objects as arguments. Java offers a convenient
way to incorporate, or wrap, a primitive data type into an object (e.g., wrapping int into
the Integer class, and wrapping double into the Double class).
 
 
Search WWH ::




Custom Search