• 25 June

    How to iterate over Map or HashMap in java

    In this post, we will see how  can we iterate a map in java. There are four ways of iterating over a map, HashMap or TreeMap. Java HashMap tutorial: HashMap in java How HashMap works in java hash and indexfor method in HashMap hashcode and equals method in java How to sort HashMap by keys […]

  • 24 June

    How to iterate a list in java

    In this post, we will see how  can we iterate a list in java. There are four ways of iterating over a list. For loop For each loop(Java 5) While loop Iterator Below example will help you to understand, how to iterate list in java. I am taking custom object list to understand better 1. […]

  • 17 June

    Difference between ArrayList and LinkedList in java

    One of the common interview question is “What is difference between ArrayList and LinkedList”.Before we actually see differences,let me give you brief introduction of both. ArrayList ArrayList is implementation of list interface. ArrayList is not synchonized(so not thread safe) ArrayList is implemented using array as internal data structure.It can be dynamically resized . LinkedList LinkedList […]

  • 16 June

    Java Thread Join Example

    In this post, we will see about Java thread join method. Thread class’s join() method can be used to stop current execution of thread until thread it joins, completes its task. So basically, it waits for the thread on which join method is getting called, to die.For example: Here when you call t1.join(), main thread […]

  • 14 June

    Java Thread Sleep

    Sleep method of java.lang.Thread is used to pause current execution of thread for specific period of time. Some important points about sleep method are : It causes current executing thread to sleep for specific amount of time. Its accuracy depends on system timers and schedulers. It keeps the monitors it has acquired, so if it […]

  • 14 June

    Java Thread example

    Thread can be called as light weight process. Java supports multithreading , so it allows your application to perform two or more task concurrently.  Multithreading can be of advantage specially when now a days, machine has multiple CPUs, so multiple tasks can be executed concurrently. Whenever we call main method in java, it actually creates […]

  • ConcurrentHashMap in java
    26 November

    ConcurrentHashMap in java

    ConcurrentHashMap was introduced in Java 5 with other concurrency utils such as CountDownLatch, CyclicBarrier and BlockingQueue. ConcurrentHashMap in java is very similar to HashTable but it provides better concurrency level. You might know , you can synchonize HashMap using Collections.synchronizedMap(Map). So what is difference between ConcurrentHashMap and Collections.synchronizedMap(Map)In case of Collections.synchronizedMap(Map), it locks whole HashTable […]

  • 19 July

    How HashSet works in java

    In this post, we will see about Hashset in java Java HashSet: [crayon-662b30953d1d7440757783/] This is one of the frequently asked question in core java interview so in this post, we will see how HashSet works in java.We have already seen How hashMap works in java and also difference between HashMap and HashSet. Lets first see […]

  • 11 July

    Difference between sleep and wait in java

    One of the common interview question is “What is difference between sleep and wait in java”.Before we actually see differences,let me give you brief introduction of both. sleep It causes current executing thread to sleep for specific amount of time. Its accuracy depends on system timers and schedulers. It keeps the monitors it has acquired, […]