Bird
Raised Fist0
Spring Bootframework~20 mins

Feature flags concept in Spring Boot - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Feature Flags Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ component_behavior
intermediate
2:00remaining
How does a feature flag affect Spring Boot application behavior?
Consider a Spring Boot app with a feature flag controlling a new payment method. What happens when the flag is OFF?
Spring Boot
public boolean isNewPaymentEnabled() {
    return featureFlagService.isEnabled("newPayment");
}

if (isNewPaymentEnabled()) {
    // use new payment method
} else {
    // use old payment method
}
AThe app uses the old payment method only.
BThe app uses both old and new payment methods simultaneously.
CThe app throws an error because the feature flag is off.
DThe app disables all payment methods.
Attempts:
2 left
💡 Hint
Think about what the flag controls and what happens when it is false.
📝 Syntax
intermediate
1:30remaining
Which code snippet correctly checks a feature flag in Spring Boot?
You want to check if a feature flag named "betaFeature" is enabled using a FeatureFlagService. Which option is correct?
Aif (featureFlagService.isEnable("betaFeature")) { /* enabled */ }
Bif (featureFlagService.enabled("betaFeature")) { /* enabled */ }
Cif (featureFlagService.isEnabled("betaFeature")) { /* enabled */ }
Dif (featureFlagService.check("betaFeature")) { /* enabled */ }
Attempts:
2 left
💡 Hint
Look for the common naming pattern for boolean checks in Java.
❓ state_output
advanced
2:30remaining
What is the output when toggling a feature flag at runtime?
Given a Spring Boot app where a feature flag "darkMode" is initially OFF, what happens if you enable it at runtime and then reload the page?
Spring Boot
boolean darkMode = featureFlagService.isEnabled("darkMode");
System.out.println("Dark mode enabled: " + darkMode);
APrints true initially and false after reload.
BAlways prints false because flags can't change at runtime.
CThrows an exception when toggling the flag.
DFirst prints false, then after enabling and reload, prints true.
Attempts:
2 left
💡 Hint
Feature flags can be dynamic if implemented properly.
🔧 Debug
advanced
3:00remaining
Why does the feature flag check always return false?
You wrote this code but the feature flag check always returns false even when enabled: @Service public class FeatureFlagService { private Map flags = Map.of("newUI", false); public boolean isEnabled(String flag) { return flags.getOrDefault(flag, false); } } What is the likely cause?
AThe flags map is immutable and never updated after initialization.
BThe isEnabled method has a typo in the flag name.
CThe service is not annotated with @Component.
DThe flags map keys are case sensitive and mismatched.
Attempts:
2 left
💡 Hint
Think about how Map.of works in Java.
🧠 Conceptual
expert
2:00remaining
What is the main benefit of using feature flags in Spring Boot applications?
Choose the best explanation for why developers use feature flags in Spring Boot projects.
AThey automatically fix bugs in the code at runtime.
BThey allow turning features on or off without redeploying the app.
CThey improve database query performance by caching results.
DThey replace the need for unit testing by isolating features.
Attempts:
2 left
💡 Hint
Think about how feature flags help with releasing new features safely.

Practice

(1/5)
1. What is the main purpose of using feature flags in a Spring Boot application?
easy
A. To improve database performance
B. To manage application logging levels
C. To handle user authentication
D. To enable or disable features without changing the code

Solution

  1. Step 1: Understand feature flags concept

    Feature flags allow toggling features on or off dynamically without redeploying code.
  2. Step 2: Identify the main use in Spring Boot

    In Spring Boot, feature flags help control feature availability safely during runtime.
  3. Final Answer:

    To enable or disable features without changing the code -> Option D
  4. Quick Check:

    Feature flags = toggle features dynamically [OK]
Hint: Feature flags toggle features without code changes [OK]
Common Mistakes:
  • Confusing feature flags with database optimization
  • Thinking feature flags manage authentication
  • Assuming feature flags control logging
