Thursday, 17 April 2014

Examples of REST Web Service

Here are some real world examples of REST web services

 1. Twitter API

The Twitter micro-blogging service includes two RESTful APIs.
The Twitter REST API methods allow developers to access core Twitter data like timelines, status data, and user information.
API Documentation

Sample Resource description
GET statuses/retweets/:id    Returns a collection of the 100 most recent retweets of the tweet specified by the id parameter.
GET search/tweets  Returns a collection of relevant Tweets matching a specified query
GET followers/ids Returns a cursored collection of user IDs for every user following the specified user.
GET users/suggestions Access to Twitter's suggested user list.

2. Last FM API

The Last.fm API allows anyone to build their own programs using Last.fm data, whether they're on the web, the desktop or mobile devices.The RESTful API allows for access to the last.fm music data resources - albums, artists, playlists etc.
Last FM REST API
Last FM API Intro

3. LinkedIn API

LinkedIn is the worlds largest business social networking hub.
The REST API provides a simple, consistent representation of people, companies, jobs, and the interactions and relationships between them.
LinkedIn REST API Documentation

Profile API
GET http://api.linkedin.com/v1/people/id=<MemberId>

Group API
GET http://api.linkedin.com/v1/groups/<GroupId>

Wednesday, 16 April 2014

Top Android Interview Questions

Here are some of Top Android Interview Question that you should be aware of.

 What is Activity ? How to define Activity ?

An activity is usually a single screen that the user sees on the device at one time and interacts with it. An
application typically has multiple activities.

