I can find some jars like HTMLPARSER and java.net package to access the source of a URL

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLConnection;

public class sample2 {
    public static void main(String args[]) throws Exception

String data=null;
URL location = new URL("http://www.google.com");
URLConnection conn = location.openConnection();
BufferedReader in = new BufferedReader(
    new InputStreamReader(
String inputLine;
while ((inputLine = in.readLine()) != null) 
    data += inputLine + "\n";

How can we access source code of a web URL that can be accessed only if we have logged in? For example how to access my gmail inbox contents url from java?
How should i pass the login credentials?