Tuesday, 28 November 2017

Useful Java Debugging Tools

I shall introduce a few easy to use and useful tools to debug java applications.

jps - List the java processes (JVMs) running on your machine. Check the man/help page for this command for more options/flags
L-IDC1JKG3QD-M:balaji-katika.github.io bkatika$ jps
20259 JConsole
4723 PlatformMonitoringApp
40345 Jps

jinfo - Useful for extracting configuration Info about Java Process. This tool is bundled by default with JDK.
Useful to analyze the system properties, VM args supplied to the process

L-IDC1JKG3QD-M:balaji-katika.github.io bkatika$ jinfo -sysprops 4723 | grep file.encoding
file.encoding.pkg = sun.io
file.encoding = UTF-8
jstat - Outputs the JVM statistics. Useful to monitor various stats (like gc, class, compiler etc.,) about the JVM. The below command displays gc statistics for java pid 4723 at 5s interval and ends after 4 samples

L-IDC1JKG3QD-M:balaji-katika.github.io bkatika$ jstat -gc 4723 5s 4
 S0C    S1C    S0U    S1U      EC       EU        OC         OU       MC     MU    CCSC   CCSU   YGC     YGCT    FGC    FGCT     GCT   
19968.0 24576.0 13758.7  0.0   262144.0 244184.8  163840.0   36106.6   51968.0 51044.1 6656.0 6468.0     10    0.104   2      0.067    0.172
19968.0 24576.0 13758.7  0.0   262144.0 244184.8  163840.0   36106.6   51968.0 51044.1 6656.0 6468.0     10    0.104   2      0.067    0.172
jstack - Used to take the stack track (thread dump) of the JVM. Useful in detecting scenarios like deadlock, high cpu, performance bottleneck etc., Several online thread analyzer are available for free like https://spotify.github.io/threaddump-analyzer/ http://fastthread.io/ 

L-IDC1JKG3QD-M:apache-cassandra-2.1.2 bkatika$ jstack 4723 | more
2017-11-15 13:40:54
Full thread dump Java HotSpot(TM) 64-Bit Server VM (25.40-b25 mixed mode):

"RMI TCP Connection(idle)" #1091 daemon prio=5 os_prio=31 tid=0x00007fcc48932800 nid=0x9d8f waiting on condition [0x0000700009b8e000]
   java.lang.Thread.State: TIMED_WAITING (parking)
        at sun.misc.Unsafe.park(Native Method)
        - parking to wait for  <0x00000006c05cef28> (a java.util.concurrent.SynchronousQueue$TransferStack)
        at java.util.concurrent.locks.LockSupport.parkNanos(LockSupport.java:215)
        at java.util.concurrent.SynchronousQueue$TransferStack.awaitFulfill(SynchronousQueue.java:460)
        at java.util.concurrent.SynchronousQueue$TransferStack.transfer(SynchronousQueue.java:362)
        at java.util.concurrent.SynchronousQueue.poll(SynchronousQueue.java:941)
        at java.util.concurrent.ThreadPoolExecutor.getTask(ThreadPoolExecutor.java:1066)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1127)
jmap - Collect the heap dump from a running JVM. The below command collects the heap in hprof format. You can use tools like jhat for analyzing the dump file

jmap -dump:format=b,file=heap_dump_11405.hprof 11405

jvisualVM - Here is the all in one Java troubleshooting tool. Provides an overview of important metrics like CPU, Memory, threads etc., through one UI. One can monitor these metrics like using intuitive graphs. Lot of plugins like Visual GC are available for free download that would further enhance the functionality of this tool.


Some good articles to understand Java Garbage Collection

Friday, 1 July 2016

Install Apps not available from Google Play Store

Note: This content in this article is targeted towards Android Users

In this post, I shall be describing the steps/tricks/hacks to install apps that cannot be downloaded/available via Google Play store. Please refer the section 'FAQs' below if you face issues while following the steps mentioned below

1. File Sharing apps like ShareIt

