Difference between an Iterator and ListIterator in Java
Iterator and ListIterator are interfaces in Java that allow us to iterate over a collection of objects. However, there are some differences between them: The Iterator interface can be used…
java interview questions,java freshers interview questions,advanced java questions,top 50 java interview questions,java questions for experienced
Iterator and ListIterator are interfaces in Java that allow us to iterate over a collection of objects. However, there are some differences between them: The Iterator interface can be used…
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…