Read all files from folder in java
To read all files from a folder in Java, you can use the java.io.File class or the java.nio.file.Files class. Here’s an example using Files class in Java 8: import java.io.IOException;…
To read all files from a folder in Java, you can use the java.io.File class or the java.nio.file.Files class. Here’s an example using Files class in Java 8: import java.io.IOException;…
In Java, serialization of inner classes can be a bit tricky due to the relationship between inner classes and their enclosing classes. Static inner classes are serializable just like any…
Circular references during serialization in Java can cause StackOverflowError or OutOfMemoryError exceptions. This happens because a circular reference creates a loop in the object graph that the serialization process tries…
Example Custom serialization in Java: import java.io.*; class Person implements Serializable { private static final long serialVersionUID = 1L; private String name; private int age; public Person(String name, int age)…
The writeReplace and readResolve methods in Java allow you to customize the serialization and deserialization process of an object. writeReplace is called during the serialization process. This method provides an…
Comparable and Comparator are two Java interfaces that allow objects to be compared and sorted. Comparable Comparable is a functional interface that is implemented by a class to define its…
In this tutorial, we will learn about using comparators with Lamda. Comparators are extensively used in collections to sort objects link users, employees, orders etc. In Java 8, comparators can…
In this post, we will learn on java8 method referenced exampls: Method references in Java 8 are compact, easy-to-read lambda expressions which will refer to an existing method. They can…
In this post, we will see questions asked on String during java interview 1. Explain String pool in java? String Pool is java string literals pool that JVM maintains a…
We can convert Java String to Input with below approaches: Example1: String str = "Hello World!"; InputStream inputStream = new ByteArrayInputStream(str.getBytes()); Example 2 with UTF8: javaCopy codeString str = "Hello…