Java Programming

________ represents an entity in the real world that can be distinctly identified.

An Object

________ is a construct that defines objects of the same type.

A class

An object is an instance of a ________


The keyword ________ is required to declare a class.


________ is invoked to create an object.

A constructor

The default value for data field of a boolean type, numeric type, object type is ________, respectively

false, 0, null

public class Test{
int x;
public Test(String t){
public static void main(String[] args){
Test test = new Test();

The program has a compile error because Test does not have a default constructor

Java assigns a default value to a date member of a class if the data is not initialized


The default constructor has no arguments


You can access a class variable using a syntax like objectName.classVariable or ClassName.classVariable


Which one of the following statements are correct

char[][] charArray = {{'a','b'}, {'c','d'}}

Assume double[][] x = new double[4][5], what are x.length and x[2].length?

4 and 5

What is the index variable for the element at the first row and first column in array a?


___is the physical aspect of the computer that can be seen


How many Elements are array matrix (int[][] matrix = new int[5][5])?


Assume int[][][] x = new char [2][5][3], how many elements are there in the array?


What is the printout of the following program?
program public class Test{
public static void main(String[] args){
int[][] values = {{3, 4, 5, 2}, {33, 6, 1, 2}};
for (int row = 0; row < values.length; row++){
java.util.Arrays.sort(Values[row].length; colu

The program prints two rows 1 3 4 5 followed by 1 2 6 33

What is the output for the following code?
public class test{
public static void main(String[] args){
int[][] matrix =
{{1, 2, 3, 4},
{4, 5, 6, 7,},
{8, 9, 10, 11}'
{12, 13, 14, 15}};
for (int i=0; i < 4; i++)
System.out.print(matrix[i][1] + " ");

2 5 9 13

analyze the following code:
int[][] matrix = new int[5][5];
for (int column = 0; column < matrix[4].length; column++)
matrix[4][column] = 10;

After the loop the last row of the matrix is 10, 10, 10, 10, 10

Assume boolean[][] x = new boolean[5][7], what are x.length and x[2].length?

5 and 7

One byte has___bits


java was originally developed by a team led by James Gosling at Sun Microsystems


a java program block starts with an open brace ({) and ends with a closing brace (})


___is the java assignment operator


which of the following expression results in a value 1

37 % 6

-24 % 5 is


the expression 4 + 20 / (3-1) * 2 is evaluates to


what is the value of (double)(5/2)


to assign a double variable d to an int variable x, you write


the equal comparison operator in java is


which of the following code displays the area of a circle if the radius is positive

if (radius > 0) system.out.println(radius

analyze the following code
boolean even = false;
if (even = true) {
system.out.println("It is even!");

the program runs fine and displays It is even!.

what is y after the following switch statement
int x= 0;
int y = 0;
switch (x + 1) {
case 0: y=0;
case 1: y=1;
default: y = -1


The following code displays ___________.
double temperature = 50;
if (temperature >= 100)
System.out.println("too hot");
else if (temperature <= 40)
System.out.println("too cold");
System.out.println("just right");

just right

in a switch statement, the default case must appear last among all cases. Otherwise, it would result in a compilation error


in java, the word true is

a boolean literal

suppose isPrime is a boolean variable, which of the flollowing is the correct and beat statement for testing if isPrime is true

if (isPrime)

suppose x=1, y=-1, and z=1. What is the printout of the following statement
if (y>0)
system.out.println("x>0 and y>0");
else if (z>0)
system.out.println("x<0 and z>0");

x<0 and z>0;

the "less than or equal to" comparison operator in Java is


what is y after the following statement is executed?
x = 0;
y = (x > 0) ? 10 : -10;


the value of a variable can be changed


a java application must have a main method


___translates high-level language program into machine language program

a compiler

When you create an array using the following statement, the element values are automatically initialized to zero
int[][] matrix = new int[5][5];


Assume x=4 and y=5, which of the following is true

x<5|| y<5

the order of the precedence (from high to low) of the operators binary +, *, &&, ||, & is:

*, +, &, ||, &&

which of the following is the correct expression that evaluates to true if the number x is between 1 and 100 or the number is negative?

((x<100) && (x>1)) || (x<0)

the not equal comparison operator in java is


the ___ operator can be used to compare two values


what is x after evaluating
x=(2>3) ? 2 : 3;


What is Math.round(3.6)?


What is Math.rint(3.6)?


To obtain the sine of 35 degrees, use _____.


A java character is stored in ______.

Two bytes

Suppose x is a char variable with a value 'b'. What is the printout of the statement System.out.println(++x)?


Which of the following statement prints smith\exam1\test.txt?


The Unicode of 'a' is 97. What is the Unicode for 'c'?


To check whether a char variable ch is an uppercase letter, you write ______.

(ch >= 'A' && ch <= 'Z')

What is the return value of "SELECT".substring(0, 5)?


Math.pow(3, 3) returns ______.


How many times will the following code print "Welcome to Java"?
int count = 0;
while (count < 10) {
System.out.println("Welcome to Java");


Analyze the following statement:
double sum = 0;
for (double d = 0; d < 10;) {
d += 0.1;
sum += sum + d;

The program compiles and runs fine.

The following loop displays __________.
for (int i = 1; i <= 10; i++) {
System.out.print(i + " ");

1 3 5 7 9

Analyze the following fragment:
duble sum = 0;
double d = 0;
while (d !=10.0) {
d += 0.1;
sum += sum + d;

The program may not stop because of the phenomenon referred to as numerical inaccuracy for operating with floating-point numbers.

You can always convert a for loop to a while loop.


You can always write a program without using break or continue in a loop.


Which of the loop statements always have their body executed at least once.

The do-while loop

What is the output of the following fragment?
int i = 1;
int j = 1;
while (i < 5) {
j = j * 2;


A variable declared in the for loop control can be used after the loop exists.


Which of the following expression yields an integer between 0 and 100, inclusive?

(int)(Math.random() * 101)

Suppose your method does not return any value, which of the following keywords can be used as a return type?


The signature of a method consists of ______.

method name and parameter list.

Each time a method is invoked, the system stores parameters and local variables in an area of memory, known as ______, which stores elements in last-in first-out fashion.

A stack

When you invoke a method with a parameter, the value of the argument is passed to the parameter. This is referred to as ______.

Pass by value

You can define two methods in the same class with the same name and parameter list.


You must have a return statement in a non-void method.


You should fill in the blank in the following code with _______.
public class Test {
public static void main(String[] args) {
System.out.print("The grade is ");
System.out.print("The grade is ");
public static ______


Analyze the following code:
class Test {
public static void main(String[] args) {
public static int xmethod(int n, long t) {
return n;
public static long xmethod(long n) {

The program displays long followed by 5.

______ is a simple but incomplete version of a method.

A stub

Variables defined in the method header are called ______.


The arraycopy method does not allocate memory space for the target array. The target array must already be created with memory space allocated.


What is the representation of the third element in an array called a?


If you declare an array double[ ] list = {3.4, 2.0, 3.5, 5.5}, the highest index in array list is ______.


What is the correct term for numbers[99]?

indexed variable

Assume int[] t = {1, 2, 3, 4}. What is t.length?


The array size is specified when the array is declared.


The array index is not limited to int type.


(for each loop) Analyze the following code:
public class Test {
public static void main(String[ ] args) {
double[ ] x = {2.5, 3, 4};
for (double value: x)
System.out.print(value + " ");

The program displays 2.5 3.0 4.0

In the following code, what is the printout for list1?
public class Test {
public static void main(String[ ] args) {
Int[] list1 = {1, 2, 3};
Int[] list2 = {1, 2, 3};
List2 = list1;
list1[0] = 0; list1 [1] = 1; list2[2] = 2;
for (int i = 0; i < list1.leng

0 1 2

public class Test {
public static void main(String[ ] args) {
Int[] x = {1, 2, 3, 4};
Int[] y = x;
x = new int[2];
for (int i = 0; i < y.length; i++)
System.out.print(y[i] + " ");

The program displays 1 2 3 4

What is Math.rint(3.5)?