Symantec Interview Question for Principal Software Engineers


Country: United States




Comment hidden because of low score. Click to expand.
4
of 4 vote

From the book: Effictive Java(Page 20)
Avoid creating unnecessary objects -
It is often appropriate to reuse a single object instead of creating a new function-ally equivalent object each time it is needed. Reuse can be both faster and more stylish. An object can always be reused if it is immutable.

As an extreme example of what not to do, consider this statement:

String s = new String("stringette"); // DON'T DO THIS!

The statement creates a new String instance each time it is executed and none of those object creations is necessary. The argument to the String constructor("stringette") is itself a String instance, functionally identical to all of the objects created by the constructor. If this usage occurs in a loop or in a frequently invoked, millions of String instances can be created needlessly.

The improved version is simply the following:

String s = "stringette";

This version uses a single String instance, rather than creating a new one each time it is executed. Furthermore, it is guaranteed that the object will be reused by any other code running in the same virtual machine that happens to contain the same string literal.

- trish August 17, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
-2
of 2 votes

Correct, but if you prefer creating String using 'new' operator you can always
interning them like: new String().intern();

- thelineofcode September 20, 2013 | Flag
Comment hidden because of low score. Click to expand.
1
of 1 vote

yes, it will.

- Alistair August 17, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
1
of 1 vote

no error, but second one is more costly...

- prashantdubey194 August 24, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
1
of 1 vote

Both are equals but Forst statement creates one object in memory and another creates 2 object one in pool area and another in non pool area.

- Alok Pandey August 27, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

I am just the messenger, just wanted to list the questions they asked.

- trish August 17, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Any reason it shouldn't?

- Varun August 17, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 4 vote

lol.
Just type it in Java and See. it will compile.

- Anonymous August 17, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Stupid question.

- bigphatkdawg September 19, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Yes its absolutely correct. :)

- kedarsdixit December 02, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Both are correct, Ideally we should use 1st one.

- kedarsdixit December 10, 2013 | Flag Reply


Add a Comment
Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

Books

is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

Learn More

Videos

CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.

Learn More

Resume Review

Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.

Learn More

Mock Interviews

Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.

Learn More