Informatica Interview Question for Software Engineer / Developers


Country: India
Interview Type: Phone Interview




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

You can't declare that kind of constant in Java. There's no way to do it based on declarations alone.

In Java, when you use the "final" keyword, you only receive the rather weak guarantee that the variable marked as final will reference the same object throughout the variable's lifespan. It doesn't guarantee that the object being referenced won't have its state changed.

For example, to use the example of StringBuffer:

final StringBuffer finalBuff = new StringBuffer();

StringBuffer buff = new StringBuffer();

buff.append ("Hello "); // perfectly OK, of course
finalBuff.append ("Hello "); //also OK, because we're not reassigning finalBuff to point to a different StringBuffer!

buff = new StringBuffer(); // OK, the old StringBuffer will be garbage collected if appropriate
finalBuff = new StringBuffer(); // compile error, cannot reassign finalBuff to a different object!
finalBuff.clear(); //again perfectly fine, this is the proper way to clear out a final StringBuffer

In other words, a final declaration locks a variable into referencing the same object for all time (well, until the variable goes out of scope and is no longer relevant). It does not, however, prevent the object itself from changing state. On the other hand, a non-final variable may, during its lifespan, reference different objects at different points in time.

The way to make objects completely constant is to design classes with no mutator methods. If there's no way to alter the state of an object, the object is fixed once constructed. String is an example of a class that does this. If you now create a final String variable, you can neither assign another String to the variable nor modify the String already in the variable.

- eugene.yarovoi June 15, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Final keyword guarantees that variable marked will not changed but in case of StringBuffer that is a reference which will never change. As mentioned above you can't assign a new object to it.

- coool.aman June 24, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

final vs immutable.

- Anonymous November 22, 2013 | Flag
Comment hidden because of low score. Click to expand.
2
of 2 vote

You can declare it in private fields without giving the set method

- joker June 17, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Agree with the last responses. Other option (overkilling?) may be to extend the class and override all the mutator fields. It wouldn't work in all cases (e.g, methods that change the state of the object and also return a value) but could be a solution for simple cases.
This requires you to be aware of the implementation of the class.

- Anonymous July 05, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

You can declare a constant in java by adding the fields in the interface. This makes sure you are not using final keyword. :P

- Anonymous July 25, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Interface members are by default static final

- Anil May 20, 2019 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

If the variable is declared inside an interface then the final keyword would not be used beacuse it is by default constant.

- adsfvdfsv August 26, 2014 | 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