Bird
0
0

What will the serialize method return when called with serialize("topic", "Kafka") in this code?

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

What will the serialize method return when called with serialize("topic", "Kafka") in this code?

public byte[] serialize(String topic, String data) {
    if (data == null) return null;
    return data.getBytes(StandardCharsets.UTF_8);
}
AAn empty byte array since data is not null.
BA null value because the topic is "topic".
CA byte array representing the UTF-8 encoding of "Kafka".
DA byte array of the string "topic".
Step-by-Step Solution
Solution:
  1. Step 1: Check input parameters

    Input data is "Kafka", which is not null.
  2. Step 2: Analyze method logic

    Since data is not null, method returns data.getBytes(StandardCharsets.UTF_8).
  3. Step 3: Understand output

    Returns UTF-8 encoded byte array of "Kafka" string.
  4. Final Answer:

    A byte array representing the UTF-8 encoding of "Kafka". -> Option C
  5. Quick Check:

    Non-null data returns UTF-8 bytes [OK]
Quick Trick: Non-null strings serialize to UTF-8 byte arrays [OK]
Common Mistakes:
  • Assuming topic affects serialization output
  • Returning null or empty array incorrectly

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Kafka Quizzes