JAVA DATE TIME API / NOTES</>↗Java Date Time API08 Aug 2025
Here are simple and reliable ways to check whether a date falls on a weekend in Java. Prefer the modern java.time API (Java 8+), which is clearer and thread-safe. Using LocalDate (recommended) import java.time.DayOfWeek; import java.time.LocalDate; public class WeekendChecker { public static boolean isWeekend(LocalDate date) { DayOfWeek dow = date.getDayOfWeek(); return dow == DayOfWeek.SATURDAY || […]
JAVA DATE TIME API / NOTES</>↗Java Date Time API07 Aug 2025
In Java, you can convert between java.util.Date and java.time.LocalDateTime using the java.time API introduced in Java 8. Here’s how you can perform the conversions: 1. Converting Date to LocalDateTime You need to use java.time.Instant and java.time.ZoneId to make this conversion. Here’s the process: package org.kodejava.datetime; import java.time.LocalDateTime; import java.time.ZoneId; import java.util.Date; public class DateToLocalDateTimeExample { […]
JAVA DATE TIME API / NOTES</>↗Java Date Time API06 Aug 2025
You can calculate date differences in Java using the ChronoUnit enum from the java.time package. The ChronoUnit class is used to measure the amount of time between two temporal objects (e.g., LocalDate, LocalDateTime, etc.) in terms of specific time units like DAYS, MONTHS, YEARS, etc. Here’s an example of how to calculate the difference between […]
IO / NOTES</>↗IO05 Aug 2025
To read a binary file into a byte array in Java, you can use various ways such as Files.readAllBytes(), FileInputStream, or DataInputStream. Below is an explanation of the most common methods. Using Files.readAllBytes() (Java NIO) This is the simplest and most efficient way if you’re using Java 7 or later. The Files.readAllBytes() method reads all […]
PLANTUML / NOTES</>↗PlantUML04 Aug 2025
PlantUML is a powerful tool to create class diagrams that help in visualizing and designing object-oriented software. Below is a comprehensive guide to creating class diagrams with PlantUML for clear object-oriented design. 1. What is PlantUML? PlantUML is a text-based tool for creating UML (Unified Modeling Language) diagrams. It uses simple plain-text descriptions to generate […]
JAVA DATE TIME API / NOTES</>↗Java Date Time API03 Aug 2025
In Java (starting from Java 8), you can format dates using the DateTimeFormatter class, which provides an easier and more modern approach to date and time formatting. This class is part of the java.time.format package and works seamlessly with the java.time API (e.g., LocalDate, LocalDateTime, ZonedDateTime). Here’s how you can format dates with DateTimeFormatter: Example […]