Bird
0
0

What will be the output of the following Kafka producer code snippet?

medium📝 Predict Output Q5 of 15
Kafka - Producers
What will be the output of the following Kafka producer code snippet?
ProducerRecord record = new ProducerRecord<>("topic1", null, "value1");
System.out.println(record.key());
System.out.println(record.value());
Anull\nvalue1
Bvalue1\nnull
Cnull\nnull
DCompilation error
Step-by-Step Solution
Solution:
  1. Step 1: Analyze record creation with null key

    The key is explicitly set to null, value is "value1".
  2. Step 2: Print key and value

    Printing key outputs null, printing value outputs "value1".
  3. Final Answer:

    null\nvalue1 -> Option A
  4. Quick Check:

    Null key prints null, value prints actual string [OK]
Quick Trick: Null key prints as null, value prints normally [OK]
Common Mistakes:
  • Swapping key and value outputs
  • Expecting error on null key
  • Confusing null with empty string

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Kafka Quizzes