Unit 6: Concurrency, Localization, and Multithreading - Practice Quiz

CSE406 — Advanced Java Programming 60 Questions
0 Correct 0 Wrong 60 Left
0/60

1 What is the main purpose of operating system task scheduling?

Describing operating system task scheduling Easy
A. To compile Java source code
B. To translate user interfaces
C. To decide which task runs next
D. To store application resources

2 What does a scheduler commonly use to manage processor time among tasks?

Describing operating system task scheduling Easy
A. Locale objects
B. Scheduling policies
C. Java packages
D. Resource bundles

3 Which interface represents a task that can be executed by a thread but does not return a result?

Creating worker threads using Runnable and Callable Easy
A. Callable
B. Runnable
C. Executor
D. Future

4 Which interface is used when a task can return a result?

Creating worker threads using Runnable and Callable Easy
A. Runnable
B. Comparator
C. ThreadGroup
D. Callable

5 Which method contains the code executed by a class implementing Runnable?

Creating worker threads using Runnable and Callable Easy
A. run()
B. call()
C. start()
D. execute()

6 What is the primary role of an ExecutorService?

Using an ExecutorService to concurrently execute tasks Easy
A. Formatting currency values
B. Creating resource files
C. Managing task execution
D. Changing thread priorities

7 Which method submits a task to an ExecutorService and can return a Future?

Using an ExecutorService to concurrently execute tasks Easy
A. start()
B. submit()
C. scheduleNow()
D. launch()

8 Which method should be called when an ExecutorService is no longer needed?

Using an ExecutorService to concurrently execute tasks Easy
A. closeThreads()
B. shutdown()
C. stopAll()
D. terminateNow()

9 What is the main purpose of a RecursiveTask?

RecursiveTask Easy
A. Returning a result from divided work
B. Changing the current locale
C. Starting a single thread
D. Formatting localized messages

10 Which method must a RecursiveTask commonly implement?

RecursiveTask Easy
A. process()
B. compute()
C. main()
D. run()

11 What is a major advantage of localizing an application?

Describing the advantages of localizing an application Easy
A. Removing all application logic
B. Reducing every file to one line
C. Supporting different regions
D. Preventing concurrent execution

12 Which item can localization adapt for users in different countries?

Describing the advantages of localizing an application Easy
A. Java class inheritance
B. Date and number formats
C. Thread stack size
D. Bytecode instructions

13 Which Java class represents a language and regional setting?

Reading and setting the locale using the Locale object Easy
A. Locale
B. Language
C. Location
D. Region

14 Which method returns the default locale of the Java runtime?

Reading and setting the locale using the Locale object Easy
A. Locale.getDefault()
B. Locale.current()
C. Locale.defaultValue()
D. Locale.readDefault()

15 What is a resource bundle primarily used to store?

Building a resource bundle for each locale Easy
A. Localized messages
B. Database connections
C. Operating system processes
D. Compiled thread objects

16 Which file type is commonly used to create a properties-based resource bundle?

Building a resource bundle for each locale Easy
A. .thread
B. .properties
C. .bundlecode
D. .locale

17 Which method is commonly used to load a resource bundle?

Calling a resource bundle from an application Easy
A. ResourceBundle.loadText()
B. Bundle.openFile()
C. ResourceBundle.getBundle()
D. Locale.getBundle()

18 Which method retrieves a value associated with a key from a ResourceBundle?

Calling a resource bundle from an application Easy
A. lookupMessage()
B. readValue()
C. findText()
D. getString()

19 What is multithreading?

Overview of multithreading Easy
A. Using multiple locales
B. Storing multiple bundles
C. Compiling multiple packages
D. Running multiple threads

20 Which state describes a thread that has been created but has not yet started running?

Thread life cycle Easy
A. Terminated
B. Running
C. Blocked
D. New

21 A system uses a fixed-size thread pool, but one submitted task performs a long computation while several short tasks wait. Which scheduling issue is most likely to occur?

Describing operating system task scheduling Medium
A. The short tasks may experience increased waiting time
B. The operating system permanently cancels the long task
C. The waiting tasks execute inside the long task's stack
D. The pool automatically changes every task to a daemon thread

22 Two runnable threads have different priorities, but both are ready to execute. What should a Java programmer conclude about the higher-priority thread?

