Monday, December 28, 2015

The real difference between Process and Thread in Java

One of the common question from programming interviews is, what is the difference between a Thread and a Process? Well, the main difference between them  is that a Process is a program which is executing some code and a thread is an independent path of execution in the process. A process can have more than one thread for doing independent task e.g. a thread for reading data from disk, a thread for processing that data and another thread for sending that data over the network. This technique to improve throughput and better utilize CPU power is also known as multi-threading. Technically, most significant difference between thread is address space and context switching. All thread from a process share same address space but a process has their own address space. Similarly, context switching between process is more expensive than context switching between threads.

Thursday, December 24, 2015

VirtualBox - /sbin/mount.vboxsf: mounting failed with the error: Protocol error [Solution]

I use Oracle's virtual machine, Virtualbox to run the Linux operating system from my Windows machine. It's the most simple way to have two operating system in your laptop or PC. Since I run most of Java program in Linux, VirtualBox gives me a nice interface to run UNIX commands right from Windows box. This blog post is about the mounting of shared folder failed error in Oracle's Virtualbox VM. It was working fine day before yesterday and now, after I restarted my virtual box and tried to mount my shared folder, I was greeted by this error: "/sbin/mount.vboxsf: mounting failed with the error: Protocol error". I was using the following command to mount my shared folder on VirtualBox:
$ mount -t vboxsf mountfolder /home/devInHost/mountfolder

I was running Oracle's VirtualBox 4.1 version with the guest operating system as RedHat Linux and host OS as Windows 8.

Tuesday, December 22, 2015

10 points about instanceof operator in Java with example

The instanceof operator in Java is used to check if an object belongs to a particular type or not at runtime. It's also a built-in keyword in Java programming language and mostly used to avoid ClassCastException in Java. It is used as safety-check before casting any object into a certain type. This operator has a form of object instanceof Type and returns true if the object satisfies IS-A relationship with the Type i.e. object is an instance of class Type or object is the instance of a class which extends Type or object is an instance of a class which implements interface Type. Once an object passed the instanceof check, it's safe to type-cast into that type, without worrying of java.lang.ClassCastException.

Wednesday, December 16, 2015

20 Java and Programming Quotes to Motivate Yourself

I always have a strong interest in knowing great peoples of my field i.e. programming. Knowing about them, following them and reading them not only gives you immense knowledge but the motivation you need to excel in what you are doing. It's motivation, not the knowledge that will propel your career. Knowledge is useless without motivation because knowing is not enough, you need to apply that knowledge, and without motivation, you just can't do that. There are times when the programmer's also felt tired and bored. These are the times when you spent hours constantly looking at the computer screen, clicking here and there, surfing the net without doing anything. That's the total waste of time and it's the result of poor motivation. If you are motivated then you will constantly work towards improving your code, writing more unit tests, creating better documentation and spending some time retrospecting, how could you have done better.

Monday, December 14, 2015

When to use intern() method of String in Java?

String.intern() method can be used to to deal with String duplication problem in Java. By carefully using the intern() method you can save a lot of memories consumed by duplicate String instances. A string is duplicate if it contains the same content as another string but occupied different memory location e.g. str1 != str2 but str1.equals(str2) is true. Since String object consumes a large amount of heap memory in average Java application, it makes sense to use intern() method to reduce duplication and take advantage of String pool feature provided by Java. You can use intern() method to intern a String object and store them into String pool for further reuse.

For example, when you create a String literal e.g. "abc", it's automatically stored in String pool, but when you create a new String object e.g. new String("abc"), even though it's same String, a new object at a different memory location is created. This is a duplicate String.

By calling  the intern() method on this object, you can instruct JVM to put this String in the pool and whenever someone else creates "abc", this object will be returned instead of creating a new object. This way, you can save a lot of memory in Java, depending upon how many Strings are duplicated in your program.

You can also read Java Performance by Charlie hunt and Java Performance, The Definitive Guide By Scott Oaks to learn more about troubleshooting Java Performance issue and optimizing the performance of Java applications.

Thursday, December 10, 2015

How to split a comma separated String in Java? Regular Expression Example

You can use String.split() function or StringTokenizer class to split a comma separated String in Java. Since splitting a String is a very common functionality, Java designers have provided a couple of split() method on java.lang.String class itself. These split() function takes a regular expression and split the String accordingly. In order to parse a comma delimited String, you can just provide a "," as a delimiter and it will return an array of String containing individual values. The split() function internally uses Java's regular expression API (java.util.regex) to do its job. If you are not very familiar with the regular expression than you can also use StringTokenizer class, which can also split a comma delimited String but StringTokenizer is an old class and not recommended and you should try to use the split() function from java.lang.String class, as any performance improvement will likely to happen on this method than the StringTokenizer class. Let's see a couple of examples to split a comma separated String in Java. You can also see Java Regular Expressions, taming the java.util.regex engine to learn the full power of Java regular expression.

Tuesday, December 8, 2015

5 Good Books for Java JEE Programming Interviews

If you are preparing for Java interviews then apart from blogs and articles, you should also take help of books specially written for Java interviews. Though nothing can substitute true job experience but the interview is little bit different beast. Even if you have a good experience, if you are not going for exact same profile job then you can expect hell lot of questions from vast topics of Java domain, which you might not have heard before. Java developers usually appear for two kinds of interviews, first for core Java development role where the focus is mostly on core Java concepts like multi-threading, concurrency, design patterns, OOP, error handling, collections, JVM internals, GC and Java performance tuning. Second kind of Java interviews for Java EE or Java web development role where the focus is mostly on Java EE related technologies e.g.

Friday, December 4, 2015

Top 30 Microsoft Interview Questions for Software Development Engineers (SDE)

In this article, I am going to some frequently asked Microsoft Interview Questions for their Software Development Engineer role. I am mostly sharing technical questions which are based upon Data structure and Algorithms, and Software design. They don't put any restriction on any programming language, which means you are free to solve these problems using C, C++, Java or Python. If you are preparing for Microsoft Interview then these questions can give you some idea about the level of knowledge you need to clear the interview. Regarding how to prepare? You can take help from standard data structure algorithm books or you can use cracking the code interview book, which contains frequently asked questions from Google, Amazon, Apple, Facebook and, of course, Microsoft. For more comprehensive preparation see the recommended books at the bottom of this article.

Thursday, December 3, 2015

Top 20 Core Java Interview Questions and Answers from Investment Banks

Core Java Interview Question Answer
This is a new series of sharing core Java interview question and answer on Finance domain and mostly on big Investment bank.Many of these Java interview questions are asked on JP Morgan, Morgan Stanley, Barclays or Goldman Sachs. Banks mostly asked core Java interview questions from multi-threading, collection, serialization, coding and OOPS design principles. Anybody who is preparing for any Java developer Interview on any Investment bank can be benefited from these set of core Java Interview questions and answers. I have collected these Java questions from my friends and I thought to share with you all. 

Wednesday, December 2, 2015

Why Programmers should take their CV seriously? 5 Tips to Make Better Resume

Recently I received an email from one of my readers that he is not getting enough interview calls though he was applying for every possible job he could from Job portals like and I asked him to send his resume to me and within 30 seconds of opening his CV, I know why he was not getting calls. Though he has right skills and some experience, his resume was not up-to-the-mark, and I am sure it get filtered by either non-technical people, junior HR or project managers. I have been interviewing people from last 10 years and I have involved in every step of conducting a programming job interview, starting from making job description, filtering resume, taking phone interviews, preparing written test papers and conducting face-to-face interviews.