Java Comparator example
Posted on Aug 10, 2010 | Leave a Comment
Sometimes we need to sort objects based on certain attributes of the object. In that situation normal sorting methodologies will not work. For example you have a list of employee objects which you have got after doing database query. Now, before displaying the data to the presentation layer (say webpage) you need to sort by employee salary or age. In that situation you can sort the employee objects if you create custom...
JfreeChart Series-3: How to create a dynamic 3D Pie Chart using JFreeChart library in Java
Posted on Jul 02, 2010 | Leave a Comment
You may refer to the earlier tutorials if you have not done so.
Jfreechart series1: How to create a dynamic bar-chart using jfreechart library in java
Jfreechart series2: How to create a dynamic pie chart using jfreechart library in java
In this tutorial I’ll show you how we can use JFreeChart library to create 3D Pie chart. First I’ll give you the source of the chart utility where I’m populating the...
How to create Windows executable EXE from a Java Jar
Posted on Dec 05, 2009 | Leave a Comment
Creating Windows executable EXE file from a Jar file:
//
Though java is a platform independent and runs on any platform but sometimes we need to deliver applications for the end users who are comfortable with Microsoft Windows. It is very hard to explain them why the .class files generated can’t get executed with double clicks. Even if you create a Jar file and try to execute this using a batch (*.bat) file, most...
Step by step guide to create Singleton design pattern with Java
Posted on Mar 31, 2009 | Leave a Comment
Singleton design pattern is a kind of design pattern which helps a java developer to apply restriction to a class to have one and only one instance. This way the developer can ensure as well as can control how an object is instantiated and can prevent others from creating or copying multiple instances of the class.
Purpose: The main purpose is that if we have to use a resource then we can create a singleton class which...
Reading user input in java
Posted on Jan 29, 2009 | Leave a Comment
Sometimes in our stand alone java program we need to read user input data. Below code snippet will show you how to read user input in a Java application.
package com.tctalk.myapp.java.src;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
/**
* ReaduserInput.java – [This code reads the user input data from command prompt]
...
creating non duplicate array from duplicate array in Java
Posted on Jan 23, 2009 | Leave a Comment
This example helps you to generate a fresh and non duplicate array of elements from an array having duplicate elements. However there is a problem in this code. The nonduplicate array tends to have 0 to fillup the empty spaces.
package com.test.java;
public class sample {
  public static void main(String[] args) {
    int dupArr[] = { 1, 2, 3, 3, 7, 8, 8, 1, 4, 1};
    int noDupArr[] = generateNonDuplicateArr(dupArr);
 ...
How to test if a String is palindrome or not in Java?
Posted on Jan 23, 2009 | Leave a Comment
Steps to check if a given string is a Palindrome or not?
Step 1: Get the string instance
Step 2: Reverse the string
Step 3: Compare the reversed string with the original string
Step 4: If it matches then it is Palindrome else not.
Below code snippet does the same thing:
package com.test.java;
Â
public class PalindromeChecker {
Â
  public static void main(String[] args) {
    String plCheckStr1...
JfreeChart Series-2: How to create a dynamic Pie Chart using JFreeChart library in Java
Posted on Jan 17, 2009 | 3 Comments
 In the earlier tutorial I showed you how to create Bar chart using JFreeChart library. In this second article I’ll explain how to create pie chart. Everything is same like the previous tutorial, except the servlet code will be changed.
So let me first put the servlet code here:
package com.cts.chartgen.servlets;
Â
import java.awt.Color;
import java.io.IOException;
import java.io.OutputStream;
Â
import javax.servlet.ServletException;
import...
File upload to BLOB field and display attachment dialog box
Posted on Jan 16, 2009 | 1 Comment
Sometimes a developer needs to provide the feature in their web application to upload file. This file can be anything like documents (PDF, doc, rtf etc.) or image (jpg, bmp, tif, gif etc.) or zip file. And after uploading the developer needs to provide another feature to download the file by clicking a link.
There can numerous ways to provide this functionality in a web application. I’m going to discuss about...
How to load a properties file in Java
Posted on Jan 09, 2009 | 1 Comment
This tutorial will explain how to access properties file through Java coding. A properties file can be accessed with the ResourceBundle class which resides in the java.util package. In the example below I’m going to provide is based on the properties file staying in the same package. For properties file staying outside the package, we need to set the CLASSPATH variable pointing to the same folder where the external...
You can subscribe by e-mail to receive news updates and breaking stories.