Note : This method shall work only if your friend has the app installed in his mobile and he/she is in your proximity
You could first install a file sharing app like ShareIt . Get the same installed on your friends mobile as well. Now through 'Share It', chose the app of your interest and use the Send/Recieve feature. It gets transferred to your mobile !!

Benefits :
File sharing apps mostly use technologies like Bluetooth tethering hotspot, Wi-Fi direct etc., and mostly no charges since it doesn't consume mobile/Wi-Fi bandwidth. Its free !!

2. Use alternate channels to Google PlayStore

Its possible that certain app stores like apkpure might have it available. There are quite a few other popular play stores that pulls the apps published from Google Playstore and have it synchronized in their repositories. Hence its possible they might have them. You could download it from these alternate channels and have it installed on your mobile. Refer to the FAQ below 'My Smartphone is not allowing apps from alternate sources' if you have issues installing it on your mobile.


My Smartphone is not allowing apps from alternate Sources

Google by default doesn't allow apps downloaded from sources other than PlayStore. You have an option to disable it though. You need to enable installation from 'Unknown Sources' from your mobile Security Settings.
In my phone (One Plus X), I could do it through Settings->Security->Unknown sources (Toggle the radio button)

What are the common reasons for an app to be not available in Play store ?

For e.g., Popular e-Commerce app 'Walmart' is not available for India users. Several reasons and here are a few

  • Google allows an app publishers to list the countries he/she wants the app to be available in. App developer/publishers might select only a few countries of his interest. Common reasons for choosing/restricting in certain countries is due to lack of support/business in the particular country. 
  • Google charges a fee for developers to register before they can publish. At the time of writing this article, its 25$ (one time registration fee. Quite cheap when compared with Apple Store which is 100$ renewable ever year !!). Its possible that app developer/publisher chose not to pay this fee and published his/her app through alternate channels (like apkpure)
What are the disadvantages/down-sides of this approach ?
A few side-effects listed below
  • You might not get latest version since your friend might be running an older one. 
  • Google does not officially support/authorize apps downloaded other than from PlayStore.

I got the app downloaded/installed. But unable to run it ?
Its possible that app developer might have written his/her app to be country specific. Android has Location/Country APIs. Developer might have leveraged it and restricted access for your location programatically.

Thursday, 12 May 2016

Leverage Github Pages to simulate REST Service (HTTP GET)

In this article, I shall talk and demonstrate about leveraging github page to be used as REST service simulator. 
Most of the developers in typical development cycle shall be implementing the solution in bits and pieces. We would be having dependencies on other network services (REST APIs). This article shall be useful for those
  • blocked on other's service implementation that is either in development or not yet started
  • All they need is a simple HTTP GET service (You could pass query parameters and headers as well !!)
  • Need some sample test data (let it be static for now. As such for testing purpose, its fine)
  • Need to test their integration over and beyond intranet

Most of you must already be knowing that Github pages allows you to host webpages. This is possible by creating a special repository with the name '<github-id>.github.io' in your git account and placing the relevant HTML/CSS. I had explored this and could create mine like most of you have already done.

I have figured out that github can as well be used as a API hosting server. Of course, with little caveats, I could simulate a HTTP GET REST service. Refer my test rest service here. To test it, hit the URL http://balaji-katika.github.io/test.json using any API testing tool like curl, PostMan etc.,
All you need is to do is to create a file with .json suffix. Access with any API testing tool  Thats it !! You are done. 


* I could as well, build this kind of simulation using a simple spring based webapp samples running on my localhost. How is it different ?
Well, you can. However, this trick might benefit when you want to access the API outside the company intranet. Further, no headache of maintaining/build the new localhost based service when all you can do is to simple create a file with test data. Isn’t it ?

* What are the caveats you talked above ?
You cannot access this endpoint from a web application. Since, browser respect CORS headers and shall prohibit your application from hitting this endpoint

* What kind of tools/apps can benefit out of this ?
Any application (except for javascript, jsp based) planning to pull data from remote service could use this technique.

