© 2014 Firstsoft Technologies (P) Limited. login
Hi 'Guest'
Home SiteMap Contact Us Disclaimer
enggedu

Home Placements Interview Questions Java Interview Questions And Answers Java Interview Questions On Arrays and Data Types ▼

Java Interview Questions On Arrays and Data Types

1. What about Array in java?

Answer

  • These are few points about the arrays in Java Programming Language.
  • Arrays are objects in Java
  • In Java an array is a collection of ordered primitives, object references
  • An array is a group of memory locations
  • All elements in an array must be of the same data type.
  • An array element starts from '0'.
  • The type of an array must be defined when array is declared.
  • 2. What are the steps to create an array?

    Answer

    • Declaration.
    • Construction.
    • Initialization.

    Declaration of an Array.

    boolean booleans[]; int ints[];
    byte bytes[]; float floats[];
    short[] shorts; long longs[];
    char chars[]; double[] doubles;
    Note: Declare an array of objects Button buttons[];

    Note: In an array declaration, square brackets can be placed either before or after the array name. The declaration of an array does not allocate any storage, it just declares the array name.

    Construction of an Array
    Using new keyword an array can be constructed. When you are constructing an array using new keyword, the size of the array must be provided. In Java arrays knows their size.
    short shorts[];
    shorts = new short[5];

    Declaration - Construction in a single line

    int ints[] = new int[4];

    Declaration - Construction - Initialization in a single line

    int ints[] = new int[]{10,20,30,40};

    Note: When an array is constructed, it's elements are automatically initialized to the default values, if there is no explicit initialization.

    Next
    1 2 3
    SLogix Student Projects
    bottom