Category: JAVA

  1. Home
  2. Blog
  3. Category: JAVA

Java SE 8 parallelSort in Arrays class

Arrays class now has several new “parallel” methods to take advantage of multi-core hardware. Arrays method parallelSort can sort large arrays more efficiently on multicore systems. Lets create a very large array and use Java SE 8 Date/Time API to compare how long it takes to sort the array with methods sort and parallelSort. SecureRandom random = new SecureRandom(); // […]

Continue Reading

Bubble Sort Using JAVA

Bubble sort is a simple sorting algorithm that works by repeatedly stepping through list to be sorted, comparing each pair of adjacent items and swapping them if they are out of order. The pass through list is repeated until no swaps are needed, which indicates that the list is now sorted. Although algorithm is simple, most of the other sorting […]

Continue Reading

Create Matrix With User Input Using Java

Using 2D array to implement the matrices in java. Below example shows how to take matrix data from the user inputs and display them. package; import java.util.Scanner; public class CreateMatrix { public static void main(String[] args) { Scanner scan = new Scanner(; System.out.println(“Enter The Number Of Matrix Rows”); int matrixRow = scan.nextInt(); System.out.println(“Enter The Number Of Matrix Columns”); int […]

Continue Reading

Two-dimensional array JAVA

We can declare a two dimensional array and directly store elements at the time of its declaration as shown below: int numbers[][]={{23,45,57,24,74},{34,67,23,55,23},{34,74,24,46,78},{23, 56,87, 89,96}, {95, 03, 45, 99,56}}; Here int represents integer type elements stored into array and array name is ‘numbers’. ‘int’ is the datatype for all elements represented inside “{” and “}” braces because an array is a […]

Continue Reading

Looping Map in Java

Below code snippet shows how to loop a Map or HashMap in Java. Map<String, String> map = new HashMap<String, String>(); map.put(“1”, “Mon”); map.put(“2”, “Tue”); map.put(“3”, “Wed”); //loop a Map for (Map.Entry<String, String> entry : map.entrySet()) { System.out.println(“Key : ” + entry.getKey() + ” Value : ” + entry.getValue()); } System.out.println(“####################”); //Java 8 only, forEach and Lambda map.forEach((k,v)->System.out.println(“Key : ” + k + […]

Continue Reading

Convert HashMap To ArrayList

Two of the most used data structures used in java are HashMap and ArrayList. Inherited from different hierarchies, HashMap inherited from Map interface which represents key-value pairs form of data. ArrayList is inherited from List interface which arranges the data in sequential manner. Conversion of HashMap to ArrayList is not straight forward as there is no direct methods in HashMap which converts HashMap to ArrayList. Let’s see how to convert HashMap to ArrayList in java with examples.

Continue Reading

Java Properties File

To store come configurable attributes of an application, we sometime use .properties files. Also know as Property Resource Bundles can be used to store strings for Internationalization.It’s like storing parameters as key value pairs. Let’s see an example here. First we will create a java project, let’s name it as “javaProperties” and added few classes to it with one properties […]

Continue Reading

Resolve ConcurrentModificationException

This tutorial gives details on “ConcurrentModificationException” and how to avoid it. As per Javadoc, “ConcurrentModificationException” may be thrown by methods that have detected concurrent modification of an object when such modification is not permissible. An example, it is not generally permissible for one thread to modify a Collection while another thread is iterating over it. Let’s see things in action. Create class “” […]

Continue Reading

JAVA Environment Variables

Once JAVA is installed, our second step is to set environment variables PATH, CLASSPATH and JAVA_HOME for compiling and running of Java applications. PATH (For Windows Users)  When we launch any java program from command prompt, operating system use PATH environment variable to locate executable programs. PATH maintains a list of directories for searching executable programs such as “.exe”, “.bat” or “.com”. […]

Continue Reading
Show Buttons
Hide Buttons