* Can you demo a real world application to help me understand better.

In the next article, I shall talk about how I could leverage this in one my hobby android application. 

Tuesday, 2 February 2016

Muhurat - My first Android App

Muhurat helps you figure out Auspicious timings from your finger tips. It shall calculate the Muhurat (Rahu, Gulika, YamaGanda etc.,) based on your last tracked location longitude and latitude. When location is not available, this application sets Bangalore (India) as the default location. Seeking your suggestions/feedback to improve and make this even more better. Please share your feedback via balaji.katika@gmail.com

You may downloaded the app from https://play.google.com/store/apps/details?id=com.tr.muhurath.app.muhurat

Special thanks to 


Is this App free ?
Its completely free for Android users and can be downloaded from Google Playstore. 

I know few other apps already doing similar stuff. Why this app again ?
This app differentiates in itself because it considers the geographical locations of the user and the sun-rise/sun-set timings are taken into account for the location while calculating the muhurat. 

Are you planning to further improve this App ?
Certainly. I am seeking inputs/feedback from people like you. Please reach me via balaji.katika@gmail.com

I am an NRI using the app outside of India. It seems to be showing incorrect timings ?
Please turn on your location settings and sync up your location services. Restart the app and it shall work correctly. You could turn off the location settings and the app shall refer to the latest available information/cache going forward.

Few screenshots of the app pasted below


Thursday, 28 May 2015

JVM Instrumentation Tools

In this blog, I shall talk about a few popular testing/debugging tools from java application instrumentation perspective running on Java Virtual Machines (JVM). The blog implicitly refers to Oracle's Hotspot JVM wherever applicable. Hence, tools specific to Oracle's JDK shall be discussed here.


jps - JVM Process Status tool
Use this command to figure out the running instrumented JVM instances running on your local/remote server. Refer here for more details.

jstat - Java Virtual Machine statistics monitoring tool
Displays performance statistics of an instrumented JVM reported above. Refer here for more details.

Statistics about classloader, compiler, garbage collector etc., can be viewed through this command

jstack - Thread dump of the JVM
Use this tool to get the thread dump with stack trace of the JVM at any given moment. Refer here for more details.

jinfo - Configuration Info
The Java specific configuration information about the JVM is displayed through this command. Refer here for more details.


jmap - JVM heap dump tool
Use this tool to collect the heap dump of the JVM. Details about the shared object mapping, object size and instances can be obtained through this tool. As of Java 8, this is an experimental and unsupported tool. Refer here for more details.

jhat - Java Heap Analysis Tool
The dump generated using the above (jmap) tool can be analyzed by this tool. Refer here for more details. It analyses the dump and provides a web service (by default runs on 7000) for users to explore the dump through their favorite web browser.




Thread Count Summary
Using a combination of the above tools, I have written a simple shell script to determine the summary of the non-daemon thread count during the execution of JVM. The script can be accessed from my gist page .

    sh thread_cnt_summary.sh <vmid> [interval] [count]
        vmid - Virtual Machine Identifier, string that indicates the target JVM
        interval - Sampling interval in seconds
        count - Number of samples to display

Heap Usage Summary

There are various tools like jConsole, jVisualVM etc., that provides details about the heap memory usage. Tools like jmap, jstat etc., provide point in time analysis of java heap memory. I could not find a suitable CLI based tool that helps to monitor the live heap memory usage of the JVM during the execution. Hence, created a wrapper around jmap to monitor java heap memory usage. This includes Eden, Survivor 1 & 2 and the tenured generation spaces.
The tool can be located at my gist page.

Thursday, 30 April 2015

Interview Experience

Just like most software engineers, I also hunt for better jobs. 'Better' here mean better work, better compensation, better culture etc., and NOT just 'salary' !! Recently switch to a better job. Most people have asked me about my experience in getting new job, what questions/technologies do the companies ask, qualities/skill set they are looking for ? blah blah... In this post, I try to provide my views to such queries.
I've briefly mentioned my career snapshot below. This blog could help the reader analyze/co-relate the  questions/experience for a similar/related profile. I've also documented the questions (as I remember !!) at the end of this blog that various companies/interviewers have asked me during my stint. 

