Interview Questions and Answers for 'TIAA' - 3 question(s) found - Order By Newest Very frequently asked in different variations. Frequently asked in Deloitte ( 2 feedback ) , HCL Tech ( 3 feedback ), TCS and Coginizant (CTS) Q1. Explain the scenerios to choose between String , StringBuilder and StringBuffer ?
or
What is the difference between String , StringBuilder and StringBuffer ? Core Java
Ans. If the Object value will not change, use String Class because a String object is immutable.
If the Object value can change and will only be modified from a single thread, use StringBuilder because StringBuilder is unsynchronized(means faster).
If the Object value may change, and can be modified by multiple threads, use a StringBuffer because StringBuffer is thread safe(synchronized). Sample Code for String Sample Code for StringBuffer Sample Code for StringBuilder Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  java   string class   string   stringbuilder   stringbuffer   String vs StringBuffer   String vs StringBuilder   String vs StringBuilder vs StringBuffer   StringBuffer vs stringBuilder Asked in 29 Companies basic   frequent Try 3 Question(s) TestRelated Questions Difference between == and .equals() ? Why is String immutable in Java ? Why Char array is preferred over String for storing password? What are different ways to create String Object? Explain. What is a String Pool ? How does making string as immutable helps with securing information ? How does String Pool pose a security threat ? How is string object immutable if we can concat a string to it ? What is StringJoiner ? Which of the following is false about main method ?
a. It should be declared public and static
b. it should have only 1 argument of type String array
c. We can override main method
d. We can overload main method Basic and Very Frequently asked. Ans. Polymorphism means the condition of occurring in several different forms.
Polymorphism in Java is achieved in two manners
1. Static polymorphism is the polymorphic resolution identified at compile time and is achieved through function overloading whereas
2. Dynamic polymorphism is the polymorphic resolution identified at runtime and is achieved through method overriding. Sample Code for overloading Sample Code for overriding Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  polymorphism  object oriented programming (oops)  oops concepts  oops concepts Asked in 108 Companies Basic   frequent Try 2 Question(s) TestRelated Questions What are points to consider in terms of access modifier when we are overriding any method? If everything is an object , Cant we declare every object as
Object obj = new String(); Why do we need polymorphism in Java ? How does java identifies which method to be called in method overriding or runtime polymorphism, when both methods share the same name and signature ? Shouldn't we make a class with all static members is its just expected to be executed as a standalone program with just one thread. Moreover Lets assume that there is no runtime Polymorphism required and there is no need for serialization ? Is this Polymorphism ?
Map<String, List<String>> inventoryManagerCountMap = new HashMap<String, ArrayList<String>>(); When are static and instance methods resolved ? During compile time or Runtime ? Which of the following is not the difference between Singleton and Static class ( Class with static members only ) ? Which of the following do you think is the primary reason you would never use a static class even the application doesn't need multiple requests or threads ?
a. Serialization
b. Runtime Polymorphism
c. Lazy Loading
d. Memory Ans. Generics are a facility of generic programming that were added to the Java programming language in 2004 within J2SE5.0. They allow "a type or method to operate on objects of various types while providing compile-time type safety. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  generics Asked in 7 Companies Related Questions What are concepts introduced with Java 5 ? Is this a valid initialization ? Explain.
Collection<Collection> collection = new LinkedList<LinkedList>(); Which of the following syntax is correct ?import static java.lang.System.*;or static import java.lang.System.*; Is it legal to initialize List like this ? Which of the following syntax are correct ?a. LinkedList<Integer> l=new LinkedList<int>();b. List<Integer> l=new LinkedList<int>();c. LinkedList<Integer> l=new LinkedList<Integer>();d. List<Integer> l = new LinkedList<Integer>(); Which of the following was not introduced with Java 5 ? What are Type Erasures in Java ? In case of generic class declared like following , What can T hold
class MyClass<T>{
T element;
} Can we use generics with arrays in Java ?