Posts

What are the different types of Garbage Collection?

In Java, there are several types of garbage collection algorithms that can be used to reclaim memory used by objects that are no longer needed by the application. The different types of garbage collection algorithms available in Java are: Serial Garbage Collection: This is the simplest and oldest form of garbage collection in Java. It uses a single thread to scan the heap and collect objects that are no longer needed. This type of garbage collection is suitable for small applications with low memory requirements. Parallel Garbage Collection: This garbage collection algorithm uses multiple threads to scan the heap and collect objects that are no longer needed. This type of garbage collection is faster than serial garbage collection and is suitable for larger applications. Concurrent Mark Sweep (CMS) Garbage Collection: This algorithm is designed to minimize pauses in the application by performing garbage collection concurrently with the application's execution. CMS garbage collectio...

What are the different types of Thread pool creation in Concurrency Control?

In Java, there are several types of thread pool creation mechanisms available in the standard library. Some of the commonly used thread pool creation mechanisms in Java are: FixedThreadPool: This type of thread pool creates a fixed number of threads at the start of the program, and these threads are reused to perform tasks throughout the lifetime of the program. The number of threads in the pool is specified at creation time. CachedThreadPool: This type of thread pool creates threads as needed to perform tasks, and idle threads are terminated after a specified time period. The number of threads in the pool is not fixed, and the pool can shrink or grow as needed. ScheduledThreadPool: This type of thread pool creates threads to perform tasks at specified intervals or at specific times. The number of threads in the pool is fixed at creation time. SingleThreadPool: This type of thread pool creates a single thread to perform all the tasks. This is useful when tasks are sequential and need t...

Most Commonly asked Java8 Stream based Interview Question — Part 1

Image
  Hello there, I hope everyone is doing well. This article will help you to get some idea about how Stream based interview questions will be asked. Image Source :  https://javadeveloperzone.com/spring-boot/spring-boot-tutorial/ I will be sharing here some common questions asked along with its answers. In most of the questions, you will be asked to create a List of Custom Object. Example Employee Class with Employee Object having data about Employee like emp_id, salary, name, Date_of_Joining, Designation. Student Class with student Object having data about Student like student_id, name, class, Stream, Date_of_birth. The Questions will be then based on this List of Objects. Implementation Example Here I am creating an Employee class. public class EmployeeObject { int emp_id; String emp_name; int emp_age; String emp_gender; String emp_dep; int year_of_joining; double emp_salary; public EmployeeObject (int emp_id, String name, int age, S...

Marker Interface and some example for Marker Interface

Image
Marker Interface are those which has no methods or Fields in it. They are called as Empty Interface. But Implementing them will give special permission to the class to perform certain functionality. Some example for Marker Interface are Cloneable Interface Serializable Interface Remote Interface Cloneable Interface When a class implements this interface, then it has the permission to clone the object using the clone() method of Object class. If we fail to override the clone method after implementing cloneable interface then it may lead to cloneNotSupportedException. Serializable Interface Serialization is used to save the state of the Object so that it can used in some other class by deserializing. Inorder to achieve this fucntionality, the class should implement this interface. Remote Interface An object that is stored on one computer but accessed from another computer is referred to as a remote object. Therefore, we must flag an object with the Remote interface in order to make it a ...

Java Concurrent API Packages | Semaphore

Image
Semaphore is the most common type of Synchronization Object which many of us familiar with. Semaphore use the counter mechanism to control access to the shared resources. Image Source : https://javadeveloperzone.com/spring-boot/spring-boot-tutorial/ If the value of counter is greater than 0 ( > 0), then access to the resource is allowed. Access is denied if the value is equal to zero ( = 0). The count only counts when the access is permitted to the shared resource. Thus, in-order for a thread to get access to the shared resource then the semaphore must grant the permission. So first, the thread tried to access the permission from the Semaphore. How it works? If suppose the value of semaphore is greater than zero, then the thread acquires the permit and so the value of semaphore gets decremented preventing another thread to get access. Else, the thread waits till the count of semaphore is incremented from zero to get the access. Once the thread completes its process with the...

Object class Methods

Image
Object class is the most important class in Java. It is present in java.lang package. Object class is the parent class for almost all the class in java either directly or indirectly. Object class by itself provides certain methods namely. tostring() method hashCode() method equals(Object obj) method finalize() method getClass() method clone() method wait(), notify() notifyAll() methods You may wonder that some methods are used in Thread class, Map Interface etc are by default Object class's methods. Each method has specific Functionality to perform which we will discuss here. toString() Method toString() method is used to convert the Object into String representation. By Default, it is always a good practise to override the toString() method to print the String Representation of the Object. HashCode() Method The JVM creates a hashcode, or distinct number, for each object. For different items, it returns different integers. It's a frequent misperception that this method's ha...

How to Deal with Broken Images?

Image
 In day to day life, platforms like E-commerce were prone to treat millions of pictures on their website or mobile application. It’s relatively feasible that on occasion, several pictures may break up to live. When you stretch to redeem those pictures on your applications, we end up noticing broken-up pictures like the one below Source: Google This isn’t something that you might need displaying up in your application. Below are few methods that would help us to recover the broken picture to hold the UX requirements of your application. 1. Occasional Cleanup and monitoring Remove the Image from the database, if the image required is not found . The most common case where we face broken images is that the image does not exist or there is some incorrect URL pointing to the image. To avoid such type of issues, we need to check the sanity of the images at some periodic intervals. To check the sanity of the Images, we have to choose a list of images that have been recently added up to th...