Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
2 views

java_mcq

The document provides a comprehensive introduction to Java, covering objective type questions related to Java fundamentals, data types, operators, and input handling. It includes multiple-choice questions that test knowledge on Java concepts such as the Java Virtual Machine (JVM), data types, operators, and error handling. The content is structured in parts, each focusing on different aspects of Java programming.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

java_mcq

The document provides a comprehensive introduction to Java, covering objective type questions related to Java fundamentals, data types, operators, and input handling. It includes multiple-choice questions that test knowledge on Java concepts such as the Java Virtual Machine (JVM), data types, operators, and error handling. The content is structured in parts, each focusing on different aspects of Java programming.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 22

Part 1 - Introduction to Java

I. Objective Type Questions:

1. A virtual machine that executes Java byte code is called:


A) javac C) Java assembler
B) OOP D) JVM

2. Machine language for Java Virtual Machine is called:


A) JVM C) Bytecode
B) Java platform D) Java compiler

3. Java language is:


A) Multithreaded C) Object Oriented
B) Platform independent D) All of the above

4. Pick the correct statement:


A) Java uses interpreter only C) Java uses compiler only
B) Java uses compiler and interpreter D) None of the above

5. Pick the correct statement:


A) A compiler translates code into high-level language all at once
B) A compiler translates code into machine language one line at a time
C) An interpreter translates code into machine language all at once
D) An interpreter translates code into machine language one line at a time

6. A machine language version of the code is called:


A) Object Code C) High Level Code
B) Source Code D) Main Method Code

7. A computer only understands


A. High-level language
B. Assembly language
C. English language
D. Machine language

8. A computer program’s capability to run on multiple operating systems is called:


A) Multiuser program C) Platform dependence
B) Platform independence D) Multilingual program

9. The file extension of a Java class file is:


A. .class
B. .doc
C. .bluej
D. .java
10. What does a stand-alone Java application need for execution?
A. A Java-compatible web browser
B. Does not need a Java-compatible web browser
C. Needs an Assembler
D. Needs an Object Linker

11. The acronym JIT in JIT Compiler stands for


A. Just In Transfer
B. Java Input Terminal
C. Just In Time
D. Java Input Token

12. The acronym JRE stands for


A. Java Routine Enabler
B. Java Runtime Environment
C. Java Robust Editor
D. Java Runtime Execution

13. Which statement is true?


A. Java application can run on Windows platform only
B. Java applications are platform dependent
C. Java applications are platform independent
D. Java applications don’t need a platform to run

14. A computer program that translates a high-level language program into machine code is:
A. Linker
B. Assembler
C. Library
D. Compiler

15. Pick the correct answer:


A. An applet can be executed in an Applet Viewer and Web Browser
B. An applet can be executed in an Applet Viewer only
C. An applet can be executed in a Web Browser only
D. An applet cannot be executed on a computer

16. A computer program that translates an assembly language program into machine code is:
A. Linker
B. Assembler
C. Library
D. Compiler

17. The file extension of a Java program is


A. .class
B. .doc
C. .bluej
D. .java
18. Which statement is true?
A. Java applications can run on Windows
B. Java applications can run on Mac
C. Java applications can run on Linux
D. All of the above

19. The acronym JVM stands for


A. Java Virtual Motor
B. Java Virtual Monitor
C. Java Virtual Mode
D. Java Virtual Machine

20. For a Java program to run as a stand-alone program it must have:


A. a main method
B. a virtual method
C. a protected method
D. an overloaded method

Part 2 - Values and Data Types

I. Objective Type Questions:

1. Abbreviation ASCII stands for:


A) American Standard Code for Interface Implementation
B) American Standard Computer for Information Interchange
C) American Standard Computer for Intelligent Interface
D) American Standard Code for Information Interchange

2. Which character set would you use if you have characters from Hindi, Japanese and German
to display?
A) ASCII Character Set C) Unicorn Character Set
B) Extended ASCII Character Set D) Unicode Character Set

3. ASCII character set can represent:


A) 127 different characters C) 128 different characters
B) 256 different characters D) Any number of characters

4. Which one is an invalid Escape Sequence?


A) /n C) /a
B) /t D) All of the above

5. Which one is not a keyword in Java?


A) abstract C) integer
B) class D) long

6. Which one is a valid identifier in Java?


A) total amount C) total_percentage_%
B) total-amount D) total_amount_$
7. Which one is a valid integer literal?
A) -7777
B) 77 38
C) 56,234
D) $788

8. Which one is a valid real literal?


