Administrator

Lokesh Gupta

A fun-loving family man, passionate about computers and problem-solving, with over 15 years of experience in Java and related technologies. An avid Sci-Fi movie enthusiast and a fan of Christopher Nolan and Quentin Tarantino.

Website: https://howtodoinjava.com

Github: https://github.com/lokeshgupta1981/

Twitter: @HowToDoInJAVA

LinkedIn: https://www.linkedin.com/in/lokeshgupta1981/

My Articles:

[SOLVED] Hibernate – No row with the given identifier exists

1. Reason The ObjectNotFoundException exception is thrown when we try to load an entity in hibernate with session.load() method and entity is not found. The exception trace looks like this: 2. Solution The correct way to solve this problem is to use session.get() method. The get() method will return null …

Polymorphism in Java

Polymorphism in Java is the ability to create member functions or fields that behaves differently in different programmatic contexts.

Java Collections Interview Questions

Java collection interview questions. These questions are most asked interview questions for beginners to medium level developers in Java interviews.

Java NIO Path (with Examples)

The Path class, introduced in the Java SE 7 release, is one of the primary entry points of the java.nio.file package. If our application uses Java New IO, we should learn more about the powerful features available in this class. In this Java tutorial, we are learning 6 ways to …

Hibernate Named Query Examples

Learn to create, group and execute named HQL and named native SQL queries in Hibernate using @NamedQuery and @NamedNativeQuery annotations.

Inserting Objects with Hibernate

Learn to insert an object into the database using hibernate’s Session interface, JPA’s EntityManager and HQL Query interface with examples.

RESTEasy Basic Authentication and Authorization Tutorial

Security is an integral part of any enterprise application. Security involves two phases i.e. authentication and authorization. Authentication verifies who you are. Authorization verifies what you are authorized to do. In this post, we will learn to build role based basic authentication/ authorization security for REST APIs. Sections in this …

Apache POI: Read and Write Excel File

Learn to read and write excel files in Java using Apache POI library – with examples. Learn to add and evaluate formula cells and add color formatting also.

Java HashMap Interview Questions

HashMap interview questions and ConcurrentHashMap interview questions. Learn questions like how hashmap works, rehashing in concurrenthashmap and more.

SOLID Principles in Java with Real-World Examples

Learn SOLID principles in Java with examples. Single Responsibility Principle, Open Closed Principle, Liskov’s Substitution Principle, Interface Segregation Principle, Dependency Inversion Principle.

Jersey Hello World Example

This Jersey tutorial will help you set up the Jersey environment in your local machine and get started with a simple Hello World REST API.

RESTEasy Cache control with ETag Example

ETags or entity tags are useful HTTP headers which can help in building a super fast application by minimizing the server load on system. ETag is set to the response to the client so a client can use various control request headers such as If-Match and If-None-Match for conditional requests. …

Java Override toString() with ToStringBuilder

ToStringBuilder is a utility class provided by apache commons lang library. ToStringBuilder is a utility class provided by apache commons lang library. It provides a consistent and better control over what and how much data, an object should expose using toString() method and in which format. It can also help …

Create Windows Executable (.exe) for Java Application

Launch4j is a cross-platform tool for wrapping Java applications distributed as jars in lightweight Windows native executable files. In this post, we will learn making such an executable file for a demo java application. Step1 ) Create a java application I am creating a very basic java class which simply …

RESTEasy Bean Validation using Hibernate Validator Provider

The Bean Validation API (JSR-303) defines a meta-data model and API for bean validation based on annotations. The functionality is achieved through the resteasy-hibernatevalidator-provider component. In order to integrate, we need to add resteasy-hibernatevalidator-provider.jar and hibernate-validator.jar files to the classpath. If you are using maven the, you need to add …

How to Reload Log4j2 Configuration

Excessive logging is a common cause of performance degradation of applications. It is one of the best practices to ensure proper logging within your Java EE application implementation. However, be careful with the logging level that you enable in your production environment. Excessive logging will trigger high IO on your …

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.

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.