Constructing an Array,Java, C ,C++, ASP, ASP.net C# ,Struts ,Questions & Answer, Struts2, Ajax, Hibernate, Swing ,JSP , Servlet, J2EE ,Core Java ,Stping, VC++, HTML, DHTML, JAVASCRIPT, VB ,CSS, interview ,questions, and answers, for,experienced, and fresher
Constructing an Array

Construct an array is basically means the create if an array object , Which object create in the heap. We can also say like they \"doing a new on the array type\" when we construct the array we must mentioned the size of the array because java would like to know how much space to allocate on the heap, And also know that the array will hold how many size of the array is the number of elements. Array constructing in a two ways : 

Constructing One-Dimensional Arrays 
In the one-dimensional arrays is most straight forward way to constructing the array for using the new keyword .and in the one dimensional array bracket signifies array holding how many elements of that type. for the int type we have a example which is shown as :
int[] testScores; // Declares the array of ints
testScores = new int[4]; //constructs an array and assigns it
//the testScores variable

We can also declare and construct an array in one statement , which is following as :int[] testScores = new int[18];

That single statement also given as a same result which is given by the upper two statements .Arrays of object type is also constructed in the same way :
Thread[] threads = new Thread[6];

The main point or key point is that :  Thread constructor is not being invoked . its not creating the thread instance . Its use for the single thread array object.

Constructing Multidimensional Arrays
 
Multidimentional arrays are basically a simply arrays of arrays . that\'s y we can use the two denominational arrays of type int , Its really object of type int array (INt[]). With its also holding the another array and each element also use the int array .and second dimension which holds the actual int primitives .
We have a example for the int type :
int[][] ratings = new int[3][];