A) 65.
B) .65
C) 65
D) 65.6
9. Which of the following is not a character literal?
A) ‘\a’ C) “a”
B) ‘a’ D) ‘\?’

10. Which one is not a reference data type in Java?


A) class C) interface
B) boolean D) class

11. Which of the following is the size of short data type in Java?
A) 8 bits C) 24 bits
B) 16 bits D) 32 bits

12. Which of the following is the size of char data type in Java?
A) 8 bits C) 24 bits
B) 16 bits D) 64 bits

13. Given statement int x =


‘Z’; What is the value of
x?
A) 90 C) 65
B) 91 D) Invalid assignment

14. Which of the following is default initial value of a boolean datatype?


A) true C) false
B) null D) void

15. The keyword that converts a variable with its value into a constant is:
A) const C) constant
B) fixed D) final

16. The smallest individual unit in a program is:


A) Identifier C) Token
B) Method D) Function

17. Which statement is incorrect?


A) You can assign a value to the variable at the time of declaration
B) You can declare a variable and initialise it separately
C) You can assign values to multiple variables in one statement
D) When declaring a variable, you cannot assign an initial value that is an expression
18) Which statement is incorrect about naming identifiers in Java?
A) An identifier can consist of any number of letters and digits
B) An identifier can begin with an underscore
C) C) An identifier can begin with a digit
D) An identifier can begin with a dollar sign
21. Name the data type that is a 64-bit integer:
A) int C) float
B) double D) long

22. Arrange the following primitive data types in the ascending order of
size: char, byte, double, int
A) byte, char, int, double
B) char, byte, int, double
C) byte, char, double, int
D) char, byte, int, double

23. Pick the correct statement


A) char data type occupies 2 bytes and the int data type occupies 4 bytes
B) char data type occupies 4 bytes and the int data type occupies 2 bytes
C) both char and int data type occupy 2 bytes
D) both char and int data type occupy 4 bytes

24. Which of the following is a keyword?


A) keyword C) attribute
B) character D) continue

25. ASCII codes of a-z are represented by decimal range:


A) 97-122 C) 65-91
B) 98-123 D) 65-92

26. Which of these is not a character literal?


A) “\t” C) ‘\t’
B) ‘t’ D) None of the above

27. Which of the following is not integral data type?


A) byte C) long
B) short D) double

Part 3 - Operators in Java

I. Objective Type Questions:

1. Which form of Operators are supported in Java?


A) Unary Operators
B) Binary Operators
C) Ternary Operators
D) All of the above
2. Which of the following is not a binary operator?
A) /
B) OR
C) ++
D) =

3. Which of the following is not a valid operator in Java?


A) %
B) --
C) ++
D) =!

4. Statement i = i -1 is equivalent to
A) i--
B) --i
C) i -= 1
D) All of the above

5. Given z = 4, the statement x = ++z + 4 evaluates to


A) 8
B) 9
C) 10
D) 11

6. Given num1 = 0, num2 = 1 the statement (num1 < num2) && (num1 > num2) evaluates to
A) true
B) false
C) 1
D) 0

7. Given num1 = 0, num2 = 1 the statement (num1 < num2) || (num1 > num2) evaluates to
A) true
B) false
C) 1
D) 0
8. Given num1 = 0, num2 = 1 the statement !(num1 > num2) evaluates to
A) true
B) false
C) 1
D) 0
E)

9. Given num1 = 0, num2 = 1 the statement !(num1 < num2) evaluates to


A) true
B) false
C) 1
D) 0

10. The expression 19 % 4 evaluates to


A) 2
B) 4
C) 3
D) 1

11. The expression 19 / 4 evaluates to


A) 2
B) 4
C) 3
D) 1

12. The statement System.out.println("One" + 1 + 1); gives the output


A) One2
B) One1
C) 2One
D) One11
13. What is the value of y after evaluating the expression given below?
y += ++y + y-- + --y; when int y = 8.
A) 32
B) 33
C) 34
D) 35

14. What is the value of x1 when x=5?


x1 = ++x - x++ + --x;
A) 4
B) 5
C) 7
D) 6

15. What is the result stored in x, after evaluating the following expression?
int x = 5;
x = x++ * 2 + 3 * --x;

A) 25
B) 24
C) 23
D) 26

16. What will be the result stored in X after evaluating the following expression?
int X = 4;
X += (X++) + (++X) + X;
A) 19
B) 20
C) 21
D) 22

17. Write the Output:


char ch= 'A';
int m=ch; m=m+5;
System.out.println(m + " " + ch);

A) 70 A
B) 71 A
C) A70
D) 72 A

