Parse and Read a CSV File in Java

In Java, there are different ways of reading and parsing CSV files. Let’s discuss some of the best approaches such as OpenCSV, Super CSV etc.

[Solved] java.lang.IncompatibleClassChangeError: Implementing class

Reason When you are working with java libraries that internally depend on cglib, then it’s very normal to encounter the below error: This error is due to an incompatible version of cglib with additional jar files in your project, such as asm. Solution The solution is very easy. Just place …

Intro to JAX-RS Custom Validation

In this example, I will show the usage of ValidatorAdapter in association with @ValidateRequest annotation. For sending the request from UI, I will use ajax. You can use form submission if needed in your project. In that case, you will need @FormParam annotation to capture request parameters. Below if the …

RESTEasy File Upload – Html Form Example

In previous post, we learned about uploading a file in JAX-RS RESTEasy application where the client to upload the file was built using HttpClient library. This client was pure java client and does not have any UI associated. In this post, I am building the same uploading feature but this …

Uploading a File with RESTEasy and HttpClient

In previous posts, we learned about file downloading and building RESTful clients. Now, let move further. In this post, I am giving sample code of file upload using jax-rs resteasy. For uploading the file, httpclient library will be used instead of HTML form. I am using MultipartFormDataInput class which is …

Consuming REST APIs with RESTEasy Client

So far in this blog, we have been learning about building RESTful webservices which are server side components. In this post, we will learn to build a RESTful client for consuming the webservices written in previous posts. I will be re-using the code base written for RESTEasy + JAXB xml …

Apache HttpClient Examples for Consuming REST APIs

Apache HttpClient simplifies the interactions with RESTful APIs by supporting various HTTP methods, headers, and request configurations. This article will explore how to consume REST APIs using Apache HttpClient5 with examples. 1. Setup Before diving into implementation, we need to import the latest version of Apache HttpClient. Next, we will …

Java 8 Date Time API

Java 8 contains the new Date and Time APIs/classes (JSR-310), called ThreeTen, which will change how you have been handling dates in Java.

JAX-RS @Path URI Matching – Static and Regex URIs

Learn to use JAX-RS @Path annotation and write resource path in it for URI matching. Paths can be written in simple form (static or path parameter) or complex form (regex based). 1. JAX-RS @Path URI Matching Types JAX-RS @Path annotation is used to specify the URI on which the resources …

RESTEasy – File Download Example

RESTEasy is JBOSS provided implementation of JAX-RS specification for building RESTful Web Services and RESTful Java applications. RESTEasy works in combination with HTTP media types for providing the response in specific formats such as images, pdf or text. The core component to configure for enabling support for multiple media types …

Writing a Native Java REST Client

So far in this blog, we have been learning about building RESTful webservices which are server side components. In this post, we will learn to build a RESTful client for consuming the webservices written in previous posts. I will be re-using the code base written for RESTEasy + JAXB xml …

JSON Response with RESTEasy

Learn to use Jackson or Jettison libraries with RESTEasy to convert the API response into JSON format with example.

RESTEasy Tutorial for Beginners

RESTEasy example web application to to create REST APis using maven and tomcat server. This resteasy tutorial helps in create restful webservices.

Spring Bean Autowire by Constructor

Spring bean autowiring “byConstructor” is the recommended approach and injects dependencies into a bean by utilizing its constructor.

Spring Bean Autowire ‘byName’ Example

In Spring Framework, autowiring by name is a feature that allows developers to inject dependencies into a bean by matching the property name with the name of the target bean. This is achieved using the @Autowired annotation (Java Configuration) along with the byName attribute (XML Configuration). 1. What is Autowiring …

Spring Bean Scopes

The beans in Spring or Spring Boot can be created in six different scopes: singleton, prototype, request, session, application and websocket.

Chain of Responsibility Design Pattern

The Chain of Responsibility is known as a behavioral pattern. The main objective of this pattern is that it avoids coupling the sender of the request to the receiver, giving more than one object the opportunity to handle the request. The core logic defined by GoF is : “Gives more …

Spring 3: Timer Tasks

Timer is a utility class which is used to schedule tasks for both one time and repeated execution in spring applications. Timer is dependent on system clock

Test Spring Security Auth with JUnit

Learn to test Spring security authentication using JUnit testcase using InMemoryDaoImpl. Also learn to build fully populated authentication object programmatically and then use it in application. SecurityContextHolder Spring security is based on security context, which is kind of static in nature. This essentially means that your do not need to …

Spring View Layer Security using JSP Taglibs

So far in previous tutorials, we have learned about securing your application behind login form, custom user detail service and even method level security also. All these security implementations were on controller or model layer of MVC. Its time to add security in view layer. It is mostly needed when …

Spring Method Security with @PreAuthorize and @Secured

Spring framework has made securing your application so much easy that you only need to use some basic configurations CORRECTLY, and that’s it !! This security can be applied to multiple levels in your web application. Spring’s basic support is for these levels: URL level security Method level security Entity …

Basic Auth with Spring Security

Learn about default basic authentication commissioned by Spring security and customize its configurations such as password encodings.

Log4j Logging Levels

Learn about Log4j log levels. Log4j2 log levels example. Learn about log4j logging level order and how log level works in this log4j tutorial.

Log4j2 XMLLayout

Log4j2 comes with multiple options to create and format log files created by the framework. It can create simple log files, HTML log files or even XML log files also. In this tutorial, we will see the example for configuring log4j to produce logs in XML format. To create a …

Java NullPointerException

Java NullPointerException (NPE) is an unchecked exception and extends RuntimeException. NullPointerException doesn’t force us to use a try-catch block to handle it. NullPointerException has been very much a nightmare for most Java developers. It usually pop up when we least expect them. I have also spent a lot of time …

Comparing Performance of Java Loops

This Java article compares the performance of an ArrayList iteration using simple for-loop, enhanced for-loop, list iterator and stream API.

Java Suppressed Exceptions with Examples

Suppressed exceptions, as name suggest, are exceptions thrown in the code but were ignored somehow. If you remember try-catch-finally block execution sequence and how they return any value or exceptions, you will recall that exceptions thrown in finally block are suppressed if an exception is thrown in try block also. …

Object level lock vs Class level lock in Java

In Java, a synchronized block of code can only be executed by one thread at a time. Also, java supports multiple threads to be executed concurrently. This may cause two or more threads to access the same fields or objects at same time. Synchronization is the process which keeps all …

Java – Internal Caching in Wrapper Classes

1. Object Creation is Expensive We know to create objects in java using the new keyword. A new instance created in Java allocates the memory in the heap, so creating new objects is considered an expensive operation. To avoid this expensive object creation process, many of the frameworks have been …

Java Interview Questions and Answers

Read all the Java interview questions and answers in this article to refresh your concepts and possibly have some new ones added to the list.

Maven Enforce Minimum Java Version

Many times, we need to enforce that java build process should halt immediately if deployment environment does not have not a specific operating system, or it does not contain a minimum required java version. If you are using maven for build process, then these limitations can be easily be configured …

Maven ant plugin – Generate build.xml from pom.xml

Suppose you had created and maintained your project from maven for long time, but now you have instructions to move it to ant build environment. Well, it does not look easy, but it really is very much. All you need to use if maven ant plugin which is specifically only …

About Us

HowToDoInJava provides tutorials and how-to guides on Java and related technologies.

It also shares the best practices, algorithms & solutions and frequently asked interview questions.