Sunteți pe pagina 1din 13

JAVA REVIEW QUESTIONS

Instructions:
1. Answer this test in 1 hour.
2. Cellphones, tablets, or the likes should be turned off.
3. No chatting with seatmates.
4. Answers should be clearly written.
5. Direct your questions to your PROCTOR.
6. Avoid erasure(s).
Test I. Multiple-Choice. Write only the letter of the correct answer.
1. What is the range of data type short in Java?
a) -128 to 127
b) -32768 to 32767
c) -2147483648 to 2147483647
d) None of the mentioned
2. What is the range of data type byte in Java?
a) -128 to 127
b) -32768 to 32767
c) -2147483648 to 2147483647
d) None of the mentioned
3. Which of the following are legal lines of Java code?
1. int w = (int)888.8;
2. byte x = (byte)100L;
3. long y = (byte)100;
4. byte z = (byte)100L;
a) 1 and 2
b) 2 and 3
c) 3 and 4
d) All statements are correct.
4. An expression involving byte, int, and literal numbers is promoted to which of these?
a) int
b) long
c) byte
d) float
5. Which data type value is returned by all transcendental math functions?
a) int
b) float
c) double
d) long
6. What is the output of this program?
class conversion {
public static void main(String args[])

{
double a = 295.04;
int b = 300;
byte c = (byte) a;
byte d = (byte) b;
System.out.println(c + " " + d);
}
}
a) 38 43
b) 39 44
c) 295 300
d) 295.04 300
7. What is the output of this program?
class increment {
public static void main(String args[])
{
int g = 3;
System.out.print(++g * 8);
}
}
a) 25
b) 24
c) 32
d) 33
8. What is the numerical range of a char in Java?
a) -128 to 127
b) 0 to 256
c) 0 to 32767
d) 0 to 65535
9. Which of these values can a boolean variable contain?
a) True & False
b) 0 & 1
c) Any integer value.
d) Both a & b
10.

11.

Which one is a valid declaration of a boolean?


a) boolean b1 = 1;
b) boolean b2 = false;
c) boolean b3 = false;
d) boolean b4 = true
What is the output of this program?
class booloperators {
public static void main(String args[])
{
boolean var1 = true;
boolean var2 = false;
System.out.println((var2 & var2));
}
}

a) 0
b) 1
c) true
d) false
12.

Which of the following can be operands of arithmetic operators?


a) Numeric
b) Boolean
c) Characters
d) Both Boolean & Characters

13.

Modulus operator, %, can be applied to which of these?


a) Integers
b) Floating point numbers
c) Both Integers and floating point numbers.
d) None of the mentioned

14. With x = 0, which of the following are legal lines of Java code for changing the
value of x to 1?
1.
x++;
2.
x = x + 1;
3.
x += 1;
4.
x =+ 1;
a) 1, 2 & 3
b) 1 & 4
c) 1, 2, 3 & 4
d) 3 & 2
15. Decrement operator, , decreases value of variable by what number?
a) 1
b) 2
c) 3
d) 4
16.

If x has a value of 3, what would be its value if execute --x?


a) 3
b) 4
c) -3
d) -4

17.

18.

Which of these statements are incorrect?


a) Assignment operators are more efficiently implemented by Java run-time system
than their equivalent long forms.
b) Assignment operators run faster than their equivalent long forms.
c) Assignment operators can be used only with numeric and character data type.
d) None
What is the output of this program?
class increment {
public static void main(String args[])
{
double var1 = 1 + 5;
double var2 = var1 / 4;

int var3 = 1 + 5;
int var4 = var3 / 4;
System.out.print(var2 + " " + var4);
}
}
a) 1 1
b) 0 1
c) 1.5 1
d) 1.5 1.0
19.

What is the output of this program?


class Modulus {
public static void main(String args[])
{
double a = 25.64;
int b = 25;
a = a % 10;
b = b % 10;
System.out.println(a + " " + b);
}
}
a) 5.640000000000001 5
b) 5.640000000000001 5.0
c) 5 5
d) 5 5.640000000000001

20.

What is the output of this program?


class Output {
public static void main(String args[])
{
int x , y;
x = 10;
x++;
--x;
y = x++;
System.out.println(x + " " + y);
}
}
a) 11 11
b) 10 10
c) 11 10
d) 10 11

21.

What is the output of this program?


