Java - Programming MCQ Questions and Answers

Test your knowledge of Java Programming Language with these interactive multiple-choice questions.

« First 5 6 7 8 Last »
« Previous Page Next Page »

101. What is the purpose of the 'module-info.java' file?

  • a) To declare Java modules (JPMS)
  • b) To configure Maven projects
  • c) To store module-level documentation
  • d) To define module test cases
Answer: A - It's the module descriptor for Java Platform Module System (Java 9+).

102. Which is not a valid Stream intermediate operation?

  • a) filter()
  • b) map()
  • c) forEach()
  • d) flatMap()
Answer: C - forEach() is a terminal operation.

103. What is the purpose of the 'jlink' tool?

  • a) To link JavaScript with Java
  • b) To create custom runtime images
  • c) To generate Javadoc links
  • d) To analyze JVM performance
Answer: B - jlink assembles modules into custom runtime images (Java 9+).

104. Which is not a valid Collectors method?

  • a) toUnmodifiableList()
  • b) toUnmodifiableSet()
  • c) toUnmodifiableMap()
  • d) toUnmodifiableCollection()
Answer: D - Only List, Set, and Map have unmodifiable collectors (Java 10+).

105. What is the purpose of the 'var' keyword in try-with-resources?

  • a) To declare resources with inferred types
  • b) To make resources mutable
  • c) To allow multiple resource types
  • d) To optimize resource handling
Answer: A - var can declare resources while maintaining type safety (Java 9+).

106. Which is not a valid Java module keyword?

  • a) requires
  • b) exports
  • c) provides
  • d) imports
Answer: D - 'imports' is not a module directive (uses 'requires' instead).

107. What is the purpose of the 'Optional.ifPresentOrElse()' method?

  • a) To handle both present and absent cases
  • b) To chain multiple Optionals
  • c) To convert Optional to Stream
  • d) To nest Optional values
Answer: A - Executes one Consumer if value present, else a Runnable (Java 9+).

108. Which is not a valid JShell command?

  • a) /vars
  • b) /methods
  • c) /classes
  • d) /types
Answer: C - JShell has /vars, /methods, and /types but not /classes.

109. What is the purpose of the 'HttpClient' class (Java 11+)?

  • a) To create HTTP servers
  • b) To make HTTP requests
  • c) To parse HTTP headers
  • d) To validate HTTP responses
Answer: B - Standard HTTP client API supporting sync/async requests.

110. Which is not a valid way to create an immutable collection?

  • a) List.of()
  • b) Set.copyOf()
  • c) Collections.unmodifiableList()
  • d) new ImmutableList()
Answer: D - There's no ImmutableList class in standard Java.

111. What is the purpose of the 'Stream.iterate()' method?

  • a) To create infinite streams
  • b) To iterate over existing streams
  • c) To optimize stream processing
  • d) To implement recursion
Answer: A - Creates sequential ordered streams (finite or infinite).

112. Which is not a valid switch expression feature (Java 17+)?

  • a) Pattern matching
  • b) Null case labels
  • c) Guarded patterns
  • d) Default parameters
Answer: D - Switch expressions don't have default parameters.

113. What is the purpose of the 'Collectors.teeing()' method?

  • a) To combine two collectors
  • b) To split streams
  • c) To parallelize collection
  • d) To optimize memory usage
Answer: A - Merges results of two collectors (Java 12+).

114. Which is not a valid Java primitive type wrapper class?

  • a) Integer
  • b) Float
  • c) Bool
  • d) Character
Answer: C - The correct wrapper for boolean is Boolean.

115. What is the purpose of the 'String.transform()' method?

  • a) To apply string mutations
  • b) To chain string operations
  • c) To optimize string concatenation
  • d) To convert between encodings
Answer: B - Applies a Function to the string (Java 12+).

116. Which is not a valid way to create a Thread?

  • a) Extending Thread class
  • b) Implementing Runnable
  • c) Implementing Callable
  • d) Using Thread.create()
Answer: D - Thread has no create() method.

117. What is the purpose of the 'Files.mismatch()' method?

  • a) To find differing bytes between files
  • b) To detect file encoding mismatches
  • c) To compare file permissions
  • d) To validate file paths
Answer: A - Returns position of first differing byte (Java 12+).

118. Which is not a valid ExecutorService method?

  • a) invokeAny()
  • b) invokeAll()
  • c) invoke()
  • d) submit()
Answer: C - There's no invoke() method in ExecutorService.

119. What is the purpose of the 'ProcessHandle' interface?

  • a) To handle file processes
  • b) To manage OS processes
  • c) To control JVM processes
  • d) To monitor database processes
Answer: B - Provides native process control (Java 9+).

120. Which is not a valid CompletableFuture method?

  • a) thenApply()
  • b) thenAccept()
  • c) thenProcess()
  • d) thenCombine()
Answer: C - There's no thenProcess() method (but there is thenRun()).
« First 5 6 7 8 Last »
« Previous Page Next Page »

Learn Computer Skills with PCBooks

Master computer skills with PCBooks! Explore interactive tutorials, MCQ tests, and online exams for programming, web development, and IT fundamentals. Perfect for beginners and advanced learners.

Online MCQ Tests for Programming

Practice programming MCQ questions and improve your coding skills with our online quizzes. Whether you're learning Python, Java, or C programming, PCBooks has you covered.

Free Web Development Tutorials

Learn HTML, CSS, and JavaScript with our free web development tutorials. Test your knowledge with interactive quizzes and online exams.