Describing operating system task scheduling Medium
A. It is guaranteed to receive twice as much CPU time
B. It may receive scheduling preference from the operating system
C. It is guaranteed to run before the other thread
D. It can execute concurrently only when the other thread terminates

23 A task must calculate and return a value when submitted to an executor. Which design is most appropriate?

Creating worker threads using Runnable and Callable Medium
A. Implement Runnable and return the value from sleep()
B. Implement Runnable and return the value from run()
C. Implement Callable and return the value from call()
D. Extend Thread and return the value from start()

24 A program submits a Callable<Integer> to an ExecutorService and receives a Future<Integer>. When is the result normally obtained?

Creating worker threads using Runnable and Callable Medium
A. By calling start() on the Future
B. By calling run() on the Future
C. By calling get() on the Future
D. By calling join() on the Future

25 An application creates a fixed thread pool with three threads and submits eight independent tasks. How many tasks can execute at the same time under normal conditions?

Using an ExecutorService to concurrently execute tasks Medium
A. Only one task
B. Exactly three tasks
C. Exactly eight tasks
D. At least eight tasks

26 A server finishes submitting work to an ExecutorService and must release its resources. Which action is appropriate after submissions are complete?

Using an ExecutorService to concurrently execute tasks Medium
A. Call execute() with a null task
B. Call shutdownNow() in every normal completion path
C. Call shutdown() and allow submitted tasks to finish
D. Call start() and wait for new tasks

27 A RecursiveTask<Long> computes the sum of a large array. Which implementation pattern best supports fork/join parallelism?

RecursiveTask Medium
A. Use Thread.sleep() before returning the complete array sum
B. Create one operating-system process for every array element
C. Split the range, fork one subtask, compute the other, then join
D. Call compute() repeatedly without dividing the input range

28 A RecursiveTask repeatedly divides its input but never reaches a condition that directly computes a small subproblem. What is the likely result?

RecursiveTask Medium
A. The ForkJoinPool automatically supplies the missing result
B. The task may recurse indefinitely or exhaust the stack
C. The task becomes a Callable without further changes
D. The task always completes with a zero result

29 A Java application is localized using resource bundles instead of hard-coded messages. What is the main maintenance benefit?

Describing the advantages of localizing an application Medium
A. The application no longer needs character encoding
B. Database transactions automatically become faster
C. Text changes can be made without changing program logic
D. All users are forced to use the same language

30 An application is deployed in several countries and displays dates, numbers, and currency values. Why is localization important in this situation?

Describing the advantages of localizing an application Medium
A. It converts every value to a plain text identifier
B. It removes the need for user-specific settings
C. It guarantees identical date formats everywhere
D. It presents culturally appropriate formats for each audience

31 Which statement creates a Locale representing French as used in Canada?

Reading and setting the locale using the Locale object Medium
A. new Locale("fr", "CA")
B. Locale.of("Canada", "French")
C. new Locale("French-Canada")
D. new Locale("CA", "fr")

32 A program calls Locale.setDefault(Locale.US) before creating a NumberFormat instance without specifying a locale. What is the expected effect?

Reading and setting the locale using the Locale object Medium
A. The formatter uses the US locale by default
B. The formatter ignores all locale information
C. The formatter always uses the user's original locale
D. The formatter uses the JVM's language-neutral locale

33 For base name Messages and locales English and French, which resource bundle naming scheme is valid?

Building a resource bundle for each locale Medium
A. en.Messages and fr.Messages
B. Messages.en.properties and Messages.fr.properties only
C. Messages-English.java and Messages-French.java
D. Messages.properties and Messages_fr.properties

34 A French resource bundle is missing a key that exists in the base bundle. What commonly happens during lookup?

Building a resource bundle for each locale Medium
A. The lookup can fall back to the base bundle
B. The JVM creates a translated value automatically
C. The application always returns an empty string
D. The key is permanently removed from all bundles

35 Which code correctly retrieves the value associated with the key "welcome" for a specified locale?

Calling a resource bundle from an application Medium
A. ResourceBundle.getString("Messages", locale, "welcome")
B. Locale.getBundle("Messages").getString(locale)
C. Bundle.load("welcome").getLocale("Messages")
D. ResourceBundle.getBundle("Messages", locale).getString("welcome")

