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 arrays and strings interview questions and answers

1
java arrays declaration:
What is the output of below java program?

import java.util.*;
import java.lang.*;

class MainClass
{  
    public static void main(String args[])
    {
        int[10] arr = {1,2,3,4,5,6,7,8,9,10};
        System.out.println("array element at 0 is.."+arr[0]);
        
    }
}
  1. array element at 0 is.. 1
  2. run time error, array index out of bounds exception
  3. compile time error as you can't give array size in its variable declaration.
  4. array element at 0 is..0
Show Answer
Share Facebook gmail Twitter
Show Answer
Share Facebook gmail Twitter
3
java arrays declaration:
What is the output of below java program?

import java.util.*;
import java.lang.*;

class MainClass
{  
    public static void main(String args[])
    {
        int[] arr = new int[]{1,2,3,4,5,6,7,8,9,10};
        System.out.println("array element at 0 is.."+arr[0]);
        
    }
}
  1. array element at 0 is.. 1
  2. run time error, array index out of bounds exception
  3. compile time error, trying to initialize with out specifying the size.
  4. compile time error, invalid array initialization
Show Answer
Share Facebook gmail Twitter
4
java arrays and indexes:
What is the output of below java program?

import java.util.*;
import java.lang.*;

class MainClass
{  
    public static void main(String args[])
    {
        int[] arr = new int[]{1,2,3,4,5,6,7,8,9,10};
        System.out.println("array element at 0 is.."+arr[-1]);
        
    }
}
  1. array element at 0 is.. 1
  2. run time error, array index out of bounds exception
  3. compile time error, trying to initialize with out specifying the size.
  4. compile time error, invalid array initialization
Show Answer
Share Facebook gmail Twitter
5
Which of the below options are not a property of java arrays.
  1. Array is a data structure which contains data of same type
  2. array is a fixed size component.
  3. arrays are stored in heap
  4. arrays are dynamically growable
Show Answer
Share Facebook gmail Twitter
6
Which of the below is the correct way of declaring and creating an array in java?
  1. int arr = new int[10];
  2. int [10] arr;
  3. int[] arr = new int[10];
  4. int[10] arr = new int[10];
Show Answer
Share Facebook gmail Twitter
7
Which of the below are correct statements about array size and array initialization, in java?
  1. It is OK to have size in the array declaration.
  2. while creating or initializing array, it is mandatory to give size of that array.
  3. while creating or initializing array, some times array size will be automatically calculated by the initialized members.
  4. length is the variable of array which holds the size of array and it is not constant.
Show Answer
Share Facebook gmail Twitter
8
What is the best way to create a String in java?
  1. String str = "skill gun";
  2. String str = new String("skill gun");
  3. both option 1 and 2 are same
  4. we can't predict
Show Answer
Share Facebook gmail Twitter
Show Answer
Share Facebook gmail Twitter
Show Answer
Share Facebook gmail Twitter
Show Answer
Share Facebook gmail Twitter
12
What is the difference between java equals() method and == operator?
  1. operator == always returns true, if both the objects are having or pointing to same address.
  2. equals() function on all objects tests if the content in both the objects are same or not.
  3. operator == some times might return false, even if both the objects are pointing to same address.
  4. it is mandatory for every class to implement equals() function. Else it gives compile time error.
Show Answer
Share Facebook gmail Twitter
Show Answer
Share Facebook gmail Twitter
Show Answer
Share Facebook gmail Twitter
15
Are String class and String objects immutable in java?
  1. String class is immutable
  2. String objects are immutable
  3. both options 1 and 2 are true
  4. String class is mutable, but String objects are immutable.
Show Answer
Share Facebook gmail Twitter
Show Answer
Share Facebook gmail Twitter
Show Answer
Share Facebook gmail Twitter
Show Answer
Share Facebook gmail Twitter
Show Answer
Share Facebook gmail Twitter
20
which is true about String class in java?
  1. replace function in string will change the content in the same memory location.
  2. concat() function will append new string to the existing string in the same location.
  3. string function has its own implementation of equals() function to check for content equivalency.
  4. length function in string class, always returns 1 less than actual size
Show Answer
Share Facebook gmail Twitter
Read more papers :