STREAM API / NOTES</>↗Stream API06 Feb 2025
To add an object to the beginning of a list using Java Streams, we typically cannot directly prepend an object in a stream-friendly way because Streams themselves are immutable and don’t directly modify the original collection. However, we can achieve this by creating a new list with the desired order. Here’s how we can approach […]
JAVA DATE TIME API / NOTES</>↗Java Date Time API07 Sep 2024
You can get the number of each day (Monday, Tuesday, etc.) for a specific month in Java using the java.time package introduced in Java 8. In the following code snippet we will use a loop to iterate the dates in the month. The number of loop is equals to the number of days in the […]
JAVA 9 / NOTES</>↗Java 922 Jul 2024
Java 9 introduced the ProcessHandle API, which allows us to interact with and retrieve information about native processes. Here’s how we can use ProcessHandle to get information about operating system processes: We can list all the processes currently running on the system and print their details: package org.kodejava.example.lang; import java.time.Duration; import java.time.Instant; public class ProcessHandleExample […]
STREAM API / NOTES</>↗Stream API21 Jul 2024
If we have a list of objects, and we want to sum a BigDecimal property of these objects, we can achieve this using the Java Stream API. This API provides a clean and efficient way to process collections of objects. To sum the BigDecimal amounts, you can use the map and reduce methods of the […]
JAVA DATE TIME API / NOTES</>↗Java Date Time API18 Jul 2024
In the following code snippet we will see hot to change a date from one format to another format. For example from 2024-11-04 to 04-Nov-24 format in Java. We can use the DateTimeFormatter class from the java.time.format package to do the conversion. The steps are: Parse the original date string. Format it to the desired […]
JDBC / NOTES</>↗JDBC15 Jul 2024
In this post, we will learn how to update records in a database using the Java Database Connectivity (JDBC) API. JDBC is a Java API which is used to connect and execute query in the database. We will be working with an MS Access database file named musicdb.accdb for this example. Our goal is to […]