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.
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.
Use the constructor parameters wisely to reduce the number of unnecessary objects and improve the performance of ConcurrentHashMap.
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 …
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 …
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 …
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 …
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 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 contains the new Date and Time APIs/classes (JSR-310), called ThreeTen, which will change how you have been handling dates in Java.
Learn to use ResteasyProviderFactory to share data between multiple classes and interceptors in a RESTEasy based web application.
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 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 …
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 …
Learn to use Jackson or Jettison libraries with RESTEasy to convert the API response into JSON format with example.
Learn to use Jackson with RESTEasy to convert the API response into XML format with example.
RESTEasy example web application to to create REST APis using maven and tomcat server. This resteasy tutorial helps in create restful webservices.
The spring bean autowiring functionality has four modes. These are ‘no‘, ‘byName‘, ‘byType‘ and ‘constructor‘. Autowiring can be in classes with @Autowired.
Spring bean autowiring “byConstructor” is the recommended approach and injects dependencies into a bean by utilizing its constructor.
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 …
Bean autowiring by Type instructs the Spring IoC container to inject a bean of the same type as the property into which it is being injected.
Explore the Spring bean lifecycle, post-initialization and pre-destruction callbacks, the best practices and potential pitfalls with examples.
The beans in Spring or Spring Boot can be created in six different scopes: singleton, prototype, request, session, application and websocket.
Learn to design a good custom key class for HashMap. As a rule, always honor the hashcode and equals contract, and make the class immutable.
Learn to read small and large files from the filesystem using the Java NIO APIs Path, FileChannel, ByteBuffer and MappedByteBuffer.
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 …
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
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 …
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 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 …
Learn about the contract that spring security expects from UserDetailsService and PasswordEncoder, initial defaults and basic customizations.
Learn about default basic authentication commissioned by Spring security and customize its configurations such as password encodings.
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 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 (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 …
In this Java exception handling tutorial, learn a few important best practices to write robust application code which is error-free as well.
Using the entrySet() specifically is more powerful and yields better performance than using the keySet() for iteration over a HashMap in Java.
We can detect the infinite loop in a LinkedList using “Floyd’s Cycle-Finding Algorithm” or Hare and Tortoise approach.
This Java article compares the performance of an ArrayList iteration using simple for-loop, enhanced for-loop, list iterator and stream API.
Learn about Spring IoC container, how it has been implemented using ApplicationContext, creating it programmatically and accessing the beans.
Dependency injection is a specific implementation of IoC where dependencies are injected into the component by the IoC container (Spring in this case).
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. …
In Java Concurrency, until we have a particular reason, it is always recommended to implement the Runnable interface to create new threads.
Learn the differences between sleep() and wait() methods in Java. Learn when o use which method and what effect they bring in Java concurrency.
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 …
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 is passed by value and not pass-by-reference. If it had been pass-by-reference, we should have been able to C like swapping of objects.
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.
Learn to create a new Maven project in IntelliJ, run commonly used Maven commands and fix Maven issues in IntelliJ with examples.
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 …
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 …
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.