Hello, Jayadev,
I'll tell you what I lived and learned; Let's hope it can give you some clues for you with real-world "practical scenarios".
The StringBuffer class is basically what it says it is (a buffer for
string). That means
you should use it when you got a lot of string manipulation, cutting, pasting, appending new words. If you remember the old lost basics (the String stuff that is covered by
scjp), a String cannot be changed, so when you do some code like
you actually create a third string object "my New String Test". Although it might not be such a bad idea in a couple of objects, consider the String manipulation used on a long servlet response, or perhaps on this little for loop:
Up here, I counted 104 String objects that could be easily use no more than 4; Consider the ammout of work to the JVM to create and then destroy all these objects. Consider you may run your app on a heavy-duty machine that doesn't have the time, RAM nor CPU to waste with that.
The loop example over here WORKS. And it works fine. When you speak of StringBuffer, however, It shows a concern of optimization included in your work.
The [Buffered]StreamReader and writers are supposed to help you in different ways, but always doing part of the hard work for you.
Java have got plenty of this I/O stuff, so it is possible that, no matter what you need, there's something in there you can use.
I can give you two main reading materials to that, if that is also what you want:
- The Java Tutorial (downloadable through java.sun.com) // IO Stuff
- The SCJP&D study book by Kathy and Bert(
http://www.amazon.com/exec/obidos/tg/detail/-/0072226846/qid=1072782357/sr=1-1/ref=sr_1_1/103-0067155-1028648?v=glance&s=books) // I think there's still IO in there, and also the StringBuffer.
HTH,
Gus
[ December 30, 2003: Message edited by: Gustavo Torreti ]
[ December 30, 2003: Message edited by: Gustavo Torreti ]