Play framework Interview Questions

How can we use any class as Map key?

If we can use any class as Map key, follow these points:

  • The class always follows the basic rule optimized with hashCode() and equals() for all instances.
  • If class filed is not used in equals () method, you should not utilize in hashCode() method.
  • When the class overrides equals () method, it always overrides hashCode() method.

Example;

Suppose I have a class MyFirstKey then I am using a HashMap key.

//MyFirstKey name argument passed is used for equals() and hashCode()
MyFirstKey key = new MyFirstKey('Meraj Ansari'); //assume hashCode=1234
myHashMap.put(key, 'Value');
 // Below code will change the key hashCode() and equals()
// but its location is not changed.
key.setName('Deepak Gupta'); //assume new hashCode=98390
 myHashMap.get(new MyFirstKey('Meraj Ansari'));

What are the similarities between ArrayList and Vector?

There are some ArrayList and Vector are similar classes in various ways such as:

  • Maintains the order of insertion and we can provide the elements in the order of insertion.
  • Iterator defines of ArrayList and Vector altogether is fail-fast by design.
  • The ArrayList and Vector both provide null values and random access to element utilizing index number.
  • Both techniques are indexed and based and backed up by an array initially.

What do you understand by EnumSet?

The java.util.EnumSet is Set define to use with enum types. All elements are an Enum set must come from only one Enum type that is defined, implicitly and explicitly if the set is created. An Enum set is not synchronized and null elements are not provided. This method also provides some useful methods such as copyOf that means (Collection c) and of(E first, E…rest) or complementOf(EnumSet s).

What do mean by concurrent Collection Classes?

The Java 1.5 Concurrent package (java.util.concurrent) obtains thread safe collection classes that provide groups to be changed while iterating.  Designing by the iterator is fail-fast and throws ConcurrentModificationException. The few classes are:

  • CopyOnWriteArrayList
  • ConcurrentHashMap
  • CopyOnWriteArraySet

How can we replace Hashtable with ConcurrentHashMap?

Replace the Hashtable with ConcurrentHashMap and that is what implementation in the Java documentation of ConcurrentHashMap. But you want to be careful with code which relies on locking behavior of Hashtable. If Hashtable locks entire Map instead of part of Map, all operation such as if(Hashtable.get(key) == null) then put (key, value) works in Hashtable but it is not concurrentHashMap.

What is Enable Database?

Play Framework allows in-built support for H2 database. For enable database, it opens the application.conf file and a document follows these two rules.

db.default.driver=org.h2.Meraj
db.default.url="jdbc:h2:mem:play"

How many directory for create a new directory in Play Framework?

Here are some directories, creating for the new directory.

App: The directory obtains the application specific code such as models, views and controllers. The model directory will obtain the application domain model. The views directory provides server side templates. And the controller’s package allows the Java code that responds for url routes.

Conf: The conf directory allows application configuration and define the file routes.

Project: The project directory provides the include scripts. The build system is based on sbt.

Public: The public directory contains our public resources such as, JavaScript, CSS, and image directory and so on.

Test: The test directory provides application check.