class Output {
public static void main(String args[])
{
int a = 1;
int b = 2;
int c;
int d;

c = ++b;
d = a++;
c++;
b++;
++a;
System.out.println(a + " " + b + " " + c);
}
}
a) 3 2 4
b) 3 2 3
c) 2 3 4
d) 3 4 4
22.

What is the value stored in x in following lines of code?


int x, y, z;
x = 0;
y = 1;
x = y = z = 8;
a) 0
b) 1
c) 9
d) 8

23.

What is the output of this program?


class operators {
public static void main(String args[])
{
int x = 8;
System.out.println(++x * 3 + " " + x);
}
}
a) 24 8
b) 24 9
c) 27 8
d) 27 9

24.

Which of these keywords is used to make a class?


a) class
b) struct
c) int
d) None of the mentioned

25.

String in Java is a?
a) class
b) object
c) variable
d) character array

26.

What is the output of this program?


class string_demo {
public static void main(String args[])

{
String obj = "I" + "like" + "Java";
System.out.println(obj);
}
}
a) I
b) like
c) Java
d) IlikeJava
27.

What is the output of this program?


class string_class {
public static void main(String args[])
{
String obj = "I LIKE JAVA";
System.out.println(obj.charAt(3));
}
}
a) I
b) L
c) K
d) E

28.

What is the output of this program?


class string_class {
public static void main(String args[])
{
String obj = "I LIKE JAVA";
System.out.println(obj.length());
}
}
a) 9
b) 10
c) 11
d) 12

29.

Why do computers use zeros and ones?


a) because combinations of zeros and ones can represent any numbers and
characters.
b) because digital devices have two stable states and it is natural to use one state
for 0 and the other for 1.
c)because binary numbers are simplest.
d) because binary numbers are the bases upon which all other number systems are
built.

30.

Computer can execute the code in ____________.


a) machine language
b) assembly language
c) high-level language
d) none of the above
6

31. ___________ translates high-level language program into machine language


program.
a) An assembler
b) A compiler
c) CPU
d) The operating system
32.

Java was developed by ____________.


a) Sun Microsystems
b) Microsoft
c) Oracle
d) IBM

33.

Java ___________ can run from a Web browser.


a) applications
b) applets
c) servlets
d) Micro Edition programs

34.

________ is an object-oriented programming language. (Choose three)


a) Java
b) C++
c) C
d) C#

35.

The main method header is written as:


a) public static void main(string[] args)
b) public static void Main(String[] args)
c) public static void main(String[] args)
d) public static main(String[] args)

36.

Which of the following statements is correct?


a) Every line in a program must end with a semicolon.
b) Every statement in a program must end with a semicolon.
c) Every comment line must end with a semicolon.
d) Every method must end with a semicolon.

37. Which of the following statements is correct to display Welcome to Java on the
console? (Choose two)
a) System.out.println('Welcome to Java');
b) System.out.println("Welcome to Java");
c) System.println('Welcome to Java');
d) System.out.print("Welcome to Java");
38.

Java compiler translates Java source code into _________.


a) Java bytecode
b) machine code
c) assembly code
d) another high-level language code

39.

_________ is a software that interprets Java bytecode.


a) Java virtual machine
b) Java compiler
c) Java debugger
d) Java API

40.

Suppose you define a Java class as follows:


public class Test {
}
In order to compile this program, the source code should be stored in a file named
a) Test.class
b) Test.doc
c) Test.txt
d) Test.java

41.

Which of the following lines is not a Java comment?


a) /** comments */
b) // comments
c) -- comments
d) /* comments */

42.

Which of the following are the reserved words? (Choose all possible answer)
a) public
b) static
c) void
d) class

43. To use Scanner in your program, you may import it using: (Choose all possible
answer)
a) import javax.util.Scanner;
b) import java.util.Scanner;
c) import javax.util.Scanner;
d) import java.util.*;
44.

Programming style is important, because ______________.


a) a program may not compile if it has a bad style
b) good programming style can make a program run faster
c) good programming style makes a program more readable
d) good programming style helps reduce programming errors

45. If a program compiles fine, but it produces incorrect result, then the program
suffers __________.
a) a compilation error
b) a runtime error
c) a logic error
d) none of these errors

46. If you forget to put a closing quotation mark on a string, what kind error will be
raised?
a) a compilation error
b) a runtime error
c) a logic error
d) relative error
47.

Suppose a Scanner object is created as follows:


