Saturday, October 10, 2015

Akka framework new ERA


An example of the way the actor system works in the Akka framework.



































Taking a complex problem and recursively splitting it into smaller sub-problems is a sound problem solving technique in general. This approach can be particularly beneficial in computer science (consistent with theSingle Responsibility Principle), as it tends to yield clean, modularized code, with little or no redundancy, that is relatively easy to maintain.
In an actor-based design, use of this technique facilitates the logical organization of actors into a hierarchical structure known as an Actor System. The actor system provides the infrastructure through which actors interact with one another.
In Akka, the only way to communicate with an actor is through an ActorRef. An ActorRef represents a reference to an actor that precludes other objects from directly accessing or manipulating that actor’s internals and state. Messages may be sent to an actor via an ActorRef using one of the following syntax protocols:
  • ! (“tell”) – sends the message and returns immediately
  • ? (“ask”) – sends the message and returns a Future representing a possible reply
Each actor has a mailbox to which its incoming messages are delivered. There are multiple mailbox implementations from which to choose, with the default implementation being FIFO.
An actor contains many instance variables to maintain state while processing multiple messages. Akka ensures that each instance of an actor runs in its own lightweight thread and that messages are processed one at a time. In this way, each actor’s state can be reliably maintained without the developer needing to explicitly worry about synchronization or race conditions.
Each actor is provided with the following useful information for performing its tasks via the Akka Actor API:
  • sender: an ActorRef to the sender of the message currently being processed
  • context: information and methods relating to the context within which the actor is running (includes, for example, an actorOf method for instantiating a new actor)
  • supervisionStrategy: defines the strategy to be used for recovering from errors
  • self: the ActorRef for the actor itself
Akka ensures that each instance of an actor runs in its own lightweight thread and that messages are processed one at a time. In this way, each actor's state can be reliably maintained without the developer needing to explicitly worry about synchronization or race conditions.













Thursday, October 8, 2015

Core java tricky questions!

  • How to find largest and smallest number in array? (solution)
  • How to find prime factors of an integer in Java? (solution)
  • How to check if LinkedList contains any cycle in Java? (solution)
  • Write a Program remove duplicates from array without using Collection API? (program)
  • How to reverse String in Java without using API methods? (Solution)
  • Write a method to check if two String are Anagram of each other? (method)
  • Write a function to find middle element of linked list in one pass? (solution)
  • How to solve Producer Consumer Problem in Java. (solution)
  • Write a program to find first non repeated characters from String in Java? (program)
  • How to check if a number is binary in Java? (answer)
  • Write a Program to Check if a number is Power of Two or not? (program)
  • Write a program to check if a number is Prime or not? (solution)
  • Write a method to count occurrences of  a character in String? (Solution)
  • How to find Fibonacci sequence upto a given Number? (solution)
  • How to check if a number is Armstrong number or not? (solution)
  • Write a method to remove duplicates from ArrayList in Java? (Solution)
  • Write a program to check if a number is Palindrome or not? (program)
  • Write a program to check if Array contains duplicate number or not? (Solution)
  • How to calculate Sum of Digits of a number in Java? (Solution)
  • How to prevent Deadlock in Java? (solution)
  • How to find largest prime factor of a number in Java? (solution)
  • How to calculate factorial using recursion in Java? (algorithm)
  • How to declare and initialize two dimensional array in Java? (solution)
  • Write a program to find missing number in a sorted array? (algorithm)
  • How to search element in array in Java? (solution)
  • 10 Points about Array in Java? (must know facts)
  • How to find top two maximum on integer array in Java? (solution)
  • How to sort array using bubble sort algorithm? (algorithm)