How do I do a HTTP GET in Java?

To send an HTTP GET request in Java, you can use the java.net.URL and java.net.HttpURLConnection classes.

Here is an example of how you can send a GET request and print the response:

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

public class Main {
  public static void main(String[] args) throws Exception {
    String url = "http://www.example.com";

    URL obj = new URL(url);
    HttpURLConnection con = (HttpURLConnection) obj.openConnection();

    // Set the request method to GET
    con.setRequestMethod("GET");

    // Send the request and get the response
    BufferedReader in = new BufferedReader(
        new InputStreamReader(con.getInputStream()));
    String inputLine;
    StringBuilder response = new StringBuilder();
    while ((inputLine = in.readLine()) != null) {
      response.append(inputLine);
    }
    in.close();

    // Print the response
    System.out.println(response.toString());
  }
}

This code creates a URL object and opens a connection to it using the openConnection method. It then sets the request method to GET using the setRequestMethod method and sends the request using the getInputStream method. Finally, it reads the response and prints it to the console.

I hope this helps! Let me know if you have any other questions.