Android Interview Questions – Ultimate Guide (The Manifest)

1. What is AndroidManifest.xml?
The AndroidManifest.xml file provides essential information about your application that the system must have before it can run any of the app’s code. This information includes the screens the app supports, the permissions it needs, etc.

2. What is the root element in the manifest file?
The root element of the manifest file is manifest. This element specifies the package name for your app, the version code, the version name, install location, etc.

3. What is the significance of the application element?
The application element is the declaration of your application. This element has sub-elements that declare the components of your application like activities, receivers, etc. It also specifies the title for your app that will be displayed in the launcher, the icon, the theme, etc.

4. How would you list all the activities in your application?
To list all the activities that the application has, an activity element, per activity, will need to be added to the application element. The android:name attribute would be set to the class name of the activity. For example:

<activity android:name=".ActivityOne" android:label="@string/title1"/>
<activity android:name=".ActivityTwo" android:label="@string/title2"/>

5. How would you list all the services in your application?
For every service that the application has, add a service element as a child of the application element. For example,

<application ..>
<service android:name=".MyService" android:enabled="true" />

6. How would you list all the broadcast receivers in your application?
For every broadcast receiver, add a receiver element to the application element. For example,

<application ...>
<receiver android:name=".MyStartServiceReceiver" />

7. What does the uses-permission element do?
The uses-permission element specifies the permission that the application needs. It is a sub-element of the manifest element. If the application needs permission to access the internet, for example, it will do it as follows:

<manifest ...>
<uses-permission android:name= "android.permission.INTERNET" />

8. How would you create a custom permission?
To create a custom permission, we first need to declare it in our app like so:

<permission android:name="your.namespace.permission.TEST" 
android:protectionLevel="normal" android:label="This is my custom  permission" />

and then, other applications can ask for that permission as follows:

<uses-permission android:name="your.namespace.permission.TEST" />

9. What is the use of permission-group element?
permission-group allows us to define a logical grouping of permissions. Members of the group are presented together in the user interface. For more,

10. How would you specify the screens your app supports?
The supports-screens element specifies all of the screens sizes that the application supports. That is, all of the screen sizes on which the layouts will work properly.

11. What do the receiver and provider tags do?
The receiver element specifies all the broadcast receivers that are a part of the app and the provider element specifies the content providers that are a part of the app.

Android Interview Questions – Ultimate Guide (The Basics)

1. What is the structure of an Android project in Eclipse?
Android Project

Image taken from TutsPlus

The src folder contains all the source code.
The gen folder contains all the auto-generated classes. The R class is in this folder. The contents of the gen folder are regenerated whenever you recompile your project or add resources. These contents should not be committed to source control nor edited manually.
Then there is the library against which you are compiling. In this case, Android 4.1.
Android Dependencies folder contains other jar files that your application depends on like the AppCompat library.
The assets folder contains files like fonts, etc. if you choose to add them.
The bin folder contains the APK file, dex file, etc. of your app once it compiles successfully.
The res folder contains various resources like strings, colors, images, styles, etc. for your Android application.
The libs folder contains third party libraries that you might want to add to your project.
The AndroidManifest.xml specifies the configuration of your app. It contains information like what permissions your app needs, what devices it supports, etc.
The proguard-project.txt file contains configuration information for ProGuard. It specifies what code gets obfuscated and what doesn’t.
The file contains configuration information for Eclipse.

2. What are the contents of res folder?
The res folder contains the various resources for your project like images, menus, layouts, etc. All of these are arranged in their corresponding sub-folders. For example, layouts are stored under layout folder. These folders may also be qualified for supporting various screen sizes or languages. For example, layouts for high pixel density phones will go under layout-hdpi.
Similarly, the drawable folder contains various drawables like images, etc. Akin to the layout folder, the drawable folder may also be qualified.
The menu folder contains files which contain information for creation of menus.
The xml folder contains files which contain information for creating preference screens (settings screen).
A complete list of the folders supported under the res folder can be found at

