Select chapter



basics (7.papers)
constructors (1.papers)
packages (1.papers)
inheritance (7.papers)
misc (3.papers)
exceptions (5.papers)
threads (4.papers)
overloading (1.papers)
jsp (3.papers)
servlets (9.papers)
jdbc (2.papers)
util (1.papers)
xml (2.papers)
IO stream (3.papers)
Hide

Sponsored Links


  

java interview questions and answers

Show Answer
Share Facebook gmail Twitter
Show Answer
Share Facebook gmail Twitter
Show Answer
Share Facebook gmail Twitter
4
What is abstraction in java?
  1. Data abstraction - in class level by using encapsulation.
  2. Behavioral abstraction - in Inheritance level.
  3. both are true
  4. none
Show Answer
Share Facebook gmail Twitter
5
What is the difference between int and Integer in Java?
  1. int is primitive data type and Integer is wrapper class.
  2. int is a wrapper type and Integer is a primitive type.
  3. both are reference types.
  4. none
Show Answer
Share Facebook gmail Twitter
6
What is the difference between & and && ?
  1. & is bitwise operator. && is logical operator.
    
    
    
  2. & evaluates both sides of the operation.
  3. && evaluates the left side of the operation, if it's true, it continues and evaluates the right side.
  4. all are correct.
Show Answer
Share Facebook gmail Twitter
7
What is serialization?
  1. Serializable is a marker interfaces that tells the JVM is can write out the state of the object to some stream (basically read all the members, and write out their state to a stream, or to disk or something). The default mechanism is a binary format. You can also use it to clone things, or keep state between invocations, send objects across the network etc.
  2. Serialization is a mechanism to pass data between two processes. Hence it is an IPC (inter process mechanism) tool used in java.
  3. both are true
  4. none
Show Answer
Share Facebook gmail Twitter
8
What is static?
  1. static is a keyword in java used to define static variables, and static methods. Static variables and static methods are also called as class variables and class methods. 
  2. static keyword can also be used to define a static initialization block, which is used to initialize static variables of a class.
  3. both are true
  4. there is no static keyword in java
Show Answer
Share Facebook gmail Twitter
9
What is memory leak?
  1. freeing same memory multiple times will lead to memory leaks.
  2. A memory leak is the repetitive allocation of memory without consequential release of it when no longer used. This will be leading to over consumption of memory.
  3. accessing an object which is initialized with null, is called as memory leak.
  4. all are true.
Show Answer
Share Facebook gmail Twitter
10
How to get current date in Java?
  1. DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
        //get current date time with Date()
        Date date = new Date();
        System.out.println(dateFormat.format(date));
  2. Calender c = new Calender();
    Date d = c.getDate();
    System.out.println(d);
  3. Both 1 and 2
  4. none are correct
Show Answer
Share Facebook gmail Twitter
11
What is method chaining?
  1. method chaining is a technique for invoking multiple method calls. It can make code more readable and help provide a fluent interface. 
    The process of calling one method from another method and that called method again calls another method and and so on is called method chaining.
  2. Invoking multiple method calls in a single statements in OOPs is called as method chaining. Each method will inturn return an object so that next method will be called properly.
  3. calling multiple methods at a time simultaneously is called as method chaining.
  4. none
Show Answer
Share Facebook gmail Twitter
12
What is Java method syntax?
  1. Syntax -
    accessmodifier returnValueType methodName(list of parameters) {
      // Method body;
    }
  2. Syntax -
    returnValueType methodName(list of parameters) {
      // Method body;
    }
  3. Syntax -
    returnValueType accessmodifier  methodName(list of parameters) {
      // Method body;
    }
  4. all are correct.
Show Answer
Share Facebook gmail Twitter
13
What are the method naming conventions in Java?
  1. Method name should start with a small letter.If the method is having more than one word , then the second word onwards, you should start with capital letter.
  2. Method name should start with a small letter.If the method is having more than one word , then the second word onwards also should start with small letter.
  3. method name can start with underscore also.
  4. all are true.
Show Answer
Share Facebook gmail Twitter
14
How to write a method returning arraylist?
  1. public class Test{
    
    public ArrayList<Integer> myNumbers()    {
        ArrayList<Integer> numbers = new ArrayList<Integer>();
        numbers.add(5);
        numbers.add(11);
        numbers.add(3);
        return(numbers);
     }
    }
    
    
    public class T{
    
    
    public static void main(String[] args){
    
       Test t = new Test();
       ArrayList arr = new ArrayList();
       t.myNumbers();        // You can catch the returned arraylist in to an ArrayList.
    
     }
    
    
    }
  2. public class Test{
    
    public ArrayList myNumbers()    {
        ArrayList<Integer> numbers = new ArrayList<Integer>();
        numbers.add(5);
        numbers.add(11);
        numbers.add(3);
        return(numbers);
     }
    }
    
    
    public class T{
    
    
    public static void main(String[] args){
    
       Test t = new Test();
       ArrayList arr = new ArrayList();
       t.myNumbers();        // You can catch the returned arraylist in to an ArrayList.
    
     }
    
    
    }
  3. public class Test{
    
    public ArrayList<Integer> myNumbers()    {
        ArrayList<Integer> numbers = new ArrayList<Integer>();
        numbers.add(5);
        numbers.add(11);
        numbers.add(3);
        return(ArrayList<Integers> numbers);
     }
    }
    
    
    public class T{
    
    
    public static void main(String[] args){
    
       Test t = new Test();
       ArrayList arr = new ArrayList();
       t.myNumbers();        // You can catch the returned arraylist in to an ArrayList.
    
     }
    
    
    }
  4. all are correct.
Show Answer
Share Facebook gmail Twitter
15
How to return a value from a method in Java?
  1. use return statement to return a value from the method.
  2. returning value should match with the return type of that method.
  3. // a method for computing the area of the rectangle
        public int getArea() {
            return width * height;
        }
    
  4. all are true.
Show Answer
Share Facebook gmail Twitter
16
How to pass parameters to a method in Java?
  1. class MainClass
    {
    public static void main(String[] args)
    {
    Rect r = new Rect();
    r.findArea(4,5);  //passing parameters         to findArea() method
    }
    }
    
    class Rect
    {
    
    void findArea(int len,int breadth)
    {
    System.out.println(len*breadth);
    }
    }
    
  2. class MainClass
    {
    public static void main(String[] args)
    {
    Rect r = new Rect();
    r.findArea(4);  //passing parameters         to findArea() method
    }
    }
    
    class Rect
    {
    
    void findArea(int len,int breadth)
    {
    System.out.println(len*breadth);
    }
    }
    
  3. class MainClass
    {
    public static void main(String[] args)
    {
    Rect r = new Rect();
    r.findArea(4,5);  //passing parameters         to findArea() method
    }
    }
    
    class Rect
    {
    
    void findArea(len,breadth)
    {
    System.out.println(len*breadth);
    }
    }
    
  4. none
Show Answer
Share Facebook gmail Twitter
Show Answer
Share Facebook gmail Twitter
18
How to return an object from a method in Java?
  1. class Rectangle {
          int length;
          int breadth;
    
          Rectangle(int l,int b) {
            length = l;
            breadth = b;
          }
    
          Rectangle getRectangleObject() {
            Rectangle rect = new Rectangle(10,20);
            return rect;
          }
    }
    
    class RetOb {
          public static void main(String args[]) {
            Rectangle ob1 = new Rectangle(40,50);
            Rectangle ob2;
    
            ob2 = ob1.getRectangleObject();
            System.out.println("ob1.length : " + ob1.length);
            System.out.println("ob1.breadth: " + ob1.breadth);
    
            System.out.println("ob2.length : " + ob2.length);
            System.out.println("ob2.breadth: " + ob2.breadth);
    
            }
    }
  2. class Rectangle {
          int length;
          int breadth;
    
          Rectangle(int l,int b) {
            length = l;
            breadth = b;
          }
    
          Rectangle getRectangleObject() {
            Rectangle rect = new Rectangle();
            return Rectangle;
          }
    }
    
    class RetOb {
          public static void main(String args[]) {
            Rectangle ob1 = new Rectangle(40,50);
            Rectangle ob2=ob1;
    
            System.out.println("ob1.length : " + ob1.length);
            System.out.println("ob1.breadth: " + ob1.breadth);
    
            System.out.println("ob2.length : " + ob2.length);
            System.out.println("ob2.breadth: " + ob2.breadth);
    
            }
    }
  3. Both 1 and 2
  4. none are correct
Show Answer
Share Facebook gmail Twitter
19
How to convert string to int?
  1. String str = "100";
    int i = Integer.parseInt(str);
  2. Integer i=100;
    String str = Integer.parseInt(i);
  3. String str = "100";
    int i = String.parseInt(str);
  4. String str = "100";
    int i = String.toInt(str);
Show Answer
Share Facebook gmail Twitter
Show Answer
Share Facebook gmail Twitter
Read more papers :