This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes what should i know about Strings in the 1.4 exam Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "what should i know about Strings in the 1.4 exam" Watch "what should i know about Strings in the 1.4 exam" New topic
Author

what should i know about Strings in the 1.4 exam

Vicken Karaoghlanian
Ranch Hand

Joined: Jul 21, 2003
Posts: 522
what should we know about Strings for the 1.4 exam? in SUN 1.4 exam objectives, it say: Describe the significance of the immutability os String objects.
i've already done that, is there anything else i should be aware of, such as, StringBuffer class, Constructors and Methods for the String Class, Constructors and Methods for the StringBuffer Class ...etc


- Do not try and bend the spoon. That's impossible. Instead, only try to realize the truth. <br />- What truth? <br />- That there is no spoon!!!
Toby Davis
Ranch Hand

Joined: Apr 09, 2002
Posts: 65
Know these methods for String:
charAt, concat, equalsIgnoreCase, length, replace, substring, trim, toString, toLowerCase, toUpperCase (also "equals" should be in the list - in fact, it's an Object method so it should be obvious - so understand how equals can be overriden and implemented, and its contract... it may show up on the exam for Strings)
StringBuffer: append, insert, reverse, toString
(Let me know if I missed one above, anyone...)
Be aware of incorrect String method being applied to a StringBuffer, or vice-versa. Understand the substring's arguments, where first element is index-based (0-based) but the second element is position-based (1+). If you understand String's immutability, then you'll have no problems understanding how String objects cannot be changed, while StringBuffer objs can - and how to catch that in code questions on the exam.
If you have the K&B book (and if you don't, I highly recommend it), Chapter 6 was excellent on this objective...
[ August 09, 2003: Message edited by: Toby Davis ]

SCJP2 (1.4)
cyril vidal
Ranch Hand

Joined: Jul 02, 2003
Posts: 247
Hi Vicken,
Maybe may have you a look a this code's snippet:

And guess the output...
Maybe you'll have some surprise...
Cyril.


SCJP 1.4, SCWCD, SCBCD, IBM XML, IBM Websphere 285, IBM Websphere 287
venu gopal
Ranch Hand

Joined: Nov 21, 2000
Posts: 40
Hi Cyril,
It's interesting. The result is
false
true
true
true
As long as the method didn't change the contents of a String it returns the same String without changing it's reference. Here s1 and s2 are pointing to different address and there is no change in the remaining strings.
public class EssaiString{public static void main (String args[]){ String s1 = "ABC";
String s2 = new String(s1);
String s3 = new String(s1);

System.out.println(s1==s2);
/* Referring to different strings */

System.out.println(s2.trim() == s2.toUpperCase());
/* s2.trim() doesn't change the string and s2.toUpperCase() doesn't change the string. It returns true. */

System.out.println(s3.concat("") == s3.replace('D','E'));
/* s3.concat("") doesn't change the string and s3.replace('D','E') doesn't change the string.(there is no D to replace). It returns true. */

String s4 = s1.toString();
/*s1.toString returns same string */

System.out.println(s4==s1);
/* s4 is refering s1 ("ABC"). it returns true. */
}
}
Cheers,
Venu.
cyril vidal
Ranch Hand

Joined: Jul 02, 2003
Posts: 247
Good job Venu!!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: what should i know about Strings in the 1.4 exam
 
Similar Threads
which methods to study...
need help for SCJP 1.4 exam
check the equality of StringBuffers
String and StringBuffer methods
String & StringBuffer