3. What happens if you store resource files outside the res folder?
Storing the resource files outside the res folder will result in a compiler error.

4. What are density independent pixels?
Specifying the sizes of UI controls, etc. in pixels makes them device dependent. This means that depending upon the pixel density of the device the UI controls (or text or whatever) are rendered on, the physical size may vary. For example, a 100px long UI control will look big on a low density device and small on a high density device. Density independent pixels provide a density-agnostic way of specifying the size of your UI controls (or whatever!). A UI control that is 220dp (dp = density independent pixels) long will look exactly the same across all devices, irrespective of its pixel density. For more, watch the DevBytes video on DPs

5. What are the contents of the assets folder?
The assets folder provides an easy way to store your files that cannot be placed under the res folder. You can place any file you want under this folder and then access it in your application. The files in the assets folder may also be organized into subfolders. To access these files, you need a reference to the AssetManager instance. Using the open() method, you can get an InputStream to the file. The following snippet shows how to load an image from the assets folder. For more,

ImageView img = (ImageView) findViewById(;
AssetManager mgr = getAssets();
InputStream is ="images/img1.jpg");
Bitmap bmp = BitmapFactory.decodeStream(is);

Android Interview Questions – Ultimate Guide (Overview)

1. What is Android?
Android is Google’s mobile OS based on the Linux kernel. Android is designed primarily for touchscreen devices like phones and tablets but provides user interfaces for televisions (Android TV), cars (Android Auto), and wristwatches (Android Wear).

2. What is an APK file?
APK is the abbreviation for Android Package. It is the file format used to distribute applications onto the Android operating system. To make an APK file, the Android program is first compiled, and then all of its parts are packaged. The APK contains all of the program’s code, resources, assets, certificates, and a manifest file. APK files are created by AAPT (Android Asset Packaging Tool).

3. What are the tools that come with the Android SDK?
The Android SDK includes a number of tools that allow you to write app for the Android OS, communicate with your app, etc. These include Android Virtual Device Manager, Android Emulator, Hierarchy Viewer, SDK Manager, lint, mksdcard, DDMS, Android Debug Bridge, etc.

4. What is AAPT?
AAPT is the abbreviation for Android Asset Packaging Tool. It is a part of the Android SDK and allows you to view, create, and update zip-compatible archives like APK, JAR, and ZIP. AAPT is located at $ANDROID_HOME/build-tools/$SDK/ and has a list of useful commands. For example, the list command that lists the contents of the APK file. For more,

$ aapt list myapp.apk 

5. What is DDMS?
DDMS is the abbreviation for Dalvik Debug Monitor Server. It is a debugging tool that comes with the SDK and provides thread and heap information, logcat, screen capture, etc. Android IDEs like Eclipse and Android Studio provide a UI view of the information provided by DDMS.

6. What is Hierarchy Viewer?
Hierarchy Viewer lets you debug and optimize your user interfaces. It provides a visual representation of the layout’s View hierarchy and also provides performance measures like the measure time, layout time, and draw time.

7. What is adb?
adb stands for Android Debug Bridge. It is a command line tool that lets you communicate with your emulator or device. It includes commands that let you list the device connected, move files from your computer to your emulator or device, get files from your emulator or device onto your computer, etc. For more,

adb pull /sdcard/log.txt /home/codelatte/

This will copy the log.txt file from the SD Card into the home folder.

8. What is Dalvik VM?
Dalvik VM is the virtual machine that executes the Android applciations. It executes .dex (Dalvik Executable) codes. Every Android app runs in its own instance of Dalvik VM.

9. What is ART?
Android Runtime (ART) is the virtual machine that replaces Dalvik. It was introduced as a feature in Android 4.4 but became the defacto VM Android 5.0. ART focuses on improving the app performance. To do this, it introduces ahead-of-time (AOT) compilation. Using AOT, the dex codes are precompiled to machine code. This eliminates the time to interpret them when the app is run.

