20 Very Useful Java Code Snippets

Following are few very useful Java code snippets for Java developers. Few of them are written by me and few are taken from other code reference. Feel free to comment about the code and also add your code snippet.

1. Converting Strings to int and int to String

2. Append text to file in Java

Updated: Thanks Simone for pointing to exception. I have changed the code.

3. Get name of current method in Java

4. Convert String to Date in Java

or

5. Connecting to Oracle using Java JDBC

6. Convert Java util.Date to sql.Date


This snippet shows how to convert a java util Date into a sql Date for use in databases.

7. Java Fast File Copy using NIO

8. Create Thumbnail of an image in Java

9. Creating JSON data in Java

Read this article for more details.
Download JAR file 
json-rpc-1.0.jar (75 kb)

10. PDF Generation in Java using iText JAR

Read this article for more details.

11. HTTP Proxy setting in Java

Read this article for more details.

12. Java Singleton example

Read this article for more details.
Update: Thanks Markus for the comment. I have updated the code and changed it to more robust implementation.

One more implementation of Singleton class. Thanks to Ralph and Lukasz Zielinski for pointing this out.

13. Capture screen shots in Java

Read this article for more details.

14. Files-Directory listing in Java

15. Creating ZIP and JAR Files in Java

16. Parsing / Reading XML file in Java

Sample XML file.

Java code to parse above XML.

17. Convert Array to Map in Java

18. Send Email using Java

19. Send HTTP request & fetching data using Java

20. Resize an Array in Java

转载于:https://my.oschina.net/u/138995/blog/214268

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值