Using Serializable interface

Hi, I have to write a program that implements the Serializable interface along with a LinkedList. It looks like this:
public class Library implements Serializable{
   private LinkedList<LibraryBranch> collection;
}However, all of my methods after that give a warning/error "class, interface, or enum expected." Do I have to write my own methods for Serializable that allows me to read and write data? I don't completely understand the Serializable interface description in the API.
Thanks for your help.
- Jeremy

I don't know, the assignment asks for it. I think I have to be able to write the objects into a file and read them back again later.

Similar Messages

  • Why we require to implement Serializable interface?

    Hi techies,
    I am new to Serialization. Why we require to use Serializable interface for Serializing objects. Since Serializable interface is a marker interface, how it prevents objects not implementing Serializable from being Serialized. Does Java Compiler checks it or how it checks it?

    JavaBreather wrote:
    Since Serializable interface is a marker interface, how it prevents objects not implementing Serializable from being >Serialized. Does Java Compiler checks it or how it checks it?Compiler does nothing but mark the class as implementing the interface. You can then later check whether “objects instanceof Interface" and find out whether or not it is present. As said above, ObjectOutputStream does the same thing.
    Marker interfaces are a misuse of interfaces, and should be avoided. You shouldn't create new ones.Annotations introduce in Java 5 are a generic mechanism of adding metadata to a class.

  • What is the use of Serializable Interface in java?

    Hello friends,
    I have one dout and i want to share with u guys:
    Why Serializable interface made and actully
    what's the use of it?
    At which place it become useful ?
    It is not contain any method then why it is made?
    If anyone have any idea about this then please reply.
    Thanks in advace
    Regards,
    Jitendra Parekh

    t is not contain any method then why it is made?To point out to the user of a class (and the programs) that the design of this class is conforming to certain restraints needed for Serialization.

  • Failed to serialize interface javax.xml.soap.SOAPElementweblogic.xml.schema

    I have generated my Web Service Client Control Class based on WSDL file provided by Web Service Provider using JAX-RPC in "Oracle Workshop for WebLogic version 10.3".
    I am using Web Service Client Control class in WebLogic Portal portlet backing class to invoke Web Service. But while invoking Web Service, I am getting following error:
    Caused by: java.rmi.RemoteException: Failed to invoke; nested exception is:
    javax.xml.soap.SOAPException: failed to serialize interface javax.xml.soap.SOAPElementweblogic.xml.schema.binding.SerializationException: mapping lookup failure. class=interface javax.xml.soap.SOAPElement class context=TypedClassContext{schemaType=['http://xyz.com/abc/UpdateSR']:updateSRRequest}
    Here is the code of my Portlet Backing class where I am using Service Control to invoke Web Service:
    URL webServiceUrl = new URL(webServiceLocation);
    ServiceFactory serviceFactory = ServiceFactory.newInstance();
    QName qName = new QName(nameSpaceURI, serviceName);
    Service siebelService = serviceFactory.createService(webServiceUrl, qName);
    updateSRServiceControl siebelServiceProxy = (updateSRServiceControl)siebelService.getPort(qName, updateSRServiceControl.class);
    UpdateSRResponse updateSRResponse = siebelServiceProxy.updateSR(updateSRRequest);
    Please let me know if more information required.
    I appreciate for help.
    Thanks in advance.
    Regards
    Neeraj

    I have generated my Web Service Client Control Class based on WSDL file provided by Web Service Provider using JAX-RPC in "Oracle Workshop for WebLogic version 10.3".
    I am using Web Service Client Control class in WebLogic Portal portlet backing class to invoke Web Service. But while invoking Web Service, I am getting following error:
    Caused by: java.rmi.RemoteException: Failed to invoke; nested exception is:
    javax.xml.soap.SOAPException: failed to serialize interface javax.xml.soap.SOAPElementweblogic.xml.schema.binding.SerializationException: mapping lookup failure. class=interface javax.xml.soap.SOAPElement class context=TypedClassContext{schemaType=['http://xyz.com/abc/UpdateSR']:updateSRRequest}
    Here is the code of my Portlet Backing class where I am using Service Control to invoke Web Service:
    URL webServiceUrl = new URL(webServiceLocation);
    ServiceFactory serviceFactory = ServiceFactory.newInstance();
    QName qName = new QName(nameSpaceURI, serviceName);
    Service siebelService = serviceFactory.createService(webServiceUrl, qName);
    updateSRServiceControl siebelServiceProxy = (updateSRServiceControl)siebelService.getPort(qName, updateSRServiceControl.class);
    UpdateSRResponse updateSRResponse = siebelServiceProxy.updateSR(updateSRRequest);
    Please let me know if more information required.
    I appreciate for help.
    Thanks in advance.
    Regards
    Neeraj

  • No performance gain when using local interfaces

    Hello,
    I'm doing some tests to compare performances between remote ejb interfaces and local ejb interfaces.
    I have two stateless session beans EJB1 and EJB2, EJB1 calls a method on EJB2, this method receives one object as the only parameter and returns it immediately. The parameter is a big object (~700ko). My test consists simply of making 1000 calls from EJB1 to EJB2, one time with remote interfaces, one time with local interface. For both tests, the EJBs run in the same container, same VM.
    The results show absolutely no differences between the remote and the local interface !
    As I found these results a bit surprising, I changed the serialization method of my parameter object this way:
    private void writeObject(java.io.ObjectOutputStream out) throws IOException {
    System.out.println("writeObject(MyBigObject)");
    out.defaultWriteObject();
    just to check if my object is serialized when using remote interface. And the response is no.
    So question is: is there an "undocumented optimization" of the stub/skel generated by weblogic which make local calls when calling a remote method inside the same VM ?
    Some precisions:
    - I'am using weblogic 8.1sp2
    - When calling remotely my EJB2 from an external batch (running in a separate VM), I see the message "writeObject(MyBigObject)" so the serialization is done in this case.

    <Fr?d?ric Chopard> wrote in message news:[email protected]..
    So question is: is there an "undocumented optimization" of the stub/skel generated by weblogic which make local calls when callinga remote method inside the same VM ?
    >
    Some precisions:
    - I'am using weblogic 8.1sp2
    - When calling remotely my EJB2 from an external batch (running in a separate VM), I see the message "writeObject(MyBigObject)" sothe serialization is done in this case.
    WebLogic 5.x, 6.x and 7.x do call by reference for co-located EJBs by default. 8.1 has this behavior turned off by default. You may
    experience call-by-reference optimization in 8.1 only if it has been turned on explicitly in the deployment descriptor.
    Hope this helps.
    Regards,
    Slava Imeshev

  • Can I use Serialization if I have to update my class files?

    Hi,
    I'm writing a game right now, and I'm using Serialization to implement saving maps in it. Its saving me a whole bunch of time right now, but I'm worried that if I make even the slightest adjustment to my class files, then old saved maps won't work anywhere.
    Is there anyway to work around this?
    Thank you for any suggestions.
    -Cuppo

    Yes there is; the description of that all can be found in the API docs for the
    Serializable interface; in short: you have to write/read the members of
    your classes yourself by implementing two special methods; that's all.You don't even have to do that. As long as you provide a serialVersionUID
    member and obey the versioning constraints in the Serialization specification
    you don't have to do any extra programing.You're right; your scenario is even simpler; I discovered something funny though:
    my 1.4.2. API docs lack all documentation of the serialVersionUID final member in
    the description of the Serializable interface. It is present in the 1.5. docs, strange ...
    kind regards,
    Jos

  • Why do we need Serializable Interface since there is no method decl. inside

    On working with Serialization in java
    I could see that the Serializable Interface is empty without any method inside.
    Also, the writeObject() and readObject() accepts only if the Serializable interface is implemented to a class.
    What is the use of implementing an empty Interface?
    Please clarify.
    Thanks in advance.
    Regards,
    R.Mahendra Babu

    The completely empty Serializable is only a marker interface -- it simply allows the serialization mechanism to verify that the class is able to be persisted.

  • Working of serializable interface, when it doesn't have any methods

    Hi,
    I am curious about how the serializable interface is used in JVM.
    This is an empty interface. ie. it does not have any method signatures or any variables inside.
    How does java use this interface, for serializing purposes.
    Also, why should it be an interface, when its all empty.

    Such marker interfaces are just used to tell something about about a class, in this cases that the developer wants that instances of a class can be serialized. The code that handles the serialization just check s"instanceof Serializable". Of course Serializbale could look like this
    public interface Serializable
    public boolean isSerializable();
    But why make things more complicated than necessary?

  • Functionality to generate UUID (for Serializable interface)

    When working with custom components, the java.io.Serializable interface often is a must. Eclipse always complains about the missing UUID-attribute. There are a few plugins around to generate them, but an integrated solution in NitroX would be really cool.

    Eclipse 3.1 will offer you the option to generate serials for you if you open the Quick Fix menu for the warning.PERFECT. :D :D Thanks for the hint. So we only have to wait for NitroX fro 3.1 :twisted:
    Apart from that I would claim it's hardly a feature in the scope of NitroX.Well. Yes an no.
    As lots of the objects that one uses in the context of the session, or as objects that should be sent over the wire (state=client) in JSF, it is in the scope of every plugin or IDE that wants to help the developer develop JSF-application, therefor it is in the scope...
    But with Eclipse providing it already (soon...) it is no discussion any more.
    regards
    Alexander

  • Why does serializable interface has no methods inside it

    Aloha
    Can anyone please help me with this....Serializable interface has no methods inside it.So how is it useful to the user.Also if I am writing a class which implements Serializable how does JVM know what to do.?

    JoachimSauer wrote:
    dannyyates wrote:
    [The JVM] doesn't know about serialisation [...]Sorry for the nitpick, but that's not completely true. The JVM needs to know about serialisation at least at little bitNo.
    since Serialization creates new objects without the code from the constructrs ever being run. ObjectInputStream loads the classes just like any other code would, although it's obviously reading the serialized stream to get that information... and then calls newInstance() on ObjectStreamClass.
    And ObjectStreamClass uses reflection to get a constructor (via java.lang.Class getDeclaredConstructor ) and then uses said java.lang.reflect.Constructor to create a new instance via newInstance()
    There is no JVM magic. It is all Java code. (With the exception of what java.lang.reflect.Constructor does because at the point it dives into sun packages but you could do the same by calling java.lang.reflect.Constructor)

  • Serializable interface problems

    I am playing around with the Serializable interface and created a class:
    import java.io.Serializable;
    public class SerialMessage implements Serializable {
         public byte[] from = new byte[4];
         public byte[] to = new byte[4];
         public byte[] message = new byte[50];
    Next I created somethign that would use this class
    import java.io.*;
    public class SOMessageUser {
         public static void main (String[] args) {
              SerialMessage one = new SerialMessage();
              SerialMessage two = new SerialMessage();
              byte[] serializedMessage;
              try {
                   ByteArrayOutputStream baos = new ByteArrayOutputStream();
                   ObjectOutputStream oos = new ObjectOutputStream(baos);
                   System.out.print("From: ");
                   System.in.read(one.from);
                   System.out.print("\n");
                   System.out.print("To: ");
                   System.in.read(one.to);
                   System.out.print("\n");     
                   System.out.print("Message: ");
                   System.in.read(one.message);
                   System.out.print("\n");
                   oos.writeObject(one);
                   serializedMessage = baos.toByteArray();
                   ByteArrayInputStream bais = new ByteArrayInputStream(serializedMessage);          
                   ObjectInputStream ois = new ObjectInputStream(bais);          
                   two = (SerialMessage)ois.readObject();
                   System.out.print ("From: " + two.from.toString());
                   System.out.print ("To: " + two.to.toString());
                   System.out.print (two.message.toString());
              } catch (Exception e) {
                   e.printStackTrace();
    Very simple as you can see somewhere I have a logical error classes compile and run but here is the output.
    From: as
    To: sa
    Message: qwertyuiopasdfghjklzxcvbn
    From: [B@422edeTo: [B@112f614[B@1d9dc39[root@linux-lev root]#
    why is it that I am gettig these numbers which I am guessing are addresses instead of my byte[]'s?

    Hi,
    >
                   System.out.print ("From: " + two.from.toString());
                   System.out.print ("To: " + two.to.toString());
                   System.out.print (two.message.toString());
              Replace your above lines with the following ones:
                   System.out.print ("From: " + new String(two.from));
                   System.out.print ("To: " + new String(two.to));
                   System.out.print (new String(two.message));

  • Restart persistance and Serializable interface

    When restarting Tomcat 5.5, I see the following things appearing in my log files:
    WARNING: Cannot serialize session attribute parameters for session 701E5E884E3423FE160B65BF6C44DEEB
    java.io.NotSerializableException: toets.toetselementen.VraagTypeSo i guess this means that the session of certain users of my website get broken. I would like to keep my users satisfied by not breaking their sessions with Tomcat restarts.
    On the Tomcat website, i found the following information:
    [http://tomcat.apache.org/tomcat-5.5-doc/config/manager.html|http://tomcat.apache.org/tomcat-5.5-doc/config/manager.html]
    The bottom of that page mentions that the session attributes must implement the Serializable interface. So I assume VraagType is somewhere used as a session attribute, and it indeed does not implement the Serializable interface:
    package toets.toetselementen;
    public class VraagType {
        private int id;
        private String type;
        public VraagType(int id, String type) {
            this.id = id;
            this.type = type;
        public int id() {
            return id;
        public String type() {
            return type;
    }So I assume the VraagType class must implement the Serializable interface to be able to have (Tomcat 5.5) restart persistance. My question is however: is it enough to simply add 'implements Serializable' to my class definition, or will I also have to implement certain methods?

    Yep, it is basically just a marker interface to let Java know that this class is allowed to be serialized. You don't want to do this with sensitive information such as an User object with a password as unencrypted string property --in such case, you could also declare it transient and live with the fact that it doesn't come back after deserialization.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • A Question regarding use of Interfaces.

    I have read about interfaces,but I havent got the real grasp or point
    of it.
    1). How is an interface an improvement over classes?
    If I define a class which has several important methods in it,and this class is extended by several other classes,and all these sub classes then call the super class's methods.
    How does an interface be more beneficial?
    2) What is the exact use of creating class intances thru interface references?
    Java talks about multiple inheritance using interfaces.
    If an interface does not have any constructive methods,but just
    empty methods,how does this become more constructive?
    Eventually a class will implement the this interface to give it some
    value? So why dont I write a class straight away rather than creating an interface,implement it and then code the required methods defined.
    I tend to avoid using interfaces becos I find them of no value.
    Rather I wud prefer to define class with some constructive methods
    and extend this class.
    Am I right in my analysis?

    Interface is also a "contract" that the class implementing a particular interface will provide certain functionality to the users of the class. For E.g Serializable interface in Java. All the classes that implement this interface indicate that the objects of these classes are serializable. Similar thing with Cloneable interface, all objects of classes that implement this interface are Cloneable....
    Hope thinking in these terms will help your understanding. Just look at Java interfaces to understand instead of some custom code.

  • Comparable, cloneable, serializable interface

    Dear all,
    Is there any example and explaination on the usage of comparable, cloneable, serializable interfaces besides the official documentation of Sun's Java API?
    Regards.

    Yes, there's Sun's official tutorial too!
    http://java.sun.com/docs/books/tutorial/
    Use the search on the right (not top right, just below that).
    Cheers,
    Radish21

  • Editing the Customer Address using Open Interface

    Hi All,
    The requirement is to edit the address details(postal codes) of the customer using Open Interface and not the APIs.
    They are insisting on using open interface as the Vertex validation(Taxation rules) is taken care only by Open Interface.
    Will need help on this.Kindly advice.

    Please refer the following whitepaper
    https://metalink2.oracle.com/cgi-bin/cr/getfile.cgi?p_attid=67196.1:1
    Thanks,
    Anil

Maybe you are looking for