public class MyActivity extends Activity implements ... {
 onCreate(Bundle savedInstanceState) {
  //Initialization of application components
 }
  // Other Callbacks as per life cycle
 onPause(){   // Commit any changes if required }
 onResume(){}
 onDestroy(){ //activity is no longer visible}
 onStop(){}
 }
Declaring the activity in the manifest
<manifest ... >
  <application ... >
      <activity android:name=".MyActivity" />
    ....
  </application ... >
</manifest >

What are Services? Provide examples of different system services in adroid.

A service is a component that runs in the background to perform long-running operations
Google Play services for location APIs, besides that there are various services for battery, alarm, sensor, connectivity etc.

What is Intent ? What is difference between explicit and implicit intent ? Give example of how to send Implicit and explicit Intent.

An Intent is a asynchronous messages between one app/activity to signal  to another app's assistance or activity for performing an action.

Implicit intents specify the action which should be performed and optionally data which provides content for the action.If an implicit intent is sent to the Android system, it searches for matching components and user will get a selection dialog and can decide which component should be used for the intent.

Implicit Intent Example:
Opening Web page using Intent
Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.google.com"));
startActivity(i);

Explicit intents explicitly define the component which should be called by the Android system,
by using the Java class as identifier.

Explicit Intent Example:
Intent i = new Intent(this, ActivityExample.class);
i.putExtra("Value", "value for ActivityExample");
startActivityForResult(i, REQUEST_CODE);

Explain android project structure ?

Manifest file :AndroidManifest.xml defines the Android application.
It contains the attributes, activities, versions, permissions, and other parameters of the application.
src : contains Java source code and packages.
bin : output directory
jni : contains native source
gen : contains automatic generated files by ADT. For example R classes.
asset : for raw resource files such as movie, sound, data files.
res : Contains local resources for the application, it contain following sub folders:
    drawable – image folders according to resolutions
    layout – XML files that are compiled into screen layouts
    values – For XML files that are compiled into many kinds of resources.
    menu -  XML files that define application menus

 

How you will write data into SQLLite database in Android ? Provide code sample.

For SQL Lite supported classes are SQLiteOpenHelper SQLiteDatabase.
public class MyDbHelper extends SQLiteOpenHelper {
    static final String DB_NAME = "mydb.db"; //
    static final int DB_VERSION = 1; //
    static final String TABLE = "mytable";
 
  public MyDbHelper(Context context) { //
   ...
  }
 }

// Get writable instance
SQLiteDatabase db = myDbHelper.getWritableDatabase();

// Create map of column names as keys and values
ContentValues values = new ContentValues();
values.put(col_name1,val1);
values.put(col_name2,val2);

// Insert the new row, returning the primary key value of the new row
returnId = db.insert( table_name, null, values);
db.close();

What do you mean by digitally signed android apps ? why it is important ?

  The Android system requires that all installed applications be digitally signed with a certificate whose private key is held by the application's developer.To protect its phone users from installing and running fraudulent software on their devices, each and every application needs to be signed with a valid certificate that ensures where the application comes from.The system will not install an application that is not signed.
You can explore more here.

What is Content Provider? How to query objects while accesing content providers ? explain how you will retrive contacts ?

  Content Provider provides way to share data across Android applications.
  Android platform provides default implementations of content providers for data types like audio, video, images, contact information etc.
  Android uses URI to identify specific object across application.
  URI has following syntax:
  content://<authority>/<dataType>/<id>
  Here authority specifies name or fully qualified class name.
  All content providers implement query() method which has following signature :
    public Cursor query(Uri uri,String[] projection,String selection,String[] selectionArgs,String sortOrder)
   Besides that content provider also implement other life cycle methods like insert, update, delete.
   Example :
   Accessing Contacts
   ContentResolver contentResolver = getContentResolver(); // Get content Resolver
   String cols[]={ContactsContract.Contacts._ID,ContactsContract.Contacts.DISPLAY_NAME};

   Cursor contactsCursor = contentResolver.query(ContactsContract.Contacts.CONTENT_URI, cols,
    null, null, null); // Fire Query method on contant resolver.

if (null == mCursor) {
     // Error Handling
    } else if (mCursor.getCount() < 1) {
  // No Matches
     } else {
       // handle results here
    }

  Applications that want to access the Contacts Provider must declare same in mainfest file:
  <uses-permission android:name="android.permission.READ_CONTACTS">

  When to use AsyncTask ? Provide example of using asyncTask.

   It should be use where you have to perform any background work in UI Thread.
   Note: AsyncTask should ideally be used for operations that take few seconds. Some tasks keep the thread running for long time so in that case it is recommended to use java.util.concurrent package such as Executor, ThreadPoolExecutor and FutureTask. (Reference: Android  documentation Link ) )
 
Sample Code for using AsyncTask
   public class MyActivity extends Activity implements OnClickListener {
        //...

class MyAsyncTask extends AsyncTask<String, Integer, String> {
           protected String doInBackground(String... args) { ..}
  protected void onProgressUpdate(Integer... values) { ..}
           protected void onPostExecute(String result) {  .. }
}

// UI Actions : on button click
public void onClick(View v) {
String inputArg = editText.getText().toString();
new MyAsyncTask().execute(inputArg); // Delegate execution to MyAsyncTask in backround.
 }

   }

Saturday, 22 February 2014

Hadoop Interview Questions


Big Data / Hadoop Interview Questions

What is Big Data ?

Big data is the term for a collection of data sets so large and complex that it becomes difficult to process using on-hand database management tools or traditional data processing applications. The challenges include capture, storage, search, sharing,  transfer, analysis and visualization.

What is HADOOP ?
The Apache Hadoop is a platform that allows for the distributed processing of large data sets across clusters of computers using simple programming models. It is designed to scale up from single servers to thousands of machines, each offering local computation and storage.

What are the different Hadoop Components ?

HDFS - filesystem of hadoop
HBase - database
Apache Oozie – work flow scheduler
Apache Mahout – machine learning and data mining
Apache Hue – Hadoop user interface, Browser for HDFS, HBase, Query Editors for Pig/Hive etc
Apache Zoo Keeper – configuration / build
Flunme & Squoop - to integrate other data source

 

What is HBase ?

HBNase is a column family-store database layered on top of HDFS.

  

What is HDFS ?

HDFS is a filesystem that can store very large data sets by scaling out across a cluster of hosts.

 

What is Hive ?

A data warehouse infrastructure built on top of Hadoop for providing data summarization, query, and analysis.

 

What is Pig?

A platform for analyzing large data sets that consists of a high-level language for expressing data analysis programs.

 

What is Flume ?

To build Hadoop applications, we need to get data from a source into HDFS.
Apache Flume is one way to bring data into HDFS.

 

What is Squoop ?

Apache Sqoop is a tool designed for efficiently transferring bulk data between Apache Hadoop and structured data stores such as relational databases.

 

What is Map Reduce ?

MapReduce is a programming model and an associated implementation for processing and generating large data sets. Users specify a map function that processes a key/value pair to generate a set of intermediate key/value pairs, and a reduce function that merges all intermediate values associated with the same intermediate key.

 

What is NoSQL database ?

Stands for Not Only SQL.Not using traditional relational DBMS.

 

What are different type of NoSQL Database, give examples ?

Key-Value Store - It has a Big Hash Table of keys & values
    Example- Riak, Amazon S3 (Dynamo)
Document-based Store- It stores documents made up of tagged elements. Example- CouchDB, MongoDB
 Column-based Store- Each storage block contains data from only one column
    Example- HBase, Cassandra
Graph-based-A network database that uses edges and nodes to represent and store data. Example- Neo4j


Thursday, 25 July 2013

HTML 5 Interview Questions

What are the differences between HTML and HTML 5 ? What are the new features added in HTML 5 ?

