Back to Top

Wednesday, 14 August 2013

JAVA: Deserializing an Object from File

 
      To deserialize an object from file, first get the serialized data from the file using FileInputStream. In case if you want to know how to serialize an object to file please check this article serialize an object to a file. Pass the FileInputStream object through ObjectInputStream. Now, get the object from ObjectInputStream using the API readObject().

Example:

Suppose we have a file named sampleClass.ser which contains the data of a serialized object of class SampleClass. Please check this post to create this file. Where SampleClass is a normal pojo class with 4 variables, among which 1 is declared as transient, that means, protected from serialization.

Wednesday, 14 August 2013 by Anijit Sarkar · 4 Read more »

Sunday, 11 August 2013

JAVA: Keyword: abstract


abstract:

     This is used to define a class or a method as an abstract operation. When a method is declared as abstract, that means, the method where it is declared (within the class) have no body of the method rather the method can be overridden, through inheritance and define it's body.
     When a class  contains any abstract method, it must be declared as abstract.
An abstract class cannot be final.
An abstract method cannot be finalstatic nor native.




Code:
package com.interview.question.java;

abstract class SampleAbstractClass {
  /**
    *
    * Sample abstract class.
    *
    * @author http://interviewquestionjava.blogspot.com
    *
    */
     
      // Sample abstract method.
      public abstract void sampleabstractmethod() ;
     
      public void sampleNormalMethod(){
            System.out.println("SampleAbstractClass.sampleNormalMethod()");
      }
     

}


public class TestAbstractClass{
     
      /**
    *
    * Sample class to call SampleAbstractClass.
    *
    * @author http://interviewquestionjava.blogspot.com
    *
    */
      public static void main(String[] args) {
           
            SampleAbstractClass objSampleAbstractClass = newSampleAbstractClass() {
                 
                  @Override
                  public void sampleabstractmethod() {
                       
                        System.out
                                    .println("TestAbstractClass.main(...).new SampleAbstractClass() {...}.sampleabstractmethod()");
                       
                  }
            };
           
            objSampleAbstractClass.sampleabstractmethod();
      }
     
}

Output:

TestAbstractClass.main(...).new SampleAbstractClass() {...}.sampleabstractmethod()

Sunday, 11 August 2013 by Anijit Sarkar · 3 Read more »

Popular Posts

All Rights Reserved JAVA INTERVIEW QUESTIONS | Privacy Policy | Anijit Sarkar
blog links Web Directory Academics Blogs