Java Programming

Java 8 – Format LocalDate to dd/MM/yyyy

Introduction Java 8 introduced the java.time package, which provides a modern and flexible way to work with dates and times. One common requirement is formatting a LocalDate object to a specific string format, such as dd/MM/yyyy. This format is widely used, particularly in countries that follow the day-month-year convention. In this guide, we’ll explore how …

Java 8 – Format LocalDate to dd/MM/yyyy Read More »

Java 8 – Get the Current Timestamp

Introduction Java 8 introduced the java.time package, which provides a modern and robust API for working with dates and times. A common requirement in many applications is obtaining the current timestamp, which represents the current date and time in a precise and standardized format. In Java 8, getting the current timestamp is straightforward, and it …

Java 8 – Get the Current Timestamp Read More »

Java 8 – Convert Instant to LocalDateTime

Introduction Java 8 introduced the java.time package, providing a modern way to work with dates and times. One common task is converting an Instant to a LocalDateTime. An Instant represents a specific moment in time, typically used for timestamps, while LocalDateTime represents a date and time without any time zone information. To convert an Instant …

Java 8 – Convert Instant to LocalDateTime Read More »

Java 8 – How to Add Days to the Current Date

Introduction Java 8 introduced the java.time package, which provides a modern and powerful way to work with dates and times. One common task in many applications is adding a certain number of days to the current date. Whether you’re calculating a future deadline, scheduling events, or determining expiry dates, Java 8 makes this easy with …

Java 8 – How to Add Days to the Current Date Read More »

Java 8 – Convert LocalDateTime to Timestamp

Introduction In Java 8, the java.time package introduced new classes to handle date and time more effectively. One common requirement is converting a LocalDateTime object to a Timestamp object, which is useful when working with databases that expect a Timestamp format. The Timestamp class is part of the older java.sql package, and converting between these …

Java 8 – Convert LocalDateTime to Timestamp Read More »

Java 8 – Difference Between Two Dates

Introduction Java 8 introduced the java.time package, which offers a modern and intuitive way to handle dates and times. Calculating the difference between two dates is a common task in many applications, whether you’re measuring the time elapsed between two events or calculating someone’s age. The java.time API makes these calculations straightforward and accurate, allowing …

Java 8 – Difference Between Two Dates Read More »

Java 8 – How to Get the Start and End of the Day

Introduction Java 8 introduced the java.time package, which provides a modern and intuitive way to handle dates and times. One common task in date and time manipulation is determining the start and end of a day. The LocalDate, LocalTime, and LocalDateTime classes in Java 8 make it easy to calculate the exact beginning and end …

Java 8 – How to Get the Start and End of the Day Read More »

Java 8 – Convert Between Time Zones

Introduction Java 8 introduced the java.time package, which provides a modern, robust API for working with dates and times. One common task when working with date and time is converting between different time zones. Java 8 makes this straightforward with classes like ZonedDateTime, ZoneId, and OffsetDateTime. These classes allow you to seamlessly convert date and …

Java 8 – Convert Between Time Zones Read More »

Java 8 – Convert LocalDateTime to LocalDate

Introduction Java 8 introduced the java.time package, which provides a modern approach to handling dates and times. The LocalDateTime class represents both date and time, while the LocalDate class represents just the date without any time information. There are scenarios where you may have a LocalDateTime object but need to extract just the date part. …

Java 8 – Convert LocalDateTime to LocalDate Read More »

Java 8 – Convert LocalDate to LocalDateTime

Introduction Java 8 introduced the java.time package, which offers a modern and intuitive approach to handling dates and times. The LocalDate class represents a date without time, while the LocalDateTime class represents both date and time. In many scenarios, you may start with a LocalDate and need to convert it to a LocalDateTime by adding …

Java 8 – Convert LocalDate to LocalDateTime Read More »

Java 8 – Add or Subtract Days, Months, and Years

Introduction Java 8 introduced the java.time package, which provides a modern approach to handling dates and times. One common task in date manipulation is adding or subtracting days, months, or years from a given date. The LocalDate, LocalTime, and LocalDateTime classes in Java 8 make these operations straightforward and intuitive. In this guide, we’ll explore …

Java 8 – Add or Subtract Days, Months, and Years Read More »

Java 8 – How to Compare Two Dates

Introduction Java 8 introduced the java.time package, which includes modern classes for handling dates and times, such as LocalDate, LocalTime, LocalDateTime, and ZonedDateTime. Comparing two dates is a common task in many applications, whether you’re checking if one date is before or after another, or if two dates are the same. The java.time API makes …

Java 8 – How to Compare Two Dates Read More »

Java 8 – How to Get the Current Date and Time

Introduction Java 8 introduced the java.time package, which includes new classes for handling dates and times in a more robust, immutable, and thread-safe manner. These classes, such as LocalDate, LocalTime, and LocalDateTime, provide a modern approach to date and time manipulation, replacing the older java.util.Date and java.util.Calendar classes. Whether you need the current date, time, …

Java 8 – How to Get the Current Date and Time Read More »

Java 8 – List All Files in a Directory

Introduction Java 8 introduced the Files class with several powerful methods for file and directory manipulation. One common task is listing all files in a directory, which can be done efficiently using the Files.list() method. This method returns a stream of Path objects, allowing you to process files in a functional and declarative style using …

Java 8 – List All Files in a Directory Read More »

Java 8 – Handle Null Values in Streams

Introduction Java 8 introduced the Stream API, providing a powerful and functional approach to processing collections of data. However, one common challenge when working with streams is handling null values effectively. Null values can cause unexpected NullPointerExceptions, which can lead to runtime errors if not properly managed. Fortunately, Java 8 provides several strategies to handle …

Java 8 – Handle Null Values in Streams Read More »

Scroll to Top