Differences between HashMap and Hashtable in Java

What are the differences between two similar Java classes? Check this article to find out
15 August 2017   512

What is HashMap? 

The HashMap class uses a hash table to store the card, providing a fast execution time for the get() and put() queries for large sets. The class implements the Map interface (data storage in the form of key / value pairs). Keys and values can be of any type, including null. All keys must necessarily be unique, and the values can be repeated. This implementation does not guarantee the order of the elements.


// K - Key, V - Value
class HashMap<K, V>

You can declare it as follows:

Map<String, Integer> hashMap = new HashMap<String, Integer>();

Map<String, String> hashMap = new HashMap<String, String>();

What is Hashtable? 

Hashtable class implements a hashtable, which maps keys to values. It inherits Dictionary class and implements the Map interface.

Main Hashtable features:

  • A Hashtable is an array of list. Each list is known as a bucket. The position of bucket is identified by calling the hashcode() method. A Hashtable contains values based on the key.
  • It contains only unique elements.
  • It may have not have any null key or value.
  • It is synchronized.

Differences between HashMap and Hashtable

After our research, we've found out that there are 3 main differences:

  1. Hashtable is synchronized, and HashMap is not. Due to this fact, HashMap is better for non-threaded applications, as unsynchronized Objects typically perform better than synchronized ones.

  2. Hashtable does not allow null keys or values and HashMap allows one null key and any number of null values.

  3. One of HashMap's subclasses is LinkedHashMap, so in the event that you'd want predictable iteration order (which is insertion order by default), you could easily swap out the HashMap for a LinkedHashMap. This wouldn't be as easy if you were using Hashtable.

What is Web3j?

Small review of lightweight Java and Android library for integration with Ethereum clients
15 December 2017   991

What is webj3?

web3j is a lightweight, highly modular, reactive, type safe Java and Android library for working with Smart Contracts and integrating with clients (nodes) on the Ethereum network:

web3j architecture
Web3j Architecture

This allows you to work with the Ethereum blockchain, without the additional overhead of having to write your own integration code for the platform.

According to the developers, these are the features:

  • Complete implementation of Ethereum's JSON-RPC client API over HTTP and IPC
  • Ethereum wallet support
  • Auto-generation of Java smart contract wrappers to create, deploy, transact with and call smart contracts from native Java code (Solidity and Truffle definition formats supported)
  • Reactive-functional API for working with filters
  • Ethereum Name Service (ENS) support
  • Support for Parity's Personal, and Geth's Personal client APIs
  • Support for Infura, so you don't have to run an Ethereum client yourself
  • Comprehensive integration tests demonstrating a number of the above scenarios
  • Command line tools
  • Android compatible
  • Support for JP Morgan's Quorum via web3j-quorum

It has five runtime dependencies:

  • RxJava for its reactive-functional API
  • OKHttp for HTTP connections
  • Jackson Core for fast JSON serialisation/deserialisation
  • Bouncy Castle (Spongy Castle on Android) for crypto
  • Jnr-unixsocket for *nix IPC (not available on Android)

It also uses JavaPoet for generating smart contract wrappers.

Lear more at GitHub.