Java Collections Interview Questions and Answers

    11 Votes

13) What is meant by serialization in Java ?

Java provides serialization to persist a class or a bean's state along with it's property values and state information into a storage. Persisted object can be retreived later and assigned to an object. Interfaces used to implement serialization are Serializable or Externizable Interface.

14) How to avoid Serialization for variable ?

To make it as static or transient.

15) Can you explain about Java design patterns classification ?

Java introduced design patterns to solve design problems. Patterns can be grouped in to three

  • Creational Patterns : This set of design patterns deal with object creation, which create objects based on the situation in which it is created. Ex: Factory Pattern
  • Structural Patterns : Structural Patterns explains the structure formation by combining objects and classes. Ex: Adapter Pattern
  • Behavioral Patterns : Behavioral patterns focus on the interactions between associated objects. Ex: Iterator Pattern


16) How to open a file in append mode ?

BufferedWriter writer = new BufferedWriter( new FileWriter( "ABCD.txt" , true ) );
That extra boolean at the end puts it in append mode.


17) How to open a file in read only mode ?

BufferedReader reader = new BufferedReader(new FileReader("ABCD.txt"));
or
File file = new File("ABCD.txt");
file.setReadOnly();


18) How to create, delete file in Java ?

public void createFile()
{
  String fileName="NEWFILE.txt";
  File file=newFile(fileName);
  try
  {
    if(file.createNewFile())
    {
        System.out.println("Filenamed"+fileName+"createdsuccessfully!");
    }
    else
    {
        System.out.println("Filewithname"+fileName+"alreadyexixts!");
    }
 }
 catch(IOExceptione){
    e.printStackTrace();
  }
}
public void deleteFile()
{
  try
  {
    File fileToDelete = newFile("NEWFILE.txt");
    if(fileToDelete.delete())
    {
         System.out.println("Filedeletedsuccessfully!");
    }
    else
    {
        System.out.println("Filedeleteoperationfailed!");
    }
}
catch(Exceptione)
{
   e.printStackTrace();
}
}


19) How to check existence of file in Java ?

File f = new File("NEWFILE.txt");

if(f.exists())
{
     System.out.println("File existed");
}
else
{
     System.out.println("File not found!");
}
Page 3 of 3

Popular Videos

communication

How to improve your Interview, Salary Negotiation, Communication & Presentation Skills.

Got a tip or Question?
Let us know

Related Articles

Java OOPS Interview Questions and Answers
Java Interview Questions
Top Advanced Java Interview Questions and Answers
Java Thread Interview Questions and Answers