Given two nodes "nodeA" and "nodeB",
gets all relationships attached to "nodeA",
rels = nodeA.getRelationships();
iterate through the collection of relationships "rels", for each relationship "rel", test whether the other end node is nodeB
rel.getOtherNode(nodeA).equals(nodeB)
if the above expression holds true for one of the relationships, then nodeA and nodeB are connected.
Here is the java API for "Node" and "Relationshiip",