In many cases, web applications give OutOfMemoryError when their threads require high levels of  memory. Image manipulation or intensive database use or calculation can lead to this very common problem. Normally when you get an OutOfMemory error in a desktop application, you can solve this problem by specifying the java commands -Xms*** (initial Java heap size) and -Xmx*** (maximum Java heap size) when running your program. To solve this issue in tomcat, you must specify these options in the tomcat startup command / script / batch. In windows tomcat is installed as a service. Tomcat provides a configuration tool to […]

java.lang.OutOfMemoryError: PermGen space // More memory for Tomcat under windows

In the past 2 entries (Part I and Part II) we learnt how to develop a basic report and how to fill it with data from a database with a jdbc connector. Now we will learn how to call a report from within a Java application and how to set some basic parameters. The most important thing when running your reports from within a java application is to have all the necessary jar libraries available from your classpath. The basic ones for running the sample report will be commons-logging-*.jar, commons-collections-*.jar, jasperrerports-*.jar and yourJDBCconnector.jar. All of them (except the jdbc connector) […]

Getting started with JasperReports // Printing reports from your java ...

This is the second part of a series of articles to get people started with JasperReports. In the second part I’ll explain how to access your database to run simple queries and show them in a very simple report created with iReport. The first thing we need to do to get moving is to have iReport ready. So if you haven’t got it installed do so. Next step is to have the database driver in your iReport library folder. This means that you will need a jdbc jar packaged driver copied to the ./lib/ directory of iReport’s base folder. This […]

Getting started with JasperReports // JDBC connections (Part II)

IReport 1
This is the first of a series of articles to get you started with JasperReports. In first place, JasperReports is one of Java’s reporting engines. It’s very powerful and has lots of features that makes it comparable to commercial reporting solutions such as Crystal Reports. The first thing you need to do to start using this great peace of software is go to the project page and download it (wait). In the project page there is some documentation that will help you getting started. You must know that JasperReports is a reporting engine that integrates many capabilities. Reports are developed […]

Getting started with JasperReports // Reporting in Java (Part I)

IMPORTANT NOTICE This post was published in 2007 and some code was used to interact with databases which had no JDBC connector. It is a very bad practice and unrecommended to send SQL statements directly to a database Such a simple thing as replacing an apostrophe with an escape character from a string sometimes can become a very tedious process, more if you’re using String’s replaceAll(…) function. Replacing apostrophes from Strings may be very useful when creating Statements to pass to an SQL database, preventing SQL injection. Many may say that using PreparedStatements is easier and safer, but in many […]

Replacing Apostrophes from Strings // Cleaning String to pass them ...

Adding a KeyListener to a JTextField to detect KeyPressed events is pretty straightforward. Buy maybe you have encountered some problems when trying to detect special key such as TAB’s. This issue is due to LowLevel keyEvents captured by Swing’s default FocusTraversalKeys. What we need to do to capture the VK_TAB KeyEvent is to remove the default FocusTraversalKeys from the component. [crayon-5ad8b425c1ac5092382617/] Once we’ve done this with the component, the tab KeyEvent will not be captured by swing’s default focus traversal keys and we will be able to add events normally. [crayon-5ad8b425c1aca196877662/]

Detecting Tab Key Pressed Event in JTextField ‘s // Event.VK_TAB ...

Internet offers many opportunities and possibilities for developers with imagination. Today, most search engines and specialized sites count with API’s to access their data from other software, sites, devices… Today I’m going to show you a dirty example of how this apis can benefit your program. In less of ten lines of code (someone intelligent would have done it in less) I will add an Icon to a jButton with an image stored in the net. To do this I will use yahoo’s Image Search API, documentation can be found here. For demonstration purposes I will use the YahooDemo applicationId, […]

Dynamic icons for your JComponents // Create an icon JButton ...

When working with tables, it may be useful to detect selection changes. If for example, you need to sum the values of a specified column in a selection range, this method will be most essential. If you explore the available methods to add listeners to a JTable, you will notice there’s no such thing as a selectionListener. This is because the JTable has its own selection model, where you can add the listener. The following code illustrates the way to go to add a selection listener: [crayon-5ad8b425c2344410187067/]

JTable, detecting selection changes // ListSelectionListener /*Selection Changed ...

When developing user interfaces for management software you usually need to check what the user inputs in order to store the values in a database or a file. Java offers different alternatives to parse a String (normally the way user inputs values to the system) to other data types. The class SimpleDateFormat from the package java.text offers a simple method to do this. You just have to call parse(String youDate) in order to get a java.util.Date. Following you can find some code which explains this method and some of its particularities: [crayon-5ad8b425c28ca883325362/]

SimpleDateFormat to check user date input // parsing String to ...

When printing reports or casting Strings to Numbers, it’s very useful to use the DecimalFormat class found in java.text. This class is pretty straightforward and easy to use, but some problems may be found when your work with this class in computers from other countries. Internationalization will cause your program to behave in a way you may not expect in some cases. If you use this class to parse a number to a String, you may find that when a user enters a number in a french computer you will be getting a ParseException, because the computer is expecting different symbols. […]

Numbers to Strings with custom symbols // DecimalFormat – DecimalFormatSymbols

Java is a very powerful object oriented language. If you search for recursion in wikipedia you will find this definition “Recursion, in mathematics and computer science, is a method of defining functions in which the function being defined is applied within its own definition.” This means, that the function will call itself again and again until it gets the correct answer. There are many pages where you can find great explanations to recursion theory. Most of them use the example of the Towers of Hanoi: Cut The Knot –Towers of Hanoi– Recursion –Towers of Hanoi– Java Recursion with examples What […]

Java recursive functions explained // Using recursion to sum an ...