Java Marker Interface Examples

I know that java.io.Serializable is a Marker Interface.
Is there any other Marker Interface/s in java API ?
Could you please list them?
Edited by: TimJac on Nov 12, 2010 12:40 PM

YoungWinston wrote:
EJP wrote:
javax.security.auth.callback.Callback.
A topic of never-ending fascination.That's nothing. Did you see his "give me a list of Singletons" thread? Riveting.
Is he the same person who used to ask for all the programs written in Java?

Similar Messages

  • Marker interface use

    In which case Marker interface is getting use plz tell

    Marker Interfaces are giving specification to the JVM about the implementing classes.
    One of the features of the Java programming language is that it mandates a separation between interfaces (pure behavior) and classes (state and behavior). Interfaces are used in Java to specify the behavior of derived classes. Often you will come across interfaces in Java that have no behavior. In other words, they are just empty interface definitions. These are known as marker interfaces. Marker interfaces are also called "tag" interfaces since they tag all the derived classes into a category based on their purpose.
    Some examples of marker interfaces in the Java API include: -
    Java.lang.Cloneable
    A class implements the Cloneable interface to indicate to the Object.clone() method that it is legal for that method to make a field-for-field copy of instances of that class.
    java.io.Serializable
    Serialization is nothing but s saving the state of an object to persistent storage as byte stream. Serializability of a class is enabled by the class implementing the java.io.Serializable interface. Classes that do not implement this interface will not have any of their state serialized or deserialized. All subtypes of a serializable class are themselves serializable. The serialization interface has no methods or fields and serves only to identify the semantics of being serializable. To allow subtypes of non-serializable classes to be serialized, the subtype may assume responsibility for saving and restoring the state of the supertype's public, protected, and (if accessible) package fields. The subtype may assume this responsibility only if the class it extends has an accessible no-arg constructor to initialize the class's state. It is an error to declare a class Serializable if this is not the case. The error will be detected at runtime.
    java.util.EventListener
    A tagging interface that all event listener interfaces must extend.
    java.rmi.Remote
    The Remote interface serves to identify interfaces whose methods may be invoked from a non-local virtual machine. Any object that is a remote object must directly or indirectly implement this interface. Only those methods specified in a "remote interface", an interface that extends java.rmi.Remote are available remotely.
    Javax.servlet.SingleThreadModel
    Ensures that servlets handle only one request at a time. This interface has no methods. If a servlet implements this interface, you are guaranteed that no two threads will execute concurrently in the servlet's service method.
    Java.util.RandomAccess
    This Marker interface used by List implementations (ArrayList, Vector) to indicate that they support fast (generally constant time) random access. The primary purpose of this interface is to allow generic algorithms to alter their behavior to provide good performance when applied to either random or sequential access lists.
    Javax.ejb.EnterpriseBean
    The EnterpriseBean interface must be implemented by every enterprise Bean class. It is a common superinterface for the SessionBean, EntityBean and MessageDrivenBean interfaces.
    Reference From Sun Documentation

  • How marker interface works?

    Marker interface have blank body containing nothing.
    I want to know how implementing class start behaving in that manner or how marker interface technology work??

    Marker interfaces are also called "tag" interfaces since they tag all the derived classes into a category based on their purpose. For example, all classes that implement the Cloneable interface can be cloned (i.e., the clone() method can be called on them). The Java compiler checks to make sure that if the clone() method is called on a class and the class implements the Cloneable interface. For example, consider the following call to the clone() method on an object o:
    MyObject o = new MyObject();
    MyObjectref = (MyObject)(o.clone());
    If the class MyObject does not implement the interface Cloneable (and Cloneable is not implemented by any of the superclasses that MyObject inherits from), the compiler will mark this line as an error. This is because the clone() method may only be called by objects of type "Cloneable." Hence, even though Cloneable is an empty interface, it serves an important purpose.

  • Java Application interface with MS Excel through DDE

    We have a financial application written in JAVA and have requests from users that want to interface with the application. Meaning, They would like the Java application interface with Excel. For example, if you had a C++ application, you could create a DDE link in Excel that points to the C++ application and receive the data.
    How could I do this with a Java Applictaion ? I was told that there was an application written that lets Java interface with Excel.
    Any ideas or does anyone know ?

    JNI

  • MARKER INTERFACE WHY?

    hello i madhav new to this forum , i have doubt on marker interface . as it doesnot have any body why we r using that one instead of skipping.Is there any concept behind is there.More about my doubt is Take Example Cloneable Interface it Doesn't Have any Method In it,Clone() method is from Object class,then what is the necessity of implementing the interface .Why it should not be like that.
    what is real technolgy behind MarkerInteface and Why we r going to be used in what situations it will needed.And Lastly is there any method related to Serailizable interface if not what it do .
    marker interface can also called as Tag interface what is tag mean here just saying combing derived classes . i didn't get that one and how it will be .
    if u could explain with example or real time project it would be better for me
    thanks in advance

    What is a "marker" interface?
    Marker Interface pattern
    c2.com - Marker Interface
    experts.about.com - Marker Interfaces
    The Purpose of the Marker Interface
    Maximize your Design ROI with Marker Interfaces and JavaDoc

  • About Marker Interfaces

    what is the use of marker interfaces and y do we need them

    Here's an example I'm using:
    I've got a program which displays lots of tables, it doesn't just display them, it prints them and it dumps them to Excell files.
    Many of these tables have a total row at the bottom which needs highlighting. I flag the TableModel with a marker interface of my own. Then the various ways that table data is handled, when passed the TableModel, know to use a modifled JTable, or to use special formating flags on the last row.

  • What is marker Interface

    hi
    what is marker interface
    what is the use of it
    plz give me reply
    bye

    Marker interface is an interface without any method.
    Eg : Serializable
    refer this link
    http://forum.java.sun.com/thread.jspa?threadID=597388&messageID=3787740

  • JSF-Marker Interface

    Hai Friends
    I want to know what is use of marker interface in java(JSF) and also how it is working without having even single method declaration & definitions inside that interfece like Remote interface,serialization and so on.
    Thanks
    Selvakumar .k

    Marker Interfaces work the same way as they do anywhere else. Please read about marker interfaces.

  • Refusal to use marker interface as parameter?

    Heya all,
    I've seen a lot of professional (ie Apache, Sun, etc) Java code that has code similar to this:
    public void serialise(Object o)
       if (o instanceof Serializable)
          throw new IllegalArgumentException("Object is not serializable");
       ... code here...
    }Whereas surely it could be re-written as:
    public void serialise(Serializable o)
       ... code here...
    }Thus giving us compile-time type safety. I seem to get the impression that 'Serializable' and 'Cloneable' and other such 'marker' interfaces shouldn't be used as parameters in this way because they are not 'real' interfaces as such. I usually prefer the second form; but I have seen both forms fairly commonly.
    Any comments/suggestions on when it's better to use different ways?

    Then allow me to be more specific, without retracting my original point. The following methods within java.io.ObjectInputStream and java.io.ObjectOutputStream which current exist as:
    public Object readObject() throws IOException {}
    public void writeObject(Object object) throws IOException {}Could easily be re-written (and be more specific and type-safe) via the following declarations:
    public Serializable readObject() throws IOException{}
    public void writeObject(final Serializable object) throws IOException {}I would further propose renaming then SerializableInputStream and SerializableOutputStream, as they do not truly take all instances of java.lang.Object.
    - Saish

  • Java 6 PBE Example from JCA

    Hi All,
    I'm new to Java, so forgive my ignorance. A google search was not fruitful. I'm using Java 6 with the NetBeans 6.0.1 Editor. I'm attempting to derive a secret key from a password as follows shown below. The code is based on the JCA [1] password based encryption example [2]. I have two issues.
    == One ==
    symmetricKey = key.getEncoded() returns a byte array consisting of 1,2,3,4. According to PBEKeySpec this should return the primary encoding. This begs the question: if the bytes corrsponding to the pbe params are not the primary encoding, how does one retrieve the derived key?
    == Two ==
    If I attempt to use a different specification (such as PBEKeySpec spec = new PBEWithSHA1AndRC2_40(...)), the IDE imports com.sun.crypto.provider.PKCS12PBECipherCore.PBEWithSHA1AndRC2_40, which does not exist. I have installed the 'Strong Policy(?)' (I'm not sure if that is an issue). Where is the IDE picking up the import, and where do I download it?
    Any help is apreciated,
    Jeff
    ==== Code ====
    char[] password = { '1', '2', '3', '4' };
    byte[] salt = { (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF };
    int iterations = 16;
    PBEKeySpec spec = new PBEKeySpec(password, salt, iterations);
    SecretKeyFactory factory =
    SecretKeyFactory.getInstance(("PBEWithMD5AndDES"));
    SecretKey key = factory.generateSecret(spec);
    byte[] symmetricKey = key.getEncoded();
    ==== References ====
    [1] http://java.sun.com/javase/6/docs/technotes/guides/security/crypto/CryptoSpec.html
    [2] http://java.sun.com/javase/6/docs/technotes/guides/security/crypto/CryptoSpec.html#PBEEx
    [3] http://java.sun.com/javase/6/docs/api/javax/crypto/spec/PBEKeySpec.html

    Jeff, my first stab at tidying your code.
    import java.io.DataInputStream;
    import java.io.File;
    import java.io.FileInputStream;
    import java.io.FileOutputStream;
    import java.io.IOException;
    import java.security.Key;
    import java.security.KeyPair;
    import java.security.KeyFactory;
    import java.security.KeyPairGenerator;
    import java.security.NoSuchAlgorithmException;
    import java.security.SecureRandom;
    import java.security.interfaces.RSAPrivateKey;
    import java.security.interfaces.RSAPublicKey;
    import java.security.spec.InvalidKeySpecException;
    import java.security.spec.PKCS8EncodedKeySpec;
    import java.security.spec.X509EncodedKeySpec;
    * @author jeffrey walton
    public class Main
        public static void main(String[] args) throws Exception
            final String PRIVATE_KEY_FILE = "private.rsa.java.key";
            final String PUBLIC_KEY_FILE = "public.rsa.java.key";
            // http://java.sun.com/j2se/1.4.2/docs/guide/security/CryptoSpec.html
            KeyPairGenerator kpg = KeyPairGenerator.getInstance("RSA");
            // Initialize
            kpg.initialize(1024, new SecureRandom());
            KeyPair keys = kpg.generateKeyPair();
            RSAPrivateKey privateKey = (RSAPrivateKey) keys.getPrivate();
            RSAPublicKey publicKey = (RSAPublicKey) keys.getPublic();
            // Print Parameters
            PrintPrivateKey(privateKey);
            PrintPublicKey(publicKey);
            // Serialize Keys
            SaveEncodedKey(PRIVATE_KEY_FILE, privateKey);
            SaveEncodedKey(PUBLIC_KEY_FILE, publicKey);
            // PrivateKey privateKey = LoadPrivateKey("private.java.key");
            privateKey = LoadPrivateKey(PRIVATE_KEY_FILE);
            PrintPrivateKey(privateKey);
            // PublicKey publicKey = LoadPublicKey("public.java.key");
            publicKey = LoadPublicKey(PUBLIC_KEY_FILE);
            PrintPublicKey(publicKey);
        static void SaveEncodedKey(String filename, Key key) throws IOException
            if (null == key)
                throw new IllegalArgumentException("key is null.");
            FileOutputStream fos = new FileOutputStream(filename);
            // PKCS #8 for Private, X.509 for Public
            // File will contain OID 1.2.840.11359.1.1.1 (RSA)
            // http://java.sun.com/j2se/1.4.2/docs/api/java/security/Key.html
            fos.write(key.getEncoded());
            fos.close();
        static RSAPrivateKey LoadPrivateKey(String filename) throws IOException, NoSuchAlgorithmException, InvalidKeySpecException
            File file = new File(filename);
            byte[] b = fullyReadFile(file);
            PKCS8EncodedKeySpec spec = new PKCS8EncodedKeySpec(b);
            KeyFactory factory = KeyFactory.getInstance("RSA");
            return (RSAPrivateKey) factory.generatePrivate(spec);
        static RSAPublicKey LoadPublicKey(String filename) throws IOException, NoSuchAlgorithmException, InvalidKeySpecException
            File file = new File(filename);
            byte[] b = fullyReadFile(file);
            X509EncodedKeySpec spec = new X509EncodedKeySpec(b);
            KeyFactory factory = KeyFactory.getInstance("RSA");
            return (RSAPublicKey) factory.generatePublic(spec);
        private static byte[] fullyReadFile(File file) throws IOException
            DataInputStream dis = new DataInputStream(new FileInputStream(file));
            byte[] bytesOfFile = new byte[(int) file.length()];
            dis.readFully(bytesOfFile);
            dis.close();
            return bytesOfFile;
        static void PrintPrivateKey(RSAPrivateKey key)
            if (null == key)
                throw new IllegalArgumentException("key is null.");
            System.out.print("Private Key ");
            System.out.println("(" + key.getFormat() + ")");
            System.out.println(" d: " + key.getPrivateExponent());
            System.out.println(" n: " + key.getModulus());
            System.out.println();
        static void PrintPublicKey(RSAPublicKey key)
            if (null == key)
                throw new IllegalArgumentException("key is null.");
            System.out.print("Public Key ");
            System.out.println("(" + key.getFormat() + ")");
            System.out.println(" e: " + key.getPublicExponent());
            System.out.println(" n: " + key.getModulus());
            System.out.println();
    }There was one silly type error in your code privateKey = LoadPrivateKey("public.rsa.cpp.key");
    The only real errors (standard new to Java IO errors) are in the use of available() get the file size(it doesn't guarantee this) and your relying on read() to fully read all the bytes of the array (it doesn't guarantee this). You could just modify these two parts but I have made several other less important changes.
    I do feel your exception handling left something to be desired so I have modified it. I would normally handle exceptions very differently but this clutters the code detracts from readability in code examples.
    Though your code for getting the exponent and modulus from the RSA keys works, there is significant redundancy so I have simplified it.
    I have modified your precondition checking of your key being null to use the standard IllegalArgumentException rather than just Exception. Since you are only doing some of the precondition checking it might be worth while checking ALL preconditions or NO preconditions. I'm always split on this when presenting example code. Although I use precondition checking extensively in production code, once again I find it detracts from the readability in example code.
    Your method naming convention is at odds with the standard Java coding standards in that you have capitalized the first letter of method names but I don't feel this is much of a problem so I have not modified it.
    The lights are about to go out!
    Edited by: sabre150 on Apr 29, 2008 8:09 AM

  • What is the significance of Marker interface? Why are we using, even though

    What is the significance of Marker interface? Why are we using, even though it has no method?

    Well, what's the significance of an interface? They can define a set of methods a class may implement but the class could equally well implement these methods without the interface so why having interfaces at all?
    The answer is that the most important aspect of an interface is that it constitutes a type (you can declare variables of it). And it's a type regardless of how many methods it defines, including none. So the reason for having a marker interface is that you're interested solely in the type aspect of interfaces.

  • Problems with Java AQ interface migrating 9i to 10g

    Hi!
    I've got problems with Java AQ Interface migrating from 9i DB, JDBC, AQ to 10g rel.2 DB, JDBC, AQ
    First, i started to occasionally receive NullPointerException in Oracle JDBC 9.2.0.8
    java.lang.NullPointerException
    at oracle.jdbc.driver.OracleStatement.describe(OracleStatement.java:6439)
    at oracle.jdbc.driver.OracleStatement.get_column_index(OracleStatement.java:6203)
    at oracle.jdbc.driver.OracleResultSetImpl.findColumn(OracleResultSetImpl.java:1557)
    at oracle.jdbc.driver.OracleResultSet.getString(OracleResultSet.java:1543)
    at gpnic.messaging.LDAPMessenger.messageFromRS(Unknown Source)
    We were using 9.2.0.8 JDBC and 9i and 10g databases.
    We decided to go up for 10g r2 JDBC Drivers, and 10.2 AQ but started to get the following errors:
    oracle.AQ.AQOracleSQLException: ORA-25216: invalid recipient, either NAME or ADDRESS must be specified
    ORA-06512: на "SYS.DBMS_AQIN", line 454
    ORA-06512: на line 1
         at oracle.AQ.AQOracleQueue.enqueue(AQOracleQueue.java:1267)
         at gpnic.comm.messaging.transport.AQTransportAdapter$AQDestanation.send(AQTransportAdapter.java:607)
         at gpnic.comm.messaging.transport.OutboundThread.run(OutboundThread.java:83)
    I'm specifying address of an agent, but oracle says I am not.
    I tried both native AQ and JMS interfaces, bot got the same error. I specify recipient the following way:
    'consumer' var contains name of AQ agent and is not null
    native AQ interface:
    aqSess = AQDriverManager.createAQSession(db_conn);
    AQQueue destQ = aqSess.getQueue(schema, queue);
    dequeueOptionsOut = new AQDequeueOption();
    dequeueOptionsOut.setWaitTime(AQDequeueOption.WAIT_NONE);
    dequeueOptionsOut.setConsumerName(consumer);
    dequeueOptionsOut.setDequeueMode(AQDequeueOption.DEQUEUE_REMOVE);
    dequeueOptionsOut.setNavigationMode(AQDequeueOption.NAVIGATION_FIRST_MESSAGE);
    AQMessageProperty mpOut = new AQMessageProperty();
    Vector vRecpt = new Vector();
    vRecpt.add(new AQAgent(consumer, null, 0));
    mpOut.setRecipientList(vRecpt);
    AQMessage aqMsg = null;
    AQEnqueueOption eOpt = null;
    //prepare message
    aqMsg = destQ.createMessage();
    CLOB chMsg = CLOB.createTemporary(db_conn, true, CLOB.DURATION_SESSION);
    chMsg.open(CLOB.MODE_READWRITE);
    chMsg.putString(1,msg);
    //creating oracle type message
    gpnic.db.SDSTypes.SdsMsgT oraMsg = new gpnic.db.SDSTypes.SdsMsgT(chMsg);
    AQObjectPayload payload = aqMsg.getObjectPayload();
    payload.setPayloadData(oraMsg);
    //setting properties
    aqMsg.setMessageProperty(mpOut);
    //do enqueueOut
    eOpt = new AQEnqueueOption();
    destQ.enqueue(eOpt, aqMsg); //<- here AQOracleSQLException is thrown
    JMS interface to Oracle AQ:
    TopicSession session;
    TopicConnection connection;
    TopicPublisher publisher;
    AQjmsAgent[] recipientList;
    connection = AQjmsTopicConnectionFactory.createTopicConnection(db_conn);
         session = connection.createTopicSession(true, Session.CLIENT_ACKNOWLEDGE);
         connection.start();
         Topic topic = ((AQjmsSession) session).getTopic(schema, queue);
         publisher = session.createPublisher(topic);
         recipientList = new AQjmsAgent[1];
         recipientList[0] = new AQjmsAgent(consumer, null);
    CLOB chMsg = CLOB.createTemporary(db_conn, true, CLOB.DURATION_SESSION);
    chMsg.open(CLOB.MODE_READWRITE);
    chMsg.putString(1,msg);
    //creating oracle type message
    gpnic.db.SDSTypes.SdsMsgT oraMsg = new gpnic.db.SDSTypes.SdsMsgT(chMsg);
    AdtMessage adtMessage = ((AQjmsSession)session).createAdtMessage();
    adtMessage.setAdtPayload(oraMsg);
    ((AQjmsTopicPublisher) publisher).publish(adtMessage, recipientList); <- here Exception is thrown
    We tried the following combinations
    9i DB, 9i jdbc, 9i aq - enqueue ok
    10g DB, 9i jdbc, 9i aq - enqueue ok
    10g DB, 10g jdbc, 10g aq - exception is thrown
    Can anyone help?

    Duplicate post, please check Upgrade 9i to 10g

  • What is the use of Marker Interfaces?

    What is the use of marker interfaces?
    As it is not having any methods or fileds what is the benefit I will get by implementing those interfaces?
    Servlet implements SingleThread
    What it will do behind the scenes exactly as singleThread model is marker interface

    The use of marker interfaces is to act as markers (shock horror)
    It is quite a common way to tell a program what a class can/can't do: Cloneable, Serializable etc etc
    This doesn't change the functionality of the class itself, but is more an indication as to what can be done with this class.
    In this case the servlet container can then tell whether or not it implements the interface, and can treat it accordingly. Implementing this interface tells the container you want it to run this servlet in singleThreaded mode.
    Thats all there is to it.
    It would be along the lines of
    Servlet servlet = loadServlet("...")
    if (servlet instanceof SingleThreadModel){
    // Single threaded servlet - start new process for it
    else {
    // regular servlet - reuse existing object.

  • Use of marker Interface

    can any bdy plz tell me what is the use of marker interface ????

    Please search the forums before asking such a common question.

  • Java.lang.ClassCastException: examples.ejb.basic.statefulSession.TraderBeanHomeImpl_ServiceStub

    I am using the example from the XML/HTTP which uses a client, servlet and request
    handler. The Servlet calls the StatefulSession TraderHome Bean.
    I am getting the following: java.lang.ClassCastException: examples.ejb.basic.statefulSession.TraderBeanHomeImpl_ServiceStub.
    Anyboy have a similar problem?
    This works with the Client prg in the ejb/basic/StatefulSssion "Client" It works
    correctly

    I am using the example from the XML/HTTP which uses a client, servlet and request
    handler. The Servlet calls the StatefulSession TraderHome Bean.
    I am getting the following: java.lang.ClassCastException: examples.ejb.basic.statefulSession.TraderBeanHomeImpl_ServiceStub.
    Anyboy have a similar problem?
    This works with the Client prg in the ejb/basic/StatefulSssion "Client" It works
    correctly

Maybe you are looking for