Category: Java

  • How to Generate QR Code in Java Spring Boot

    As we know that QR Codes are becoming the most widely recognized 2D barcodes worldwide. The big benefit of the QR code is that we can store large amounts of data in a limited space. Here, In this article, we will learn how to generate a QR code using Java Spring boot. Create a Java spring

    Read article →

  • Data Structure Problems

    Reverse Array : Reverse the given array by using temporary variable. Output : Rotate an array : Rotate the given array with respect to the number of times.

    Read article →

  • Commonly used Data Structures : Java

    Arrays Stacks Queues Linked Lists Trees Graphs Hash-table Arrays: An array is the simplest and most widely used data structure. Other data structures like stacks and queues are derived from arrays. Here’s an image of a simple array of size 4, containing elements (1, 2, 3 and 4). The following are the two types of

    Read article →

  • Priority Queue

    Priority Queues are used to short heaps. Priority queues are used in operating system for load balancing and interrupt handling. Priority queues are used in huffman codes for data compression. In traffic light, depending upon the traffic, the colors will be given priority. Difference b/w priority queue and normal queue: In a queue, the first-in-first-out rule is

    Read article →

  • Java : Interesting and Cool Tricks

    Java : Interesting and Cool Tricks

    1) Java String : concat() vs + operator for concatenation intern() private String str1 = new String(“Hello”); private String str2 = “Hello”; System.out.println(str1 == str2); //false private String str3 = str1.intern(); System.out.println(str3 == str2); //true As you can see, both str1 and str2 have the same content, but they are not equal initially. We then

    Read article →

  • Java Concurrency : Atomic Wrapper

    Java Concurrency : Atomic Wrapper

    Java provides atomic classes such as AtomicInteger, AtomicLong, AtomicBoolean and AtomicReference. Objects of these classes represent the atomic variable of int, long, boolean, and object reference respectively which can be atomically updated. class Counter extends Thread { // Atomic counter Variable AtomicInteger count; // Constructor of class Counter() { count = new AtomicInteger(); } // method which would be called

    Read article →

  • Java 8 Features

    Java 8 Features

    Java 8 provides the following features: Lambda Expression Method Reference Default Methods Functional Interface Optional Class String Joiner Stream API Concurrency Enhancements Lambda Expression: A new feature in java 8 allowing us to treat actions as objects. It is a short block of code and it’s similar to methods, but they do not need a

    Read article →

  • Topic v/s Queue – JMS

    Topic v/s Queue – JMS

    A queue means a message goes to one and only one possible subscriber. A topic goes to each and every subscriber.  Topics are for the publisher-subscriber model, while queues are for point-to-point. A JMS topic is the type of destination in a 1-to-many model of distribution.

    Read article →

  • Singleton class in Java and how can we make a class as singleton?

    Singleton class in Java and how can we make a class as singleton?

    Singleton class is a class whose only one instance can be created at any given time in one JVM. Make constructor as private, so that instance cannot be created outside the class. Private static instance needs to be created in that class itself. Static method should created a new instance if the value is null.

    Read article →

  • How can you make a class Immutable?

    How can you make a class Immutable?

    Declare the class as a final so it can’t be extended. Make all fields private so that direct access will be avoided. Do not implement setter methods for a variables. Make all mutable fields final so that it’s value can be assigned only once. Perform cloning of objects in getter methods for returning the copy

    Read article →