   HTML5 is upgraded version of HTML, which is being worked on by the WHATWG & W3c community.
   HTML has following features over HTML :
   New Semantics Elements
     aside, figure, dialog, mark, time, meter, progress tags.
   New Structure Elements     header, footer, section, article, nav tags.
   Media Support
     audio,video tags.
   Improved Interactivity
    datagrid, command, menu tags.
   Offline or Application Cache support which allows site to store data on client side.
   Data Storage, Client Side data storage.
   Support for Microdata, for adding machine-readable annotations to documents.
   Web Workers, for background threads in JavaScript.

   Drag and Drop API
   Web Sockets for comuunication with service side processes.
   Supports SVG & MathML , allows SVG & MathML elements to be used inside a document
   Canvas API for Gaming/Animation.
   Enhance Form elements : datetime,range,datalist,email,url,date,month,week,time etc.
      

What is the use of canvas Element in HTML 5?

  <canvas> is an HTML element which can be used to draw graphics using scripting.
  Using this you can draw graphics, use images, make tranformation,
  add stlyes & do animation. Canvas API is used for HTML5 based game development.
 
  How to use Canvas Element :

   <html>
    ..
   <script type="application/javascript">
 
     function draw() {
      var canvas = document.getElementById("canvas");
      if (canvas.getContext) {
        var context = canvas.getContext("2d");
       
        //work with shapes
        context.fillStyle = ...       
        context.fillRect(...);
       
        //work with text
        context.fillText(..);

      }
    }
  </script>
  ...
   <canvas id="canvas" width="150" height="150"></canvas>
   ..
  </html> 

What is the use of Web Worker in HTML 5? Explain how to use Web Worker ?

 Web Workers are for running scripts in the background independently of any user interface scripts.
 Sample Code snaps for Web Worker :
 Create a Web Worker Object
  var worker = new Worker('worker.js');

