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:

Hibernate Tutorials

These tutorials have been published to help you start with persistence with Hibernate and JPA. These are updated to version Hibernate 6.x.

Mocking an In-memory JNDI DataSource

Learn to create and inject an in-memory DataSource that can be used to mock J2EE container provided JNDI DataSource without running a server.

Batch Processing with Hibernate/JPA

Learn to execute bulk SQL INSERT and UPDATE statements using Hibernate / JPA batch processing, and to configure session-specific batch sizes.

Stored Procedures with Hibernate

Hibernate provides support for executing the stored procedures and capturing their outputs using StoredProcedureQuery and ProcedureCall APIs.

Guide to Hibernate Search

Learn to configure full text and query index-based searches in Hibernate using backends like Lucene, Elasticsearch or OpenSearch.

Guide to Hibernate Interceptors

Learn to use Hibernate Interceptor for getting callbacks for persistence events and register it with Session and SessionFactory interfaces.

Guide to Pagination with Hibernate

Learn to implement and test the pagination functionality in hibernate using the HQL setFirstResult(), setMaxResults() and ScrollableResults.

Guide to Sorting using Hibernate

Learn to sort the entities fetched from the database using hibernate HQL, native SQL, Criteria queries and Comparator interface.

Deleting Entities with Hibernate

Learn to delete a single entity or a list of entities matching some criteria using hibernate native APIs and Jakarta persistence APIs.

JUnit Tutorials

This JUnit tutorial series lists down the articles written for the creation and execution of JUnit 4 and JUnit 5 tests.

Creating New Directories in Java

Learn to create a new single directory or nested directory along with parent directories in a specified path using Java IO and NIO classes.

Writing Byte[] to a File in Java

Learn to write the given byte[] into a file using different solutions. We will be using the Java NIO, Commons IO and Guava APIs that provide simple APIs for this usecase.

Java Stream Tutorials

This Java tutorial lists down the published tutorials on this blog related to Stream API, methods and its related concepts with examples.

Reading a Large File Efficiently in Java

Learn to read all lines from a large file (size in GB) in Java and avoid any performance pitfalls such as very high usage of memory or even OutOfMemoryError if the File is large enough.

Rename or Move a File or Directory in Java

Learn to rename a file or directory at a specified path or move to a new directory in Java. We will learn to use the classes from Standard IO, New IO, Guava and Commons IO.

Getting Filesystem Paths in Java

Learn the difference between path, absolute and canonical paths. Also, learn to get the path of a file in Java using standard IO and New IO classes.

Primitive Type Streams in Java

Learn to create and operate on the streams of primitive types (IntStream, LongStream and DoubleStream) in Java with examples.

Java Date Time Tutorials

The legacy Java API had been a big pain point for Java developers for quite a long time. With the release of Java 8 release (JSR-310), package java.time introduced the new immutable classes that solved the issue with the original classes. Following articles have been published to help you start with some very common …

How to Set the JVM Timezone

Learn to set the default time zone used by the JVM using an environment variable, JVM argument and TimeZone class.

Finding the Day of Week for a Date in Java

Learn to find the day of the week for a given date using the legacy Date and Calendar classes as well as the new Java 8 Date API. 1. Overview There may be a requirement to show the day of the week (Monday to Sunday) in the UI, and then …

Getting the Start and the End of a Day in Java

Learn to get the start and the end of a date using Java date API, e.g., LocalDateTime and ZonedDateTime. We may require to get this information in many cases. For example, we have to filter the events that occurred at different times in a single day based on event timestamps. …

Difference between ZonedDateTime and OffsetDateTime

Learn about ZonedDateTime and OffsetDateTime classes in Java, and what are the main differences between both classes in depth. 1. Understanding Zone Id and Zone Offsets Before jumping to the internals of the classes, let’s make sure we understand the difference between the zone identifier and zone offsets. Most programming …

Localized Date Time Formats in Java

Starting with JDK 8, we have a comprehensive date-time API containing classes such as LocalDate, LocalTime, LocalDateTime, ZonedDateTime, OffsetDateTime, and OffsetTime. These classes allow easy formatting of the date-time output via DateTimeFormatter.ofPattern(). The API also allows further customize the output based on specified Locale information to support localization and internationalization features. In …

Java 8 Date Time API

Java supports creating and modifying the date and time using primarily two packages java.time and java.util. The package java.time was part of Java 8 release (JSR-310) that introduced the new immutable classes solving the shortcomings of the legacy java.util.Date and java.util.Calendar classes. 1. Legacy Date Time API (Prior to Java …

Java Array

Arrays in Java, conceptually, are no different than in other programming languages. The java.util.Arrays class provides many useful static methods to work with arrays and perform common operations on them. 1. Array Basics 2. Array Operations 3. Searching and Sorting 4. Conversions 5. Advance Topics Happy Learning !! Sourcecode on …

Java ArrayStoreException and How to resolve it?

Learn why we get the ArrayStoreException while working with arrays in Java and how to identify the root cause and fix this error. 1. Root Cause of ArrayStoreException Java arrays are covariant and support the subtyping rules of Java, an array of type T[] may contain elements of type T …

Calculate Sum and Average of Array Items

Learn to find the sum and average of the numbers stored in an array. We will be using the Java Stream API and simple for loop to find these values. Note that the numbers in Java are represented with 8 primitives i.e. short, char, byte, boolean, int, float, long and …

Convert a List to Array and back in Java

Learn to convert a list to an array in Java and also convert a given array to a list. We will learn the conversions using the core Java APIs. 1. Converting List to Array We can use the following two approaches to convert a given list to an array. 1.1. …

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.