36 A call to bundle.getString("title") throws MissingResourceException. Which cause is most likely?

Calling a resource bundle from an application Medium
A. The executor has more than one worker thread
B. The current thread has entered the waiting state
C. The Locale object contains a country code
D. The requested key is absent from the available bundles

37 Two threads update the same counter using counter++ without synchronization. Why might the final count be lower than expected?

Overview of multithreading Medium
A. The operating system converts increments into decrements
B. Java permits only one thread to access integer fields
C. The counter is automatically reset when a thread starts
D. The increment is a non-atomic read-modify-write operation

38 A thread is blocked while waiting for a monitor lock held by another thread. Which state best describes it?

Thread life cycle Medium
A. TERMINATED
B. NEW
C. BLOCKED
D. RUNNABLE

39 A developer writes a task's logic in run() and wants the task to execute on a new thread. Which call is required?

Creating tasks and threads Medium
A. thread.run()
B. thread.execute()
C. thread.begin()
D. thread.start()

40 A class must extend an existing application superclass but also define work for a thread. Which approach avoids Java's single-inheritance limitation?

Thread class and Runnable interface Medium
A. Declare run() as static in the application superclass
B. Implement Runnable and pass the object to a Thread
C. Create a second superclass only for the thread
D. Extend both Thread and the application superclass

41 A Java application has eight runnable threads on a four-core processor. The operating system uses preemptive scheduling, but the JVM does not guarantee any ordering for equal-priority threads. Which conclusion is most accurate?

Describing operating system task scheduling Hard
A. At most four threads execute at one instant, while runnable threads may be time-sliced
B. Exactly four threads execute continuously until completion
C. All eight threads execute simultaneously on four cores
D. Thread priority determines the exact execution order on every operating system

42 A task must return a computed value and may throw a checked exception. Which design directly models both requirements when submitted to an executor?

Creating worker threads using Runnable and Callable Hard
A. Implement Callable<V> and throw the checked exception from call()
B. Extend Thread and return the value from run()
C. Implement Runnable and store the result in a shared field
D. Implement Runnable and declare the checked exception on run()

43 A Callable<Integer> is submitted to an executor, and its computation throws IOException. What does future.get() report to the calling thread?

Creating worker threads using Runnable and Callable Hard
A. CancellationException because the task failed
B. ExecutionException whose cause is IOException
C. CompletionException whose cause is IOException
D. IOException directly without any wrapper

44 A fixed thread pool contains two threads. Three tasks are submitted, and the first two block indefinitely while the third is queued. What happens when the caller invokes future3.get()?

Using an ExecutorService to concurrently execute tasks Hard
A. The call blocks until a worker becomes available for the third task
B. The executor cancels one blocked task to maintain progress
C. The third task starts immediately because queue capacity is unlimited
D. The third task runs on the caller thread automatically

45 After submitting tasks to an ExecutorService, the application calls shutdown(). Which statement describes the contract correctly?

Using an ExecutorService to concurrently execute tasks Hard
A. The executor terminates immediately regardless of task state
B. Queued tasks are discarded immediately
C. Running tasks are interrupted before shutdown returns
D. New tasks are rejected, but previously submitted tasks may complete

46 Two tasks submitted to a single-thread executor each wait for the other's Future.get() result. What is the most likely outcome if neither task completes independently?

Using an ExecutorService to concurrently execute tasks Hard
A. The executor detects the cycle and reorders the tasks
B. The tasks deadlock because one worker cannot execute both blocked tasks
C. Both tasks complete because futures release the worker
D. The second task is always rejected by a single-thread executor

47 A RecursiveTask<Long> recursively forks both child subtasks and then calls join() on the left child before joining the right child. Why can this still perform well in a ForkJoinPool?

RecursiveTask Hard
A. ForkJoinPool executes all recursive calls on one kernel thread
B. Calling join() converts the task into a nonblocking callback
C. RecursiveTask automatically creates one operating-system process per child
D. Workers can steal available tasks from other workers' deques

48 A RecursiveTask computes a sum over an array. Its base case is if (length <= threshold), but the recursive branch calls fork() on the left task and immediately computes the right task before joining the left. What is the primary reason for this pattern?

