Tuesday, August 28, 2012

Interview questions

Eureka Server

Eureka is a REST (Representational State Transfer) based service that is primarily used in the AWS cloud for locating services for the purpose of load balancing and failover of middle-tier servers. We call this service, the Eureka Server. Eureka also comes with a Java-based client component,the Eureka Client, which makes interactions with the service much easier. The client also has a built-in load balancer that does basic round-robin load balancing. At Netflix, a much more sophisticated load balancer wraps Eureka to provide weighted load balancing based on several factors like traffic, resource usage, error conditions etc to provide superior resiliency.


What is the difference between http POST,PUT and PATCH methods?

POST -
HTTP.POST can be used when the client is sending data to the server and the server will decide the URI for the newly created resource.

PUT - More or less similar to POST the only difference is its idempotent. So multiple PUT request should not alter the state or result.

PATCH - HTTP.PATCH can be used when the client is sending one or more changes to be applied by the the server. The PATCH method requests that a set of changes described in the request entity be applied to the resource identified by the Request-URI. The set of changes is represented in a format called a patch document.

PATCH is used for partial updation of resource.

How transaction are handled in Spring ?

https://docs.spring.io/spring/docs/2.5.x/reference/transaction.html

Data structure related

Design a data structure for the following operations:
I. Enqueue
II. Dequeue
III. Delete a given number(if it is present in the queue, else do nothing)
IV. isNumberPresent
All these operations should take O(1) time


Solution : Use LinkedHashMap of java.

package edu.example.datastructure;

import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Map.Entry;

public class EfficientQueue  {
   
    private final Map<Integer,Integer> map;
   
    EfficientQueue() {
        map = new LinkedHashMap<Integer, Integer>();
    }
   
    public void enqueue(Integer i) {
        map.put(i, i);
    }
   
    public Integer remove(Integer i) {
        return map.remove(i);
    }
   
    public Integer dequeue() {
        Iterator<Entry<Integer, Integer>> iter = map.entrySet().iterator();
        if (iter.hasNext())
            return map.remove(iter.next().getKey());
        else
            return null;
    }
   
    public boolean isPresent(Integer i) {
        return map.get(i) == null ?false:true;
    }
   
    public boolean hasNext() {
        return !map.isEmpty();
    }

   

   

}

No comments:

Post a Comment