The oracle OCA Java book is good but it does leave some gaps, more make this work which is good in some ways frustrating in others. Anyway it is filling in lots of little gaps which is what I need. I had to postpone the exam as I just wasn't ready.
Articles and bits I liked this week,
Trying to make some tools for work although one API responds so much slower using the below instead of browser, taken URLs out. At first I thought it was because the API was first on the list, rejigged it so the problem URL not first same issue. At least it is a start. (done in my own time)
package com.company;
import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Map;
import java.util.HashMap;
public class apiTester {
public Map<String, String> apiURLs = new HashMap<>();
public apiTester() {
apiURLs.put("google", "https://www.google.co.uk/");
apiURLs.put("bbc", "http://www.bbc.co.uk/");
}
public void runTests() {
long startTime, stopTime = 1;
for (String apiName : apiURLs.keySet()) {
startTime = System.currentTimeMillis();
HttpURLConnection connection = null;
try {
URL apiURL = new URL(apiURLs.get(apiName));
connection =
(HttpURLConnection)apiURL.openConnection();
connection.setRequestMethod("GET");
connection.connect();
} catch (MalformedURLException ex) {
System.out.println("Bad URL");
ex.printStackTrace();
} catch (IOException ex) {
ex.printStackTrace();
} finally {
if (connection != null)
connection.disconnect();
}
stopTime = System.currentTimeMillis();
System.out.print(String.format("%1$-20s" ,apiName));
System.out.println((int) (stopTime - startTime) + "ms");
}
}
}
No comments:
Post a Comment