Total Pageviews

Wednesday, August 20, 2014

Android Architecture (The Stack)

The Android operating system is like a cake consisting of various layers. Each layer has its own characteristics and purpose. The layers are not cleanly separated but often seep into each other.

Lets discuss about each layer from bottom to top.

  • Linux Kernel


Android is built on top of a solid and proven foundation: the Linux kernel. Created by Linus Torvalds in 1991, Linux can be found today in everything from wristwatches to supercomputers. Linux provides the hardware abstraction layer for Android, allowing Android to be ported to a wide variety of platforms in the future. There are many good reasons for choosing Linux as the base of the Android stack. Some of the main ones are its portability, security, and features

  • Native Libraries


The native libraries are C/C++ libraries, often taken from the open source community in order to provide necessary services to the Android application layer. Among others, they include:
Webkit            
A fast web-rendering engine used by Safari, Chrome, and other browsers
SQLite
A full-featured SQL database
Apache Harmony
An open source implementation of Java
OpenGL
3D graphics libraries
OpenSSL
The secure locket layer
Although many of these libraries are used as-is, one notable exception is Bionic, which is basically a rewritten version of the standard C library. Bionic is used for two reasons:
Technology
To make it purpose-built for tiny, battery-powered devices
License
To make it license-friendly for others who might want to adopt it and change it
Dalvik

Dalvik is a purpose-built virtual machine designed specifically for Android, developed by Dan Bornstein and his team at Google.
The Java virtual machine (VM) was designed to be a one-size-fits-all solution, and the Dalvik team felt they could do a better job by focusing strictly on mobile devices. They looked at which constraints specific to a mobile environment are least likely to change in the near future. One of these is battery life, and the other is processing power. Dalvik was built from the ground up to address those constraints.
Another side effect of replacing the Java VM with the Dalvik VM is the licensing. Whereas the Java language, Java tools, and Java libraries are free, the Java virtual machine is not. This was more of an issue back in 2005 when the work on Dalvik started. Nowadays, there are open source alternatives to Sun’s Java VM, namely the OpenJDK and Apache Harmony projects.
By developing a truly open source and license-friendly virtual machine, Android yet again provides a full-featured platform that others are encouraged to adopt for a variety of devices without having to worry about the license.
Android and Java
In Java, you write your Java source file, compile it into a Java byte code using the Java compiler, and then run this byte code on the Java VM. In Android, things are different. You still write the Java source file, and you still compile it to Java byte code using the same Java compiler. But at that point, you recompile it once again using the Dalvik compiler to Dalvik byte code. It is this Dalvik byte code that is then executed on the Dalvik VM.
You may wonder, why not compile straight from Java into the Dalvik byte code? There are a couple of good reasons for the extra steps. Back in 2005, when work on Dalvik started, the Java language was going through frequent changes, but the Java byte code was more or less set in stone. So, the Android team chose to base Dalvik on Java byte code instead of Java source code. A side effect of this is that in theory you could write Android applications in any other language that compiles down to Java byte code. For example, you could use Python or Ruby.

  • Application Framework

Sitting above the native libraries and runtime, you’ll find the Application Framework layer. This layer provides the high-level building blocks you will use to create your applications. The framework comes preinstalled with Android, but you can also extend it with your own components as needed.
The most important parts of the framework are as follows:
Activity Manager: This controls the life cycle of applications 
Content providers: These objects encapsulate data that needs to be shared between applications, such as contacts.
Resource manager: Resources are anything that goes with your program that is not code.
Location manager: An Android phone always knows where it is.
Notification manager: Events such as arriving messages, appointments, proximity alerts and more can be presented in an unobtrusive fashion to the user.

  • Applications

