0% found this document useful (0 votes)
4 views13 pages

Java Unit 1 MCQ Bca

The document is a collection of multiple-choice questions (MCQs) related to Java programming, covering topics such as Java basics, tokens, statements, command-line arguments, programming style, data types, type casting, Java Virtual Machine, variable scope, and object-oriented programming principles. Each question is accompanied by the correct answer and an explanation. The content is structured for educational purposes, likely for a Java programming course at the Vision Institute of Technology, Aligarh.

Uploaded by

shahrukhkamal7
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views13 pages

Java Unit 1 MCQ Bca

The document is a collection of multiple-choice questions (MCQs) related to Java programming, covering topics such as Java basics, tokens, statements, command-line arguments, programming style, data types, type casting, Java Virtual Machine, variable scope, and object-oriented programming principles. Each question is accompanied by the correct answer and an explanation. The content is structured for educational purposes, likely for a Java programming course at the Vision Institute of Technology, Aligarh.

Uploaded by

shahrukhkamal7
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

VISION INSTITUTE OF TECHNOLOGY,ALIGARH

Subject: java programming

Unit-1(mcq)

1. Introduction to Java

1. What is Java primarily known for?


A) Being a low-level language
B) Being platform-independent
C) Not supporting OOP principles
D) Using pointers like C

Answer: B) Being platform-independent


Explanation: Java is platform-independent because of its Write Once, Run
Anywhere (WORA) nature, thanks to the JVM.

2. Which company originally developed Java?


A) Microsoft
B) Apple
C) Sun Microsystems
D) Oracle

Answer: C) Sun Microsystems


Explanation: Java was created by James Gosling at Sun Microsystems in 1995.
Oracle later acquired Sun Microsystems.

2. Java Tokens

3. Which of the following is NOT a Java token?


A) Keywords
B) Identifiers
C) Arrays
D) Operators

Answer: C) Arrays
Explanation: Tokens in Java include keywords, identifiers, literals, operators, and
separators. Arrays are data structures, not tokens.

4. Which keyword is used to define a class in Java?


A) method
B) class
C) void
D) public

Answer: B) class
Explanation: The class keyword is used to declare a class in Java.

Page1 Faculty: VIKRAM SHARMA


Vikram1532018@[Link]
VISION INSTITUTE OF TECHNOLOGY,ALIGARH
Subject: java programming

Unit-1(mcq)

3. Java Statements

5. Which of the following is a valid Java statement?


A) int x = 10;
B) int x == 10;
C) int x: 10;
D) int x =;

Answer: A) int x = 10;


Explanation: A statement must end with a semicolon (;) and use = for assignment.

6. Which type of statement is used for decision-making in Java?


A) Loop statement
B) Conditional statement
C) Declaration statement
D) Input statement

Answer: B) Conditional statement


Explanation: Conditional statements like if, switch, and ?: help in decision-
making.

4. Command-Line Arguments

7. Where do command-line arguments appear in a Java program?


A) As parameters of the main method
B) Inside the constructor
C) In the [Link]() statement
D) In the static block

Answer: A) As parameters of the main method


Explanation: Command-line arguments are passed as an array of Strings to public
static void main(String[] args).

8. How can you access the first command-line argument in Java?


A) args[0]
B) args(0)
C) [Link][0]
D) [Link](1)

Answer: A) args[0]
Explanation: args is an array, and the first argument is accessed using args[0].

Page2 Faculty: VIKRAM SHARMA


Vikram1532018@[Link]
VISION INSTITUTE OF TECHNOLOGY,ALIGARH
Subject: java programming

Unit-1(mcq)

5. Programming Style

9. Which of the following is a good Java programming practice?


A) Using short, single-letter variable names
B) Writing all code in one method
C) Adding comments to explain complex logic
D) Using global variables excessively

Answer: C) Adding comments to explain complex logic


Explanation: Good programming style includes comments, indentation,
meaningful names, and modular code.