RecursiveTask Hard
A. It reduces scheduling overhead while leaving one branch available for parallel work
B. It prevents the left task from ever running concurrently
C. It makes the result independent of the threshold value
D. It guarantees that array elements are processed in source order

49 A RecursiveTask invokes fork() on a child but never invokes join() or otherwise retrieves that child's result. Which defect is present?

RecursiveTask Hard
A. The child is guaranteed to execute twice
B. ForkJoinPool automatically joins all children at pool termination
C. The parent result cannot depend safely on the child's completion
D. The child runs synchronously before fork() returns

50 An application separates translatable text, locale-specific number formats, and date formats from business logic. Which architectural advantage follows most directly?

Describing the advantages of localizing an application Hard
A. Translation eliminates the need for input validation
B. Localized applications require fewer runtime resources
C. New locales can often be added without changing core application logic
D. All locales use identical parsing and display rules

51 A program calls Locale.setDefault(Locale.FRANCE) after creating a NumberFormat instance without an explicit locale. What should be expected of that existing formatter?

Reading and setting the locale using the Locale object Hard
A. It must switch to France immediately
B. It throws an exception because the default locale changed
C. It remains configured according to the locale used when it was created
D. It becomes locale-neutral until recreated

52 A service must format output for each request independently in a multithreaded server. Which approach avoids unintended cross-request effects?

Reading and setting the locale using the Locale object Hard
A. Use explicit locale arguments when creating formatters
B. Assume the operating system locale changes per request
C. Set the JVM-wide default locale for every request
D. Mutate one shared formatter before each response

53 An application requests Messages for locale fr_CA. Which class-based resource bundle lookup is most specific before fallback occurs?

Building a resource bundle for each locale Hard
A. fr_CA.Messages
B. Messages_frCanada
C. Messages_fr_CA
D. Messages_CA_fr

54 A properties resource bundle contains welcome=Bienvenue encoded as UTF-8, but the runtime interprets the file using an incompatible encoding. What is the most appropriate remedy in a modern Java application?

Building a resource bundle for each locale Hard
A. Rename the key to include the encoding
B. Set the default time zone before loading the bundle
C. Use a UTF-8-compatible resource-bundle loading strategy
D. Replace every accented character with a locale code

55 A call to ResourceBundle.getBundle("Messages", requestedLocale) cannot find a bundle for the exact locale but finds the base bundle. What is the normal result?

Calling a resource bundle from an application Hard
A. The base bundle is used after locale fallback
B. The requested locale is permanently changed to the base locale
C. The call always returns null
D. The JVM creates an empty bundle dynamically

56 A bundle is loaded once and reused across threads for read-only calls to getString(). Which statement is most accurate?

Calling a resource bundle from an application Hard
A. Resource bundles are generally safe for concurrent read access after construction
B. Concurrent reads always reload the underlying file
C. Every read requires external synchronization
D. The bundle becomes invalid after the first thread reads it

57 Two threads increment a shared integer using counter++ one million times each without synchronization. Which outcome is valid under the Java Memory Model?

Overview of multithreading Hard
A. The final value must be exactly two million
B. The final value may be less than two million because increments can be lost
C. The final value must be zero because integers are immutable
D. The program cannot compile because shared fields require locks

58 A thread has been started and is currently waiting inside Object.wait() while owning no monitor. Which Thread.State best describes it?

Thread life cycle Hard
A. TERMINATED
B. TIMED_WAITING
C. BLOCKED
D. WAITING

59 A thread's run() method completes normally. Another part of the program later calls start() on the same Thread object to repeat the task. What occurs?

Creating tasks and threads Hard
A. The thread transitions from TERMINATED back to RUNNABLE
B. The call is ignored because the thread is terminated
C. The call throws IllegalThreadStateException
D. The task runs again on a new worker automatically

60 A class must inherit behavior from BaseWorker and also define concurrent work. Which design preserves the required inheritance while remaining compatible with Thread construction?

Thread class and Runnable interface Hard
A. Extend Thread and ignore BaseWorker
B. Implement Runnable and pass the object to a Thread
C. Implement Thread because interfaces can provide scheduling
D. Declare two superclass clauses for the class