Category Archives: Java

[Java、HBase] Retrieving timestamp form HBase row

Ref. stackoverflow: retrieving timestamp from hbase row HTableInterface hTableInterface = CONNECTION.getTable(Table.SCHEMA_NAME); Result result = hTableInterface.get(get); Date date = new Date(result.raw()[0].getTimestamp()); System.out.println(“DateTime: ” + sdf.format(date)); we must edit HBaseSettings to set hbaseConf.set(HBASE_ENV_KEY_ZOOKEEPER_QUORUM, “target_zookeeper_address”);

Posted in HBase, Java | Tagged , | Leave a comment

[Java] Transform currentTimeMillis to readable date format

Ref. stackoverflow: how-to-transform-currenttimemillis-to-a-readable-date-format SimpleDateFormat sdf = new SimpleDateFormat(“MMM dd,yyyy HH:mm”); Date date = new Date(System.currentTimeMillis()); System.out.println(“DateTime: ” + sdf.format(date));

Posted in Java | Tagged | Leave a comment

[Java] Check UUID format

Ref. BUKKIT: Best way to check if a String is a UUID private static boolean checkUUIDFromat(String uuid) { if (uuid.matches(“[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}”)) { return true; } return false; }

Posted in Java | Leave a comment

[Java] Check string is a messy code?

Ref: Java判断字符串是否是乱码(亲测可用) public static boolean isChinese(char c) { Character.UnicodeBlock ub = Character.UnicodeBlock.of(c); if (ub == Character.UnicodeBlock.CJK_UNIFIED_IDEOGRAPHS || ub == Character.UnicodeBlock.CJK_COMPATIBILITY_IDEOGRAPHS || ub == Character.UnicodeBlock.CJK_UNIFIED_IDEOGRAPHS_EXTENSION_A || ub == Character.UnicodeBlock.GENERAL_PUNCTUATION || ub == Character.UnicodeBlock.CJK_SYMBOLS_AND_PUNCTUATION || ub == Character.UnicodeBlock.HALFWIDTH_AND_FULLWIDTH_FORMS) { return true; } … Continue reading

Posted in Java | Leave a comment

[Java] To use Arrays.asList function, must be careful…

Ref: java.util.Arrays.asList用法及注意事项 java集合中部分异常java.lang.UnsupportedOperationException一个共同点 Because the ArrayList made by Arrays.asList function could not be modified anymore…

Posted in Java | Leave a comment

[Java] JSON escape special character

Ref: 剑飘江湖的博客 – JSON格式数据中特殊字符的处理 public static String stringToJson(String s) { if (StringUtils.isEmpty(s)) { return s; } StringBuffer sb = new StringBuffer (); for (int i=0; i<s.length(); i++) { char c = s.charAt(i); switch (c) { case ‘”‘: sb.append(“\””); break; /*case … Continue reading

Posted in Java | Leave a comment

[Java] New arraylist with value

Ref: stackoverflow: Initialization of an ArrayList in one line List<String> places = Arrays.asList(“Buenos Aires”, “Córdoba”, “La Plata”);

Posted in Java | Leave a comment

[Java] Get key from value

Ref: Java Hashmap: How to get key from value? private Object getKeyFromValue(Map map, Object value) { for (Object object : map.keySet()) { if (map.get(object).equals(value)) { return object; } } return null; }

Posted in Java | Leave a comment

[Java] Check Json body.

Ref: stackoverflow:How to check whether a given string is valid JSON in Java public boolean isJSONValid(String test) { try { new JSONObject(test); } catch (JSONException ex) { // edited, to include @Arthur’s comment // e.g. in case JSONArray is valid … Continue reading

Posted in Java | Leave a comment

[Java] Eclipse IDE.

Download and install JDK. Edit Windows Environment setting. (Advanced system settings => Advance => Environment variables => Choose Path and click edited => Add the location of the bin folder of the JDK installation.) Ex: “C:Program Files (x86)Javajre1.8.0_31bin” Check the … Continue reading

Posted in Eclipse, Java | Leave a comment