6. Constants, Variables, and Data Types

10. Which keyword is used to declare a constant variable in Java?


A) const
B) final
C) static
D) constant

Answer: B) final
Explanation: final prevents modification of variables after initialization.

11. Which of the following is NOT a primitive data type in Java?


A) boolean
B) String
C) char
D) float

Answer: B) String
Explanation: String is an object (class), not a primitive data type.

7. Type Casting

12. Which of the following is an example of explicit type casting?


A) int x = 10.5;
B) double y = 10;
C) int z = (int) 10.5;
D) float f = 5.5;

Page3 Faculty: VIKRAM SHARMA


Vikram1532018@[Link]
VISION INSTITUTE OF TECHNOLOGY,ALIGARH
Subject: java programming

Unit-1(mcq)

Answer: C) int z = (int) 10.5;


Explanation: Explicit casting uses (type) value.

8. Java Virtual Machine (JVM)

13. What is the function of the Java Virtual Machine (JVM)?


A) Converts Java code to binary code
B) Executes Java bytecode
C) Translates Java to Python
D) Compiles Java into machine code

Answer: B) Executes Java bytecode


Explanation: The JVM runs Java bytecode on different platforms.

9. Standard Default Values

14. What is the default value of an uninitialized int variable in Java?


A) 0
B) null
C) undefined
D) NaN

Answer: A) 0
Explanation: The default values for primitive data types in Java are:

o int → 0
o boolean → false
o float → 0.0f
o double → 0.0
o String (and other objects) → null
15. What is the default value of a boolean variable?
A) true
B) false
C) 0
D) null

Answer: B) false
Explanation: In Java, boolean variables default to false when not explicitly
assigned a value.

Page4 Faculty: VIKRAM SHARMA


Vikram1532018@[Link]
VISION INSTITUTE OF TECHNOLOGY,ALIGARH
Subject: java programming

Unit-1(mcq)

10. Variable Scope

16. Which of the following best describes the scope of a local variable?
A) Available throughout the class
B) Available within the method it is declared
C) Available in all methods of a class
D) Available in all Java classes

Answer: B) Available within the method it is declared


Explanation: Local variables are accessible only inside the block or method where
they are declared.

17. Which keyword is used to define a global constant in Java?


A) global
B) final
C) const
D) static

Answer: B) final
Explanation: The final keyword ensures a variable cannot be modified after
initialization.

11. Java Program Structure

18. Which of the following is the correct signature of the main method in Java?
A) public static main(String[] args)
B) public static void main(String args)
C) public void main(String[] args)
D) public static void main(String[] args)

Answer: D) public static void main(String[] args)


Explanation: The main method must be public, static, and return void.

19. Which part of a Java program is executed first?


A) static block
B) Constructor
C) main method
D) finally block

Answer: A) static block


Explanation: Static blocks execute before the main method.

Page5 Faculty: VIKRAM SHARMA


Vikram1532018@[Link]
VISION INSTITUTE OF TECHNOLOGY,ALIGARH
Subject: java programming

Unit-1(mcq)

12. Java Tokens - Identifiers & Keywords

20. Which of the following is a valid identifier in Java?


A) 2variable
B) variable_name
C) public
D) int

Answer: B) variable_name
Explanation: Identifiers must begin with a letter, _, or $, and cannot be a Java
keyword.

21. Which of the following is NOT a Java keyword?


A) private
B) static
C) String
D) final

Answer: C) String
Explanation: String is a class, not a keyword.

13. Type Casting

22. What is the process of converting a smaller data type to a larger one called?
A) Explicit Casting
B) Implicit Casting
C) Narrowing
D) Overloading

Answer: B) Implicit Casting


Explanation: Implicit casting (or widening) happens automatically, e.g., int →
double.

23. Which of the following requires explicit casting?


A) int to double
B) double to int
C) char to int
D) byte to int

Answer: B) double to int


