Search Tutorials

Hazelcast Hello World Example- Getting started with Hazelcast | JavaInUse

Hazelcast Hello World Example- Getting started with Hazelcast

In this tutorial we will create a simple application to get started with Hazelcast.


This tutorial is explained in the below Youtube Video.

Lets Begin

In this example we set up a basic Hazelcast cluster. We will create multiple Hazelcast nodes.
We will create Eclipse maven project as follows-

Our pom file will be as follows-
<project xmlns="" xmlns:xsi="" xsi:schemaLocation="">
We make use of XML configuration which is used by default. Hazelcast searches for hazelcast.xml on classpath.
By default the configuration makes use of multicast discover mechanism.
<hazelcast xmlns:xsi=""

Next we start the Hazelcast instance. It by default loads the hazelcast.xml.
import com.hazelcast.core.Hazelcast;
import com.hazelcast.core.HazelcastInstance;

public class HazelcastMain {
	public static void main(String[] args) {
HazelcastInstance hz = Hazelcast.newHazelcastInstance();
Start the Hazelcast node instances by running the We can see that Hazelcast node with port 5701 gets started.
Run this program again- Another Hazel cast node with port 5702 gets started and added to the cluster.
By running this program multiple times we can add multiple Hazelcast nodes to our cluster. We can run multiple Hazelcast instances in one JVM. Its useful for testing.

Enabling TCP discover mechanism

In the hazelcast.xml we disable the default multicast discover mechanism and enable the TCP enabled hazelcast node discovery mechanism for the cluster.
<hazelcast xmlns:xsi=""

			<multicast enabled="false" />
			<tcp-ip enabled="true">

Here we specify that the nodes with ip address and will get added to the cluster.For this the Hazelcast node should be up on these servers.

Download Source Code

Download it - Hazelcast Hello World application


See Also

Hazelcast Tutorial- Working with Hazelcast collections- Map,List,Set,Queue. Hazelcast Tutorial- Understanding Replicated Maps using example. Hazelcast - Main Menu