10. Explain Android’s Architecture
Android Architecture
At the bottom of the Android software stack is the modified Linux kernel. The kernel provides features like memory management, power management, process management, etc. On top of this kernel are libraries and APIs written in C. These libraries include WebKit for rendering webpages, SQLite for data storage, OpenGL for graphics rendering, etc. The Android runtime is also at this level. Depending on the Android version, this could be either Dalvik or ART. Then there is the Android application framework which allows developers to write applications. Finally, there are the apps. For more,

Simplyfying Node EventEmitters

Node is centered around events. Whenever something interesting happens, an event is triggered and you have the ability to respond to that event. All this magic is possible because of EventEmitters. In this post I will give you a quick introduction to EventEmitters.

Node comes built-in with a lot of EventEmitters. For example, every readable stream is an EventEmitter. All readable streams have data and end events associated with them. The request object of an HTTP server is a readable stream.

Responding to Events

You can respond to the events by registering callbacks for the events you are interested in. This is done by calling the on() method of the EventEmitter and passing it the string representing the event, and a callback to be called. For example, when the request to the server has completed its arrival, you may want to do something:

	// do something

The on() method calls the callback as many times as the event happens. If you only want to respond only once, replace on() with once():

	// do something

Creating your own EventEmitter

Every EventEmitter signals the happening of an interesting event by calling its emit() method. The emit() method takes in a string as a required argument and optional arguments that provide more information about the event. To show you how this works, and also to show you how you can create your own EventEmitter, here is a code snippet:

var fs = require("fs");
var events = require("events");
var watcher = new events.EventEmitter();
const WATCH_DIR = ".";
const CHANGE = "change";


watcher.on(CHANGE,function(){ console.log("dir has changed"); });

What I have done here is create a simple EventEmitter that watches the current directory and emit()s an event whenever a change has been made. The callback simply logs a message to the console.

It is also possible to extend the functionality provided by EventEmitters by using inheritance. This can be done as follows:

