Bird
0
0

Given the following code snippet in a Kafka Streams app, what will be the output if the key "user123" exists with value "active" in the state store?

medium📝 Predict Output Q13 of 15
Kafka - Advanced Stream Processing

Given the following code snippet in a Kafka Streams app, what will be the output if the key "user123" exists with value "active" in the state store?

var store = streams.store("userStatusStore", ReadOnlyKeyValueStore.class);
var status = store.get("user123");
System.out.println(status);
Anull
B"active"
CThrows NullPointerException
DCompilation error
Step-by-Step Solution
Solution:
  1. Step 1: Understand store.get(key) behavior

    The get method returns the value for the key if it exists, else null.
  2. Step 2: Check given key and value

    Since "user123" exists with value "active", store.get("user123") returns "active".
  3. Final Answer:

    "active" -> Option B
  4. Quick Check:

    store.get(existingKey) = value [OK]
Quick Trick: store.get(key) returns value or null if missing [OK]
Common Mistakes:
  • Assuming null is returned even if key exists
  • Expecting exceptions on missing keys
  • Confusing syntax causing compile errors

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Kafka Quizzes