Java Questions Flashcards

1
Q

Which one of the following is NOT true?

  1. Java is an Object Oriented language.
  2. Java has a preprocessor to parse #define, #include type statements.
  3. Java has no explicit pointer type.
  4. Java code is portable across platforms.
  5. JavaScript has no direct relationship to Java.
A
  1. Java has a preprocessor to parse #define, #include type statements.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

A Java Applet has a main method. True or False?

A

False

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

In Java, the closest analogy to a C function is called a/an:
1. attribute
2. class
3. interface
4. method
5. object

A
  1. method
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Select the correct answer by reviewing the following program.
1 HelloWorld.java: Hello World Application
2 #include java.lang.;
3 public class HelloWorld {
4 public void main(int argv, String args
) {
5 System.out.println(“Hello World!”);
6 }
7 }

  1. Only line 1 is incorrect.
    2 Only lines 1 and 5 are incorrect.
    3 Only lines 1, 2 and 4 are incorrect.
    4 Only lines 2 and 5 are incorrect.
    5 Only line 4 is incorrect.
A
  1. Only lines 1, 2 and 4 are incorrect.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Which one of the following regarding Java identifiers is incorrect?
1 Must not start with a digit
2 The characters must be letters, digits, or underscore symbols
3 Can be of any length
4 Are not case-sensitive
5 Cannot be Java keywords

A
  1. Are not case-sensitive
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Which one of the following variable names is the best to choose for a
variable to store the window height in a windowing application?
1 window_height
2 _windowHeight
3 windowHeight
4 w
5 WindowHeight

A
  1. windowHeight
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Which one of the following is suitable to be used as a Java identifier?
1 System
2 length
3 public
4 class
5 String

A
  1. length
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Which one of the following statements is incorrect?
1 int is a primitive data type.
2 String is a derived data type.
3 Array is a derived data type.
4 Float is a primitive data type.
5 boolean is a primitive data type.

A
  1. Float is a primitive data type.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Which one of the assignment statements is INCORRECT?
1 double a = 2;
2 double b = 2.7;
3 float c = 1.7;
4 double d = 2.70;
5 double e = 2/3;

A
  1. float c = 1.7;

Correct assignment: float c = 1.7F

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Consider the following variable definitions.
float x = 1.2F; int y = 2; double z = 4.0;
char p = ‘a’; short q = 1;
Which one of the assignment statements is NOT valid?
1 y = q;
2 x = z;
3 x = y;
4 z = y;
5 x = p;

A
  1. x = z

byte -> short -> int -> long -> float -> double
char -> int

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Which of the following are variable types in Java? You may select more
than one answer.
1 instance variable
2 local variable
3 method variable
4 global variable
5 static variable

A

1, 2 ,5

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What is a local variable in Java?

A

A variable defined inside a Java method.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Which one of the following declarations is NOT valid?
1 final int MAX_LENGTH = 420;
2 final double PI = 3.1428;
3 final char CHAR_CONST = “Z”;
4 final boolean BOOL_CONST = true;
5 final String STR_CONST = “Hello World”;

A

(3) final char CHAR_CONST = “Z”;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Consider the following Java program.

1 class CompareNumbers {
2 public static void main(String args[]) {
3 int a = 20, b = 10;
4 boolean c = 0;
5 if (a < b) c = 1;
6 System.out.println(“c = “ + c);
7 }
8 }

Which one of the following is correct?
1 The output will be: c = 0
2 The output will be: c = 1
3 The program will have a compilation error.
4 The program will have a run-time error.

A
  1. The program will have a compilation error.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Consider the following Java program.

1 class TwoWayExample {
2 public static void main(String args[]) {
3 int a = 20;
4 boolean b;
5 b = (a < 10) ? true : false;
6 System.out.println(“b = “ + b);
7 }
8 }

Which one of the following is correct?
1 The output will be: b = true
2 The output will be: b = false
3 The program will have a compilation error.
4 The program will have a run-time error.

A
  1. The output will be: b = false
How well did you know this?
1
Not at all
2
3
4
5
Perfectly