HttpURLConnection example

HttpURLConnection allows to open an HTTP connection and get a response.

URL url = new URL("http://www.tutoref.com");
HttpURLConnection http = (HttpURLConnection)url.openConnection();
int statusCode = http.getResponseCode();
// if statusCode == 200, it means it's ok.
// other ways, it's an error you can deal with it.

 

How to convert Date into LocalDateTime in Java 8

Date to LocalDateTime

Date date = new Date();
Instant instant = date.toInstant();
LocalDateTime ldt = LocalDateTime.ofInstant(instant, ZoneId.systemDefault());

 

LocalDateTime to Date

LocalDateTime ldt = LocalDateTime.now();
ZonedDateTime zdt = ldt.atZone(ZoneId.systemDefault());
Date date = Date.from(zdt.toInstant());