The BASE for JAVA LEARNING

by PRO FE S S OR


QUIZ for SECTION VI

To find an answer, click on the desired question.


QUESTION 1:

Create an array of 10 integers and initialize every integer to a different value.

QUESTION 2:

Create an array of 100 integers, each one initialized to 0. (Use the new operator)

QUESTION 3:

Given the following two-dimentsional array of characters named 'letter',
identify letter[2][1], and letter[1][2].

char[][] letter = { {'S', 'C', 'E' }, { 'A', 'Y', 'G' }, { 'D', 'J', 'B' } };

QUESTION 4:

Fill blank: An array followed by dot and _______ yields the number of elements of the array.

QUESTION 5:

Given the following code, determine what is it displayed ?

class Quiz
{ public static void main(String[] args)
{ String msg = new String("Welcome ");
String name = "Student of JAVA ";
msg = msg + name;
System.out.println(msg + msg.length());
}
}

QUESTION 6:

What does it mean that Strings are Immutable ? What advantage would that have ?

QUESTION 7:

What's the main difference between a StringBuffer Object and a String Object ?

QUESTION 8:

Write a program to display the character exactly at the center of an odd number of elements String Object.

Example: If a String Object is "amigo", the character displayed by the program is 'i'.
If a String Object is "fantastic", the character displayed by the program is 'a'.
























ANSWER to QUESTION 1:

int[] number = {1,2,3,4,5,6,7,8,9,10};


Click your Back Button on your Browser to go back to the QUIZ Section.





















ANSWER to QUESTION 2:

int[] number = new int[100];


Click your Back Button on your Browser to go back to the QUIZ Section.





















ANSWER to QUESTION 3:


letter[2][1] is equal to 'J'.

letter[1][2] is equal to 'G'.


Click your Back Button on your Browser to go back to the QUIZ Section.





















ANSWER to QUESTION 4:

length


Click your Back Button on your Browser to go back to the QUIZ Section.





















ANSWER to QUESTION 5:

It would display: "Welcome Student of JAVA 16"


Click your Back Button on your Browser to go back to the QUIZ Section.





















ANSWER to QUESTION 6:

Strings are immutable because their contents in Memory remain the same, until garbage collection is applied as required. As Strings are dynamically allocated, the process is faster, as their contents are always new, and no substitution is made in memory.


Click your Back Button on your Browser to go back to the QUIZ Section.





















ANSWER to QUESTION 7:

Strings Objects are Immutable while StringBuffer Objects are not.

A StringBuffer class is instantiated by using the 'new' operator every time, while a String Object can be instantiated by using 'new' operator or by using the assignment operator directly.


Click your Back Button on your Browser to go back to the QUIZ Section.





















ANSWER to QUESTION 8:

class Quiz
{ public static void main(String[] args)
{ String topic = "Encapsulation";
System.out.println(topic.charAt(topic.length()/2)); // displays character 'u'
}
}


Click your Back Button on your Browser to go back to the QUIZ Section.





Click here to go to the JAVA Mini-Course page