Found 9117 Articles for Object Oriented Programming

IntFunction Interface in Java with Examples

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

817 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 of functional interfaces are Predicate, Runnable, and Comparable interfaces. The IntFunction interface is defined in the 'java.util.function' package. In this article, we are going to explore the IntFunction Interface and its built-in methods with the help of example programs. IntFunction Interface in Java The IntFunction Interface has a ... Read More

Internal Working of TreeMap in Java

Shriansh Kumar
Updated on 20-Jul-2023 17:44:35

1K+ Views

TreeMap is a class of Java Collection Framework that implements NavigableMap Interface. It stores the elements of the map in a tree structure and provides an efficient alternative to store the key-value pairs in sorted order. Internally, TreeMap uses a red-black tree, which is a self-balancing binary search tree. A TreeMap must implement the Comparable Interface or a custom Comparator so that it can maintain the sorting order of its elements otherwise, we will encounter a java.lang.ClassCastException. This article aims to explain how TreeMap works internally in Java. Internal Working of TreeMap in Java To understand the internal ... Read More

Integer.valueOf() vs Integer.parseInt() with Examples

Shriansh Kumar
Updated on 20-Jul-2023 17:05:54

859 Views

In Java, both Integer.parseInt() and Integer.valueOf() methods are used for the conversion of a String into an Integer. These static methods belong to the Integer class of java.lang package and throws a NumberFormatException if the string is not a valid representation of an integer. But wait, the question arise here is that why Java provides two methods with the same functionality. Although they are used to serve similar jobs, there exist a few distinctions between them in terms of syntax and return type. In this article, we are going to explain the difference between Integer.parseInt() and Integer.valueOf() methods with ... Read More

Integer.MAX_VALUE and Integer.MIN_VALUE in Java with Examples

Shriansh Kumar
Updated on 20-Jul-2023 17:03:12

9K+ Views

The Integer class of Java provides two constants named Integer.MAX_VALUE and Integer.MIN_VALUE represents the maximum and minimum possible values for an integer variable in Java. The actual value of Integer.MAX_VALUE is 231 -1 which is equivalent to 2147483647 and the actual value of Integer.MIN_VALUE is -231 which is equivalent to -2147483648. For our convenience, instead of writing this big whole number in our program, we use their constant representation. This article aims to explore the utility and how to use Integer.MAX_VALUE and Integer.MIN_VALUE in our Java programs. Examples of Integer.MAX_VALUE and Integer.MIN_VALUE in Java In this section, we ... Read More

IntConsumer Interface in Java with Examples

Shriansh Kumar
Updated on 20-Jul-2023 17:00:36

476 Views

The IntConsumer Interface is a functional interface that represents an operation that accepts a single int-valued argument and returns no result. This is the int-consuming primitive specialization of the Consumer interface. Here, the functional interface means an interface that contains only a single abstract method and exhibits single functionality. Some examples of functional interfaces are Predicate, Runnable, and Comparable interfaces. In this article, we are going to explore the IntConsumer Interface and its built-in methods with the help of example programs. IntConsumer Interface in Java In Java, the IntConsumer Interface provides only two methods: ... Read More

Instance Control Flow in Java

Shriansh Kumar
Updated on 20-Jul-2023 16:53:21

695 Views

Instance control flow is a fundamental concept of Java programming language that a beginner, as well as an experienced one, must know about. In Java, the instance control flow is a step by step process of execution of members lies within the class. The members that exist inside a class include instance variables, instance methods, and instance blocks. Whenever we execute a Java program, JVM looks for the main() method first and then, it loads the class into memory. Moving further, the class gets initialized and its static block, if any, is executed. After the execution of the ... Read More

Inner Class And Anonymous Inner Class that Implements Runnable in Java

Shriansh Kumar
Updated on 20-Jul-2023 16:50:54

807 Views

In Java, the Inner class and Anonymous inner class are two types of Nested classes. Here, nested class means a class within another class. The inner class is a nested class defined without the static keyword, i.e., the inner class is a non-static nested class. The type of nested inner class that has no name is called as anonymous class. The Runnable Interface is a way of creating threads in Java multithreading. Java provides the functionality of multithreading to perform multiple operations simultaneously. In it, the operation gets divided into multiple smaller parts called a thread. Let's explore ... Read More

Iterate TreeMap in Reverse Order in Java

Shriansh Kumar
Updated on 17-Apr-2025 10:48:26

1K+ Views

The TreeMap is a class of Java Collection Framework that implements NavigableMap Interface. It stores the elements of the map in a tree structure and provides an efficient alternative to store the key-value pairs in sorted order. In other words, it always returns the elements in ascending order. However, Java provides a few ways to iterate through the TreeMap in descending order. In this article, we are going to explore the ways of iterating TreeMap in Reverse order. How to Iterate TreeMap in Reverse Order? In Java, we can use the following ways to print elements of TreeMap in reverse ... Read More

How to Get and Set Default Character Encoding or Charset in Java?

Shriansh Kumar
Updated on 20-Jul-2023 16:44:22

3K+ Views

In Java, the default character encoding is determined by the 'file.encoding' which is a system property and is usually set by the operating system or the JVM. However, sometimes a Java programmer may need to get or set the default character encoding programmatically for various reasons. For this purpose, the 'java.nio.charset' package provides various classes and methods. In this article, we are going to learn the different ways to get and set default character encoding or charset. Get and Set Default Character Encoding or Charset in Java First, let's discuss what is default character encoding or charset. ... Read More

How to Generate MD5 Checksum for Files in Java?

Shriansh Kumar
Updated on 20-Jul-2023 16:41:13

812 Views

Checksum is an encrypted sequence of characters that are generated with the help of various hashing algorithms like MD5 and SHA-1. The checksum is applicable for the downloadable files. Whenever we generate a checksum for files, it stays the same as long as the file does not get altered or corrupted. In this article, we are going to explore the MD5 checksum which is a hash value used to verify the integrity of files. It is a way of ensuring that the file one has downloaded or transferred is exactly the same as the original one. To generate MD5 checksum ... Read More

Advertisements