Explanation: Narrowing conversions (like double to int) require explicit casting:

Page6 Faculty: VIKRAM SHARMA


Vikram1532018@[Link]
VISION INSTITUTE OF TECHNOLOGY,ALIGARH
Subject: java programming

Unit-1(mcq)

java
CopyEdit
double d = 5.5;
int x = (int) d; // Explicit casting

14. Java Virtual Machine (JVM)

24. What does the JVM do?


A) Converts Java source code into machine code
B) Interprets Java bytecode at runtime
C) Translates Java into Python
D) Runs Java programs only on Windows

Answer: B) Interprets Java bytecode at runtime


Explanation: The JVM interprets bytecode, allowing Java to be platform-
independent.

25. Which component of the JVM is responsible for garbage collection?


A) ClassLoader
B) Compiler
C) Garbage Collector
D) JIT Compiler

Answer: C) Garbage Collector


Explanation: The Garbage Collector (GC) reclaims memory from objects no longer
in use.

15. Java Operators

26. What is the output of [Link](5 + "5");?


A) 10
B) 55
C) 5 + 5
D) Compilation error

Answer: B) 55
Explanation: When a number is concatenated with a String, the number is
converted to a String.

27. Which operator is used to compare two values in Java?


A) =
B) ==

Page7 Faculty: VIKRAM SHARMA


Vikram1532018@[Link]
VISION INSTITUTE OF TECHNOLOGY,ALIGARH
Subject: java programming

Unit-1(mcq)

C) ===
D) !=

Answer: B) ==
Explanation: The == operator compares two values, while = is an assignment
operator.

16. Java Control Statements

28. Which of the following loops is an entry-controlled loop?


A) while
B) do-while
C) for
D) Both A and C

Answer: D) Both A and C


Explanation: while and for loops check conditions before execution.

29. Which of the following can be used to exit from a loop?


A) break
B) continue
C) goto
D) skip

Answer: A) break
Explanation: The break statement terminates a loop.

17. Java Methods

30. Which keyword is used to call a constructor of the parent class?


A) this
B) super
C) final
D) static

Answer: B) super
Explanation: super() calls the parent class constructor.

31. Which method is called automatically when an object is created?


A) main()
B) start()

Page8 Faculty: VIKRAM SHARMA


Vikram1532018@[Link]
VISION INSTITUTE OF TECHNOLOGY,ALIGARH
Subject: java programming

Unit-1(mcq)

C) Constructor
D) init()

Answer: C) Constructor
Explanation: A constructor initializes an object.

18. Object-Oriented Programming (OOP) in Java

32. Which of the following is NOT a principle of OOP?


A) Encapsulation
B) Polymorphism
C) Compilation
D) Inheritance

Answer: C) Compilation
Explanation: The four main principles of OOP are Encapsulation, Abstraction,
Inheritance, and Polymorphism. Compilation is a part of Java's execution process, not an
OOP principle.

33. Which keyword is used to inherit a class in Java?


A) inherits
B) extends
C) implements
D) super

Answer: B) extends
Explanation: The extends keyword is used to inherit from a superclass.

34. Which keyword is used to implement an interface in Java?


A) inherits
B) extends
C) implements
D) abstract

Answer: C) implements
Explanation: A class implements an interface using the implements keyword.

19. Java Exception Handling

35. Which keyword is used to handle exceptions in Java?


A) throw
B) try

Page9 Faculty: VIKRAM SHARMA


Vikram1532018@[Link]
VISION INSTITUTE OF TECHNOLOGY,ALIGARH
Subject: java programming

Unit-1(mcq)

C) catch
D) Both B and C

Answer: D) Both B and C


Explanation: try is used to write code that may cause exceptions, and catch handles them.

36. Which of the following is a checked exception in Java?


A) NullPointerException
B) ArithmeticException
C) IOException
D) ArrayIndexOutOfBoundsException

