javase

A Simple Example: Hello World!

You can subscribe and publish a message like so:
 Pubnub pubnub = new Pubnub("demo", "demo");
 
 try {
   pubnub.subscribe("hello_world", new Callback() {
 
       @Override
       public void connectCallback(String channel, Object message) {
           System.out.println("SUBSCRIBE : CONNECT on channel:" + channel
                      + " : " + message.getClass() + " : "
                      + message.toString());
       }
 
       @Override
       public void disconnectCallback(String channel, Object message) {
           System.out.println("SUBSCRIBE : DISCONNECT on channel:" + channel
                      + " : " + message.getClass() + " : "
                      + message.toString());
       }
 
       public void reconnectCallback(String channel, Object message) {
           System.out.println("SUBSCRIBE : RECONNECT on channel:" + channel
                      + " : " + message.getClass() + " : "
                      + message.toString());
       }
 
       @Override
       public void successCallback(String channel, Object message) {
           System.out.println("SUBSCRIBE : " + channel + " : "
                      + message.getClass() + " : " + message.toString());
       }
 
       @Override
       public void errorCallback(String channel, PubnubError error) {
           System.out.println("SUBSCRIBE : ERROR on channel " + channel
                      + " : " + error.toString());
       }
     }
   );
 } catch (PubnubException e) {
   System.out.println(e.toString());
 }
 
 Callback callback = new Callback() {
   public void successCallback(String channel, Object response) {
     System.out.println(response.toString());
   }
   public void errorCallback(String channel, PubnubError error) {
   System.out.println(error.toString());
   }
 };
 pubnub.publish("demo", "Hello World !!" , callback);
More Fun Awaits:

Look at the Quick Start.
Try out a Tutorial.
Find out more about PubNub Features.

Where do I get the code?

GitHub

Or you can git clone the Java Standard Edition SDK repository with the following command:

git clone https://github.com/pubnub/java.git

How do I get started?

Getting set up
Dependencies

Following jars need to be added to your project:

Importing the code:
 import com.pubnub.api.*;
 import org.json.*;

What other Java based SDKs are supported?

PubNub supports an amazing array of platforms and frameworks with easy to use APIs for Mobile, Browser, Desktop and Server. Select one of the SDKs for Java below to find out more.

Table 1. PubNub Java based SDKs to suit various application requirements.
PubNub SDK Description

java

Java: Java Standard Edition - Everything else! Java development for POJOs, J2EE, J2SE, etc.

android

Android: Android - Client for the Mobile Android OS provides a superior alternative to C2DM for broadcasting messages to entire user base. C2DM is hard to implement, and it imposes artificial limits for you to reach your users quickly. C2DM is not recommended as it is a "broadcast" mechanism according to Google. C2DM is Slow, and limited to 1 message at a time. Use PubNub Instead!

java microedition

Java MicroEdition: Java Micro Edition ( J2ME ) - Client for the J2ME Mobile Platform.

blackberry

Blackberry: Blackberry - Client for the Blackberry Mobile Platform.

codename one

Codename One: Codename One - Easy amazing, fast, native mobile app development using Java for all platforms.