category : Java

Java: JDK居然有个叫整型池的东西

其实下面这些个assert语句都可以通过junit测试。 12345678@Testpublic void integerValueOfTest() { Assert.assertTrue(Integer.valueOf(-128) == Integer.valueOf(-128)); Assert.assertFalse(Integer.valueOf(128) == Integer.valueOf(128)); Assert.assertTrue(Integer.valueOf(127) == Integer.valueOf(127)); Assert.assertTrue(Integer.valueOf(1) == Integer.valueOf(1)); Assert.assertFalse(Integer.valueOf(1000) == Integer.valueOf(1000));}

Java Mail中文乱码


Jackson: deserialize nested object

I am implementing a RESTful server inside my company. The workflow is very straight-forward: request and response. However, nothing is easy, the RESTful service is based on an existed project, which handles database operations, and the entities inside that project is pretty complex(a lot of interfaces and abstract classes).

Java: Test a file is image or not

There are many ways to check whether a file is image. For example, check the file extension(jpg, png, gif …). But this is not so safe, in a web environment, user may rename XXX.exe, to XXX.jpg, then s/he can succeed to upload it. In this case, it can induce security problem.