Java ExecutorService Examples To Create Thread Pool

Java ExecutorService Examples To Create Thread Pool

Table Of Content Introduction Java ExecutorService Implementations Creating ExecutorService Creating with Executors Factory Methods Directly create an ExecutorService ExecutorService Usage execute(Runnable) submit(Runnable) submit(Callable) invokeAny() invokeAll() 1. Introduction Java ExecutorService is a framework which simplifies the creation of ThreadPool in Java and allows the execution of the task concurrently in asynchronous mode.  It accepts both Runnable and …

Read More

How to split a string in java or split by period/dot in java?

How to split a string in java or split by period/dot in java?

To splits a string in java into multiple Strings given the delimiter that separates them use java method split(regex). The returned object is an array which contains the split Strings. We can also pass a limit parameter split(regex,limit) to the number of elements in the returned array. If we pass 0 as a limit, then the method …

Read More

How to check if Key or Value exists in a Map ?

How to check if Key or Value exists in a Map ?

In this tutorial we will see how to check if Key or Value exists in a Map. Map or HashMap is the java collection class which stores data in Key-Value pair. Java collections is a set of classes and interfaces that implement commonly reusable collection data structures. To check if Key or Value exists in a Map, Map or …

Read More

How to get user home directory in java for all OS?

How to get user home directory in java for all OS?

How to get user home directory in java is the common question arises while creating Java/Swing GUI applications. You can get home directory of user using System.getProperty(“user.home”) function. Below java code shows you how to get User home directory. This code will work on Java 1.8 for all OS. Output: There is a bug#JDK-6519127 which …

Read More

How to convert java.util.Date from java.time.LocalDate?

How to convert java.util.Date from java.time.LocalDate?

The following Java code snippet shows how to convert java.util.Date from java.time.LocalDate  and vice versa. In the first part of the code snippet we convert java.util.Date from java.time.LocalDate and back to LocalDate object. In the second part we convert java.time.LocalDate from java.util.Date and back to java.util.Date object.

Read More

How to get Free, Used and Total Memory in Java ?

How to get Free, Used and Total Memory in Java ?

As you know that Java does the automatic garbage collection which you need not worry about. However sometime you want to know how large the java heap space is and how much of it is left. Information about Free, Used and Total memory in java can be used for checking your code efficiency. To obtain …

Read More

How to convert String to Int in Java ?

How to convert String to Int in Java ?

To convert String to Int in Java, you can use the below methods of Integer class. Methods to convert String to Int 1) Integer.parseInt() code example /** * Created on Nov 19, 2016 Copyright(c) https://kodehelp.com All Rights Reserved. */ package com.kodehelp.java.lang; /** * @author https://kodehelp.com */ public class ConvertStringToInt { public static void main(String args[]){ …

Read More

How to generate pseudorandom numbers in Java ?

How to generate pseudorandom numbers in Java ?

In this post we will see how to generate pseudorandom numbers in Java. Before that we will see what is Random numbers. Random numbers are the numbers that occur in sequence such that the values are uniformly distributed over a defined interval or set, which is impossible to predict future values based on present and …

Read More

What is the difference between HashTable and HashMap in Java?

What is the difference between HashTable and HashMap in Java?

Both HashTable and HashMap are java collections and implements java.util.Map interface. Difference between HashTable and HashMap is the most common interview question. Many of the candidates who face the interview struggle to answer this question. Difference between HashTable and HashMap in Java Thread Safe: HashTable is thread-safe and can be shared between multiple threads but …

Read More

How to Sort a Map by key in Java?

How to Sort a Map by key in Java?

Here we will see how to sort a Map by key in java. There are two ways to sort a Map by Key –   First Approach Second Approach

Read More

How to write Bubble Sort in Java ?

How to write Bubble Sort in Java ?

We all have learnt sorting techniques in our college academic curriculum. Out of those sorting techniques the simplest technique we learnt is Bubble Sort in Java. The Bubble sort takes an array of numbers and sort them within the array indexes in either ascending or descending order. Bubble sort is simplest of all sorting techniques …

Read More

How To Send a Plain Text EMail in Java using JavaMail API ?

How To Send a Plain Text EMail in Java using JavaMail API ?

Java Mail API is used to create your own email client. This class provides the code required to model your email client similar to Outlook, Hotmail and many others. In JavaMail you’ll find APIs and provider implementations allowing you to develop fully functional email client applications. Below java program shows you how to send a plain text …

Read More

How to use Preferences API to store application/Program configurations ?

How to use Preferences API to store application/Program configurations ?

Introduction Preferences (Java.util.pref) API is included in JDK can be used to remember and retrieve application preferences. Using this API you can manage preference data such as storing, retrieving, removing and cleaning preference data. This API is not intended to save application data. Also it reduces the burden of application developer to write the code …

Read More

How to Use File Separator to construct file path in java?

How to Use File Separator to construct file path in java?

Many java developers might have came across the code where the developer need to use file separator for the file path or directory path. Many of them are using “/” or “\” depending upon the operating system. Using the forward or backward slash is not a good practice while coding in the java, because your code may …

Read More

How to get current working directory in java?

How to get current working directory in java?

You can get current working directory using System.getProperty(“user.dir”) function. Here current working directory means the root folder of your current Java project. Below java code shows how to get current working directory of user –   References: Oracle Java Docs for System Properties

Read More