• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Reg : marker interface

 
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hai all,

i faced the following question in interview panel. Please answer the following question.

Question : What is the need of marker interface?

My Ans : Marker Interface has no methods like serializable, clonable.
we don't want to override any methods JVM will take care.

Question :
If the abstract class has method declaration no implementation method.So What is need of that abstract class.


Question: Which Collection class can you used to store different type of object(like other collection object, java bean object,and other objects)


Question: if you not to synchronization the shared object what will be the impact in real time

Thanks in advance,
Abiramkumar.P
 
Ranch Hand
Posts: 234
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Marker Interface question:-

It is just a indication to compiler to treat the objects implementing marker interface differently.

what special treatment compiler gives is not the programmers business.

Abstract Class question:-

Abstract class forces the classes (extending abstract class) to have their own implementation of the methods.

Collection question:-

All collections without generics.

Synchronization question:-

We can face dirty read problem .
Simple example :-
take Air Ticketing System.

Two agents:- working at the same time.
one agent checks number of available tickets to a flight A. say ticket available is 1.
second agent also checked tickets for same flight and find available ticket is 1.

Mean while first agent booked the ticket.
Now no ticlet is available. But second agent thinks still 1 ticket is available.
 
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by bittoo garg:
Marker Interface question:-

It is just a indication to compiler to treat the objects implementing marker interface differently.

what special treatment compiler gives is not the programmers business.



The compiler doesn't treat marker interfaces any differently to any other interface.
There are marker interfaces in the standard API which indicate to the JVM/standard library code that certain things can be done to an object. Examples include the Cloneable and Serializable interfaces.

But it is also possible to create your own marker interfaces and in this case you would also have to write the code that made use of the fact that a given class implemented the interface. This is usually done using the instanceof keyword.
 
chennai Kumar
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hai all,

Marker Interface question:-

JVM will take care of some operation we dont want to worry.

Collection question:-

i told that arraylist has stored different collection object, but when you reterive we have to do manually casting.

Synchronization question:-

Transaction will impact(overhead).

I answerd like this, but intervier not satisfied. he expecting more.

another question is regarding vector.

In vector, compare to arrylist other than synchronized what is the different.
 
Brij Garg
Ranch Hand
Posts: 234
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Joanne. After reading your reply and going thru google, i got few things about marker interface.These are......

Classes that imlpements marker interfaces are brought into special category class.
Marker interfce does not add any functionality to the class.
It just mark the class that if class want to perform thing A then it should be marked with MarkerA, if class want to perform thing B then it should be marked with MarkerB.

Example:-

clone is not a method in Cloneable interface. But objects need to clone have to implement Cloneable interface.

So a category is fixed by Sun.. if you want to clone then you have to be Cloneable.
purpose of doing this is not clear ???


We can create our own Marker interfaces....

say... A store has brands of different countries A,B,C.....

brands of country A have been tagged with COUNTRY_A marker.
brands of country B have been marked with COUNTRY_B marker.

so that it is easy to identify brands county wise.
 
Joanne Neal
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by bittoo garg:
clone is not a method in Cloneable interface. But objects need to clone have to implement Cloneable interface.

So a category is fixed by Sun.. if you want to clone then you have to be Cloneable.
purpose of doing this is not clear ???



The merits of doing it this way are often debated on various Java forums. I'm of the opinion that it's highly unlikely it will ever be changed, so the reasons for doing it this way are not worth worrying about - you just have to live with it.
Apart from that I think your summary sounds okay.
 
Brij Garg
Ranch Hand
Posts: 234
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Abiram,

What was your answer to this


In vector, compare to arrylist other than synchronized what is the different.



I dont think there is any other difference.
ArrayList also implementd RandomAccess Interface (java 1.5)
 
Marshal
Posts: 79240
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Go and find a Java1.4 API website, and you find that most classes in the Collections Framework would hold java.lang.Object, ie any kind of class you can think of. As you said, classcasts were needed, which are notoriously error-prone.
 
chennai Kumar
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hai bittoo garg ,

ya, now Arraylist we can make it synchronize now using of

collectionutils.synchronizedList(list);

so i dont know what to answer.

Thanks
reply
    Bookmark Topic Watch Topic
  • New Topic