SupportWriter space ↗
REFERENCE LIBRARY

References from other publishers

Republished articles with source attribution. This collection is separate from Diary Coding’s original guides and does not display ads.

Read original guides → · Editorial policy

FOR YOUR CURIOSITY

Latest notes.

UTIL PACKAGE / NOTES</>↗
Util Package07 Apr 2025

How do I provide a default value using Optional?

In Java, the Optional class provides a way to handle possible null values in a more functional style. If you’re using an Optional and want to provide a default value, you can do so using the orElse() or orElseGet() methods. Here’s an explanation and code examples for both: 1. Using Optional.orElse() The orElse() method provides […]

Wayan · 3 min read
UTIL PACKAGE / NOTES</>↗
Util Package07 Apr 2025

How do I check if an Optional has a value?

To check if a Java Optional has a value, you can use the isPresent() or isEmpty() methods: Using isPresent() This method returns true if the Optional contains a value, and false if it is empty. Optional<String> optional = Optional.of("Hello"); if (optional.isPresent()) { System.out.println("Value is present: " + optional.get()); } else { System.out.println("Value is not present."); […]

Wayan · 2 min read
UTIL PACKAGE / NOTES</>↗
Util Package07 Apr 2025

How do I create an Optional in Java?

To create an Optional in Java, you can use the Optional class, which was introduced in Java 8 as part of the java.util package. It is used to represent a value that can either exist (non-null) or be absent (null), making your code more robust and reducing the risk of NullPointerExceptions. Here are some common […]

Wayan · 3 min read
CORE API / NOTES</>↗
Core API07 Apr 2025

How do I set and read custom HTTP Headers using HttpURLConnection in Java?

To set and read custom HTTP headers using HttpURLConnection in Java, you can make use of its methods setRequestProperty to set headers and getHeaderField to read them. Here’s how you can do it: Setting Custom HTTP Headers You can set custom HTTP headers on a request using the setRequestProperty method. For example: package org.kodejava.net; import […]

Wayan · 3 min read
HTTPCLIENT / NOTES</>↗
HttpClient06 Apr 2025

How do I send a simple GET request using Java 11 HttpClient?

In Java 11, you can use the HttpClient to send HTTP requests easily. Here’s how you can send a simple GET request using HttpClient: Full Example: package org.kodejava.net.http; import java.net.URI; import java.net.http.HttpClient; import java.net.http.HttpRequest; import java.net.http.HttpResponse; public class SimpleGetRequestExample { public static void main(String[] args) { try { // Create an HttpClient instance HttpClient httpClient […]

Wayan · 3 min read
✳

Knowledge grows when shared.

Stay curious. There is always something new to learn.

Explore notes ↗
Putu Adi Guna Permana
ABOUT THE AUTHOR

Dr (C). Ir. Putu Adi Guna Permana, S.Kom., M.Kom., IPM., ASEAN Eng.

Writer and founder of Diary Coding — sharing notes, tutorials, and experiences about programming for anyone who wants to keep learning.