Win a copy of TDD for a Shopping Website LiveProject this week in the Testing forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

what should i know about Strings in the 1.4 exam

 
Ranch Hand
Posts: 522
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Ranch Hand
Posts: 247
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Vicken,
Maybe may have you a look a this code's snippet:

And guess the output...
Maybe you'll have some surprise...
Cyril.
 
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 247
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Good job Venu!!
 
Where does a nanny get ground to air missles? Protect this tiny ad:
free, earth-friendly heat - a kickstarter for putting coin in your pocket while saving the earth
https://coderanch.com/t/751654/free-earth-friendly-heat-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic