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 decide which task runs next
B. To compile Java source code
C. To translate user interfaces
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. Resource bundles
C. Java packages
D. Scheduling policies

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. Future
B. Executor
C. Runnable
D. Callable

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

Creating worker threads using Runnable and Callable Easy
A. Comparator
B. Runnable
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. execute()
B. call()
C. start()
D. run()

6 What is the primary role of an ExecutorService?

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

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

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

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

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

9 What is the main purpose of a RecursiveTask?

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

10 Which method must a RecursiveTask commonly implement?

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

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. Region
B. Language
C. Locale
D. Location

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.defaultValue()
C. Locale.readDefault()
D. Locale.current()

15 What is a resource bundle primarily used to store?

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

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

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

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

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

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

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

19 What is multithreading?

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

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

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

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 operating system permanently cancels the long task
B. The waiting tasks execute inside the long task's stack
C. The pool automatically changes every task to a daemon thread
D. The short tasks may experience increased waiting time

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 run before the other thread
B. It may receive scheduling preference from the operating system
C. It can execute concurrently only when the other thread terminates
D. It is guaranteed to receive twice as much CPU time

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 run()
B. Extend Thread and return the value from start()
C. Implement Callable and return the value from call()
D. Implement Runnable and return the value from sleep()

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 run() on the Future
B. By calling join() on the Future
C. By calling start() on the Future
D. By calling get() 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. Exactly eight tasks
B. Exactly three tasks
C. Only one task
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 start() and wait for new tasks
C. Call shutdownNow() in every normal completion path
D. Call shutdown() and allow submitted tasks to finish

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. Call compute() repeatedly without dividing the input range
C. Split the range, fork one subtask, compute the other, then join
D. Create one operating-system process for every array element

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 task always completes with a zero result
B. The task becomes a Callable without further changes
C. The ForkJoinPool automatically supplies the missing result
D. The task may recurse indefinitely or exhaust the stack

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. All users are forced to use the same language
D. Text changes can be made without changing program logic

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. Locale.of("Canada", "French")
B. new Locale("French-Canada")
C. new Locale("CA", "fr")
D. new Locale("fr", "CA")

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 ignores all locale information
B. The formatter uses the US locale by default
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. Messages-English.java and Messages-French.java
B. Messages.en.properties and Messages.fr.properties only
C. en.Messages and fr.Messages
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. Bundle.load("welcome").getLocale("Messages")
B. ResourceBundle.getString("Messages", locale, "welcome")
C. ResourceBundle.getBundle("Messages", locale).getString("welcome")
D. Locale.getBundle("Messages").getString(locale)

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

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

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. Java permits only one thread to access integer fields
B. The increment is a non-atomic read-modify-write operation
C. The counter is automatically reset when a thread starts
D. The operating system converts increments into decrements

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. RUNNABLE
B. BLOCKED
C. NEW
D. TERMINATED

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.start()
C. thread.execute()
D. thread.begin()

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. Create a second superclass only for the thread
B. Extend both Thread and the application superclass
C. Declare run() as static in the application superclass
D. Implement Runnable and pass the object to a Thread

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. Thread priority determines the exact execution order on every operating system
C. All eight threads execute simultaneously on four cores
D. Exactly four threads execute continuously until completion

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 Runnable and declare the checked exception on run()
B. Extend Thread and return the value from run()
C. Implement Callable<V> and throw the checked exception from call()
D. Implement Runnable and store the result in a shared field

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. CompletionException whose cause is IOException
B. IOException directly without any wrapper
C. CancellationException because the task failed
D. ExecutionException whose cause is IOException

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 third task runs on the caller thread automatically
B. The call blocks until a worker becomes available for the third task
C. The executor cancels one blocked task to maintain progress
D. The third task starts immediately because queue capacity is unlimited

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. Running tasks are interrupted before shutdown returns
B. The executor terminates immediately regardless of task state
C. New tasks are rejected, but previously submitted tasks may complete
D. Queued tasks are discarded immediately

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

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 makes the result independent of the threshold value
B. It prevents the left task from ever running concurrently
C. It guarantees that array elements are processed in source order
D. It reduces scheduling overhead while leaving one branch available for parallel work

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 runs synchronously before fork() returns
B. The parent result cannot depend safely on the child's completion
C. The child is guaranteed to execute twice
D. ForkJoinPool automatically joins all children at pool termination

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. All locales use identical parsing and display rules
B. New locales can often be added without changing core application logic
C. Translation eliminates the need for input validation
D. Localized applications require fewer runtime resources

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 throws an exception because the default locale changed
B. It must switch to France immediately
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. Mutate one shared formatter before each response
B. Set the JVM-wide default locale for every request
C. Use explicit locale arguments when creating formatters
D. Assume the operating system locale changes per request

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. Messages_frCanada
B. Messages_CA_fr
C. Messages_fr_CA
D. fr_CA.Messages

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. Use a UTF-8-compatible resource-bundle loading strategy
B. Set the default time zone before loading the bundle
C. Rename the key to include the encoding
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 call always returns null
B. The requested locale is permanently changed to the base locale
C. The base bundle is used after locale fallback
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. The bundle becomes invalid after the first thread reads it
C. Every read requires external synchronization
D. Concurrent reads always reload the underlying file

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 zero because integers are immutable
B. The final value may be less than two million because increments can be lost
C. The final value must be exactly two million
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. TIMED_WAITING
B. WAITING
C. BLOCKED
D. TERMINATED

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 call is ignored because the thread is terminated
B. The task runs again on a new worker automatically
C. The thread transitions from TERMINATED back to RUNNABLE
D. The call throws IllegalThreadStateException

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. Implement Thread because interfaces can provide scheduling
B. Extend Thread and ignore BaseWorker
C. Implement Runnable and pass the object to a Thread
D. Declare two superclass clauses for the class