Shriansh Kumar has Published 324 Articles

How to add an element to an Array in Java?

Shriansh Kumar

Shriansh Kumar

Updated on 20-Jul-2023 20:10:49

19K+ Views

Array is a linear data structure that is used to store a group of elements with similar datatypes. It stores data in a sequential manner. Once we create an array we can’t change its size i.e. it is of fixed length. Adding an element to a given array is a ... Read More

How do I generate random integers within a specific range in Java?

Shriansh Kumar

Shriansh Kumar

Updated on 20-Jul-2023 20:07:50

1K+ Views

Suppose we are in a situation where we need to generate random integer numbers within a specific range through Java programs. For the given scenario, there are two distinct ways available in Java. We can use either the Random class or random() method. Let’s discuss them in the next section. ... Read More

Get Unique Values from ArrayList in Java

Shriansh Kumar

Shriansh Kumar

Updated on 20-Jul-2023 19:55:09

2K+ Views

ArrayList is a class of Java Collection Framework that implements List Interface. It is a linear structure that stores and accesses each element sequentially. It allows the storage of duplicate elements however, there are a few approaches that may help to get unique values from an ArrayList. In this article, ... Read More

How can I modify an element of a PriorityQueue in Java?

Shriansh Kumar

Shriansh Kumar

Updated on 20-Jul-2023 19:50:54

695 Views

Generally, the Queue follows the First in First out (FIFO) approach but a PriorityQueue follows a priority based approach while accessing elements. Each element of the queue has a priority associated with it. The elements are prioritized based on natural sorting order. However, we can provide custom orders using a ... Read More

Difference between SAX Parser and DOM Parser in Java

Shriansh Kumar

Shriansh Kumar

Updated on 20-Jul-2023 19:45:54

4K+ Views

Both SAX and DOM are a type of XML parser APIs. Here, API stands for Application Programming Interface and Parser is used to read and extract content from an XML document in desired format. From this line, it is clear that SAX and DOM are used to read XML documents. ... Read More

Getter and Setter in Java

Shriansh Kumar

Shriansh Kumar

Updated on 20-Jul-2023 19:35:47

2K+ Views

Getter and setter are two special methods in Java that allow accessing and modifying data members' values. They are mostly used in encapsulation and data hiding to protect our sensitive data from unauthorized access. In encapsulation, we group related data and behavior together in a class and hide the implementation ... Read More

Producer Consumer Solution using BlockingQueue in Java Thread

Shriansh Kumar

Shriansh Kumar

Updated on 20-Jul-2023 19:30:21

2K+ Views

Producer Consumer is the most common problem of Java concurrency and multi-threading. It arises during the synchronization that helps to manage multiple threads trying to access a shared resource. This article will help us to find Producer Consumer Solution using BlockingQueue in Java Thread. Producer Consumer Problem and BlockingQueue Understanding ... Read More

Program to Emulate N Dice Roller

Shriansh Kumar

Shriansh Kumar

Updated on 20-Jul-2023 19:25:03

315 Views

Suppose we have ‘N’ number of dice and we roll all of them at a time, then we need to show all the values that occurred on all dice. We have to emulate the same situation using Java programs. To solve this problem, we will use a class named ‘Random’ ... Read More

Steps to Create a Servlet

Shriansh Kumar

Shriansh Kumar

Updated on 20-Jul-2023 19:19:58

2K+ Views

Servlets are small Java modules that are used on the server side of a web connection to enhance the functionality of web server. All the methods and classes for creating a servlet are available in ‘javax.servlet’ and ‘javax.servlet.http’ packages. Hence, it is important to import them into your program before ... Read More

IntFunction Interface in Java with Examples

Shriansh Kumar

Shriansh Kumar

Updated on 20-Jul-2023 17:59:27

849 Views

In Java, the IntFunction interface is a functional interface that represents a function that accepts an integer type value as an argument and returns a result of any data type. Here, the functional interface means an interface that contains only a single abstract method and exhibits single functionality. Some examples ... Read More

Advertisements