java.time

java.time is Java’s modern date and time API, introduced in Java 8 to replace the older java.util.Date and java.util.Calendar classes. It’s part of the Java Time API (JSR-310) and is more consistent, immutable, and thread-safe. Let me walk you through the main classes with examples. 1. LocalDate – Date without time Represents a date…

0 Comments

default methods and static methods in interface

In Java 8, interfaces were enhanced significantly with the introduction of default methods and static methods. Earlier, interfaces could only declare abstract methods (implicitly public abstract) and constants (implicitly public static final). 🔹 1. Default Methods in Interfaces A default method is a method in an interface that has a body and uses the…

0 Comments

Iterator in Java

🔹 What is an Iterator? An Iterator in Java is an object that allows you to traverse (iterate) through a collection (like ArrayList, HashSet, etc.) one element at a time.It is part of the java.util package and is the standard way to loop through collections when you don’t want to use traditional loops. 🔹…

0 Comments

Map in Java

In Java, a Map is a data structure that stores key–value pairs. Each key is unique, but values can be duplicated. Maps are part of the Java Collections Framework, but they are not a subtype of Collection. Instead, they are their own interface in java.util. Here’s a breakdown: Map Interface Found in java.util. Represents…

0 Comments

List in Java

In Java, a List is an ordered collection (also called a sequence) that allows duplicate elements. It is part of the Java Collections Framework and is defined in the java.util package. 🔑 Key Points about Lists They maintain insertion order. Can contain duplicate elements. Elements can be accessed via index (zero-based). Lists are dynamic…

0 Comments

Set in Java

In Java, a Set is a collection that: Stores unique elements (no duplicates allowed). Does not guarantee order (depending on the implementation). Is part of the Java Collections Framework (java.util package). 🔑 Main Set Implementations 1. HashSet Backed by a hash table. Elements are unordered. Fast for add(), remove(), contains() (O(1) on average). import…

0 Comments

Date in Java

In Java, handling dates and calendars can be done using different APIs depending on which version of Java you’re working with: ✅ Modern Approach (Java 8 and later) Java 8 introduced the java.time package (JSR-310), which provides a much better and cleaner API for date and time handling. Common Classes: LocalDate → Date without…

0 Comments

StringTokenizer Random Scanner Properties UUID in Java

1. StringTokenizer Used to split strings into tokens based on delimiters.(Note: It’s a legacy class; String.split() or Scanner is usually preferred.) import java.util.StringTokenizer; public class Example { public static void main(String[] args) { String text = "Java,Python,C++"; StringTokenizer st = new StringTokenizer(text, ","); while (st.hasMoreTokens()) { System.out.println(st.nextToken()); } } } import java.util.StringTokenizer; public class…

0 Comments

HttpClient in Java

In Java 11, HttpClient was introduced as part of the java.net.http package, providing a modern, fully asynchronous, and flexible HTTP client API to replace the older HttpURLConnection. It supports HTTP/1.1, HTTP/2, synchronous and asynchronous requests, and built-in support for handling JSON, time-outs, redirects, and authentication. Here’s a detailed overview and examples: 1. Creating an…

0 Comments

New String Methods in Java 11

1. isBlank() Checks if a string is empty or contains only whitespace characters. String s1 = " "; String s2 = "Hello"; System.out.println(s1.isBlank()); // true System.out.println(s2.isBlank()); // false String s1 = " "; String s2 = "Hello"; System.out.println(s1.isBlank()); // true System.out.println(s2.isBlank()); // false Difference from isEmpty():isEmpty() only checks if the length is 0. isBlank()…

0 Comments

End of content

No more pages to load