How to Shake the Gesture

HI,
How to Shake Gesture of the the Device while automating?
for both android and iOS.

http://www.rubydoc.info/github/appium/ruby_lib/Appium/Device:shake

but how to get driver and it is in phython right?
i want code in java