Or using google's public language api, if remote access is an option:
try {
String s = URLEncoder.encode("Há tantos burros mandando em homens de inteligência, que, às vezes, fico pensando que a burrice é uma Ciência", "UTF-8");
URL url = new URL("http://ajax.googleapis.com/ajax/services/language/detect?v=1.0&q="+s);
BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));
String str;
StringBuilder buffer = new StringBuilder();
while ((str = in.readLine()) != null) {
buffer.append(str);
}
in.close();
JSONObject obj = (JSONObject) ((JSONObject)JSONValue.parse(buffer.toString())).get("responseData");
System.out.println(obj.get("language"));
System.out.println(obj.get("confidence"));
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}