var events = require("events");
function Watcher(watchDir){
	this.watchDir = watchDir;
Watcher.prototype = Object.create(events.EventEmitter.prototype); = function(){ ... };
// add more methods

Adding / Removing Listeners

It possible to provide multiple listeners for a particular event, each of which does something different. Here:

var callback1 = function(){ ... };
var callback2 = function(){ ... };

You can remove one of the listeners by using the removeListener() method:


or you could remove all the listeners for a particular event as:


Setting a Maximum Limit on Listeners

By default, EventEmitters will print a warning if you add more than 10 listeners for a particular event. You can increase mthis limit on the number of listeners by using the setMaxListeners method:


That’s it on EventEmitters. For more, you can always look at the official docs.

JavaScript Filter, Map, Reduce in 5 Minutes

This post will summarize JavaScript’s filter, map, and reduce methods with simple examples.


From a given array of numbers, we want to keep the even numbers only. In other words, we want to filter the array. Code:

		return num % 2 === 0;

The argument to filter is a function that tests if the current element of the array passes a condition; in our case, if it is even. If it passes the condition, the element is added to another array. After all the elements have been checked, the newly generated array is returned. The original array stays intact.


From a given set of temperature readings, we want to convert the temperature in Kelvin to either Celsius or Farenheit. In other words, we want to map the Kelvin value to the corresponding Celcius or Farenheit value. JavaScript’s map method does just that. It takes in a function that does the transformation and returns an array of transformed values. Code:

var readings = [562,881,996,662];
var toCelsius = function(temp){ return temp - 273; }
var toFarenheit = function(temp){ return (temp-273) * 1.8 + 32; }


Given an array of numbers, we want to find its sum. In other words, we want to reduce it to its sum. Code:

		return total += num;

The reduce method takes two parameters – a function that performs the reduction and an initial value. The reduction function is passed two values by reduce – the intermediate sum (total) and the current element (num). We return the sum of intermediate sum and current number. At the end, our array gets reduced to its sum.

JavaScript Filtering Array Contents

In this post I will show you can filter the contents of an array – keep only the elements that meet a specific criteria. I will first show you how you can implement this yourself and then show you how you can use the in-built filter method of the array. Here we go:

function filter(array,test){
	var passed = [];
	for(var i = 0; i < array.length; i++){
	return passed;
var colors = ["red","green","blue","black"];
	return color.charAt(0) === "b";

The filter function takes an array and a function that tests an element of the array. If that element passes the test, it is added to passed. The filter function does not modify the original array. Filtering is such a common task that arrays have a predefined filter that takes in a function that checks the array element that was passed to it. Here is how it works:

var colors = ["red","green","blue","black"];
	return color.charAt(0) === "b";

That’s it on filtering.

JavaScript Higher Order Functions

In this post I will be talking about higher order functions in JavaScript and how they work. For a function to be a higher order function, it must meet atleast one of the criteria below:

  1. It takes a function as an argument
  2. It returns a function

In the last post about closures and lexical scoping, we created a function greaterThan that returned another function. The greaterThan function is a higher order function. This is what it looks like:

function greaterThan(m){
    return function(n){ return n > m; }

All the functions that return closures are, by definition, higher order functions. So what’s the benefit of using higher order functions? Well, many.

First, they help in abstracting the code. One has to traverse arrays a lot of times in programming. The usual way is to write a loop and maintain a counter. There is nothing wrong with this approach but one can certainly do better. JavaScript has an in-built forEach function that abstracts the array traversal for you.

var arr = [1,2,3,4,5,6];
	if(n%2===0) console.log(n);

The forEach function hides the array traversal from you and only asks you to specify what action needs to be taken on each item of the array. You pass in a function that specifies the action that needs to be taken. As forEach begins stepping through the array, it passes the element to your function which decides what needs to be done. This also reduces the number of lines you need to code as you do not have to write the same loop over and over again.

Second, they let you create your own control flows. Consider the example taken from the book “Eloquent JavaScript”:

function unless ( test , then ) {
	if (! test ) then () ;
function repeat ( times , body ) {
	for ( var i = 0; i < times ; i ++) body (i);
repeat (3 , function ( n ) {
		unless ( n % 2, function () {
		console . log (n , " is even ") ;
	}) ;
}) ;

The two functions unless and repeat help us to create a new control flow. The working of the above code goes like this: repeat simply repeats a given function as many times as you want and passes in the current count of the iteration to the function. So, any function you pass in can use this value if it likes. In our case, our function makes use of this value. It then calls unless and passes in the value generated by n%2. unless works like “unless this condition is true, you execute the passed function”. In our case, the passed function just logs the value.

Finally, they help you modify other functions:

function make(func,value){
	return func(value);

This one is pretty self-explanatory. Depending on what you pass in as the first argument, you get a corresponding return value.

That’s it on higher order functions.

Simplifying Lexical Scoping and Closures in JavaScript

In this post I will quickly introduce the concepts of lexical scoping and closures in JavaScript. Both of them are quite easy to understand so here we go with an example:

function outer(a){
	function inner(){

In the above snippet, the outer function accepts a parameter a and the function inner logs it to the browser console. This is possible because of lexical scoping. Lexical scoping determines how variable scopes are resolved in inner functions. An inner function(s) has access to the variables of its enclosing function and that is why inner has access to a.

Here is a slightly trickier example:

function outer(a){
	function inner(){
		var a = 5;

This code will always log 5 to the console because the inner function inner has a variable named a which is also the name of the variable of the enclosing function. In this case, the inner a will “hide” the outer a.
That’s it for lexical scoping – how variables are scoped for inner functions.

Onto closures. Consider the snippet:

function greaterThan(m){
	return function(n){ return n > m; }
var gt10 = greaterThan(10);

The browser console will log true since 32 is greater than 10. What is happening might not be so intuitive at first but a closer look will show that it is not all so hard to grasp. First of all, functions are just regular values – deal with it. Here is how this works:
You create a function named greaterThan that returns another function named.. er.. unnamed actually. Since functions can be stored in variables, you store the returned function in a variable named gt10. This can be used to compare a given value and see if it is greater than 10. Why 10? Because you initially passed in 10 to greaterThan. The inner function “remembers” that you had passed in 10 to its outer function when it was returned. When this returned function is called, it compares the passed argument with the one that was passed to its outer function. The returned function is a closure.

A closure, thus, is an inner function that remembers the environment (values of the outer function) in which it was created. That’s it.

Listing, Adding, and Removing Properties in JavaScript Object

In this post I will show you how to list all the properties of a JavaScript object, their values, and how you can add and remove properties. Let’s jump straight into it.

So we have a person named John Doe and we would like to list down all the properties of the person object along with their values. Here is how to do it:

var person = {name:"John Doe",age:27};
for(var property in person){
	console.log(property + ":" + person[property]);

This will also list the global properties (variables), if any, declared on the window object.

This leads to the next question: what if I want to list all the properties that a person has? I dont care for the values, just the properties. Well, use the Object.keys(obj) function. This will return an array containing all the properties of the object.

var person = {name:"John Doe",age:27};
var props = Object.keys(person);

Now let’s say that John Doe wants to register himself as a voter. To do this, we must first check if he is atleast 18 years old. Then if he is 18, give him voting rights by adding voter : true to his object. Here is how you’d do it:

var person = {name:"John Doe",age:27};
function registerVoter(person){
	if(!"age" in person)
	// or person.age >= 18
	if(person["age"] >= 18)
		person["voter"] = true;
		// or person.voter = true;

A few years later, John Doe got a rap sheet and his voting right was taken away from him. Here is how you’d take away his voting right:

var person = {name:"John Doe",age:27};
function unregisterVoter(person){
	if("voter" in person)
		// or delete person.voter
		delete person["voter"];

That’s it!

How to calculate MD5 hash in Java?

MD5 is a cryptographic hash function that takes in arbirtary data and produces a 128-bit hash from it. This hash can be used to verify the integrity of data. For example, you can check the integrity of the file you received over the internet by calculating its MD5 hash and comparing it with the hash that was advertised. If the two hash values do not match, there is something definitely wrong. Either the file is corrupt or it has been changed in transit. In any case, it is better to just discard the file.

Without further ado, here is the code to produce MD5 hash of the string “hello world”:

import java.nio.file.Files;
import java.nio.file.Paths;
import java.nio.file.Path;
import javax.xml.bind.DatatypeConverter;

MessageDigest md = MessageDigest.getInstance("MD5");
byte[] digest = md.digest("hello world".getBytes("UTF-8"));
println "${DatatypeConverter.printHexBinary(digest)}"

The MessageDigest class allows you to generate the message digest using an algorithm like SHA-1, MD5, etc. The digest is generated from bytes of data so we need to call the getBytes(). The digest() accepts the bytes and computes the hash. The computed hash is returned as byte[]. The printHexBinary() method converts the hash in bytes into a string.

The following code shows computing the MD5 hash of a file:

import java.nio.file.Files;
import java.nio.file.Paths;
import java.nio.file.Path;
import javax.xml.bind.DatatypeConverter;

Path path = Paths.get( System.getProperty("user.home") ).resolve("2015-03-");
byte[] data = Files.readAllBytes(path);
MessageDigest md = MessageDigest.getInstance("MD5");
byte[] digest = md.digest(data);
println "${DatatypeConverter.printHexBinary(digest)}"

The readAllBytes method reads all the bytes of the file into memory and then calculates the hash value. If you do not want to copy all the bytes into memory at once, you can do it as follows:

import java.nio.file.Files;
import java.nio.file.Paths;
import java.nio.file.Path;
import javax.xml.bind.DatatypeConverter;

MessageDigest md = MessageDigest.getInstance("MD5");
byte[] buffer = new byte[1024];
int read = 0;
File file = new File(System.getProperty("user.home"),"2015-03-");
InputStream is = new FileInputStream(file);
while( ( != -1){
byte[] digest = md.digest();
println "${DatatypeConverter.printHexBinary(digest)}"

That’s it on computing MD5 in Java