Developer/Designer Notes

Archive for March, 2007

Java String or StringBuffer (or StringBuilder)

Posted by Kiran Mova on March 27, 2007

String operations make Java slower, because String is immutable. StringBuffer is more efficient. Anyone who has either prepared or taken Java Certification or Interviews would have come across this question. But really, while programming how does one decide between these classes, why are they even provided by the language?

While running the code against JTest, I came across a line which looked like:

void func(String var2) {

String var1 = new String(var2) ;

}

new String(String) ? What is the intent of this line. How is it different from:

String var1 = var2;

Why is Java providing such a constructor if it doesn’t make sense? Apparently it does make sense in one case, during creation of substrings. Check this article at Java Glossary by Roedy Green. He explains, that if one doesn’t use new String(String), there might be a potential memory leak. Also his article on String class itself is very informative. (He has updated with the notes on StringBuilder introduced recently into Java.)

Jon has details in his article –Strings/StringBuffers, the memory usage and shows how it impacts the performance. The article from JavaWorld by Reggie Hutcherson walks through the byte code operations involved when using Strings and StringBuffers.

For brief guidelines on when to use String and StringBuffer, check the DZone Article.

Now if you are still wondering why Strings were made immutable in the first place. Check this article – why is String immutable and final? Strings(and all the wrapper classes like Integer) are special classes, they are treated like primitive data-types. (Unlike the usual usual Java object philosophy where objects are references and passed by values in the function calls.)

The story doesn’t end there, there is a hack to make the string mutable by using the reflection API. But why would anyone do it?

Posted in coding, java | Leave a Comment »

What does a Research Job mean to a BE/BS Graduate?

Posted by Kiran Mova on March 27, 2007

Doing a Research Job. The picture that comes to my mind is of a technical expert who is solving the most complex problems. An expert in the field who is capable of providing advice to programmers/designers.

I spoke to a friend(who is doing Ph D in social networking topics) sometime back. He told me that he is presenting a paper at the weblogs and social media conference. There are other Ph D students from Europe and US as well..

I asked him what does holding a Ph D mean to do a Research Job?

“Engineering Research Job”, he said, “doesn’t involve a lot of reading. It is more about generating ideas, thinking through those ideas and proving them one way or the other. The reading that one has to do it to check on what others in the same field are doing and know about the latest advancements.”

He continued, “Being a Ph D holder, suggests that a person is capable of doing an research job. But having a Ph D is not enough, it is about what research papers have been published and how many have linked to these published papers.”

I got to thinking, can a non Ph D person like me do a research job? Given that I have the aptitude and the discipline to learn and stay focused on the topic of research, can I be an research person? Is it practical?

I am contractor, most of my work items and their priorities are defined by my Lead. Doing what he needs me to do is of course my top priority. Fortunately, the work items assigned to me are in the field of web which also happens to be my area of interest. So I am in a favourable situation here, to gain deeper understanding of the topics.

(Of course, next time I take up a new job, I should consider getting into a place that advances and provides a similar opportunity. If not, try to finish the job as early as possible and find a suitable place some where else.)

What I am good at is the technologies that are used to implement the web applications. So I am going to pick up more on these aspects for my research.

Update 04/08 : Check this advice to programmer by from Jermey Allison

Posted in culture | Leave a Comment »