Why use StringBuilder instead of StringBuffer?
The String class is just not sufficient to perform all the String related tasks.That is why the classes like StringBuffer and StringBuilder is added.StringBuffer class is added in Java 5 .It has exactly the same API as StringBuffer except (the twist in the story) ,the methods in StringBuilder class are not Thread safe.We can also say that the methods in StringBuilder class are not synchronized.The recommendation of many experienced programmers and Sun itself is that use StringBuilder instead of StringBuffer because the StringBuilder will run faster than StringBuffer.
Apart from this huge difference between StringBuilder and StringBuffer, everything which is true for StringBuffer holds true for StringBuilder class.
NOTE:-If you want to give SCJP examination then you must clearly know the distinction between the String,StringBuffer and StringBuilder class.The questions may be on how well you know the API of these classes and implementation of these classes.So there may be questions on StringBuilder or StringBuffer which may contain some piece of Thread code.Don't be panic by watching the Thread code.Just Rehearse the use of StringBuilder and StringBuffer in Threads.It is not that tough.
Suggested Reading:-
How JVM handles Strings
Method Chaining in Java Strings
Important String Methods
Simple twisting questions on Strings
StringBuffer class explained
Sponsored Listings
Get your SCJP kit freee
Are you Intelligent!!!!!
Apart from this huge difference between StringBuilder and StringBuffer, everything which is true for StringBuffer holds true for StringBuilder class.
NOTE:-If you want to give SCJP examination then you must clearly know the distinction between the String,StringBuffer and StringBuilder class.The questions may be on how well you know the API of these classes and implementation of these classes.So there may be questions on StringBuilder or StringBuffer which may contain some piece of Thread code.Don't be panic by watching the Thread code.Just Rehearse the use of StringBuilder and StringBuffer in Threads.It is not that tough.
Suggested Reading:-
How JVM handles Strings
Method Chaining in Java Strings
Important String Methods
Simple twisting questions on Strings
StringBuffer class explained
Sponsored Listings
Get your SCJP kit freee
Are you Intelligent!!!!!


















0 comments:
Post a Comment
Post a Comment