Category: Java

  • JMS v/s MQ

    JMS v/s MQ

    The difference being that JMS messages have some standard header fields at the begining of the message buffer and “native” mq messages contain just the data your program sent to the buffer. Performance is not the only reason to send plain messages (MQ format) without the JMS Headers from JMS Client to MQ Server. AMQP (Advance Message Queuing Protocol) The Advanced Message Queuing Protocol (AMQP) is an open standard for

    Read article →

  • Java Messaging Service (JMS) using ActiveMQ

    Java Messaging Service (JMS) using ActiveMQ

    Java Messaging Service is an api that provides the facility to create and send the messages. JMS makes easy to develop enterprise applications that asynchronously send and receive business data and events. It defines a common enterprise messaging API that is designed to be easily and efficiently supported by a wide range of enterprise messaging

    Read article →

  • What will happen if you store null key in HashMap?

    What will happen if you store null key in HashMap?

    In HashMap, only one null key is allowed. If key of the HashMap is null then it will always be present in the index 0. NullPointerException is thrown if you try to call hashCode() method on null key.As a result, when a get() method is called then value of the first index is returned.

    Read article →

  • Can we use any class as a Map key in HashMap?

    Can we use any class as a Map key in HashMap?

    Yes. We can use any class as a Map key, however the following points should be considered before using them. If a class overrides an equals() method, it should also overrides hashCode() method. Best practice for user defined key class is to make immutable, so that the hashcode value can be cached for fast performance.

    Read article →

  • What is the importance of hashcode() and equals() methods?

    What is the importance of hashcode() and equals() methods?

    HashMap uses the key object hashCode() and equals methods to determine the index to put the key-value pair. The methods are also used when we try to get the value from HashMap. If these methods are not implemented correctly, two different keys might produce the same hasCode() and equals() output and in that case, rather

    Read article →

  • How hashmap works in java?

    How hashmap works in java?

    Hashmap stores a key-value pair in Map.Entry static nested class implementation. HashMap works on hashing algorithm and uses hashcode() and equals() method in put() and get() methods. When we call put() method by passing key-value pair, HashMap uses key hashcode() with a hashing to find out the index to store the key-value pair. The entry

    Read article →

  • Difference between enum and constant in java

    Difference between enum and constant in java

    Enum is a java keyword, we can use it for a variable to be set of predefined constant value. Before Java 1.5 we used public static final keywords to represent constants. Enum was introduced in Java 1.5 and since then we use it represent constants or string name for a variable. Also Enums are thread

    Read article →

  • Algorithm Analysis

    Algorithm Analysis

    Runtime Analysis of an Algorithm

    Read article →

  • Binary Search

    Binary Search

    Binary search is used to search a key element from multiple elements. Binary search is faster than linear search. In case of binary search, array elements must be in ascending order. If you have unsorted array, you can sort the array using Arrays. public class BinarySearch { public static void main(String str[]) { int[] elements = new int[]{11,17,18,45,50,71,95,98}; int index = binarySearch(elements,

    Read article →

  • Linear Search

    Linear Search

    The list of array is traversed sequentially and every element is checked. In this type of searching, we simply traverse the list completely and match each element of the list with the item whose location is to be found. If the match found then location of the item is returned otherwise the algorithm return NULL.

    Read article →