Skip to content
Floodgate Docs

Java SDK Documentation

The guide will walk you through the installation and usage of the Floodgate Java SDK.

Requirements

The Floodgate Java SDK is currently compatible with JDK 11+

Getting Started

The first step is to install the Floodgate SDK as a dependency in your application using your application’s dependency manager.

Maven


<dependency>
  <groupId>io.floodgate</groupId>
  <artifactId>sdk</artifactId>
  <version>1.0.0</version>
</dependency>

Gradle


// Ensure Maven Central listed as repository

repositories {
    ...
    mavenCentral()
    ...
}

// Add floodgate SDK as a dependency

dependencies {
    ...
    compile group: 'io.floodgate', name: 'sdk', version: '1.0.0'
    ...
}

Add Required Imports


package your.package.name;
...
import io.floodgate.sdk.*;
...

Now you have the Floodgate SDK installed and imported you can create a new instance of the Floodgate Client.


// See javadoc if you have more complex requirements
FloodgateClient client = FloodgateClientFactory.create("ENTER-YOUR-SDK-KEY");

Evaluating a Flag

Using the floodgateClient object you can now evaluate a flag using the GetValue method. The GetValue method requires two parameters with an optional third.

PropertyRequiredDescription
KeyYesThis is the Flag Key which you entered when creating the flag.
Default ValueYesThis is the value which you want the flag to evaluate to if no flag data can be found.
User ObjectNoThis is an optional value which can be passed containing information about the user. This information is required to evaluate flags when doing user targeting or percentage rollout releases.

The example below shows an evaluation of a flag called my-feature-flag passing in a default value of false.


boolean myFeatureFlag = client.getValue("my-feature-flag", false);

if (myFeatureFlag) {
    System.out.println("my-feature-flag enabled");
} else {
    System.out.println("my-feature-flag not yet enabled");
}

View the Code

All our SDKs are open source and you are free to check out what’s going on inside them. In fact we encourage contributions from the Floodgate community. You can view the source code on GitHub.