Best way to Convert Integer to String in Java with Example

Integer to String conversion in Java
There are many ways to convert an Integer to String in Java e.g. by using Integer.toString(int) or by using String.valueOf(int), or by using new Integer(int).toString(), or by using String.format() method, or by using DecimalFormat, String concatenation, or by using StringBuilder and StringBuffer etc. Some of them we have already seen on my earlier posts e.g. how to convert int to String and converting double to String. Even though those posts gives you tricks to convert primitive int to String and primitive double to String, you can still use those tricks to convert a wrapper class object e.g. Integer or Double to String in Java. Both are good ways, but out of those which is the best way to convert an Integer to String in Java?  You will find out in this article.

Top 5 Reasons of Exception in thread "main" java.lang.NoClassDefFoundError in Java

NoClassDefFoundError in Java
The Exception in thread "main" java.lang.NoClassDefFoundError is a common error in Java which occurs if a ClassLoader is not able to find a particular class in the classpath while trying to load it. The Exception in thread "main" suggests that this error has occurred in the main thread, the thread which is responsible for running Java application. This error can occur to any thread but if it happens in main thread then your program will crash. As per Javadoc, NoClassDefFoundError can be thrown during linking or loading of the class file. It's denoted by java.lang.NoClassDefFoundError and comes when that particular class is present during compile time but somehow not available during runtime. This could be due to missing JAR file, any permission issue, or incorrect classpath on runtime, depending upon your environment.

How to create a ZIP File in Java? ZipEntry and ZipOutputStream Compression Example

Since compressing and archiving old log file is an essential housekeeping job in any Java application environment, a Java programmer should know how to compress files in .zip format and then how to read them programmatically if required. The JDK provides full support to create and read ZIP files in Java. There is a separate package to hold all classes related zipping and unzipping files and streams. In this series of article, you will learn how to use those classes e.g. ZipFile, ZipEntry, ZipInputStream, and ZipOutputStream etc. This is the second article about how to work with compressed archives in Java e.g. .zip files. In the last article, I have shown you how to read ZIP archives in Java and today, I'll teach you how to compress files in the ZIP file format by yourself using a Java program. You will compress a bunch of text file to create a .zip file by using JDK's ZIP file support classes.