Friday, July 7, 2017

Java Programs

Here is a list of basic java programs which are often required to know either for interviews or for any java test or exam.

Fibonacci Sequence


                      In fibonacci sequence, the next number is the sum of the previous two numbers. The first two numbers are 0 and 1. Example : 0, 1, 1, 2, 3, 5, 8, 13 etc...

Number Palindrome


                            Palindrome number is a number that remains the same when its digits are reversed. Example: 67876

Palindrome


                              Palindrome refers to a word that doesn't change when its letters are reversed.Example : racecar

Armstrong Number

                               An n-digit number equal to the sum of the nth powers of its digits. A 3 digit positive integer is called an armstrong number if the sum of cubes of the individual digits is equal to that number. Example: 153: 13 + 53 + 33 = 153

Array Left Rotation

                      Left rotate the array of "m" elements, "n" number of times.
Example:
Input:m = 7 ; n = 4
I/P Array : [5,4,3,6,7,8,9]
O/P Array: [7,8,9,5,4,3,6]

Prime Number

                         Algorithm to find out if the given number is Prime Number or Not.


Thursday, March 16, 2017

Getting Started - Module , Controller and Rendering data

The main parts of a very simple angularJS application are Module, Controller, scope and directives.They are described below along with a simple AngularJS application code.

Module :

The module is a container for the different parts of the application. The main module is declared using ng-app directive in the view (HTML file). This ng-app directive bootstraps the application using this module.

<html ng-app='mySimpleApp'>
var myApp = angular.module('mySimpleApp', []);


Controller:

Controllers are used to manage the flow of the data in the application.This is the ViewModel part of the MVVM architecture. It is declared in the view(HTML file) using ng-controller directive.

<div ng-controller='MySimpleController'></div>

In the js file, it is defined as following.

app.controller('MySimpleController', MySimpleController);

function MySimpleController ($scope) {
  $scope.message = "My Simple AngularJS app";
}

Scope:

Scope is the glue between the View and the ViewModel or the controller. Both the View and the ViewModel have reference to the scope, but not to each other. This enables the ViewModel to be independent of the HTML DOM and the directives.
In the js file, it is defined as following.

function MySimpleController ($scope) {
  $scope.message = "My Simple AngularJS app";
}

In the HTML file, it is used as follows. The scope can be directly referenced by the HTML using the double curly braces {{ }} . It can also be referenced using the ng-model directive.

<div>
        Message is:{{message}}
      </div>
      <div>
      <input type="text" ng-model="message">
</div>

Download code here:

My First Simplest AngularJS application

View the output here:

My First Simplest AngularJS application output




Note: This is the most simplest definition of these components. It gets really complex as your application grows big.


Saturday, March 11, 2017

AngularJS - Introduction and Concepts

AngularJS is a javascript framework. It is a library written in javascript.It is distributed as a javascript file.It can be included in a webpage using a <script></script> tag.

Model-View-ViewModel (MVVM) or MV-Whatever Architecture:


AngularJS follows MVVM design pattern. There are three main components in this pattern.

Model: 

The raw data from the Database or the server.This component makes the call to the server to get the required data.It handles the Business logic.But it does not involve in displaying the data.

View: 

The User Interface i.e., the HTML and CSS. This component does not change the data , neither does it handles any event. It just displays the data.

ViewModel : 

The data that represents the state of the view.It handles the presentation logic.

Declarative Binder : 

Declaratively binds the model of the ViewModel to the view.We need not write any code for it.The AngularJS framework does the work for us.




MV-Whatever : 

AngularJS does not strictly follow MVVM design pattern. It is flexible enough to let the developers choose their pattern depending on the situation. Hence it is also called as MV-Whatever or MV*.

Dependency Injection by AngularJS:


Dependency Injection (DI) is a design pattern that implements Inversion of Control.The dependency is injected into the client by AngularJS.Client is not responsible for instantiating the dependency.
This helps in the loose coupling of the different components. AngularJS provides lot of components such as factory, value, service etc that can be injected into other components using DI.


Friday, March 3, 2017

Development Environment Setup for MAC

Tools Needed:

  • Browser - Google Chrome / Safari
  • Code editor - Atom
  • AngularJS
  • Browser Sync (Needs NodeJS)

Download and install Code editor - Atom


  • Click on the "Download For Mac" button
  • Locate atom-mac.zip in Finder.
  • Double-click on the zip file to expand it.
  • Move the Atom.app to Applications folder.
  • Open Atom application to verify that it is installed properly.


Download and install BrowserSync:

node and npm(node package manager) are required to  download the browserSync tool which is in the node package repository.

  • Click on macOS Installer and download the package.
  • Install the package.
  • Open terminal and type node --version. It should give you the installed version number of Node.js.
  • Type npm --version. It should give you the npm version 
  • To install BrowserSync, type   sudo npm install -g browser-sync in the command line and give the administrator password.
  • To check if it is installed successfully, use the following command in the command line.
    • browser-sync -- version and check if it gives the installed version number.
  • Use the following command in the command line to start BrowserSync
    • browser-sync start --server --directory --files "**/*"

Download and install AngularJS:

  • Click on Develop -> Download
  • Click on the latest AngularJS version (1.*).
  • Save the angular.min.js file to the working directory.