Saturday, November 27, 2010

Interview with Proxxxxx in Hyderabad

Questions and answers
=====================
1. Spring instance check
2. How to maintain inserted order in Set
3. Xsd include vs Import
4. why should we overide hashCode and equals
5. immutable collection
6. String intern
7. Template design pattern
8. Any other soa
9. Builder
10. Abstract constructor
11. Soap action
12. Soap method
13. Jms
14. Spring jms
15. Spring aop core
16. Dwr
17. Drools
18. Int n=null

==============================================================================
Q2. How to maintain inserted order in Set
LinkedHashSet - maintain inserted set
TreeSet - Sorted set

Q3. Xsd include vs Import
The difference between the include element and the import element is that import element allows references to schema components from schema documents with different target namespaces and the include element adds the schema components from other schema documents that have the same target namespace (or no specified target namespace) to the containing schema. In short, the import element allows you to use schema components from any schema; the include element allows you to add all the components of an included schema to the containing schema.

Q4. why should we overide hashCode and equals
Objects that are equal according to the equals method must return the same hashCode value

If two objects are not equal according to equals, they are not required to return different hashCode values.

Hash code equal but not the strings
public static void main(String[] args) {
String str1 = "2L";
String str2 = "3-";

System.out.println("String equality: " + str1.equals(str2));
System.out.println("HashCode eqauality: " + (str1.hashCode() == str2.hashCode()));
}

Q5. immutable collection
public static Collection unmodifiableCollection(Collection c)

Q6. String intern()
Returns a canonical representation for the string object.

A pool of strings, initially empty, is maintained privately by the class String.

When the intern method is invoked, if the pool already contains a string equal to this String object as determined by the equals(Object) method, then the string from the pool is returned. Otherwise, this String object is added to the pool and a reference to this String object is returned.

Q7. Builder Pattern


The telescoping constructor anti-pattern occurs when the increase of object constructor parameter combination leads to an exponential list of constructors. Instead of using numerous constructors, the builder pattern uses another object, a builder, that receives each initialization parameter step by step and then returns the resulting constructed object at once.

Definition[edit]

The intent of the Builder design pattern is to separate the construction of a complex object from its representation. By doing so the same construction process can create different representations. [2]

Advantages[3][edit]

  • Allows you to vary a product’s internal representation.
  • Encapsulates code for construction and representation.
  • Provides control over steps of construction process.

Disadvantages[3][edit]

  • Requires creating a separate ConcreteBuilder for each different type of Product.
  • Requires the builder classes to be mutable.

References: https://en.wikipedia.org/wiki/Builder_pattern



No comments:

Post a Comment