18. What is the output of the following program snippet?


char x = ‘a’; int m;
m = (x == ‘a’) ? ‘A’ : ‘a’;
System.out.println(“m=”+m);

A) m=65
B) m=97
C) m=’a’
D) m=’A’

19. What will be the output of the following code?


int k=5, j=9;
k += k++ - ++j + k;
System.out.println(“k= ”+ k);
System.out.println(“j= ”+ j);
A) k=7 j= 11
B) k=6 j= 11
C) k=7 j= 10
D) k=6 j= 10

20. What will be the output of the following code?


int a = 5;
a++;
a -= (a--) - (--a);
System.out.println(a);

A) 3
B) 4
C) 5
D) 6
21. An operator taking three operands for its operation is:

A. A unary operator

B. A binary operator

C. A ternary operator

D. There is no such operator

22. What is the output of the code snippet?


int x = 'a';
System.out.println(x);
A. ‘a’
B. 97
C. null
D. x

23. The expression 8 % 2 * 3 evaluates to:

A. 2
B. 12
C. 0
D. 48

24. The value of b evaluates to:


boolean b = (true == false) ? true : false;
A. true
B. false
C. null
D. Runtime error

25. What is the output of the code snippet?


char c = (char)65;
System.out.println(c);

A. 65
A. A
B. null
C. c
Part 4 - Inputs in Java

I. Objective Type Questions:

1. Which of the following are valid comments?


1. /* comment */
2. /* comment
3. // comment
4. */ comment */

A) 1 only
B) 3 only
C) 1 and 3
D) 1, 3 and 4

2. Name the type of error that occurs for the following statement:
System.out.println(Math.sqrt(36-45));

A) Syntax error
B) Runtime error
C) Logical error
D) No error

3. Name the type of error that occurs for the following statement:
int a;b;c;

A) Syntax error
B) Runtime error
C) Logical error
D) No error

4. Pick the statement that will include all the classes present in java.util package into your program:
A) include java.util
B) java.util
C) package java.util
D) import java.util

5. Name the type of error that occurs for the following scenario:
Division by a variable that contains a value zero.
A) Syntax error
B) Runtime error
C) Logical error
D) No error
6. Name the type of error that occurs for the following scenario:
Multiplication operator used when the operation should be division.
A) Syntax error
B) Runtime error
C) Logical error
D) No error

7. Name the type of error that occurs for the following scenario:
Missing semicolon at the end of a statement.
A) Syntax error
B) Runtime error
C) Logical error
D) No error

8. Which option completes the following statement:


Scanner sc = ------- Scanner (------);
A) new and System.in
B) old and System.in
C) new and System.out
D) new and java.in

9. Name the package that contains Scanner class.


A) java.io
B) java.scanner
C) scanner.io
D) java.util

10. Which of the following statement we must write to import just the Scanner class from
the java.util package
A) import java.util.*
B) import package java.util.Scanner
C) include java.util.Scanner
D) import java.util.Scanner

11. Which of the following is/are an invalid comment(s)?


1. /* comment */
2. /** comment **/
3. // comment
4. */ comment */

A) 2 only
B) 4 only
C) 2 and 4
D) 2, 3 and 4
12. Name the method of Scanner class that is used to input an integer data from the standard
input device
A) NextInt()
B) nextInteger()
C) nextNumber()
D) nextInt()

13. Name the keyword used to call a package in the program


A) package
B) include
C) call
D) import

14. Name the input source that a Scanner object uses to accept data from the standard input device
A) System.in
B) System.input
C) Scanner.in
D) Java.input

15. The following code snipped will result in:


int i;
i++;

A) Syntax error
B) Runtime error
C) Logical error
D) No error

16. Pick the invalid method that is not in the Scanner class:
A) nextInt()
B) next()
C) nextNumber()
D) nextLong()

17. Pick the default delimiter used in the Scanner class:


A) Semicolon
B) Comma
C) Whitespace
D) There is no default delimiter

18. The pacakage that contains methods to display date and time is:
A) Java.date
B) Java.lang
C) Java.io
D) Java.util
19. Which statement is true?
A) The next() method is used to read the next complete token
B) The nextLine() method is used to read a complete line of text
C) The next().charAt(0) returns the first character
D) All of the above

20. Name the method of Scanner class that checks if the Scanner has another token in its input:
A) hasNext()
B) nextToken()
C) getNext()
D) hasNextToken()

Part 5- Mathematical Library Methods

I. Objective Type Questions:

1. What is the output of the following Math function?


Math.floor(-7.7)

