JAVA DATE TIME API / NOTES</>↗Java Date Time API14 Aug 2025
To create a custom date comparator in Java, you can follow these steps: 1. Understand the Requirements A date comparator is used to sort objects based on date values. For instance, consider a User class that has a Date field (e.g., ). We’ll compare and sort User instances by that date. birthDate 2. Define a […]
UTIL PACKAGE / NOTES</>↗Util Package13 Aug 2025
The TreeMap class in Java is part of the java.util package and provides an implementation of the Map interface that keeps its keys sorted in a natural order (according to ) or a custom order (defined by a Comparator, if provided during construction)Comparable. It’s commonly used when you need to access keys in sorted order […]
NET PACKAGE / NOTES</>↗Net Package12 Aug 2025
In Java, you can encode and decode URLs using the java.net.URLEncoder and java.net.URLDecoder classes. These classes handle encoding and decoding in compliance with the application/x-www-form-urlencoded MIME type. Here’s how you can encode and decode URLs: Code Example import java.io.UnsupportedEncodingException; import java.net.URLEncoder; import java.net.URLDecoder; public class URLEncoderDecoderExample { public static void main(String[] args) { try { […]
NET PACKAGE / NOTES</>↗Net Package11 Aug 2025
Here are common ways to resolve domain names in Java, from simplest to more advanced use cases. Basic A/AAAA record lookup (IPv4/IPv6) Uses the system resolver and OS DNS settings. Returns all IPs (both IPv4 and IPv6 where available). import java.net.InetAddress; import java.net.UnknownHostException; public class DnsLookup { public static void main(String[] args) { String host […]
NET PACKAGE / NOTES</>↗Net Package11 Aug 2025
Here are the most common and reliable ways to get hostnames and IP addresses in Java (Java 21). Pick the approach that matches your runtime (desktop app, server app, behind proxy, etc.). Quick local host info Good for simple cases, but can return 127.0.0.1 if your host isn’t configured in DNS/hosts. import java.net.InetAddress; public class […]
NET PACKAGE / NOTES</>↗Net Package09 Aug 2025
Building a simple web server in Java involves creating a server socket to listen on a specific port, accepting client requests, and sending responses back to the client. Below is a basic example of building a simple HTTP server in Java. Example Code package org.kodejava.net; import java.io.*; import java.net.*; public class SimpleWebServer { public static […]