About java

About java

  1. There is no good solution to the problem of large integer decimal to hexadecimal conversion on Google, because the decimal number to be converted has more than 300 digits, and long can not be installed. There is no directly usable function that can be used to share it with Mr. Wang's method: Idea: Convert a decimal string to a big integer, put the big integer into the byte stream, and convert each byte to hexadecimal, with a zero-filling code: import java.math.BigInteger; public static String convertDecimalToUpperHexStr(String decimalStr ){ BigInteger bi = new BigInteger(decimalStr); byte[] bytes = bi.toByteArray(); StringBuilder sb = new StringBuilder(); int i=0; for(byte b: bytes) {String hexStr = Integer.toHexString( b & 0xFF); if (i==0&&"0".equals(hexStr)) i=1; else sb.append( hexStr.length()==1?("0"+hexStr):hexStr );} return sb.toString().toUpperCase();}
  2. Meaningful slashes have problems with the url http://ip:port/servername post data, and it was finally found that the server side mapped the action to "/". When the browser accesses, it will automatically add a slash to get the request, and the client The client request cannot find the specified action, resulting in an error. Need to pay attention to understanding the meaning of the code.
  3. android eclipse plugin url https://dl-ssl.google.com/android/eclipse/
  4. Obtain user ip through proxy such as apache nginx
public static String getRemoteAddr(HttpServletRequest req) { 

String ip = req.getHeader("x-forwarded-for"); 

if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {

ip = req.getHeader("Proxy-Client-IP"); 

} 

if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { 

ip = req.getHeader("WL-Proxy-Client-IP"); 

} 

if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { 

ip = req.getRemoteAddr(); 

} 

return ip; 

}
  1. If SVN's cache program makes your machine respond very slowly, you can refer to this solution. But you may need to change your previous usage habits. Turn off SVN's cache monitoring. That is, close the tsvncache.exe program to monitor the directory. The specific steps are as follows: a) Right-click any directory to open the right-click menu, and open the settings window under "tortoisesvn" => "settings" b) Find the setting item of "icon overlays", and set "status cache" to "none"
  2. Java exception: java.lang.ClassFormatError: Truncated class file After experimenting several times, I found that suddenly I copied the class file from the maven build on my own XP machine to the server and couldn't run it. Copying directly from the Linux environment of the test machine was fine. In the end, it was found that the file was selected as a binary transmission in ssh. Just remove this option.
  3. org.apache.juli.ClassLoaderLogManager not found JAVA_HOME is not set and set to/usr/local/jdk after installation
  4. java.net.UnknownHostException sc-server02: sc-server02: modify/etc/hosts 127.0.0.1 localhost.localdomain localhost sc-server02
  5. IntelliJ IDEA create patch Use the  Changes  view. In the  group by directory  mode you can right click on the directory with changes and choose Create Patch from the context menu. The answer on stackoverflow is actually very clumsy. Choose create or apply patch in the VCS menu Yes, if you have any questions, ask the help menu!
  6. IntelliJ IDEA open Multiple Projects change remember After selecting remember, the result cannot be opened in a new window. Just select confirm window in general startup/shutdown in preferences.
  7. System.currentTimeMillis problem It needs to switch from user mode to kernel mode, and the massive use of memcache in tens of thousands of requests per second will cause performance loss. Therefore, the system time is cached for 10ms, and this method can be used where accuracy below 10ms is not required
Reference: https://cloud.tencent.com/developer/article/1067253 About java-Cloud + Community-Tencent Cloud