And finally, there are the applications that you and other developers create. These applications are what end users find valuable about Android. They can come preinstalled on the device or can be downloaded from one of the many Android markets.
The APK
An application is a single application package (APK) file. An APK file roughly has three main components. An API consists of the following major components:
Dalvik executable
This is all your Java source code compiled down to a Dalvik executable. This is the code that runs your application.
Resources
Resources are everything that is not code. Your application may contain a number of images and audio/video clips, as well as numerous XML files describing layouts, language packs, and so on. Collectively, these items are the resources.
Native libraries
Optionally, your application may include some native code, such as C/C++ libraries.
These libraries could be packaged together with your APK file.

Sunday, August 17, 2014

Fun with Google

Google offers so much more than just search.
From the silly to the useful, these Google features will make you love Google even more than you probably already did.

  • Google Image search "Atari Breakout" and prepare to forget whatever else you were supposed to be doing.
  • You can set a timer on Google (and get an alarm to sound when time is up) by Googling any amount of time followed by "timer."
  • Google Sky lets you explore the far reaches of the universe using images from NASA satellite, the Sloan Digital Sky Survey, and the Hubble Telescope.
  • Google nGrams is a fun tool that lets you search for words in 5.2 million books published between 1500 and 2008 so you can see how much it's been used over time.
  • Intimidated by huge numbers? Google will help you figure out how to pronounce that 12-string number if you type "=english" after it.
  • Unleash your inner child by checking out Google's Build with Chrome.
  • You can add "+anything" when typing your email address and it will still work. This can be good for filtering emails (for example, you could set up a folder for all emails sent to "youremail+datingsite@gmail.com").
  • Google recently released a fun new Maps game called SmartyPins that gives you geographic trivia.
  • Getting married? Google will help you plan your wedding, announce the news, locate a venue, fill in the plans, make a website, and more.

  • There's a "Manual" feature in Google Translate that lets you draw characters or symbols.
  • Find a gorgeous font that you can use for free (Google Fonts).
  • Get your culture on by using Google Art Project to check out super high-res photos of artwork from the world's greatest museums.


Loved playing "Atari Breakout"? Here's one more..
  • Google search "zerg rush" and end up with finger pain!


  • Google recreated Pacman and made a doodle for it on Pacman's 30th anniversary. 30th Anniversary of PAC-MAN reminds me of my childhood :D
  • Developers at Google are so cool! Check these funny things to know why..
Google search the following one at a time
"Do A Barrel Roll"
"Tilt"
"Recursion"
"Define Anagram"

  • Open Google Play and click search icon without entering any search terms. 
    You'll get search results with Unicorns everywhere ^_^
  • Search for "Do The Harlem Shake" in Youtube
  • Typing in “/Pitchforks” in a Google Hangouts dialogue box will launch a stream of angry townspeople racing across the screen with pitchforks. “/ShyDino” will feature a green dinosaur hiding behind a small house in your chat window, while typing “/BikeShed” will also change the background color. And they didn't forget My Little Pony: Friendship is Magic in Google Hangouts, either: Typing in “/Ponies” or “/Ponystream” will make animated ponies dash across your chat window.
  • In Google Maps, search for “Police Telephone Box.” It will bring youEarl’s Court Station. Go to the location’s streetview and you’ll see the Doctor Who TARDIS on the sidewalk. Click the double-white arrows in front of the police box and you’ll be sent to the inside of the time machine. Once inside, you’ll be able to have a 360-degree view of its interior.
  • In the late 80s, video game developer Konami utilized a special cheat code that could be used on the company's video games. The “Konami Code” was made popular with Contra for the Nintendo Entertainment System. When players input “up, up, down, down, left, right, left, right, B, A, start” during the game’s title sequence, they could unlock 30 extra lives to get through the game instead of the standard three.
    Google has used the Konami Code on a few of its products, including Google Play Games, Google Docs, and Google’s Chromebook Pixel. Swiping the Konami Code in the Google Play Games mobile app willunlock a clever achievement that reads, “All Your Games Belong To Us.” In Google Docs, typing the Konami Code will reverse your entire document, and in Google’s Chromebook Pixel, typing in the code will make the LCD stripe on the outside of the computer blink in a frenzy of various colors.   

  • Bored with image search? Now you can have a spinning layout to search for images. Check Google Sphere