 Receive notifications from the worker,
  worker.onmessage = function (oEvent) {
     //Called back by the worker
  ;
 
  Start Worker
   worker.postMessage(""); // start the worker
   start it by calling the postMessage() method:

Which Browsers support HTML 5?

  No browsers have full HTML5 support, but major browsers continue to add new HTML5 features to their latest versions.

What is difference between Local storage & Session storage?

    SessionStorage object stores data for a specific session, where as localStorage object stores data for even if the browser is closed.

What is  HTML 5 Application Cache?

 Application cache enables offline browsing, you can specify resources that the browser should cache and make available to offline users.
 As most of the resources are available locally, it helps to improve site performance.
 You need to add manifest file declarion
  <html manifest="demo.appcache">
  ...
  </html

  Here demo.appcahce lists resources that the browser should cache for your application.
  Sample Cache File :
    CACHE MANIFEST
         
    # This is a comment

    CACHE:
    /css/mycss.css
    /js/myscreen.js
    /img/myimage.png
    ..
    FALLBACK:
    / /offline.html
    NETWORK:
    *

What is Web Socket ? Where to use Web Sockets ?

Web Socket API enables Web pages to use the WebSocket protocol (defined by the IETF) for two-way communication with a remote host.It provides bidirectional communication between server & client(browser).
Usage: It is used in developing low latency/ Real time client server application & online games. 

Monday, 15 July 2013

Java Technical Lead Interview Questions

Part-1

Q1. Why to use Hibernate or what are benefits of using it?
Ans:
  • Its ORM tools, which improve productivity, it helps developers get rid of writing complex and tedious SQL statement, no more need of JDBC APIs for result set or data handling.
  • Maintainability, it helps reduce the lines of code, makes system more understandable and emphasizes more on business logic.
  • Hibernate provides first and second level caching strategy. It integrates well with the major open source (OSCache, EHCache, JBossCache etc.) caching products.
  • Hibernates provides portability across the relational databases. You can work with different database using database dialect without any major persistence layer code changes.
  • Hibernate is open source.
  • Hibernate provides good Code generation tool & Plug-ins.


Q2. Why to use Spring or what are benefits of using it?
Ans:
  • It supports AOP, which provides easy implementation for Transaction Management, Auditing, and Logging etc.
  • It’s easy to manage dependency between different classes and components using spring’s dependency injection features.
  • It’s easy to Test your code using spring. It provides various classes for Junit support.
  • It provides easy integration of other component like ORM (Hibernate), Web Services etc. It provides different Templates & classes which ease the third party framework integration.
  • Besides that it provides other features like Batch Processing, MVC framework, Security etc.


Q3. What are the different Design Principles?
Ans:  Here are some of design principles:
Open Close Principle
  Software entities like classes, modules and functions should be open for extension but closed for modifications.  When you need to extend their behavior you don't have to change the class but to extend it.

Dependency Inversion Principle
 High-level modules should not depend on low-level modules. Both should depend on abstractions.
 Abstractions should not depend on details. Details should depend on abstractions.

Interface Segregation Principle
 Clients should not be forced to depend upon interfaces that they don't use.

Single Responsibility Principle
 Each class will handle only one responsibility. A class should have only one reason to change.

Liskov's Substitution Principle
   Derived types must be completely substitutable for their base types.

Don’t Repeat Yourself – DRY
 Don’t Repeat Yourself is the principle that any code in your program should only be written once, and never duplicated.

Separation of Concerns
 Separation of Concerns is when you separate your program into modules that each deal with one particular focus, or concern.

Don’t Make Me Think
 Your code should be written in a way that is logical and understandable, if anyone were to read it. If it requires too much thinking, then it should probably be simplified.

KISS
Keeping your code simple and eliminate unnecessary complexity

Q4. What do you mean by High Cohesion and Low Coupling?
Ans:
 High Cohesion - How focused are the responsibilities of the modules you are designing.
Cohesion is a measure of how strongly-related or focused the responsibilities of a single module are. As applied to object-oriented programming, if the methods that serve the given class tend to be similar in many aspects, then the class is said to have high cohesion

Low Coupling - The degree to which modules rely on other modules.

Q5. Messaging vs. Web Service, When to use what?
Ans: Here are some of points that we should consider for choosing between Messaging Vs Web Service:
  • Messaging technologies are TCP based, so it may be blocked by firewall.Web service is designed as a transport over HTTP, so it typically passes firewalls. But it is one directional, here server cannot call client.
  • Client of web service (especially RestFull web service) is very simple, so it can be easily implemented as a thin client.
  • Messaging should be used where message persistence & failover support is required.
  • Messaging is ideal for requests which may take a long time to process. Requests are queued and can be processed offline without blocking the client
  • Generally, Web service used for a blocking task where as messaging used for a non-blocking task.
  • Messaging solutions more suited for High-volume distributed messaging.
  • Messaging Technology require great amount of investment in commercial software product like TIBCO, MQSeries etc which is not required in case of web service.
Q6. REST vs. SOAP , When to use what?
 Difference between REST & SOAP

Q7. JSON vs. XML, When to use what?
JSON Vs XML

Also Check
Scrum Master Interview Questions
Agile Interview Questions
REST Web Service Interview Questions

References