Author: Editorial Team
-
static transient field and final transient field
The question is sometimes asked as – Can we define a field as ‘static transient’ and ‘final transient’ field? Yes, we can define a field as ‘static transient’. We don’t receive any error and compiler doesn’t complain. However, this is not useful as static fields are not serialized. Static variables belong to a class and…
-
transient keyword in Java and example
Variables may be marked transient to indicate that they are not part of the persistent state of an object. transient is the modifier applicable only for variables. If you define any data member as transient, it will not be serialized. At the time of serialization JVM ignores the original value of transient variable and save…
-
Serialization and Deserialization example
In the following example, we are serializing instance of Student class. Student class has two fields, rollNo and age. We are saving state of the object in test.ser file. ObjectOutputStream class has method writeObject to write object state and ObjectInputStream class has method readObject to read object state.During serialization we are reading state of object…
-
Serialization and Deserialization in Java
Generally all applications require objects to be saved. Once a program is executed/terminated, the object is destroyed by itself. If you want to persist the state of an object you can use the serialization concept by converting data into a byte stream. Serialization means to convert state of an object into a byte stream. Deserialization…
-
What is the difference between Set and Map?
Duplicate Objects Set doesn’t allow duplicates. Map doesn’t allow duplicate keys while it allows duplicate values. Null elements Set just allow one null element as there is no duplicate permitted while in Map you can have null values and at most one null key. Order Set doesn’t maintain any order. Few of its classes sort…
-
What Is RandomAccess Interface?
This interface is a member of the Java Collections Framework. This interface introduced in Java version 1.4. It marks the implementations of list which can be accessed randomly. This way a caller can either access the data randomly if that is efficient, or use another means if it is not. Marker interface used by List…
-
Write Java program to print Fibonacci series
Fibonacci series is a series of numbers in which each number(Fibonnaci number) is the sum of the two preceding numbers, starting from 0 and 1. For example:0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55 There are two ways to generate Fibonacci series in Java: Fibonacci series without recursion Output Fibonacci series using…
-
What is the difference between ArrayList and LinkedList?
Differences between ArrayList and LinkedList can be summarized in following points:
-
What’s the difference between Enumeration and Iterator interfaces ?
Difference between Enumeration and Iterator can be summarized with the help of following points: Both Iterator and Enumeration are available in java.util package. Both Iterator and Enumerations are unidirectional forward access cursor. According to Java API Docs, Iterator is always preferred over the Enumeration. NOTE: The functionality of this interface is duplicated by the Iterator…
-
What is the trade-off between using an unsorted array versus a sorted array ?
The tradeoff is in terms of speed. The major advantage of a sorted array is that to search an element in sorted array is faster. Sorted array has time complexity of O(log n), compared to that of an unsorted array, which is O (n). The disadvantage of a sorted array is that the insertion operation…
