Write PDF file in Java using iText

In this tutorial we will see how to write PDF file in Java using iText library.

Review the code listed below. Running this program will generate a PDF file at location c:/itext.pdf. You can change the location in the program to suit your platform:
Continue reading “Write PDF file in Java using iText”

PDF Generation in Java: iText Tutorial

iText is a free and open source PDF library (License Type: AGPL) for Java. It is unarguably the best and most efficient PDF library currently available for Java.

Adding PDF support to your application for functionalities like reporting can be an excellent idea given that PDF is a well accepted format and easy to share. Besides, PDF files also look good as compared to other formats.
Continue reading “PDF Generation in Java: iText Tutorial”

Read PDF file in Java using iText

In this post we will read PDF file in Java using iText library.

The Java program will assume there is a PDF file at location c:/temp/test.pdf. Change this path according to your environment.
Continue reading “Read PDF file in Java using iText”

How to fix issues with your eclipse while working on Java 7

If you have recently installed Java 7, chances are that you might be facing errors using the brand new features of Java 7. This is because of Eclipse Java 7 compliance issue of the compiler.

Follow the steps listed below to fix these errors and run programs using new features of Java in eclipse.
Continue reading “How to fix issues with your eclipse while working on Java 7″

Java 7 Multi Catch Block

In the pre Java 7 world, you would handle exceptions by writing separate catch blocks for different types of exceptions that can occur in the try block. In case of related exception, the derived class exception are listed above the base class exception, e.g. FileNotFoundException should be listed above IOException since former is derived from the latter. Java 7 multi catch block provides you the flexibility to combine such catch blocks, provided you have similar code to handle these exceptions.

Save 20% on hosting plans at Go Daddy

Lets have a look at Continue reading “Java 7 Multi Catch Block”

Java 7 Try with Resources Statement

In the pre Java 7 world, you would typically acquire and use resources inside a try block, handle exceptions in the catch block(s) and release the resources in the finally block. The finally block is always executed irrespective of whether exceptions occur or not. The Java 7 try with resources statement eliminates the need for finally block for resource management. You can do so by declaring your resources in the brackets following the token try.
Continue reading “Java 7 Try with Resources Statement”

Java 7 Switch String Support

Java 7 switch String support should have been added long way back! It was first requested 17 years ago!!

Until the previous version it supported variables and expressions which resolved into int, byte, short or char only. But now with the addition of String support, it will surely save a lot of complex if-else structures and improve the overall code readability.

Here is a self explanatory example of Switch with Strings in action:
Continue reading “Java 7 Switch String Support”

Java 7 Features with Examples

There are a lot of new features added in JDK 7. In this series of tutorials we will review some of these new Java 7 features with examples.

java 7 features with examples
Continue reading “Java 7 Features with Examples”

Java Null Pointer Check

In this post we will see a simple method to put a Java null pointer check in place with minimal effort.

NullPointerException unarguably is the worst nightmare for a Java developer. You can see this exception on even some of the reputed sites on the internet.

Basically you get this exception when you are trying to access some method over an object reference which is pointing to null.
Continue reading “Java Null Pointer Check”

Class.forName Example

In this post we will see a Class.forName Example and how it can be used to create dynamic objects.

Class.forName is commonly used while creating JDBC connections, but developers rarely know what it means.

It is a very unique way provided by Java to dynamically create objects without even knowing the class name at the time of coding (compile time)!
Continue reading “Class.forName Example”