Writing Junit Test on Java Thread

In this tutorial you will see how to write test case on Java thread using junit. Writing junit to test thread in Java will show an example on single threaded environment.


Java 8



It is advisable to structure the code in such a way so that the code could be easily tested on several distinct areas:

  1. the code that launches the thread and wait for result.
  2. the worker code that runs in the thread.
  3. the concurrency issue may occur when multiple threads are active.

Continue reading “Writing Junit Test on Java Thread”

Future or Past Date in Java

This tutorial will show you how can you calculate either future date from a particular date to “plus a number of given days” or past date from a particular date to “minus a number of given days”.

Future or past date calculation may be required for various purposes such as to calculate the age of a person on future date or on past date.

I will show you this calculation in Java language. If you need to calculate in PHP please read here https://www.roytuts.com/calculate-future-or-past-date-in-php/ Continue reading “Future or Past Date in Java”

Solving Josephus problem using Java

The Josephus problem (or Josephus permutation) is a theoretical problem related to a certain counting-out game.

People are standing in a circle waiting to be executed. Counting begins at a specified point in the circle and proceeds around the circle in a specified direction. After a specified number of people are skipped, the next person is executed. The procedure is repeated with the remaining people, starting with the next person, going in the same direction and skipping the same number of people, until only one person remains, and is freed.

For more information you can read https://en.wikipedia.org/wiki/Josephus_problem

Continue reading “Solving Josephus problem using Java”

Creating Custom HashMap in Java

Here we will see how to create a custom HashMap uaing Java language. We have seen the built-in implementation of HashMap in Java API and we know how HashMap works and its usages.

The intention of this example is not to create a rigid HashMap that provides the same functionalities as Java API provides but to give an idea how you can create your own HashMap.

We know also how HashMap works internally and here also we will look into the internal works of HashMap with same basic functionalities.

Continue reading “Creating Custom HashMap in Java”

Sort large File using Java

Here we will see how the huge volume of data in a file can be sorted easily.

You can use tutorial Generate File with Random Content in Java to generate a large text file.

For a smaller file whose contents fit into the memory, sorting the file programmatically can often be as simple as reading the contents of the file into memory and then writing the sorted data back into a file. But a file that is gigabytes in size (for example, 10GB in size), reading all the data into memory as required by traditional programmatic sorting may not be possible for most of the contexts.

Continue reading “Sort large File using Java”