code: public static String toUnicodeLiteral(String s) {
  
          StringBuffer result = new StringBuffer();
          char[] carr = s.toCharArray();
  
          String unicode;
          for (int i = 0; i < carr.length; i++) {
              result.append("\\u");
              // append leading zeros
              unicode = Integer.toHexString(carr[i]).toUpperCase();
              for (int j = 4 - unicode.length(); j > 0; j--) {
                  result.append("0");
              }
              result.append(unicode);
          }
          return result.toString();
      }
docs: Returns the java String literal for the given String. <p>
  
  This is the form of the String that had to be written into source code
  using the unicode escape sequence for special characters. <p>
  
  Example: "&Auml" would be transformed to "\\u00C4".<p>
  
  @param s a string that may contain non-ascii characters
  
  @return the java unicode escaped string Literal of the given input string