Tuesday, June 10, 2014

Java 8 : Frequently Asked Questions for Interview - 1

What was lacking in Java before JAVA 8? Why are Lambda expressions introduced?

Now-a-days there is rising demand and requirement for 
1. Highly COMPLICATED applications
2. Programs that are executed on machines with MULTI-CORE CPU

Java (before Java8) has various cavets that makes it hard to write programs that could satisfy modern computing requirements because :

1. Programs using locks are error-prone and time-consuming
2. There is limits on level-of-abstraction that library writers can use
  • eg. lack of efficient parallel operations over large collections of data
3. There is lack of tools for expressing behavior easily without having to be involved in client code
4. Anonymous inner classes are hard-to-read & too verbose.
  • Callbacks and event handlers makes the process of reading code difficult.

What is Functional Programming?

  • Abstracting over behavior.
  • It is different from Object Oriented Programming in the sense that OOPs is mostly abstraction over data. 
  • Long before OOPs was introduced, there were several functional programming languages such as Lisp and Scheme. However, their benefits were not much appreciated outside academic circles. 
  • Functional programming is important because it is well suited for concurrent and event-driven (or “reactive”) programming

Whats new/Different for a Java programmer in Java 8 ?

  1. Learn to write and read lambda-enabled code
  2. Learn new syntax and a new idioms ( better than writing hugely complex thread-safe code )
  3. Write performance critical code
  4. Write easier-to-read code (code expressing business logic clearly rather than how its achieving it)
  5. Be able to blend both OOPS and functional programming together
  6. Even if you are not interested in concurrency, Java 8 provides a powerful upgrade. For example: Collection libraries can be given powerful APIs if the language has a convenient syntax for function expressions.
  7. ENJOY!
    • Code is easier to maintain, more reliable and less error-prone

No comments:

Post a Comment