A) 8.0
B) 7.0
C) -7.0
D) -8.0

2. What is the output of the following Math function?


Math.ceil(5.4) + Math.ceil(4.5)

A) 9.0
B) 10.0
C) 11.0
D) 12.0

3. What is the output of the following Math function?


Math.ceil(-5.4) + Math.ceil(-4.5)

A) -9.0
B) -10.0
C) 9.0
D) 10.0

4. What is the output of the following Math function?


Math.abs(Math.min(-2.84, -6.54))

A) -2.84
B) -6.54
C) 2.84
D) 6.54
5. What is the output of the following Math function?
Math.sqrt(Math.floor(25.9))

A) 25.0
B) 5.0
C) 26.0
D) 6.0

6. What is the output of the following Math function?

Math.ceil(4.5 + 4.4)

A) 8.0
B) 9.0
C) 10.0
D) Runtime error

7. What is the output of the following expression?


Math.round(Math.abs(-0.5))

A) 1
B) -1
C) 0
D) Runtime error

8. Which package includes the Math class?


A) Java.math
B) Java.util
C) Java.lang
D) Java.io

9. Which package is imported by default in a Java program?


A) Java.math
B) Java.util
C) Java.lang
D) Java.io
10. Which statement is correct?
Math.random() returns a:
A) double value greater than or equal to 0.0 and less than 1.0
B) int value greater than or equal to 0 and less than 1
C) double value greater than or equal to 0.0 and less than or equal to 1.0
D) int value greater than or equal to 0 and less than or equal to 1

11. What will be the output of Math.cbrt(-64)?


A) -4.0
B) 4.0
C) 0.0
D) Runtime error – we cannot use a negative number

12. What will be the output of Math.pow(-1, 0)?


A) -1.0
B) 1.0
C) 0.0
D) Runtime error – we cannot use a negative number

13. Which package is imported by default in a Java program?


A) Java.math
B) Java.util
C) Java.lang
D) Java.io

14. Which of the following is a method to find the cube root of a number?
A) cubeRoot(x)
B) Cbrt(x)
C) Math.cubeRoot(x)
D) Math.cbrt(x)

15. Which of the following is true for Math.round() method?


A) If the argument type is double, the return type is long.
B) If the argument type is float, the return type is int.
C) The method returns the closest int or long.
D) All of the above are true.

16. What will be the output of Math.abs(-3.1)?


A) -3.1
B) 3.0
C) 3.1
D) -3.0
Part 6 - Conditional Constructs in Java

I. Objective Type Questions:

1. What is the value of variable x?


int a = 99, b= 76;
boolean x = (a > b) ? true : false;
A) true
B) false
C) 99
D) 76

2. What is the value of variable x?


int a = 99, b= 76;
int x = (a < b) ? a : b;
A) true
B) false
C) 99
D) 76

3. An if-else statement can be represented by which operator in Java?


A) iff
B) ?
C) !
D) ?:

4. Which option is the correct rewrite of the following statement?


if (salary > 10000)
bonus = salary * 0.1;
else
bonus = 0;

A) bonus = (salary > 10000) ? salary * 0.1 : 0;


B) salary = (salary > 10000) ? salary * 0.1 : 0;
C) salary = (bonus > 10000) ? salary * 0.1 : 0;
D) bonus = (bonus > 10000) ? salary * 0.1 : 0;

5. Given the following code snippet:

int x = 1, y = 1;
if (n > 0)
{
x++;
--y;
}
What will be the value of x and y when n = 0?

A) x = 2, y = 0
B) x = 0, y = 2
C) x = 1, y = 0
D) x = 1, y = 1

6. Given the following code snippet:

int x = 1, y = 1;
if (n > 0)
{
x++;
--y;
}

What will be the value of x and y when n = 1?

A) x = 2, y = 0
B) x = 0, y = 2
C) x = 1, y = 0
D) x = 1, y = 1

7. What type of type casting is shown in the following statements?


1) char c = (char) 120;
2) int x = 't';

A) Explicit in both 1) and 2)


B) Implicit in both 1) and 2)
C) Explicit in 1) and Implicit in 2)
D) Implicit in 1) and Explicit in 2)

8. Which statement(s) is/are true for the given code snippet?

if (x = y);
x=0
else
x++

A) The assignment operator is used instead of the equality operator


B) There should be no semicolon after if (x = y);
C) Semicolon is required after x = 0 and x++
D) All of the above are true
9. Given the following code snippet.

String grade = (marks >= 90) ? "A": (marks > 80) ? "B" : "C";

