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)

Tuesday, July 14, 2015

Languages - Static and dynamic type differance

Static Typing: The languages such as Java and Scala are static typed.
The variables have to be defined and initialized before they are used in a code.
for ex. int x; x = 10;
System.out.println(x);
Dynamic Typing: Perl is an dynamic typed language.
Variables need not be initialized before they are used in code.
y=10; use this variable in the later part of code

Friday, June 26, 2015

Anguler life cycle

An Overview of the AngularJS Life Cycle
The Bootstrap Phase
The Compilation Phase
The Runtime Data Binding Phase
Now that you understand the components involved in an AngularJS application, you need to understand what happens during the life cycle, which has three phases: bootstrap, compilation, and runtime. Understanding the life cycle of an AngularJS application makes it easier to understand how to design and implement your code.
The three phases of the life cycle of an AngularJS application happen each time a web page is loaded in the browser. The following sections describe these phases of an AngularJS application.
The first phase of the AngularJS life cycle is the bootstrap phase, which occurs when the AngularJS JavaScript library is downloaded to the browser. AngularJS initializes its own necessary components and then initializes your module, which the ng-app directive points to. The module is loaded, and any dependencies are injected into your module and made available to code within the module.
The second phase of the AngularJS life cycle is the HTML compilation stage. Initially when a web page is loaded, a static form of the DOM is loaded in the browser. During the compilation phase, the static DOM is replaced with a dynamic DOM that represents the AngularJS view.
This phase involves two parts: traversing the static DOM and collecting all the directives and then linking the directives to the appropriate JavaScript functionality in the AngularJS built-in library or custom directive code. The directives are combined with a scope to produce the dynamic or live view.
The final phase of the AngularJS application is the runtime phase, which exists until the user reloads or navigates away from a web page. At that point, any changes in the scope are reflected in the view, and any changes in the view are directly updated in the scope, making the scope the single source of data for the view.
AngularJS behaves differently from traditional methods of binding data. Traditional methods combine a template with data received from the engine and then manipulate the DOM each time the data changes. AngularJS compiles the DOM only once and then links the compiled template as necessary, making it much more efficient than traditional methods.

Friday, April 10, 2015

Anguler js boot strap event

https://docs.angularjs.org/guide/bootstrap 


 AngularJS bootstrapping. There are two options for bootstrapping:
automatic bootstrap and manual bootstrap. Let’s explore both of
these options:
Automati c Bootst rap
Three main things happen when AngularJS is automatically
bootstrapping. First, AngularJS creates an injector object, which
will be used later on for dependency injection. Then, AngularJS
creates the root scope, which is the root for all the scopes in the
application. Finally, AngularJS compiles the Document Object
Model (DOM) starting from the ng-app directive, compiling
and processing all the directives and bindings that it finds in the

DOM.

<!doctype html>
<html ng-app=”myApp”>
<head>
<script src=”https://ajax.googleapis.com/ajax/libs/
angularjs/1.2.9/angular.min.js”></script>
</head>
<body>
<div>
</div>
</body>

</html>

Manual Bootst rap
Sometimes you want to perform operations before AngularJS
starts. These operations can be configurations, retrieving relevant
data or anything else you might think about. AngularJS enables
you to manual bootstrap the application. You will need to remove
the ng-app directive from the HTML and use the angular.

bootstrap function instead.

Tuesday, March 10, 2015

Java Script util function to get bytes of file size from KB and MB

var convetFileSizeInBytes= function (size) { var totalSize=0; var kilobyte = 1024; var megabyte = kilobyte * 1024; if(size.indexOf("b")>0){ totalSize=size.replace('b',''); } if(size.indexOf("KB")>0){ totalSize=size.replace('KB',''); totalSize= Math.round(totalSize*kilobyte); } if(size.indexOf("MB")>0){ totalSize=size.replace('MB',''); totalSize= Math.round(totalSize*megabyte); } return totalSize; }; call above if ur inputs like this convetFileSizeInBytes("10KB"); you will get byte values and you can use that for validation