Found 2616 Articles for Java

How to find the Entry with largest Value in a Java Map

Shriansh Kumar
Updated on 20-Jul-2023 15:51:32

965 Views

In Java, Map is an object that stores its element in key-value pairs. The Key is an object that is used to fetch and receive value associated with it. The keys must be unique, but the values associated with them may be duplicated depending on the type of Map class we use. There are several approaches to find an entry with the largest key in Java map and these approaches also depend on the type of Map class we are working with. In this article, we will discuss how to find the entry with largest key in HashMap ... Read More

How to Find Prime and Palindrome Numbers using Multi-Threading in Java?

Shriansh Kumar
Updated on 20-Jul-2023 15:37:02

381 Views

Multithreading is a feature of the Java programming language that allows us to perform multiple operations simultaneously. In it, the operation gets divided into multiple smaller parts called a thread. Each thread performs one independent task without affecting the other thread's performance. The main benefit of multithreading is the optimal use of resources like CPU and it boosts the execution time of allocated operations. Finding prime and palindrome numbers are two of the basic programming task that every beginner programmer perfroms. However, in this article, we are going to do the same task in an exciting way. We will ... Read More

How to find Max Memory, Free Memory and Total Memory in Java?

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

726 Views

Memory management is an important aspect of any Java application. Having the knowledge of how much memory is available, how much is used and how much is free may help you to optimize your code and avoid performance issues or memory leaks. This article aims to help in finding max memory, free memory and total memory that are a crucial part of Java Heap. Note that the amount of memory allocated to a Java program depends on the environment. Java Program to find Max Memory, Free Memory and Total Memory Java provides the following methods and classes that ... Read More

How to find duplicate elements in a Stream in Java

Shriansh Kumar
Updated on 19-Jul-2023 19:06:38

7K+ Views

Finding duplicate elements in a stream of data is one of the common questions that is asked in Java interviews and even in the exams of many students. Java provides several ways to find duplicate elements, we will focus mainly on two ways: the first one is by using Set of Java Collection Framework and the other one is by using the built-in method of stream named Collections.frequency(). Java Program to find duplicate elements in a Stream Before discussing the different ways to get duplicate items from a collection of data, it is necessary to ... Read More

How to Find User Defined Objects From LinkedHashSet in Java?

Shriansh Kumar
Updated on 19-Jul-2023 18:49:36

150 Views

LinkedHashSet is a class of Java Collection Framework that implements the Set interface and extends the HashSet class. It is a linked list type of collection class. It stores and returns the objects in the order in which they were inserted, therefore it does not allow duplicate objects. In this article, we will use the built-in method 'contains()'' to find user-defined objects from LinkedHashSet. The user-defined objects are created with the help of constructors. Java Program to get User-Defined Objects from LinkedHashSet Let's have a brief introduction of two important in-built methods that we will use in our ... Read More

How to Find the Number of Arguments Provided at Runtime in Java?

Shriansh Kumar
Updated on 19-Jul-2023 18:40:22

437 Views

In Java, one way of passing arguments at runtime is by using the command line or terminal. While retrieving those values of command line arguments, we may need to find the number of arguments provided by the user at runtime which is possible with the help of length property. This article aims to explain the process of passing and getting the number of arguments provided by user with the help of example programs. Getting the Number of Arguments provided by User at Runtime Before finding the number of command line arguments, our first step is ... Read More

How to determine length or size of an Array in Java?

Shriansh Kumar
Updated on 19-Jul-2023 18:26:08

954 Views

In Java, one of the convenient ways to determine the length or size of an array is by using its length property. It counts the number of elements stored in an array and returns the count. Finding the length of an array is one of the common yet crucial operation as it is used to find the number of elements of an array, append new elements into it and retrieve stored items. This article aims to explain the various ways to get the length or size of an array. Java Program to determine the length or size of an Array ... Read More

How to Create TreeMap Objects using Comparable Interface in Java?

Shriansh Kumar
Updated on 19-Jul-2023 18:11:04

179 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. Note that while creating objects of TreeMap we need to use the comparable interface so that we can maintain the sorting order of its elements. In this article, we are going to discuss a few Java programs to create TreeMap objects using comparable interface. Java Program to create TreeMap Objects using Comparable Interface Before jumping to the Java program ... Read More

How to Create Your Own Annotations in Java?

Shriansh Kumar
Updated on 19-Jul-2023 18:07:51

393 Views

When we start learning Java, we often wonder about symbols like @override and @inherited. They are a special kind of tag termed as Annotations that can be applied to classes, methods, fields, parameters, and other elements of the code. Java provides support for some built-in annotations, however, we are allowed to create our own annotations too. In this article, we are going learn how to create and use our own custom annotations. Creating Custom Annotations in Java Before creating our own annotations, let's familiarize ourselves with the basics of annotations in Java. Annotations They are ... Read More

How to Fix int cannot be dereferenced Error in Java?

Shriansh Kumar
Updated on 19-Jul-2023 17:56:33

4K+ Views

"int cannot be dereferenced", a common error in Java that may occur while converting a variable of integer type into String or while comparing it with other primitive type variables. It might be difficult to debug for a beginner programmer, but once we get the alternative ways of converting and comparing integers, it will become a piece of cake for us. Try to stick with us till the end of this article to find the reasons and possible solutions for fixing the 'int cannot be dereferenced error'. How to Fix int cannot be dereferenced Error in Java ... Read More

Advertisements