Found 2620 Articles for Java

How to Invoke Method by Name in Java Dynamically Using Reflection?

Deepti S
Updated on 18-Oct-2023 16:29:33

157 Views

The Reflection API in Java allows you to dynamically call any method using its string name. When using the java.lang.reflect API, you can load classes by name even if they aren't accessible at compile time thanks to reflection's robust mechanism. It empowers you to dynamically invoke any method using reflection and makes it possible you to retrieve all methods from a class, including private and public ones. Those who are unfamiliar with Java might find this idea strange. With no explicit code for calling the method during compilation, Java can execute a method when its name is provided as a ... Read More

How to iterate over a TreeMap in Java?

Deepti S
Updated on 18-Oct-2023 16:25:59

644 Views

With the help of the AbstractMap Class, Java's TreeMap implements the Map interface and NavigableMap. This map is sorted using either the keys' inherent ordering or a Comparator that was provided when the map was created. When working with a TreeMap in Java, the objective is to iterate via its elements. However, due to TreeMap not being a Collection, we cannot directly iterate over it using iterators. Methods Used To iterate through a TreeMap in Java, we need to utilize the TreeMap.entrySet() method. This function gives back a collection-view (SetMap.Entry>) of all the mappings that were saved in the TreeMap. ... Read More

How to Iterate HashMap in Java?

Deepti S
Updated on 18-Oct-2023 16:24:21

115 Views

(Key, Value) pairs are used to store data in Java HashMap collections. Although it is unsynchronized, it is comparable to HashTable. As a result, a HashMap can be accessed by numerous threads without encountering any troubles. Despite the fact that HashMap allows for the storage of null keys as well, there can most effective be one null key object and an infinite wide variety of null values. regarding the order of the map, this class gives no guarantees. To index the value, the key is utilised. We can store unique keys with HashMap. If we try to insert one, the ... Read More

How to iterate HashSet in Java?

Deepti S
Updated on 18-Oct-2023 16:22:29

213 Views

The Java HashSet class employs a hash table internally to implement the Set interface, which uses a HashMap instance. The class does not guarantee that the items will remain the same over time because the iteration order of the factors within the hash set is not always guaranteed. Null elements may be included in this class. The hash function provides efficient performance for fundamental operations like add, delete, contains, and size, assuming it effectively distributes the elements through the buckets. The Set interface is implemented by HashSet, which extends AbstractSet. It creates a collection using the hashing technique and saves ... Read More

How to iterate over a 2D list (list of lists) in Java?

Deepti S
Updated on 18-Oct-2023 16:03:46

626 Views

A data structure known as a 2D list or list of lists can be utilised for saving a collection of data in a two-dimensional format. A row in the 2D list is represented by each inner list in this list of lists. A 2D list could be utilised, for instance, to store the data for a chessboard, where every component in the list corresponds to a single square on the board. Methods Used A 2D list can be iterated in one of the two methods that follow − Using Loops Using iterator Method 1: Employing Loops There are ... Read More

How to Iterate LinkedHashMap in Reverse Order in Java?

Deepti S
Updated on 18-Oct-2023 16:01:17

407 Views

The LinkedHashMap serves the purpose of maintaining the precise order of element addition. It elucidates the method for accessing elements in the sequence they were inserted. In addition to storing values based on their keys, the LinkedHashMap class expands upon the functionalities of the Hash Map class and implements the Map interface. It exclusively accommodates unique elements or mappings. It affords us the flexibility to utilize various data types, such as text, float, integer, etc., for assigning keys and values. By initially reversing the elements, we can alter the order of elements in the linked hash map. Subsequently, we can ... Read More

How to Create Spring Bean in 3 Different Ways?

Harischandra Prasad
Updated on 16-Oct-2023 12:40:08

287 Views

Spring is a highly popular framework within the Java EE ecosystem. It is an open-source and lightweight framework that empowers Java developers to build reliable, scalable, and simplified business applications. The primary goal of this framework is to offer you a variety of tools for managing your business items. In contrast to conventional Java frameworks and APIs such as JSP, JDBC and Java Servlet, developing web applications is far simpler. In Spring, objects—primarily those controlled by the Spring IoC Container. It plays a significant role in the application. A Bean is nothing more than an object that a Spring Ioc ... Read More

How to Create Hyperlink in Spreadsheet using Java?

Harischandra Prasad
Updated on 16-Oct-2023 12:37:18

58 Views

Java programmers may create, edit, and display MS Office files using the widely used Apache POI API. Through its classes and methods, this open-source library developed by the Apache Software Foundation provides a variety of functions for turning user input data or files into Microsoft Office documents. Apache POI's versatility and reliability have made it a popular option among developers worldwide. Its broad capability and smooth integration make it an invaluable asset for any project needing MS Office file handling. The API's continuous updates and active community guarantee that it is always up to date with the newest file format ... Read More

How to Create Custom Class in Java?

Harischandra Prasad
Updated on 16-Oct-2023 12:32:55

234 Views

In Java, a class is a fundamental component of object-oriented programming. It serves as a blueprint or template for defining the structure and behavior of objects. A class contains both data, represented by fields or variables, and behaviors, represented by methods or functions, which manipulate that data. In Java, a custom class is a user-defined class that allows you to create objects with specific properties and behaviors tailored to your application's requirements. It serves as a blueprint or template for creating objects of that class type. Custom classes encapsulate related data and operations into a single entity, promoting code organization, ... Read More

How to Create and Setup Spring Boot Project in IntelliJ IDE?

Harischandra Prasad
Updated on 16-Oct-2023 12:29:36

82 Views

The Spring Boot framework incorporates all of Spring's capabilities and features because it is built upon the basis of Spring. Developers are drawn to it because of its effective production-ready environment, which frees them up to focus on the logic of the application rather than on setup and configuration. Microservices-based applications that are suitable for deployment in a production environment may be created quickly thanks to Spring Boot. Some of the key features of Spring Boot are − Auto-configuration − Spring Boot's standout feature is its auto-configuration capability. It analyzes the project's classpath and automatically configures the necessary beans ... Read More

Advertisements