Java code for basic graph operations