Source:
Internet
16 Google Easter Eggs You Might Have Missed
Check Out These Awesome Google Features You Didn't Know Existed
Konami Code Easter Egg Discovered In Google Play Games


Most frequently asked Java Interview Questions

This is a sample from my recent round of Java interviews:
  • String questions: Check if one string is a rotation of other string, check if a string is a palindrome, check if a string is a substring of other string,  return the index of the first occurence of a substring in other string,  reverse a string, Difference between StringBuilder, StringBuffer and String
  • LinkedList questions: Reverse a linked list recursively(in-place) and iteratively, delete a node from linked list, find the nth node, find the nth node from the end, test if a linked list has a cycle, write test cases
  • What is immutable, Implement an immutable class (e.g. myDateTime)
  • What are volatile, synchronized, atomic
  • What are some ways to implement a singleton in Java
  • Implement a counting semaphore
  • JVM/GC questions
  • Checked vs unchecked exceptions, finalize
  • What is a queue, stack, heap
  • Level-order BFS on a binary tree
  • What happens in the system during a recursive call
  • Remove an item from an array of ints, print the second largest number in an array, remove a character from a string
  • Write a method receiving a stream of integers, caching the last 10 min of data and returning a number if it's less than the current input
  • Mutexes, ReadWriteLock, ConcurrentHashMap, ArrayBlockingQueue, Thread pools, LinkedList vs ArrayList, Object Pooling, Read-Modify-Write, java.util.concurrent, java.util.concurrent.atomic, CAS, Collections, ADT, Java 5 Generics
  • HashMap vs HashTable vs ConcurrentHashMap
  • Synchronous vs asynchronous, thread contention, race conditions/deadlocks and how to prevent/debug them, thread confinement, cache coherence, false sharing, cache lines
  • How would you write a socket client/server in Java
  • Java IO/NIO, socket multiplexing, blocking vs non-blocking, select/epoll
  • Sleep vs wait
  • Process vs thread, Java threads vs Pthreads, Linux threads vs Solaris threads, what happens when a process/thread is started/terminated, what happens during context switch
  • Java Memory Model, Weak references
  • Jini, JMS, Javaspaces, JGroups, Hibernate trivia
  • Abstract Class vs Interface
  • Memoization, give an example
  • Can you have a protected method in Interface
  • How to force a stop-of-the-world GC
  • What can be done to interrupt a synchronized method that is blocked
  • Java performance, heap profiling, GC tuning, thread dumps, Hotspot vs JRockit
  • How would you implement low latency data structures
  • How would you debug performance issues, what do you do if a database query is "slow", describe the troubleshooting approach when a customer complains that the UI is "slow"
  • Knight Tour puzzle- write a method for a knight to find another figure (a fool) on a chessboard
  • Clock puzzles - find the angle between hr,min,sec handles, etc
  • 3 jars puzzle (one jar is filled with 8 gallons, two jars are empty (capacity 5, 3), write a routine to get to 4-4 state
  • Inner join vs outer join
  • What are ACID properties in a database
  • What is caching; How would you implement a caching server for a streaming video service (messaging/queues, data structures, expiration/eviction), how would you benchmark the performance of your broadcasting/caching  server/service, how do you scale it to thousands of customers, what is CDN
  • How would you design a high throughput order management system, matching engine, market data engine, FIX engine (trading)
  • How would you design a data collection service (i.e. downloading/streaming data from multiple sources from the web), distributed data feeds/CRUD data store design,indexing, performance/scalability/availability considerations
  • What is the fastest way to do a grep on 10GB plain text file on a laptop 
  • Describe the projects you're most proud of, the most difficult problems you've solved as an engineer, what is your favorite programming language

I've found these resources helpful:
  • Brainbench Java tests