Monthly Archives: September 2014

Difference between Process and Thread

Process What's Process? In computing, a process is an instance of a computer program that is being executed. It contains the program code and its current activity. Depending on the operating system (OS), a process may be made up of multiple threads of execution that execute instructions concurrently. Process states An operating system kernel that allows multi-tasking needs processes to have certain states. Names for these states are not standardized, but they have similar functionality. Orphan Process and Zombie Process Orphan process An orphan process is a computer process whose parent process has finished or terminated, though it remains running itself. In a Unix-like operating system, any orphaned process will be immediately adopted by the special init system process. This operation…

Continue Reading

Difference between wait() and sleep(), yield() in Java

Differences between wait() and sleep() or sleep() and yield() method in Java Thread is one of the very old questions asked in Java interviews. Though both wait and sleep put threads to the waiting state, they are completely different in terms of behavior and use cases. JavaDoc Definition Thread Class public static void sleep(long millis[, int nanos]) throws InterruptedException Causes the currently executing thread to sleep (temporarily cease execution) for the specified number of milliseconds plus the specified number of nanoseconds, subject to the precision and accuracy of system timers and schedulers. The thread does not lose ownership of any monitors. Parameters:millis - the length of time to sleep in millisecondsnanos - 0-999999 additional nanoseconds to sleep Throws:IllegalArgumentException - if the value of millis…

Continue Reading

Object Initialization Order in Java

An object is a chunk of memory bundled with the code that manipulates memory. In the memory, the object maintains its state (the values of its instance variables), which can change and evolve throughout its lifetime. To get a newly-created object off to a good start, its newly-allocated memory must be initialized to a proper initial state. Here we take an in-depth look at the mechanisms Java uses to manage object initialization. Java's Initialization Mechanisms At the beginning of an object's life, the Java virtual machine (JVM) allocates enough memory on the heap to accommodate the object's instance variables. When that memory is first allocated, however, the data it contains is unpredictable. If the memory were used as is, the…

Continue Reading

HashMap Internal Implementation Analysis in Java

Most of you will agree that HashMap is a most favorite topic for discussion in interviews nowadays. Now, I am continuing this discussion with you all. I am assuming that if you are interested in the internal working of HashMap, you already know the basics of HashMap, so I'm skipping that part. But if you are new to the concept, follow official java docs. Single Statement Answer If anybody asks me to describe "How HashMap works?", I simply answer: "On the principle of Hashing". As simple as it is. Now before answering it, one must be very sure to know at least the basics of Hashing. Right? What is Hashing Hashing in its simplest form is a way to assign a…

Continue Reading
Contact Us
  • Nanyang Technological University, Singapore
  • root [at] haozhexie [dot] com