Java tutorial
//package com.java2s; public class Main { public static long parseLongWithDefault(String s, long defValue) { if (s == null) { return defValue; } try { return Long.parseLong(s); } catch (NumberFormatException e) { return defValue; } } public static Long parseLong(String s) { try { return new Long(s); } catch (NumberFormatException e) { return null; } } }