@JK_007, Hazelcast can be configured either declaratively (XML) or programmatically (API) or a combination of both can be used. Both are correct ways to create a cache.
The choice really depends on your use case. Declarative way is the static way of defining your configuration. You can mention separate set of configuration for each distributed data structure you intend to use in your application. For e.g. the following snippet in your hazelcast.xml creates a IMAP with name simpleMapand the below mentioned configuration.
<map name="simpleMap">
<backup-count>0</backup-count>
<max-idle-seconds>0</max-idle-seconds>
<eviction-policy>LRU</eviction-policy>
<time-to-live-seconds>30</time-to-live-seconds>
<max-size>3000</max-size>
<eviction-percentage>30</eviction-percentage>
<merge-policy>com.hazelcast.map.merge.PutIfAbsentMapMergePolicy</merge-policy>
</map>
You can also define your hazelcast XML configuration file from multiple XML configuration snippets. In order to do the same, you can use the <import/> element to load different XML configuration files.
The programmatic way is very useful if you need to define caches during runtime, ( for e.g. on the basis of some condition) and also for testing. You can view it as a solution to the static nature of hazelcast.xml.
For each tag in the hazecast xml, you can find its programmatic equivalent in the Config object. Summarizing, if you need dynamic capabilities (add/modify configurations), go for programmatic way. If you are very sure that nothing needs to be done during runtime, you may use declarative way.