Brief about my profile

Around 10 years of work experience as a software engineer at various product development companies. Vast experience in design and development of application software with various tools/technologies using C/C++ and Java (present). Mostly worked for management applications in storage and virtualization domain. 


How is the overall market ?

Its certainly better when compared to 2009-10 times but not very good. Considering the growing number of tech startups, one can certainly expect good number of calls.

What kind of questions to expect ?

Well, it mostly depends on the kind of job role and requirements. Most high paying companies focus on problem solving, algorithms, computer science fundamentals. Of course, your current project and relevant skill set also matters but relatively the weight age is higher for the former.

What kind of algorithms do they ask ?

Usually they begin with standard questions like detecting the loop in linked list and then dig deeper that involves questions around heap, graphs etc., And then on dynamic programing (DP). Yes, DP has become a norm these days and they use it as the decider.

How many rounds will there be ?

Most companies have 4-5 technical rounds excluding the telephonic or screening (online, programing etc.,) followed by the managerial/HR rounds.

How will the HR round be ? What kind of HR questions do they ask ?

As the experience increases, I've found their role in hiring decreases. They just facilitate the process and aid the manager/recruitment team in logistics. 

What qualities in my resume boost/attract my potential employers ?

Most people mention about the present/past projects but thats not enough. Employers are looking beyond it. For example, you could mention about open source contributions/community projects you are involved with. Something apart from your regular work you did. This talks about your passion to explore technologies. Some examples below.
  • Open source doesn't necessarily be some top level apache project. It could be your petty/hobby projects (as simple as shopping cart applications) or your contributions to other's ideas. 
  • Some simple scripts to help automate your daily activities that could help other folks facing similar problems (a script to automatically detect untracked files in your git workspace and add it to the staged environment)
  • Contributions to open forums like stackexchange, yahoo answers, quora etc.,
  • Your experiences/opinions shared to wider audience through blogging sites (e.g : new features in JDK 8, some upcoming technology like docker)

Are the above mandatory ?

Not exactly. But they'll certainly put you in front of the queue while screening/shortlisting profiles in the initial recruitment phases. Its never late. You could start doing from now.

What qualities shall distract/under weigh my resume ? 

One thing I noticed is the frequent switches as they indicate your instability and unreliability. I would say at least 3 yrs in single company shall be a good number. Something like 5+ yrs in a single company shall strike out your temporary stints (like 6months, < 1 yr etc.,) because the fault could be on the employer side as it failed to retain you while some other company (>5 yrs) could do that. 

Interview Questions

Documented below some of the questions I have been asked by various companies

Company Name
Questions (that I remember)
Digital Insight (Telephonic)
Dec 2014
   Write a program to chose every k elements from the end of the single link list and reverse them
            e.g: If k==3, a b c d e f g h i j k => j k g h i d e f a b c       
   How to identify non repeated integer from a array of integers
Explain Decorator pattern
Snapdeal F2F
Dec 2014
   Write code for put/get in Map
   Design question related to orders and customers. Prevent rows in child table to be deleted using constraints table/cache
   Puzzle - 3 couples on one side of river need to cross using a boat of capacity 2 where both male/female can drive it...Safety (women cannot be alone with any male other than her husband)
Digital Insight F2F
Dec 2014
Program to print nodes for a given element in tree at a distance of K (could be children or parent or siblings)
   Design question on Badminton game
   longest palindrome in a given string (DP problem)
Flipkart (Telephonic Managerial position)
Dec 2014
what are the 3 qualities you would reject/hire in a candidate
Did you have any prior experience in appraisals. How would you keep employees happy ?
Write the code to recursively/iteratively compute fibonacci number
Decorator/Proxy pattern overview and examples
How would you scale web applications. Approach and techniques.
Dell Telephonic

