All relationships have a type.
For example, if the graph represents a social network, a relationship type could be KNOWS.
If a relationship of the type KNOWS connects two nodes, that probably represents two people that know each other.
A lot of the semantics (that is the meaning) of a graph is encoded in the relationship types of the application.
And although relationships are directed they are equally well traversed regardless of which direction they are traversed.

Note that starting a database server is an expensive operation, so don’t start up a new instance every time you need to interact with the database!
The instance can be shared by multiple threads.
Transactions are thread confined.

As seen, we register a shutdown hook that will make sure the database shuts down when the JVM exits.
Now it’s time to interact with the database.

Wrap operations in a transaction

All operations have to be performed in a transaction.
This is a conscious design decision, since we believe transaction demarcation to be an important part of working with a real enterprise database.
Now, transaction handling in Neo4j is very easy:

For brevity, we do not spell out wrapping of operations in a transaction throughout the manual.

Create a small graph

Now, let’s create a few nodes.
The API is very intuitive.
Feel free to have a look at the Neo4j Javadocs.
They’re included in the distribution, as well.
Here’s how to create a small graph consisting of two nodes, connected with one relationship and some properties: