Golang is a programming language that has gained immense popularity in recent years. One of its many features is the ability to generate random numbers of different types. In this article, we will focus on generating random Int31n type numbers in Golang. Int31n is a type of 32-bit signed integer. It is a commonly used data type in programming and is often required for a wide range of applications. Here's how you can generate random numbers of type Int31n in Golang. Step 1: Import the Math/rand Package To generate a random number in Golang, you need to import the math/rand ... Read More
Random number generation is an essential feature of many programming applications. In Golang, you can generate random numbers of different types, including Int31. In this article, we will discuss how to generate random Int31 type numbers in Golang. What is Int31 Type? Int31 is a data type in Golang that represents a signed 32-bit integer number. The Int31 type is useful when you need to generate random numbers within the range of -2147483648 to 2147483647. Generating Random Int31 Type Numbers in Golang To generate a random Int31 type number in Golang, you can use the rand.Int31() function from the math/rand ... Read More
Servlets are small java modules that are used on 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 working with the servlet. This article will guide you step by step to getting started with your first servlet application. Before moving on it is necessary to know how servlet works. Let’s discuss it briefly. Servlets The benefits of using servlets are as follows − Just like the java ... Read More
When the stack ran out of space then StackOverflowError occurs. It is a runtime error indicating that JVM has run out of resources. The main reasons for this kind of error may be: Circular references, infinite Recursion or heavy application that utilizes more memory. In this article, we will discuss the above listed reasons for StackOverflowError in the simplest way possible. StackOverflowError in Java Memory Mnagement in java Before moving to the StackOverflowError it is important to know about how memory space managed by java for a particular program or application. Every interface, class, object, variable and method of a ... Read More
Sorting and searching are the basic operations we can perform on arrays. Sorting means rearranging the elements of a given list or array in ascending or descending order whereas searching means finding an element or its index in a list. Although various algorithms are available to perform these operations, in this article, we will use a few of them to sort and search an element in java. One by one we will look at them. Approach 1: Using inbuilt methods of Arrays In this section, we will discuss the following methods that helps in sorting and searching of elements in ... Read More
In java, the subtractExact() is a static method of the class StrictMath. It is available in ‘java.lang’ package. In this article, we will discuss StrictMath and some of its inbuilt methods. We will also see the implementation of subtractExact() method and how it is different from other methods of this class. StrictMath Class in Java StrictMath is a final class that extends object class. We can use its methods without creating instance because all the methods of this class are static and we can call a static method without an object. To call a Static Mehtod Class_name.static_method_name To ... Read More
Suppose you have a sorted array with no duplicate values and from a certain index this array is rotated. You have to search for a particular element in it. If it is available in the array then return the index otherwise return -1. In this article, we will solve the given problem using two approaches Linear search and Binary search. Approach 1: Using Linear Search This approach will search for the given element in sequential manner. Algorithm Step 1 − First, declare and initialize an array named ‘araylist’ and an integer variable named ‘searchElem’ that we are going ... Read More
There are numerous ways of joining strings in java. The StringJoiner class and String.join() method are two of them. Both are used to join two or any number of strings but the difference lies in their implementation. In this article, we will try to find the differences that exist in the usage of StringJoiner class and String.join() method. StringJoiner Class It is a class available in java.util package and it is added from JDK 8. We can join multiple strings at a time. Before using, it is necessary to import it into our program using the following command ... Read More
Scanner is a class available in ‘java.util’ package used to take input from numerous sources like a file, or console. The most common source of taking input is from standard input i.e. keyboard. The scanner class has few methods to take input of primitives and strings from the keyboard. We will understand scanner class and its various methods through this article. Scanner and nextChar() The following methods of Scanner class is used to take input − nextInt() − To take integer as an input. nextLong() − To take long as an input. nextDouble() − To take double as an ... Read More
String and Arrays are two distinct things. Array is a linear data structure that is used to store group of elements with similar datatypes but a string is a class in Java that stores a series of characters. Those characters are actually String-type objects. Since strings are objects we can say that string arrays are group of string-type objects. In this article, we will understand string arrays in java and perform some operations on them. String Arrays The string array is a combination of array and string both. Therefore, it has the properties of both array and string such ... Read More