Posts

Resolve OutOfMemoryError With ExcelExport : Export Excel Utility with Apache POI Stream API (SXSSF)

                                 Whenever we try to export excel of huge data (for ex: around 200000-300000 records), most of the time we end up with OutOfMemoryError:JavaHeapSpace. And also consuming more time to process or export that much of data. Main reason to this kind of problem is that, the prior version of Apache POI (prior to 3.8) will not provide proper solution for this kind of situations and also we have other issues with the API designed with those versions. Even I had faced issues of not supporting more than 65000 rows of data during exporting excel with prior versions of POI. But with the version 3.8 and higher they come with solutions for all these problems. To resolve Memory issue and performance issue of Excel Export they have utilized stream API to design their API to support huge data export and performance issues. With stream API we can flush only few rows of data into the Memory and reamining we can flush to the hard memory (permanent Memory). In this examp

Reading a file while file being written at the same time

Below code describes how to read a file when a particular file is actively being written. Here is a full example. For the below example the mentioned file should be existed in the mentioned path else it will throw FileNotFoundException. import java.io.BufferedInputStream; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; public class ReadingFileWhileWrite extends Thread { boolean running = true; BufferedInputStream reader = null; public static void main(String[] args) throws FileNotFoundException { ReadingFileWhileWrite tw = new ReadingFileWhileWrite(); tw.reader = new BufferedInputStream(new FileInputStream("TestFile.txt")); tw.start(); } public void run() { while (running) { try { if (reader.available() > 0) { System.out.print((char) reader.read()); } else { try {

How To Resolve "Java compiler level does not match the version of the installed Java project facet." Issue in Eclipse, STS tool or Eclipse Based Tools

Image
                  I have faced this issue during the Java 7 upgrade from Java 6 into one of our application. You will face this issue suppose if your application or project built on lower versions of Java (in my case it is Java 1.6) and you are trying to upgrade it to the Higher versions of Java (in My case it is Java 1.7), then Eclipse will throw this error in the tool. You will face this error even after changing the compiler version from build path. To fix this issue Follow the Below Mentioned Steps. 1.  Open the ' Markers ' Tab at the bottom of the eclipse or STS tool beside the ' Properties ' Tab. (as shown in the below figure) 2. Right Click on the Error as mentioned in the below figure. in The context menu click on the ' Quick Fix ' item as shown below in the figure. 3. Select the correct Java Project Facet from the ' Quick Fix ' Window. and click on the ' Finish ' Button. 4.  After Clicking on '

Java Important Links

The Story of the Java Platform  http://java.sun.com/nav/whatis/storyofjava.html Java Technology—An Early History  http://java.sun.com/features/1998/05/birthday.html Java Community Process   http://java.sun.com/aboutJava/communityprocess/ J2SE Platform Documentation  http://java.sun.com/docs/index.html J2EE home page  http://java.sun.com/j2ee J2EE Blueprints  http://java.sun.com/j2ee/blueprints/index.html EJB home page  http://java.sun.com/products/ejb Servlets home page  http://www.java.sun.com/products/servlet JSP home page  http://www.java.sun.com/products/jsp JDBC home page  http://www.java.sun.com/products/jdbc JMS home page  http://www.java.sun.com/products/jms JNDI home page  http://java.sun.com/products/jndi Connector home page  http://java.sun.com/j2ee/connector

Java Performance Checklist

• Specify the required performance. Ensure performance objectives are clear. Specify target response times for as much of the system as possible. Specify all variations in benchmarks, including expected response ranges (e.g., 80%  of responses for X must fall within 3 seconds). Include benchmarks for the full range of scaling expected (e.g., low to high numbers  of users, data, files, file sizes, objects, etc.). Specify and use a benchmark suite based on real user behavior. This is particularly  important for multi-user benchmarks. Agree on all target times with users, customers, managers, etc., before tuning. • Make your benchmarks long enough: over five seconds is a good target. Use elapsed time (wall-clock time) for the primary time measurements. Ensure the benchmark harness does not interfere with the performance of the  application. Run benchmarks before starting tuning, and again after each tuning exercise. Take care that you are not measuring artificial s

Be-Aware of the Performance of the String Concatenation...

                  The string concatenation operator (+) is a convenient way to combine a few strings into one. It is fine for generating a single line of output or for constructing the string representation of a small, fixed-size object, but it does not scale. Using the string concatenation operator repeatedly to concatenate n strings requires time quadratic in n. It is an unfortunate consequence of the fact that strings are immutable. When two strings are concatenated, the contents of both are copied. For example, consider the following method that constructs a string representation of a billing statement by repeatedly concatenating a line for each item: // In-appropriate use of string concatenation - Hits Performance drastically! public String statement() {      String res = "";      for (int i = 0; i < numOfItems(); i++)       res += lineOfItem(i); // String concatenation       return res; }                   This method performs very slow if the number of

Some Important Facts About Core Java

There are 4 important OOPS concepts in Java : Inheritance, Abstraction, Encapsulation and Polymorphism. There are two types of variables in Java : Primitive types and Object Types The default value of Boolean is false (the same applies for the Wrapper class too). Marker interface is the one which doesn't contains any methods , it is like empty interface. You cannot override the 'main' method of the Java, even-though if you try to do so it will not give any exception, program compiles and executes fine. The reason is : 'main' method is of type static . Static methods are class level methods. Even-though it looks like method overriding, it is not overriding. These are two different method with respect to the corresponding class. You can Overload the 'main' method of Java, it is valid in Java. You can have only one 'Public' class and any number of non-public classes in any java source file. Inheritance is an example for IS-A relationship. C