Q: what should be the value passed in function to connect to my google drive using java program? I got following code from google developers site:    
package javaapplication24;
import com.google.api.client.http.GenericUrl;
import com.google.api.client.http.HttpResponse;
import com.google.api.services.drive.Drive;
import com.google.api.services.drive.model.File;

import java.io.IOException;
import java.io.InputStream;

// ...

public class NewClass {

// ...

/**
* Print a file's metadata.
*
 * @param args
* @param service Drive API service instance.
* @param fileId ID of the file to print metadata for.
*/

private static void printFile(Drive service, String fileId) {


try {
  File file = service.files().get(fileId).execute();

  System.out.println("Title: " + file.getTitle());
  System.out.println("Description: " + file.getDescription());
  System.out.println("MIME type: " + file.getMimeType());
} catch (IOException e) {
  System.out.println("An error occured: " + e);
}
}

/**
 * Download a file's content.
 *
 * @param service Drive API service instance.
 * @param file Drive File instance.
 * @return InputStream containing the file's content if successful,
 *         {@code null} otherwise.
 */
private static InputStream downloadFile(File file, Drive service) {
if (file.getDownloadUrl() != null && file.getDownloadUrl().length() > 0) {
  try {
    HttpResponse resp =
        service.getRequestFactory().buildGetRequest(new GenericUrl(file.getDownloadUrl()))
            .execute();
    return resp.getContent();
  } catch (IOException e) {
    // An error occurred.
    e.printStackTrace();
    return null;
  }
} else {
  // The file doesn't have any content stored on Drive.
  return null;
}
}

// ...
}

I know i need to write a main function with this and call the functions printFile and DownloadFile but I am not getting what is to be passed in function as variable service?

A: You have to understand how it works first!

*

*In order to download or print details about your files, you need to authenticate your app from your google account with right scope(permissions like readonly, modify/delete and so on).

*Once authentication is done. You will get access token to access the data.

This is a small fragment of code that says what the Drive service means
     /**
     * Build and return an authorized Drive client service.
     * @return an authorized Drive client service
     * @throws IOException
     */
    public static Drive getDriveService() throws IOException {
        Credential credential = authorize();
        return new Drive.Builder(
                HTTP_TRANSPORT, JSON_FACTORY, credential)
                .setApplicationName(APPLICATION_NAME)
                .build();
    }

Head on to this link to learn more about it
https://developers.google.com/drive/web/quickstart/java
Note: It would be unnecessarily long answer, if i copy paste the complete code here
