In order to automate test cases with java using testNG and Appium :
This is the following code i use to run appium with protractor by console :
appium --default-capabilities '{"app":"safari","browserName":"safari","appium-version":"1.5.1","platformName":"iOS","platformVersion":"9.3","deviceName":"iPad Air","nativeInstrumentsLib":true}' --command-timeout "0" --pre-launch --nodeconfig "/Users/me/nodeconfig.json" --launch-timeout "180000"
For java using testNG and Appium:
create a base class where you will set the appium driver with all the capabilities and than extend this base class to get the appium driver.
u can also do this by invoking that class constructor. U can go through this sites to get idea:
http://toolsqa.com/selenium-webdriver/constant-variables/
http://blog.xebia.in/2016/01/11/Design-Patterns-in-Selenium-Automation-Part1-POM/