why we need to use marker interface? [duplicate] - java

This question already has answers here:
Marker Interfaces in Java?
(10 answers)
Closed 3 years ago.
I just need some clarifications regarding marker interface in java. I have read that its an empty interface in java. I just want to know why and where we need to use this. Can anyone please help.

Shortly said, it is used to mark (or annotate) types with some information that the JVM compiler will use. For instance, the Serializable is a marker interfaces that a type must implement if it needs to have its state persisted (serialized and deserialized).

Related

Why we need empty class in Java [duplicate]

This question already has answers here:
What is the use of an empty abstract class?
(3 answers)
Closed 5 years ago.
Yesterday, I had an interviewing with a company.
They ask me "Why do we need an empty class in Java?"
I never use an empty class so I have no idea about the purpose of this.
Anyone help?
Thank you so much.
No, we don't need an empty class in Java. We can create one but there is literally no benefit of having that empty class.

Best practice for signaling that a method is deprecated? [duplicate]

This question already has answers here:
How to declare or mark a Java method as deprecated?
(6 answers)
Closed 8 years ago.
I have a method in one of my classes that I don't want it to be used any more. Basically it breaks encapsulation, and I now have better methods I want to be used instead.
What's the best practice for signaling that a method is deprecated?
Add an #Deprecated annotation to that method and tell witch other classes to use in javadoc.
Mark using Deprecated annotation.

What is the use of marker interface in java when we have no methods in it and how it gets into action? [duplicate]

This question already has answers here:
What is the use of marker interfaces in Java?
(10 answers)
Closed 8 years ago.
I am confused about marker interfaces in java.
Could anyone please tell me when we have no methods in marker interfaces, then from where it is called. Do we have to implement this explicitly also.
It's just like any other interface.
And used to type check the object at run time.
For ex:
And somewhere else Runtime realizes objects like
if (SomeObjImpMarkerInterface instanceof SomeMarkerInterface ) {
// Hey this object is that type
} else {
// Not that type.
}

How to implement class adapter pattern in Java [duplicate]

This question already has answers here:
Implementing Class Adapter Pattern in Java
(5 answers)
Closed 9 years ago.
Is it possible to implement class adapter pattern in Java?
I'm trying to read everything on the internet but still have found an example.
It is possible, but pure interfaces must be used instead of abstract classes, since Java does not support multiple inheritance.
There are two variations of the Adapter pattern: inheritance-based (a.k.a. class Adapter) and composition-based. The inheritance variation requires the use of multiple inheritance, which doesn't exist in Java and therefore it's impossible to implement. But of course, you can do the composition-based implementation, without any problems.

Difference Between parcelable and Serialization? [duplicate]

This question already has answers here:
Benefit of using Parcelable instead of serializing object
(9 answers)
Closed 9 years ago.
can anyone please explain me what it means by the performance issue the serialization encounters and make the Parcelable an efficient way rather than serialization in android to pass an object from one activity to another.
Thanks In Advance.
You should read a nice blogpost about it : http://www.developerphil.com/parcelable-vs-serializable/

Categories

Resources