Scanner input = new Scanner(System.in);
What method do you use to read an int value?
a) input.nextInt();
b) input.nextInteger();
c) input.int();
d) input.integer();

48.

The following code fragment reads in two numbers:

Scanner input = new Scanner(System.in);


int i = input.nextInt();
double d = input.nextDouble();
System.out.println((i + d));
Assume the input is 2.5 3.2, what will be the output?
a.
b.
c.
d.
49.

5.7
5.6
5
6

What are the correct ways to enter these two numbers?


A. Enter an integer, a space, a double value, and then the Enter key.
B. Enter an integer, two spaces, a double value, and then the Enter key.
C. Enter an integer, an Enter key, a double value, and then the Enter key.
D. Enter a numeric value with a decimal point, a space, an integer, and then the
Enter key.

50.

If you enter 1 2 3, when you run this program, what will be the output?

import java.util.Scanner;
public class Test1 {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.print("Enter three numbers: ");
double number1 = input.nextDouble();
double number2 = input.nextDouble();
double number3 = input.nextDouble();
// Compute average
double average = (number1 + number2 + number3) / 3;
// Display result
System.out.println(average);

}
}
A. 1.0
B. 2.0
C. 3.0
D. 4.0
51.

Which of the following is a valid identifier?


A. $343
B. class
C. 9X
D. radius

52. Which of the following are correct names for variables according to Java naming
conventions? (Choose all that applies)
A. radius
B. Radius
C. RADIUS
D. findArea
53.

Which of the following are correct ways to declare variables?


A. int length; int width;
B. int length, width;
C. int length; width;
D. int length, int width;

54.

____________ is the Java assignment operator.


A. ==
B. :=
C. =
D. =:

55.

To assign a value 1 to variable x, you write


A. 1 = x;
B. x = 1;
C. x := 1;
D. 1 := x;

56.

To declare a constant MAX_LENGTH inside a method with value 99.98, you write
A. final MAX_LENGTH = 99.98;
B. final float MAX_LENGTH = 99.98;
C. double MAX_LENGTH = 99.98;
D. final double MAX_LENGTH = 99.98;

57. Which of the following is a constant, according to Java naming conventions?


(Choose all that applies.)
A. MAX_VALUE

10

B. Test
C. read
D. ReadInt
58.

Which of these data types requires the most amount of memory?


A. long
B. int
C. short
D. byte

59.

What is the result of 45 / 4?


A. 10
B. 11
C. 11.25
D. 12

60.

Which of the following expression results in a value 1?


A. 2 % 1
B. 15 % 4
C. 25 % 5
D. 37 % 6

61.

Analyze the following code.

public class Test {


public static void main(String[] args) {
int month = 09;
System.out.println("month is " + month);
}
}
A. The program displays month is 09
B. The program displays month is 9
C. The program displays month is 9.0
D. The program has a syntax error, because 09 is an incorrect literal value.
62. The expression 4 + 20 / (3 - 1) * 2 is evaluated to
A. 4
B. 20
C. 24
D. 9
63. To add a value 1 to variable x, you write
A. 1 + x = x;
B. x += 1;
C. x := 1;
D. x = x + 1;
64. To add number to sum, you write (Note: Java is case-sensitive)

11

A. number += sum;
B. number = sum + number;
C. sum += number;
D. sum = sum + number;
65. Suppose x is 1. What is x after x += 2?
A. 0
B. 1
C. 2
D. 3
66. What is x after the following statements?
int x = 2;
int y = 1;
x *= y + 1;

A. x is 1.
B. x is 2.
C. x is 3.
D. x is 4.
67. What is the value of i printed?
public class Test {
public static void main(String[] args) {
int j = 0;
int i = ++j + j * 5;
System.out.println("What is i? " + i);
}
}
A. 0
B. 1
C. 5
D. 6
68. What is the value of i printed in the following code?
public class Test {
public static void main(String[] args) {
int j = 0;
int i = j++ + j * 5;
System.out.println("What is i? " + i);
}
}

12

A. 0
B. 1
C. 5
D. 6
69. What is y displayed in the following code?
public class Test {
public static void main(String[] args) {
int x = 1;
int y = x++ + x;
System.out.println("y is " + y);
}
}
A. y is 1.
B. y is 2.
C. y is 3.
D. y is 4.
70. Which of the following assignment statements is illegal?
A. float f = -34;
B. int t = 23;
C. short s = 10;
D. int t = (int)false;

13

S-ar putea să vă placă și