Why Migrate?
- Performance: Java Core achieves faster evaluation times and lower CPU consumption, making it more efficient than the legacy SDK.
- New Features: Access to Parameter Stores, CMAB (Contextual Multi-Armed Bandits), observabilityClient, and more
- Future Support: All new features and improvements will only be available in Java Core
- Maintenance: The legacy Java SDK is in maintenance mode and will only receive critical bug fixes
Installation Differences
Legacy Java/Kotlin SDK
Java Core SDK
Java Core requires both the core library and a platform-specific native library:API Differences
Key Package and Class Changes
Feature | Legacy Java SDK | Java Core SDK |
---|---|---|
Package | com.statsig.sdk.* | com.statsig.* |
Main Class | Statsig (static methods) | Statsig (instance methods) |
Options | StatsigOptions | StatsigOptions.Builder() |
User | StatsigUser | StatsigUser.Builder() |
Check Gate | Statsig.checkGateSync() | statsig.checkGate() |
Get Config | Statsig.getConfigSync() | statsig.getDynamicConfig() |
Get Experiment | Statsig.getExperimentSync() | statsig.getExperiment() |
Get Layer | Statsig.getLayerSync() | statsig.getLayer() |
Log Event | Statsig.logEvent() | statsig.logEvent() |
Initialization
Checking Gates
Getting Configs
Getting Experiments
Getting Layers
Logging Events
Configuration Options Differences
Migration Steps
Java Migration Steps
Java Migration Steps
-
Update Dependencies
- Replace
com.statsig:serversdk
withcom.statsig:javacore
- Add the platform-specific dependency
- Replace
-
Update Imports
- Replace
import com.statsig.sdk.*
withimport com.statsig.*
- Replace
-
Update Initialization
- Change from static methods to instance methods
- Use the builder pattern for options and StatsigUser
- Replace
new StatsigUser("user_id")
withnew StatsigUser.Builder().setUserID("user_id").build()
- Initialize with
new Statsig(key, options)
and callinitialize()
-
Update User Creation
- Use the builder pattern:
new StatsigUser.Builder().setUserID("user_id").build()
- Use the builder pattern:
-
Update Method Calls
- Replace static methods with instance methods
- Remove
Sync
suffix from method names - Update method signatures as needed
-
Test Thoroughly
- Verify all feature gates, experiments, and configs work as expected
- Check that event logging is functioning correctly
Kotlin Migration Steps
Kotlin Migration Steps
-
Update Dependencies
- Replace
com.statsig:serversdk
withcom.statsig:javacore
- Add the platform-specific dependency
- Replace
-
Update Imports
- Replace
import com.statsig.sdk.*
withimport com.statsig.*
- Replace
-
Update Initialization
- Change from static methods to instance methods
- Replace
.apply {}
blocks with the builder pattern - Replace
val user = StatsigUser("user_id")
withval user = StatsigUser.Builder().setUserID("user_id").build()
- Initialize with
val statsig = Statsig("key", options)
and callinitialize()
-
Update User Creation
- Use the builder pattern:
val user = StatsigUser.Builder().setUserID("user_id").build()
- Use the builder pattern:
-
Update Method Calls
- Replace static methods with instance methods
- Remove
Sync
suffix from method names - Update method signatures as needed
- Replace
mapOf("key" to "value")
with appropriate map creation methods
-
Test Thoroughly
- Verify all feature gates, experiments, and configs work as expected
- Check that event logging is functioning correctly
New Features in Java Core
Parameter Stores
Java Core introduces Parameter Stores, which allow you to manage parameters across multiple feature gates, experiments, and dynamic configs:Improved Performance
Java Core offers significantly better performance:- Faster evaluation times
- More efficient network usage
- Reduced CPU usage
- Better memory management
Troubleshooting
Common Issues
-
Missing Platform-Specific Dependency
- Error:
java.lang.UnsatisfiedLinkError: no statsig_jni in java.library.path
- Solution: Add the correct platform-specific dependency
- Error:
-
Incompatible Method Calls
- Error:
java.lang.NoSuchMethodError
- Solution: Update method calls to match the new API
- Error:
-
Configuration Differences
- Issue: Features not evaluating as expected
- Solution: Verify options are correctly configured in the new format