Really I tried a lot with MCP3208 external ADC to interface with the Raspberry pi. Searched for various codes but nothing was available in JAVA. So after some research i got some python code and modified that to JAVA. in this i have used the Pi4J library.
/**** *Author : Bikash Narayan Panda *Use : This is used to read ADC data foem the MCP3208 SPI based ADC. *Date :19/Nov/2014 *Tags: Please Include the Pi4J Library. * * **/ import java.io.IOException; import com.pi4j.io.gpio.GpioController; import com.pi4j.io.gpio.GpioFactory; import com.pi4j.io.gpio.GpioPinDigitalInput; import com.pi4j.io.gpio.GpioPinDigitalOutput; import com.pi4j.io.gpio.PinPullResistance; import com.pi4j.io.gpio.PinState; import com.pi4j.io.gpio.RaspiPin; public class SensorTest { public static int readadc(int adcnum, GpioPinDigitalOutput clockpin, GpioPinDigitalOutput mosi