Help us update the repository. Were you asked any of these questions in your recent interview ?

More questions

Java - Interview Questions and Answers on Performance

Q1.  What are the Disadvantages of using Collection Classes over Arrays ?

Ans. Collections can only hold objects, It can't hold primitive data types.

Collections have performance overheads as they deal with objects and offer dynamic memory expansion. This dynamic expansion could be a bigger overhead if the collection class needs consecutive memory location like Vectors.

Collections doesn't allow modification while traversal as it may lead to concurrentModificationException.

Q2.  How Java provide high Performance ?

Ans. Java uses Just-In-Time compiler to enable high performance. Just-In-Time compiler is a program that turns Java bytecode into instructions that can be sent directly to the processor.

Q3.  Can you provide some implementation of a Dictionary having large number of words ? 

Ans. Simplest implementation we can have is a List wherein we can place ordered words and hence can perform Binary Search.

Other implementation with better search performance is to use HashMap with key as first character of the word and value as a LinkedList.

Further level up, we can have linked Hashmaps like ,

hashmap {
a ( key ) -> hashmap (key-aa , value (hashmap(key-aaa,value)
b ( key ) -> hashmap (key-ba , value (hashmap(key-baa,value)
z( key ) -> hashmap (key-za , value (hashmap(key-zaa,value)

upto n levels ( where n is the average size of the word in dictionary.

Q4.  What are advantages of using Servlets over CGI ?

Ans. Better Performance as Servlets doesn't require a separate process for a single request.

Servlets are platform independent as they are written in Java.

Q5.  What are the advantages of Hibernate ?

Ans. 1. No need to know SQL, RDBMS, and DB Schema.
2. Underlying Database can be changed without much effort by changing SQL dialect and DB connection.
3.Improved Performance by means of Caching.

Q6.  Can we declare Entity class as final in hibernate ?

Ans. Yes but as Hibernate creates the Proxy Classes inherited from the Entity Classes to communicate with Database for lazy initialization. Declaring entity classes as final will prohibit communication with database lazily and hence will be a performance hit.

Q7.  What things you would care about to improve the performance of Application if its identified that its DB communication that needs to be improved ?

Ans. 1. Query Optimization ( Query Rewriting , Prepared Statements )
2. Restructuring Indexes.
3. DB Caching Tuning ( if using ORM )
4. Identifying the problems ( if any ) with the ORM Strategy ( If using ORM )

Q8.  Which of the following nearly involves same Test execution plan ?

 a. Unit and Integration tests
 b. Unit and Regression Tests
 c. Integration and Performance Tests
 d. Performance and Load Tests

Ans. Performance and Load Tests

Subscribe to Java News and Posts. Get latest updates and posts on Java from
Enter your email address:
Delivered by FeedBurner
comments powered by Disqus