On this page

Java API & SDK Docs 13.4.2

Breaking changes in v9.0.0

PubNub Java SDK version 9.0.0 unifies the codebases for Java and Kotlin SDKs, introduces a new way of instantiating the PubNub client, and changes asynchronous API callbacks and emitted status events. These changes can impact applications built with previous versions (< 9.0.0) of the Java SDK.

For more details about what has changed, refer to Java/Kotlin SDK migration guide.

This guide walks you through a simple "Hello, World" application that demonstrates the core concepts of PubNub:

  • Setting up a connection
  • Sending messages
  • Receiving messages in real-time

Overview

This guide helps you get up and running with PubNub in your Java application. The Java software development kit (SDK) provides a simple interface for integrating PubNub real-time messaging. You'll learn how to set up PubNub, configure event listeners, subscribe to channels, and publish messages in a Java environment.

Chat applications

If you want to create a mobile chat application with PubNub, refer to Kotlin Chat SDK for details on all available chat features.

Prerequisites

Before we dive in, make sure you have:

  • A basic understanding of Java
  • An IDE like IntelliJ IDEA or Eclipse
  • Java 8 or later installed
  • A PubNub account (we'll help you set this up!)

Setup

Get your PubNub keys

First, get your PubNub keys:

  • Sign in or create an account on the PubNub Admin Portal.
  • Create an app (or use an existing one).
  • Find your publish and subscribe keys in the app dashboard.

When you create an app, PubNub automatically generates a keyset. You can use the same keyset for development and production, but we recommend separate keysets for each environment to improve security and management.

Install the SDK

SDK version

Always use the latest SDK version to have access to the newest features and avoid security vulnerabilities, bugs, and performance issues.

You can install the PubNub Java SDK in several ways:

Maven

Add the following dependency to your pom.xml:

1<dependency>
2 <groupId>com.pubnub</groupId>
3 <artifactId>pubnub-gson</artifactId>
4 <version>13.4.2</version>
5</dependency>

Gradle

Add the following to your build.gradle file:

1implementation group: 'com.pubnub', name: 'pubnub-gson', version: '13.4.2'

Source code

Clone the GitHub repository:

1git clone https://github.com/pubnub/kotlin

Steps

Initialize PubNub

In your Java application, create a new class (e.g., App.java) and initialize PubNub.

Make sure to replace the demo keys with your app's publish and subscribe keys from the Admin Portal.

May 12, 2026