java

java

Create Random int,float, boolean using ThreadLocalRandom in Java

Similar to 'java.util.Random' or 'Math.random()', ThreadLocalRandom is also a Random number generator in Java. With multithreading environment, it is better to use 'ThreadLocalRandom' instead of above two.

Read
java

Java program to convert string to byte array and byte array to string

In this tutorial, we will learn how to convert string to byte array and byte array back to a string. Converting a string to a byte array is useful in many cases like IO operations.

Read
java

SortedSet in Java explanation with Example

SortedSet is a interface that extends 'Set'. You can do all set operations on its elements. Only difference is that the elements of SortedSet implemented classes are ordered. By default, all the elements are sorted in natural order.

Read
java

Java program to rotate each word in a string

The problem is to rotate each words of a String. For this we need to extract all words from the string. Following steps are used in this program to reverse each words :.

Read
java

Java program to convert octal to binary

In this tutorial, we will learn how to convert one octal number to binary in Java. But before that, let's check what is octal number and what is its relation with binary.

Read
java

Java System.nanoTime and System.currentTimeMillis

In this tutorial, we will learn two most commonly used Java System functions - System.nanoTime and System.currentTimeMillis(). Both are time related functions, i.e. to get a time from the system (not the current time ).

Read
java

Java program to print all files and folders in a directory in sorted order

In this tutorial, we will print out all files and folders of a directory in sorted order using Java. To run this program, you will have to change the directory name defined inside 'main' method. order

Read
java

Java program to find square root and cubic root of a number

Java has inbuilt methods to find square root and cube root of a number . Both of these methods are already included in the 'Math' module.

Read
java

Java program to read contents of a file using FileReader

Using 'FileReader' class, we can read contents of a file. Using this class, we can read the contents as a stream of characters. In this tutorial, I will show you one simple example to use 'FileReader' class in Java .

Read
java

Java program to read contents of a file using FileInputStream

To create a object of 'FileInputStream', we have three different ways. (i.e. three different constructors available). We can create by passing a file name , i.e. full path of the file (e.g. C://filename.txt ) or by passing a 'File' object or by passing a 'FileDescriptor' . In this example, I will show you by passing a 'File' object to the constructor.

Read