The Gremlin Console automatically has a host of static imports in place so that you can save keystrokes and make Gremlin look less verbose. When you do:
g.E().project('EDGE','IN','OUT','PROP')
.by(id())
.by(inV().union(id()).fold())
.by(outV().union(id()).fold())
.by(properties().fold())
What you're really doing is:
g.E().project('EDGE','IN','OUT','PROP')
.by(__.id())
.by(__.inV().union(__.id()).fold())
.by(__.outV().union(__.id()).fold())
.by(__.properties().fold())
In your Java application you merely need to include an import
statement like:
import static org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__.*;
and the original syntax from the Groovy console will paste perfectly into a Java application. Or if you prefer the more verbose syntax use a standard import
of the __
class and then explicitly use that to spawn your child traversals as demonstrated in teh second example above. Please see the full list of suggested imports in the Reference Documentation.