What will be the value of grade when marks = 81?

A) A
B) B
C) C
D) Runtime error

10. Given the following code snippet.

int p = 3, q = 2, r = 1;
switch(n)
{
case 1: p++;
case 2: q++;
case 3: r++;
}

What will be the value of p, q and r when n = 2?

A) p = 3, q = 3, r = 2
B) p = 3, q = 3, r = 3
C) p = 3, q = 2, r = 2
D) p = 3, q = 2, r = 1

11. Given the following code snippet.

int p = 3, q = 2, r = 1;
switch(n)
{
case 1: p++;
case 2: q++;
case 3: r++;
}

What will be the value of p, q and r when n = 0?

A) p = 3, q = 3, r = 2
B) p = 3, q = 3, r = 3
C) p = 3, q = 2, r = 2
D) p = 3, q = 2, r = 1
12. Which statement will produce the absolute value of variable x?
A) x = x < 0 ? -x : -x;
B) x = x < 0 ? x : -x;
C) x = x > 0 ? -x : x;
D) x = x < 0 ? -x : x;

13. Which keyword is optional in the switch statement?


A) switch
B) case
C) default
D) None of the above

14. Which keyword is mandatory in the switch statement?


A) break
B) case
C) default
D) return

15. if ((a < b) && (a < c)), then which of the following statement is true?
A) a is the smallest number
B) b is the smallest number
C) c is the smallest number
D) b is the largest number

Part 7 - Iterative Constructs

I. Objective Type Questions:

1. How many times the following loop will


execute? int counter = 1;
do
{
System.out.println(counter);
}
while (++counter < 5);

A) 4
B) 5
C) 6
D) Infinite time
2. How many times the following loop will
execute? int counter = 1;
do
{
System.out.println(counter);
}
while (counter++ < 5);

A) 4
B) 5
C) 6
D) Infinite time

3. How many times the following loop will


execute? int counter = 6;
do
{
System.out.println(counter);
}
while (counter++ < 5);

A) 1
B) 2
C) 5
D) 6

4. for (int i = 5; i > 10; i++)


System.out.println(i);

A) 0
B) 1
C) 5
D) Infinite time

5. What will be the final value of x and y at the end of code


snippet? int x = 2, y = 10;
for (int i = 1; i < 5; i++) x+
+; y++;

A) x = 6, y = 14
B) x = 6, y = 11
C) x = 5, y = 11
D) x = 5, y = 14
6. Given the following code
snippet: int j = 1, k = 2;
while (++k <
5) j *= k;

Which of the following statement is true?

A) The output will be 1 and the loop will execute 0 time


B) The output will be 3 and the loop will execute 1 time
C) The output will be 12 and the loop will execute 2 times
D) The output will be 60 and the loop will execute 3 times

7. How many times the following loop will


execute? for (int i = 1; i <= 6; i++)
for (int j = 1; j <=6; j++)
System.out.println("Loop");

A) 6
B) 25
C) 36
D) 49

8. How many times the following code snipped will display


“Loop”? for (int i = 1; i <= 3; i++)
for (int j = 1; j <=3; j++);
System.out.println("Loop");

A) 1
B) 3
C) 9
D) 10

9. Which of the following statement is correct?


A) A for loop always executes once
B) A while loop always executes once
C) A do-while loop always executes once
D) All loops always execute once

10. A loop that never terminates is:


A) A null loop
B) A for loop
C) An empty loop
D) An infinite loop
11. Which of the following statement is correct?
A) A while loop is entry-controlled whereas do-while is exit-controlled
B) A do-while loop is entry-controlled whereas while is exit-controlled
C) Both while and do-while are exit-controlled
D) Both while and do-while are entry-controlled

12. Which of the following statement is not true?


A) To execute a do-while loop the condition must be true when entering the loop
B) To execute a while loop the condition must be true when entering the loop
C) To execute a for loop the condition must be true when entering the loop
D) All are true

13. Which of the following for loops will cause the body of the loop to be executed 5 times?
A) for (int i = 5; i > 1; i-- )
B) for (int i = 1; i < 5; i++ )
C) for (int i = 0; i < 5; i++ )
D) for (int i = 0; i <= 5; i++ )

14. Which of the following is not a jump statement in Java?


A) continue
B) break
C) jump
D) return

15. Which of the following is an empty loop?


A) do {i++;} while (i < 5);
B) while (i < 5) i++;
C) for (i = 0; i < 5; i++);
D) None of the above

Please take print and study the bits

Any doubts you can clarify by phone or at School 9848199823

You might also like