Getting HTTP Status Code I have code that take in a URL (via URL or String) and returns the status code.  I am new to web development, so it is very possible that I may be taking a poor approach at this.  One thing I don't like about my code is the need for the InetSocketAddress to be hardcoded, but I have not been able to find a way around this short of passing it in as parameters. As an inexperienced programmer and complete newbie to web development, what improvements to the following code would you suggest?

import java.io.IOException;
import java.net.*;

public class HttpStatusCodeRequester {
    public static int getHttpStatusCode(URL url) {
        try {
            Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress("proxy.mycompany.com", 8099));
            HttpURLConnection connection = (HttpURLConnection) url.openConnection(proxy);
            connection.setRequestMethod("GET");
            connection.connect();
            int responseCode = connection.getResponseCode();
            connection.disconnect();
            return responseCode;
        } catch (IOException e) {
            System.err.println("HTTP Status Code Request failed for " + url + " in HttpStatusCodeRequester.getHttpStatusCode(URL)!");
            e.printStackTrace();
            return -1;
        }
    }

    public static int getHttpStatusCode(String url) {
        try {
            return getHttpStatusCode(new URL(url));
        } catch (MalformedURLException e) {
            System.err.println("Malformed URL passed into HttpStatusCodeRequester.getHttpStatusCode(String)!");
            e.printStackTrace();
            return -1;
        }
    }
}
You could use Properties and read from them... IMHO, I think almost everything that goes quoted ("like this") can be either a constant or sent to a Properties file, you could have one for messages and one for configuration for example.

Also, I've noticed that you have two return statements per method, I would recommend to have only one, you don't really need one inside the catch block since the exception is suppossed to be handled then returned. It is also good for readability.

Bear in mind that exceptions could happen before you reach the connection.disconnect(); statement so I would recommend a try, catch, finally and perform all your clean up un the finally block.

Another thing... I think it is better to handle the exception differently depending on the scenario or error that caused it, for example, a connection couldn't been stablished, wrong URL, timeout (I don't know), etc.