Answer: C) IOException
Explanation: Checked exceptions must be handled or declared with throws. IOException is
an example of a checked exception.

20. Java Strings and Arrays

37. Which class is used to manipulate strings in Java?


A) String
B) StringBuilder
C) StringBuffer
D) All of the above

Answer: D) All of the above


Explanation: Java provides String (immutable), StringBuffer (mutable, synchronized),
and StringBuilder (mutable, not synchronized).

38. What will "Hello".charAt(1) return?


A) H
B) e
C) l
D) o

Answer: B) e
Explanation: The index starts from 0, so charAt(1) returns the second character.

21. Java Input/Output (I/O)

39. Which package is used for input and output operations in Java?
A) [Link]
B) [Link]

Page10 Faculty: VIKRAM SHARMA


Vikram1532018@[Link]
VISION INSTITUTE OF TECHNOLOGY,ALIGARH
Subject: java programming

Unit-1(mcq)

C) [Link]
D) [Link]

Answer: B) [Link]
Explanation: The [Link] package provides classes for input and output operations.

40. Which class is used to read user input in Java?


A) Scanner
B) BufferedReader
C) InputStreamReader
D) All of the above

Answer: D) All of the above


Explanation: Scanner, BufferedReader, and InputStreamReader can all read user input.

22. Multithreading in Java

41. Which keyword is used to create a thread in Java?


A) extends Thread
B) implements Runnable
C) Both A and B
D) create Thread

Answer: C) Both A and B


Explanation: Java supports multithreading using Thread class (extends Thread) and
Runnable interface (implements Runnable).

42. Which method is used to start a thread?


A) run()
B) start()
C) execute()
D) call()

Answer: B) start()
Explanation: start() method invokes the thread’s run() method.

23. Java Collections Framework

43. Which of the following is NOT a collection type in Java?


A) List
B) Set

Page11 Faculty: VIKRAM SHARMA


Vikram1532018@[Link]
VISION INSTITUTE OF TECHNOLOGY,ALIGARH
Subject: java programming

Unit-1(mcq)

C) Map
D) Array

Answer: D) Array
Explanation: Arrays are part of Java but not part of the Collections Framework.

44. Which class implements a dynamically resizable array?


A) LinkedList
B) ArrayList
C) Vector
D) HashSet

Answer: B) ArrayList
Explanation: ArrayList grows dynamically when elements are added.

24. Java File Handling

45. Which class is used to read files in Java?


A) FileReader
B) FileInputStream
C) BufferedReader
D) All of the above

Answer: D) All of the above


Explanation: Different classes handle different file formats and methods.

25. Miscellaneous Java Concepts

46. Which method is called when an object is garbage collected?


A) finalize()
B) delete()
C) destroy()
D) cleanup()

Answer: A) finalize()
Explanation: finalize() is invoked before garbage collection.

47. Which keyword is used to prevent inheritance of a class?


A) static
B) private
C) final
D) protected

Page12 Faculty: VIKRAM SHARMA


Vikram1532018@[Link]
VISION INSTITUTE OF TECHNOLOGY,ALIGARH
Subject: java programming

Unit-1(mcq)

Answer: C) final
Explanation: Declaring a class final prevents it from being inherited.

26. Java Memory Management

48. Which area of memory stores object instances?


A) Stack
B) Heap
C) Registers
D) Static

Answer: B) Heap
Explanation: Objects are stored in the heap memory, while local variables are stored in the
stack.

49. Which method is used to request garbage collection in Java?


A) destroy()
B) finalize()
C) [Link]()
D) collectGarbage()

Answer: C) [Link]()
Explanation: [Link]() requests Java's garbage collector to run.

27. Java Networking

50. Which package is used for networking in Java?


A) [Link]
B) [Link]
C) [Link]
D) [Link]

Answer: A) [Link]
Explanation: Java provides networking support th1. Introduction to Java

Page13 Faculty: VIKRAM SHARMA


Vikram1532018@[Link]

You might also like