SringSring

Thursday, 25 September 2014

Core JAVA Stuff

1)Why Strings are immutable? What are its benefits?
2) How  does CuncurentHashMap work?
3) How to make Object immutable in java?
    why should you make an Object immutable?
4) Open Close Design Princeple?
5) NoClassDefFoundError vs ClassNotFoundError ?
6) How Hashmap works internally?
    Impartance of hashCode and equals methos?
    What is the key requirement for an object to be used as a key in hash based collection e.g. HashMap or Hashtable or ConcurrentHashMap?
    What happens internally when you invoke get(Key key) method in hash based collections like HashMap and Hashtable?
    Why should an object which is to be used as key in collection classes need to be immutable?
   Have you heard of ConcurrentHashMap, if so what is it?



7) Addvantages of GarbageCollection in java?
8) types of GC's in java?
9) Heap generation for GC in java?
10) When an Object is elible for GC?
11) why 'wait' and notify are defined in the Object class?
12) Explain ThreadLocal in java? When do we need it?
13) What happens if you serialize a class contains member which is not serializable?
14) Can u Override static metgods in java?
15) Explain feature of Java7?
16) Comparator and Comparable in java?
17) Explain Stratagy, Proxy, Template and Singleton patterns?
18) Why do we need Singleton? whet are the benfits?
19) Dobble chack in Singleton pattern?
    public static Singleton getInstanceDC() { if (_instance == null) { synchronized (Singleton.class) { if (_instance == null) { _instance = new Singleton(); } } } return _instance; } }

20) Can we make a constructor final?
     NO
21) if the method throws Nullpointer in Super class and Subclass has Runtime Exception ?
Yes
22) Does Polymorphisam applicable for static methods?
      Polymorphisam  is not working for static methods.

23) Can we catch RuntimeException and CustomRuntime class?
24) Inner class vs Annonimus class ?
25) Sort the array of Integers?
26) Servlets thread safety, Servlets listeners.
27)  why use ORM, which ORM to use, ORM with cache, problems in using ORM like Concurrency and persistence exceptions.
28) JAX-WS, web services, REST, where to use REST?
29) Messaging advanced, guaranteed delivery and integration, and where to use messaging and where to use web services.
30) Which data type you should used to represent currency in Java?
      A)  BigDecimal is the best type for representing currency decimal values.

31) When to use abstract class and interface in Java?
      A)
  • If you have a lot of methods and want default implementation for some of them, then go with abstract class
  • If you want to implement multiple inheritance then you have to use interface. As java does not support multiple inheritance, subclass can not extend more than one class but you can implement multiple interface so you can use interface for that.
  • If your base contract keeps on changing, then you should use abstract class, as if you keep changing your base contract and use interface, then you have to change all the classes which implements that interface.

  • 32)  What kind of reference types are exists in Java? Differences?
   A) Weak Reference :: Its a reference that is not strong enough to force the object to remain in memory . Its the garbage collector's whims to collect that object for garbage collection. You can't force that GC not to collect it .
Soft Reference :: Its more or less same like the weak reference . But you can say that it holds the object a bit more strongly than the weak reference from garbage collection.
If the Garbage collectors collect the weak reference in the first life cycle itself, it will collect the soft reference in the next cycle of Garbage collection.
Strong Reference :: Its just opposite to the above two kind of references . They are less like to get garbage collected (Mostly they are never collected.)

Weak Reference :
A weak reference, simply put, is a reference that isn't strong enough to force an object to remain in memory. Weak references allow you to leverage the garbage collector's ability to determine reachability for you, so you don't have to do it yourself.
Soft Reference :
A soft reference is exactly like a weak reference, except that it is less eager to throw away the object to which it refers. An object which is only weakly reachable (the strongest references to it are WeakReferences) will be discarded at the next garbage collection cycle, but an object which is softly reachable will generally stick around for a while.
Phantom Reference :
A phantom reference is quite different than either SoftReference or WeakReference. Its grip on its object is so tenuous that you can't even retrieve the object -- its get() method always returns null. 

33) Can we Override or customized the Error class in java?
34) Difference between CountDownLatch and CyclicBarrier in Java?
     Both CyclicBarrier and CountDownLatch are used to implement a scenario where one Thread waits for one or more Thread to complete their job before starts processing. The differences are:
1) CyclicBarrier is resulable, CountDownLatch is not.
2) Both CyclicBarrier and CountDownLatch wait for fixed number of threads.
3) CountDownLatch is advanceable but CyclicBarrier is not.
- See more at: http://www.java2novice.com/java_interview_questions/countdownlatch-cyclicbarrier/#sthash.G95c7XjD.dpuf

35) Can Enum types implement interface in Java?
36) Which design pattern have you used recently? (give any example except Singleton and MVC e.g. Decorator, Strategy or Factory pattern)
37) What are the objectives of Java Technology ? 
    [A programming language that is easy to program ,Increase speed of development,Code Portability - Write once deploy any where
    Multi Threading,Improved Security]
38) Explain the architecture of code execution process inside JRE ?
    JVM Architecture?


No comments:

Post a Comment