More interview questions and answers
Select two correct options from the followings.
Class, Method, and Variable Modifiers
Flow Control
Error Handling
Package Control
Primitives
Variable Keywords
void Return Type Keyword
Select three correct options than comes when we compile and run following code: public class R4RSCJPTest { public static void main(String args[]) { int i=1, j=1; try { i++; j--; if(i/j > 1) i++; } catch(ArithmeticException e) { System.out.println(0); } catch(ArrayIndexOutOfBoundsException e) { System.out.println(1); } catch(Exception e) { System.out.println(2); } finally { System.out.println(3); } System.out.println(4); } }
Select correct options that comes when we compile and run following code: public class R4RSCJPTest { public static void main(String args[]) { int i=2, j=1; try { i--; j++; if(i != j) i--; } catch(ArithmeticException e) { System.out.println(0); } catch(ArrayIndexOutOfBoundsException e) { System.out.println(1); } catch(Exception e) { System.out.println(2); } finally { System.out.println(3); } System.out.println(4); } }
What happen when we compile and run following code: public class R4RSCJPTest { public static void main(String args[]) { String str1 = "xyz"; String str2 = new String("xyz"); if(str1 == str2) System.out.println(0); else System.out.println(1); if(str1.equals(str2)) System.out.println(2); else System.out.println(3); } }
What result comes when compile and run following code: public class Test { public static void main(String args[]) { String str1 = "xyz"; String str2 = "xyz"; if(str1 == str2) System.out.println(0); else System.out.println(1); if(str1.equals(str2)) System.out.println(2); else System.out.println(3); } }
What result comes when we compile and run following code: public class R4RSCJPTest { public static void main(String args[]) { int i = 2; do { i++; }while (i > 2); System.out.println(i); } }
In the following method at what stage does the object initially referenced by s becomes available for garbage collection? void method abc() { String str1 = new String("xyz"); String str2 = new String("xyz"); str1 = str1+1; //1 str1 = null; //2 str2 = str2 + str1; //3 } //4
From the following statement select two correct options.
Select two options which are correct in case of interface.
What result comes when we compile and run following code: public class R4RSCJPTest { public static void main(String args[]) { int i; float f = 2.4f; i = ((int)Math.ceil(f)) * ((int) Math.floor(f)); System.out.println(i); } }
What result come when we compile and run following code: public class R4RSCJPTest { public static void main(String args[]) { int i; float f = 1.7f; double d1 = 2.7; double d2 = 2.4; i = ((int)Math.ceil(f)) * ((int)Math.round(d1)) * ((int)Math.round(d2)); System.out.println(i); } }
Which of these classes are defined in java.io and used for file handling are abstract.
What result comes when we compile and run following code: public class R4RSCJPTest { public static void main(String args[]) { String str1="abcd"; String str2="efgh"; String str3=str1.concat(str2); str1.concat(str2); System.out.println(str1); } }
What result comes when we compile and run following code: public class Test { public static void main(String args[]) { String str1="abcd"; String str2="efgh"; String str3=str1.concat(str2); str1 = str1.concat(str2); System.out.println(str1); } }
What result comes when we compile and run following code: public class Test { public static void main(String args[]) { String str1="abcd"; String str2="efgh"; String str3=str1.concat(str2); str1 = str1.concat(str2); System.out.println(str1); } }
What result comes when we compile and run following code: public class Test { public static void main(String args[]) { String str1="abcd"; String str2="efgh"; String str3=str1.concat(str2); str1 = str1.concat(str2); System.out.println(str1); } }
Literals and Ranges of All Primitive Data Types
Range of Primitive Types
Literal Values for All Primitive Types
Integer Literals
Decimal Literals
Octal Literals
Hexadecimal Literals
Floating-Point Literals
Boolean Literals
Character Literals
Literal Values for Strings
Which primitive type would be best to represent the number of stars in the universe? A) long B) char C) char [] D) int
Which primitive type would be best to represent a single multiple choice question on a test, with only one answer allowed? A) float B) int C) char [] D) char
Which primitive type would be best to represent a single multiple choice question on a test, with more than one answer allowed? A) char B) long C) char [] D) int
Which primitive type would be best to represent the population of the U.S. in 2003? A) int (or long ) B) float (or double) C) char D) long
Which primitive type would be best to represent the amount of money (in dollars and cents) you plan on having at retirement? A) char B) long C) int (or long) D) float (or double)
Array
Choose correct collection interface which we use to represent stored elements into in particular sequence order.
Declaring an Array
Constructing an Array
Select correct method which is defined in Object class and can also used to convert an Integer Object into primitive int type.
Which are the legal identifiers from below.Select three correct options.
Select correct width (in bits) of double primitive type in Java.
What result comes when we compile and run following code: public class R4RSCJPTest { public static void main(String args[]) { int x = 15, y; if(x < 15) y = 3; if(x>= 15) y = 4; System.out.println("Value of y is " + y); } }
Initializing an Array
What result comes when we compile and run following code: class R4RSCJPTest { int i; int j; String str; public static void main(String args[]) { R4RSCJPTest test = new R4RSCJPTest(); System.out.println("String is " + test.str + " " + test.i + " " + test.j); } }
Select three correct options related to Java programming language.
What result comes when we compile and run following code: class R4RSCJPTest { public static void main() { System.out.println("Welcome"); } }
Select correct options which is use to declare main method.
Initializing Elements in a Loop
Declaring, Constructing, and Initializing on One Line
What result comes when we compile and run following code: public class R4RSCJPTest { public static void main(String args[]) { int x, y; int z = 4; z++; y = 3; y++; z = y = z = 2; System.out.println("Value of z is = "+z ); } }
Constructing and Initializing an Anonymous Array
Arrays of Primitives
Arrays of Object References
What result comes when we compile and run following code: public class R4RSCJPTest { public static void main(String args[]) { int x, y; int z = 4; z++; y = 4; y++; z+= y-= x = 2; if( z == 6) z-= 3; else z+= 3; System.out.println("Value of z is "+z ); } }
Array Reference Assignments for One-Dimensional Arrays
Array Reference Assignments for Multidimensional Arrays
Using a Variable or Array Element That Is Uninitialized and Unassigned
What result comes when we compile and run following code: public class R4RSCJPTest { int i = 1; public static void main(String args[]) { int i = 2; i = new_i(i); System.out.println("New value of i is " +i); } public static int new_i(int i) { i = 3; i *= 4; return i; } }
What result comes when we compile and run following code: public class R4RSCJPTest { int i = 1; public static void main(String args[]) { int i = 2; new_i(i); System.out.println("New value of i is " +i); } public static void new_i(int i) { i = 3; i *= 4; } }
What result comes when we compile and run following code: public class R4RSCJPTest { int i[] = {0}; public static void main(String args[]) { int i[] = {1}; new_i(i); System.out.println("New value of i[0] is " +i[0]); } public static void new_i(int i[]) { i[0] = 2; i[0] *= 3; } }
What result comes when we compile and run(with command line argument R4R welcome in intellegence world. in following code: public class R4RSCJPTest { public static void main(String args[]) { System.out.println(args[0]+" "+args [args.length-1]); } }
What result comes when we compile and run(with command line argument like: R4R welcomes you in intelligence world) following code: public class test { public static void main(String args[]) { System.out.println(args[0]+" "+args.length); } }
What result comes when we compile and run following code: class R4RSCJPTest { public static void main(String args[]) { int i,j,k,l=0; k = l++; j = ++k; i = --j; System.out.println("Value of i is " +i); } }
What result comes when we compile and run following code: public class R4RSCJPTest { public static void main(String args[]) { char c; int i; c = 'A'; //1 i = c; //2 c = i + 1; //3 i++; //4 } }
Select correct signed of left shift operator.
What result comes when we compile and run following code: public class R4RSCJPTest { public static void main(String args[]) { int i = 1; boolean t = true; boolean f = false, boo; boo = (t && ((i++) == 0)); boo = (f && ((i+=2) > 0)); System.out.println("Value of i is " +i); } }
What result comes when we compile and run following code: public class R4RSCJPTest { public static void main(String args[]) { int i = 1; boolean t = true; boolean f = false, boo; boo = (t & ((i++) == 0)); boo = (f & ((i+=2) > 0)); System.out.println("Value of i is " +i); } }
Primitive Instance Variables
Object Reference Instance Variables
Array Instance Variables
Local Primitives
Local Objects
Local Arrays
Command-Line Arguments to Main
Declarations and Modifiers
Class Declarations and Modifiers
Class Access
Default Access
Public Access
Other (Nonaccess) Class Modifiers
Final Classes
Abstract Classes
Creating an Abstract Superclass and Concrete Subclass
Method and Variable Declarations and Modifiers.
Member Access
Public Members
Private Members
Local Variables and Access Modifiers
Nonaccess Member Modifiers
Final Methods
Final Arguments
What result comes when we compile and following code: public class R4RSCJPTest { public static void main(String args[]) { byte i = 4; i = (byte)~i; System.out.println("Value of i is " +i); } }
Select operator which we use in Java for bitwise inversion.
What result comes when we compile and run following code: public class R4RSCJPTest { public static void main(String args[]) { int i,j; i = 1 & 5; j = 2 | 7; System.out.println("Value of i is " + i + ", Value of j is " + j ); } }
What result comes when we compile and run following code: public class R4RSCJPTest { public static void main(String args[]) { int i = -1; int j = i>>3; int k = j & 129; System.out.println("Value of k is " +k); } }