Move Non-Zero Array Elements to Left using Java

Introduction This examples shows how to move all non-zero elements (if any) in an array to the left and all zero elements to the right of the array using Java. Your integer array may hold zero (0) and non-zero (1, 2, 4, etc.) elements. You have a requirement to have all non-zero elements first followed by 0 elements in the…

Solving Josephus Problem using Java

Introduction The Josephus problem (or Josephus permutation) is a theoretical problem related to a certain counting-out game. The problem is described as below. 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…

Tic-tac-toe game using Java

Tic-tac-toe (also known as noughts and crosses or Xs and Os, respectively) is a paper and pencil game for two players, X and O, who take turns marking the spaces in a 3×3 grid. The player who succeeds in placing three of their marks in a horizontal, vertical, or diagonal row wins the game. Here we will see how this…

TDD – Test Driven Development

TDD or Test Driven Development is related to the test-first programming concepts of extreme programming. Test driven development where you write test before you develop a final code for your application. Life cycle of test-driven development: Write a test Run the written test Write code that corrects the failing test Clean up your code Go to step 1.

Junit Testing Spring REST Services

Introduction In this tutorial we will see how to write Junit test cases on Spring REST services. Before continue to reading this tutorial please read first Spring RESTful Webservice CRUD Example We have total four operations on this REST example. If you want you may add more operation such as find all products and apply Junit on it.

Analyze Code Quality Of Java Application Using SonarQube

Table of Contents Introduction Prerequisites Project Setup SonarQube Configuration Known Issue Source Code Introduction This tutorial will show you how to analyze code quality of Java applications using SonarQube. Maintaining the quality of code is an important part of the application and it is required to find out any bugs, issues in the developed code so that you can remove…

Creating Custom HashMap in Java

Introduction Here we will see an example on creating a custom HashMap in Java. 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…

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…

Generate File With Random Content In Java

File with Random Content This tutorial will show you how to generate file with random content in Java. I will generate random content in a text file using wordnet-random-name API in Java. You can set limit to any number of lines for the text file to hold generated random content in it. This kind of random content is a quick…

Compare Date Without Time In Java

Compare Date This tutorial shows how to compare date without time in Java between two dates. Situation may arise when you need to compare two dates in your Java applications and if you need to compare only date part without time part for accurate results then you need to first remove the time part from the actual date and perform…