JUnit Mockito doReturn Example

In this post, I will be showing one of the most widely used and popular JUnit Testing Mocking framework – Mockito. Mockito is one of the widely used testing API for Java. I am going to show you how to work with doReturn() and when to use it for testing your Java class using Junit.

jQuery toggle() animation example

This example shows how to use jQuery toggle() function to show or hide a section inside a paragraph. So by clicking on a button the section will be displayed or hidden using the jQuery toggle() function.

Exception Handling Best Practices in Java

I am going to tell you what are the best practices for handling exceptions in Java applications. An exception is an event that occurs during the execution of a program that disrupts the normal flow of the program and the program terminates abnormally. Types of Exception – the exception can be either a checked exception or an unchecked exception.

Adding DropDown or ComboBox dynamically using jQuery

This tutorial will show you how we can create combobox using jQuery. We will also alert the value when we select the item from the combobox or dropdown.

EhCache Implementation Using Spring Boot Framework

EhCache In this tutorial I am going to explain you how to use EhCache in application with Spring Boot framework. Caching mechanism improves application’s performance by loading the repeated data from the cache instead of fetching it from persistent storage, thus reducing the network round trips. The terms “buffer” and “cache” tend to be used interchangeably; note however they represent…

Logging Best Practices using Log4j

Log4j is a logging library for Java applications and the purpose of inserting log statements into the code is a low-tech method for debugging it. It may also be the only way because debuggers are not always available or applicable. This is often the case for distributed applications.

Callable and Future in Java

Here I am going to give you an example on Callable and Future in Java. public interface Callable<V> A task that returns a result and may throw an exception. Implementors define a single method with no arguments called call. The Callable interface is similar to Runnable, in that both are designed for classes whose instances are potentially executed by another…

SOAP Fault handling using Exception in JAX-WS webservice

This tutorial will show you how we can generate SOAP fault error code and message using Exception handling in SOAP based JAX-WS webservice. For this tutorial we will create a standalone project in Eclipse. If you already have an idea on how to create a maven project in Eclipse will be great otherwise I will tell you here how to…

Log4j Configurations – Controlling Logging to Multiple Files

Introduction The purpose of inserting log statements into the code is a low-tech method for debugging it. It may also be the only way because debuggers are not always available or applicable. This is often the case for distributed applications. Features of Log4j We can enable logging at runtime without modifying the application binary. We can control the behavior of…

Sanitize JSON using Java

Introduction Here I am going to tell you how to sanitize JSON (JavaScript Object Notation) string using Java program. Given JSON-like content, convert it to valid JSON. The OWASP JSON Sanitizer Project is a simple to use Java library that can be attached at either end of a data-pipeline to help satisfy Postel’s principle: be conservative in what you do,…