2. Which of the following is the correct way to check a feature flag in a Spring Boot controller method?
easy
A. if(featureFlagService.isFeatureEnabled("newFeature")) { ... }
B. if(featureFlagService.checkFlag("newFeature")) { ... }
C. if(featureFlagService.enableFeature("newFeature")) { ... }
D. if(featureFlagService.toggleFeature("newFeature")) { ... }

Solution

  1. Step 1: Recall typical method naming for feature flags

    Common method to check if a feature is enabled is named like isFeatureEnabled.
  2. Step 2: Match method name with options

    Only if(featureFlagService.isFeatureEnabled("newFeature")) { ... } uses isFeatureEnabled which clearly indicates checking status.
  3. Final Answer:

    if(featureFlagService.isFeatureEnabled("newFeature")) { ... } -> Option A
  4. Quick Check:

    Check feature flag with isFeatureEnabled() [OK]
Hint: Look for method named isFeatureEnabled() to check flags [OK]
Common Mistakes:
  • Using methods that sound like they change state (enableFeature, toggleFeature)
  • Using incorrect method names not standard in feature flag services
3. Given the following Spring Boot code snippet, what will be the output if the feature flag "betaFeature" is disabled?
if(featureFlagService.isFeatureEnabled("betaFeature")) {
    System.out.println("Beta feature is ON");
} else {
    System.out.println("Beta feature is OFF");
}
medium
A. Beta feature is ON
B. Beta feature is OFF
C. No output
D. Runtime error

Solution

  1. Step 1: Understand the condition check

    The code prints "Beta feature is ON" only if the flag is enabled (true).
  2. Step 2: Analyze the flag state given

    The flag "betaFeature" is disabled, so isFeatureEnabled returns false, triggering the else block.
  3. Final Answer:

    Beta feature is OFF -> Option B
  4. Quick Check:

    Flag disabled = else block runs [OK]
Hint: Disabled flag triggers else block output [OK]
Common Mistakes:
  • Assuming disabled flag prints ON message
  • Expecting no output when else block exists
  • Thinking code throws error on false flag
4. Identify the error in this Spring Boot feature flag usage:
@GetMapping("/feature")
public String feature() {
    if(featureFlagService.isFeatureEnabled) {
        return "Feature ON";
    } else {
        return "Feature OFF";
    }
}
medium
A. Return type should be void
B. Incorrect HTTP method annotation
C. Missing parentheses when calling isFeatureEnabled method
D. Feature flag service not injected

Solution

  1. Step 1: Check method call syntax

    isFeatureEnabled is a method and must be called with parentheses ().
  2. Step 2: Verify other code parts

    HTTP annotation and return type are correct; no injection info given but not error here.
  3. Final Answer:

    Missing parentheses when calling isFeatureEnabled method -> Option C
  4. Quick Check:

    Method calls need () [OK]
Hint: Method calls always need parentheses () [OK]
Common Mistakes:
  • Forgetting () after method names
  • Confusing HTTP method annotations
  • Assuming return type must be void
5. You want to implement a feature flag in Spring Boot that disables a new payment method only for users in a "betaTesters" group. Which approach correctly combines feature flags with user context?
hard
A. Check if feature flag is enabled and user belongs to betaTesters before allowing payment
B. Enable feature flag globally and ignore user groups
C. Disable feature flag and allow all users access
D. Use feature flag only in frontend without backend checks

Solution

  1. Step 1: Understand combining feature flags with user context

    Feature flags can be combined with user group checks to control feature access precisely.
  2. Step 2: Evaluate options for correct logic

    Check if feature flag is enabled and user belongs to betaTesters before allowing payment correctly checks both the flag and user group before enabling the feature.
  3. Final Answer:

    Check if feature flag is enabled and user belongs to betaTesters before allowing payment -> Option A
  4. Quick Check:

    Feature flag + user group check = controlled access [OK]
Hint: Combine flag check with user group for precise control [OK]
Common Mistakes:
  • Ignoring user groups when using feature flags
  • Relying only on frontend checks
  • Enabling feature globally without restrictions
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard