Beans Creation Scan the application to create beans Create beans and their dependencies Invoke init() Call initialization method (if configured) Defined in three different ways for different configurations Invoked once then bean and its dependencies are created Use beans in Application Using the beans in the application according to the requirements Invoke destroy() Call destroy …
WebSocket in Java
The WebSocket API is an advanced technology that makes it possible to open a two-way interactive communication session between the user’s browser and a server. With this API, you can send messages to a server and receive event-driven responses without having to poll the server for a reply. Writing a WebSocket server in Java This example shows …
How to iterate HashMap in Java
Iterate the Entry // Java program to demonstrate iteration over // Map.entrySet() entries using for-each loop import java.util.Map; import java.util.HashMap; class IterationDemo { public static void main(String[] arg) { Map<String,String> gfg = new HashMap<String,String>(); // enter name/url pair gfg.put("GFG", "geeksforgeeks.org"); gfg.put("Practice", "practice.geeksforgeeks.org"); gfg.put("Code", "code.geeksforgeeks.org"); gfg.put("Quiz", "quiz.geeksforgeeks.org"); // using for-each loop for iteration over Map.entrySet() for …
PriorityQueue in Java
A PriorityQueue is used when the objects are supposed to be processed based on the priority. It is known that a Queue follows the First-In-First-Out algorithm, but sometimes the elements of the queue are needed to be processed according to the priority, that’s when the PriorityQueue comes into play. The PriorityQueue is based on the …
Difference between LinkedList and ArrayList in Java
ArrayList and LinkedList both implement the List interface and maintain insertion order. Both are non-synchronized classes. However, there are many differences between the ArrayList and LinkedList classes that are given below.
How to Install Java on Windows 11
1. Check If Java is Already Installed java -version javac –version 2. Download Java Go to download page. 3. Install Java from downloaded .exe file 4. Configure Environment Variable Start Menu -> Search -> Edit System Environment Variables -> Environment Variable -> NEW -> Enter "JAVA_HOME" and "PATH_TO_JDK" 5. Test in Command Prompt echo %JAVA_HOME% …
Permutation – Java
What is the algorithm if we want to get the whole permutation combinations from a given array in java? I will introduce the algorithm in my own word: We take [a, b, c] as an example. We initialize an variable named as "cur", which means the current index we are concerning about how many different …
How to reverse String in java
Use the code below: // conversion from String object to StringBuffer StringBuffer sbr = new StringBuffer(str); // To reverse the string sbr.reverse();
How to convert Array to List
Plain Java public void givenUsingCoreJava_whenArrayConvertedToList_thenCorrect() { Integer[] sourceArray = { 0, 1, 2, 3, 4, 5 }; List<Integer> targetList = Arrays.asList(sourceArray); } Commons Collection public void givenUsingCommonsCollections_whenArrayConvertedToList_thenCorrect() { Integer[] sourceArray = { 0, 1, 2, 3, 4, 5 }; List<Integer> targetList = new ArrayList<>(6); CollectionUtils.addAll(targetList, sourceArray); } Guava public void givenUsingGuava_whenListConvertedToArray_thenCorrect() { List<Integer> sourceList = …
Hello World in Spring Boot
Build Maven Porject in Intellij Edit POM <?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.example</groupId> <artifactId>myproject</artifactId> <version>0.0.1-SNAPSHOT</version> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.6.1</version> </parent> <!– Additional lines to be added here… –> Adding Classpath Dependencies <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> </dependencies> Write Main and Controller Run Program