Jan 2014
Primarily on Java
Iterators (failsafe vs failfast)
java threads
Dell F2F
Jan 2015
Design and code workqueue/workpool
   questions about current projects and challenges
   SOAP vs RESTful
   SSL overview
   write code to construct tree if both inorder and pre-order traversal of a tree is given
Media IQ - F2F  
Jan 2014
   program to find out largest palindrome in a given string (DP questions)
   Program to print the last node in each level of level order traversal
 design and code for LRU cache
   design n elevators and m floors
   program to find the max number of platforms required for a railway station given the arrival and departure of the trains in an array
 VMWare - F2F (Internal)

Write code to reverse singly linked list using recursion
Write code for BlockingQueue using java synchronization techniques. Multiple readers and single writer
Write code for LRU cache
Code to find last node at each level in BFS
TaxiForSure (Telephonic Managerial Position)
Jan 2015
Highly Adhesive and Low coupling
find sum of array using recursion
Decorator pattern
TaxiForSure F2F
Jan 2015
What is the Challenging project
How to scale website
How to optimize database
Wallmart Labs (Telephonic) Jan 2015

Jan 2015
Implement decorator pattern
difference between synchronized map vs concurrent map
garbage collection fundamentals like parellel vs concurrent
weak vs soft refernce in java
Code for factorial and geometric progression

Wallmart Labs (F2F)
Feb 2015
Explain the fundamentals of SSH and its working
Fundamentals of program memory and its working… cache, page table, TLB, various segment
logic and code to find the median of continous stream of integers
code to construct balanced binary tree from an array of integers
given an integer array of size N  and input K, construct an array of size N-K with minimum elements from each rolling window of size K. (Can be solved using combination of heap and map)
Java specific questions like synchronization, volatile, memory gc concepts, producer consumer problem
design problems on high availability and scalability

Microsoft F2F
Feb 2015
How will you simulate inheritance without actually using the in-built inheriteance in OOPs
Features and basics of OOPs
Write code to demonstrate polymorphism using C++ templates
Write code for circular array based queue
High availabilty/distributed systems
How to implement de-duplication at file/block level in a file system. How to take care of cloning/moving to a different data disk

Monday, 13 April 2015

My MAC venture

I am an ardent fan of Linux and the regular user of windows (Of course, have grown-up with it). Experimented with various flavors of linux (viz., RedHat, Fedora, SuSE, CentOS etc.,) and several versions of Windows. However, was always reluctant to try Mac systems. Though, I keep hearing lot of good things about Mac, but never attempted at it. Finally, broken the ice and gave it a try. Found a bit confusing but interesting. Especially having used windows GUI since a long time. Sharing my learning and experience though this blog. This article shall be helpful for those switching/adapting to Mac machines with windows/linux background like me. It primarily aims at comparing Windows and OS/X. Examples mentioned in this article are with reference to Yosemite (10.x) version of OS/X

Note: This blog is work-in-progress and shall be updated continuously as and when I come across new stuff

System Administration Tools

DescriptionWindowsLinuxOS X
Software/Package Management ToolsYum, zypper,apt-get etc.,Homebrew
Process/Task ManagementTask ManagertopActivity Monitor

Keyboard Mapping

The Option key on a Mac is the same as the Alt key in Windows.
The Command (cmd) key works in a similar way to the Control key in Windows. 
The most common use of Control key on Mac is to mimic the right click action.
Additional information available at https://support.microsoft.com/en-us/kb/970299
Some of the frequently used keys are provided below

DescriptionWindowsLinuxOS X
Command (mostly) or Control (sometimes)


Shortcuts (Key-combinations)

Additional information at https://support.apple.com/en-us/HT201236
Some of the useful shortcuts provided below for reference.

DescriptionWindowsLinuxOS X
CopyCtrl + C
CutCtrl + V
PasteCtrl + V
RedoCtrl + Z
LockCtrl + Alt +Del