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

Record in Java

What is a Record in Java? A record is a special kind of class introduced in Java 16 (preview earlier), and fully standard from Java 16 onwards, designed to model immutable data. Think of it as a concise way to define a class whose main purpose is to store data. A record automatically provides:…

0 Comments

Stack in Java

In Java, a stack is a data structure that follows the LIFO (Last In, First Out) principle. This means the most recently added element is the first one to be removed. 1. Using java.util.Stack Java provides a built-in Stack class in java.util package. Example: import java.util.Stack; public class StackExample { public static void main(String[]…

0 Comments

Sequenced Collections

In Java 21, sequenced collections are part of the java.util package and are designed to maintain element insertion order, meaning the order in which elements were added is preserved. This is different from regular collections like HashSet or HashMap which do not guarantee order. Java 21 introduces enhancements to sequenced collections, building on previous…

0 Comments

Sealed Class in Java

1. What is a Sealed Class? A sealed class is a class that restricts which other classes or interfaces can extend or implement it. It allows you to control the inheritance hierarchy more strictly than abstract classes. Think of it like saying: “Only these specific classes are allowed to inherit from me.” 2. Why…

0 Comments

Generics in Java

🔹 What are Generics in Java? Generics allow you to write classes, interfaces, and methods where the type of data is specified as a parameter.This makes your code type-safe, reusable, and easier to read. Instead of writing separate classes/methods for different data types, you can use type parameters (<T>, <E>, <K, V>, etc.). 🔹…

0 Comments

Logging in Java

1. Using java.util.logging (built-in Java logging) import java.util.logging.Logger; import java.util.logging.Level; public class LoggingExample { private static final Logger logger = Logger.getLogger(LoggingExample.class.getName()); public static void main(String[] args) { logger.info("This is an info message"); logger.warning("This is a warning message"); logger.severe("This is a severe message"); int x = 5; int y = 0; try { int result…

0 Comments

Lombok Library

What is Lombok? Lombok is a Java library that helps reduce boilerplate code—the repetitive code you often write in Java, like getters, setters, constructors, toString(), hashCode(), etc. It does this through annotations that are processed at compile-time, so the generated code doesn’t appear in your source files but is present in the compiled bytecode.…

0 Comments

End of content

No more pages to load