Java Programming

0.0(0)
studied byStudied by 0 people
0.0(0)
full-widthCall Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/90

encourage image

There's no tags or description

Looks like no tags are added yet.

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

91 Terms

1
New cards

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

An Object

2
New cards

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

A class

3
New cards

An object is an instance of a ________

class

4
New cards

The keyword ________ is required to declare a class.

class

5
New cards

________ is invoked to create an object.

A constructor

6
New cards

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

false, 0, null

7
New cards

public class Test{

int x;

public Test(String t){

System.out.println("Test");

}

public static void main(String[] args){

Test test = new Test();

System.out.println(test.x);

}

}

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

8
New cards

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

True

9
New cards

The default constructor has no arguments

True

10
New cards

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

True

11
New cards

Which one of the following statements are correct

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

12
New cards

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

4 and 5

13
New cards

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

a[0][0]

14
New cards

___is the physical aspect of the computer that can be seen

hardware

15
New cards

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

25

16
New cards

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

30

17
New cards

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; column++);

System.out.print(values[row][column]+" ");

System.out.println();

}

}

}

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

18
New cards

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

19
New cards

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

20
New cards

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

5 and 7

21
New cards

One byte has___bits

8

22
New cards

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

true

23
New cards

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

true

24
New cards

___is the java assignment operator

=

25
New cards

which of the following expression results in a value 1

37 % 6

26
New cards

-24 % 5 is

-4

27
New cards

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

24

28
New cards

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

2.0

29
New cards

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

x=(int)d;

30
New cards

the equal comparison operator in java is

==

31
New cards

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

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

32
New cards

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!.

33
New cards

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

}

-1

34
New cards

The following code displays ___________.

double temperature = 50;

if (temperature >= 100)

System.out.println("too hot");

else if (temperature <= 40)

System.out.println("too cold");

else

System.out.println("just right");

just right

35
New cards

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

false

36
New cards

in java, the word true is

a boolean literal

37
New cards

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

if (isPrime)

38
New cards

suppose x=1, y=-1, and z=1. What is the printout of the following statement

if(x>0)

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;

39
New cards

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

<=

40
New cards

what is y after the following statement is executed?

x = 0;

y = (x > 0) ? 10 : -10;

-10

41
New cards

the value of a variable can be changed

true

42
New cards

a java application must have a main method

true

43
New cards

___translates high-level language program into machine language program

a compiler

44
New cards

When you create an array using the following statement, the element values are automatically initialized to zero

int[][] matrix = new int[5][5];

true

45
New cards

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

x<5|| y<5

46
New cards

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

*, +, &, ||, &&

47
New cards

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)

48
New cards

the not equal comparison operator in java is

!=

49
New cards

the ___ operator can be used to compare two values

relational

50
New cards

what is x after evaluating

x=(2>3) ? 2 : 3;

3

51
New cards

What is Math.round(3.6)?

4

52
New cards

What is Math.rint(3.6)?

4.0

53
New cards

To obtain the sine of 35 degrees, use _____.

Math.sin(Math.toRadians(35))

54
New cards

A java character is stored in ______.

Two bytes

55
New cards

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

c

56
New cards

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

System.out.println("smith\\exam1\\test.txt");

57
New cards

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

99

58
New cards

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

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

59
New cards

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

"SELEC"

60
New cards

Math.pow(3, 3) returns ______.

27.0

61
New cards

How many times will the following code print "Welcome to Java"?

int count = 0;

while (count < 10) {

System.out.println("Welcome to Java");

count++;

}

10

62
New cards

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.

63
New cards

The following loop displays __________.

for (int i = 1; i <= 10; i++) {

System.out.print(i + " ");

i++;

}

1 3 5 7 9

64
New cards

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.

65
New cards

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

True

66
New cards

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

True

67
New cards

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

The do-while loop

68
New cards

What is the output of the following fragment?

int i = 1;

int j = 1;

while (i < 5) {

i++;

j = j * 2;

}

System.out.println(j);

16

69
New cards

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

False

70
New cards

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

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

71
New cards

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

Void

72
New cards

The signature of a method consists of ______.

method name and parameter list.

73
New cards

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

74
New cards

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

75
New cards

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

False

76
New cards

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

True

77
New cards

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 ");

printGrade(78.5);

System.out.print("The grade is ");

printGrade(59.5);

}

public static ______ printGrade(double score) {

if (score >= 90.0) {

System.out.println('A');

}

else if (score >= 80.0) {

System.out.println('B');

}

else if (score >= 70.0) {

System.out.println('C');

}

else if (score >= 60.0) {

System.out.println('D');

}

else {

System.out.println('F');

}

}

}

Void

78
New cards

Analyze the following code:

class Test {

public static void main(String[] args) {

System.out.println(xmethod(5));

}

public static int xmethod(int n, long t) {

System.out.println("int");

return n;

}

public static long xmethod(long n) {

System.out.println("long");

return n;

}

}

The program displays long followed by 5.

79
New cards

______ is a simple but incomplete version of a method.

A stub

80
New cards

Variables defined in the method header are called ______.

Parameters

81
New cards

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

True

82
New cards

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

a[2]

83
New cards

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

3

84
New cards

What is the correct term for numbers[99]?

indexed variable

85
New cards

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

4

86
New cards

The array size is specified when the array is declared.

True

87
New cards

The array index is not limited to int type.

False

88
New cards

(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

89
New cards

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.length; i+)

System.out.print(list1[i] + " ");

}

}

0 1 2

90
New cards

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

91
New cards

What is Math.rint(3.5)?

4.0