Friday, November 13, 2009

Java Report Generation


 iReport 
                   Report generation is process of fetching data from database and displaying those data to Users. It may be with some period of time like weekly, monthly.etc.. Report generation is used to view historical data.
iReport is the free, open source report designer for Jasper Reports, available for all major operating systems under the GNU General Public License. Use iReport to create very complex layouts containing charts, images, sub reports, crosstabs and much more. Access your data through JDBC, Table Models, JavaBeans, XML, Hibernate, CSV, and custom sources. Then publish your reports as PDF, RTF, XML, XLS, CSV, HTML, XHTML, text, DOCX, or Open Office.


Example:- 


   


/* Datewise Report 
 * 
 */
package Package;


import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.OutputStream;
import java.net.InetAddress;
import java.sql.*;
import javax.swing.JDialog;
import javax.swing.ProgressMonitor;
import javax.swing.SwingUtilities;
import javax.swing.Timer;
import javax.swing.event.*;


import java.awt.event.*;


import net.sf.jasperreports.engine.JRExporterParameter;
import net.sf.jasperreports.engine.JasperCompileManager;
import net.sf.jasperreports.engine.JasperExportManager;
import net.sf.jasperreports.engine.JasperFillManager;
import net.sf.jasperreports.engine.JasperPrint;
import net.sf.jasperreports.engine.JasperReport;
import net.sf.jasperreports.engine.design.JasperDesign;
import net.sf.jasperreports.engine.export.JRXlsExporter;
import net.sf.jasperreports.engine.export.JRXlsExporterParameter;
import net.sf.jasperreports.engine.xml.JRXmlLoader;
import net.sf.jasperreports.view.JasperViewer;


class Datevicereport extends JDialog  {
private boolean isExitOnClose = false;


ProgressMonitor conso;


int counter = 0;


Datevicereport() {
setTitle("Datewise Report");

Report();
this.dispose();
}



public void Report() {
try {
/*
* String jdbcString="jdbc:mysql://"; InetAddress address=null;
* address = InetAddress.getLocalHost(); String Ipaddr =
* address.getHostAddress(); String databaseName =
* jdbcString.concat(Ipaddr).concat("/SinglePhase");
*/
String databaseName = "jdbc:mysql://localhost/singlephase";
String userName = "root";
String password = "";
String reportFile = "DateReport.jrxml";
runReport(databaseName, userName, password, reportFile);
} catch (Exception e) {


}
}


public Connection connectDB(String databaseName, String userName,
String password) {
Connection jdbcConnection = null;
try {
Class.forName("com.mysql.jdbc.Driver").newInstance();
jdbcConnection = DriverManager.getConnection(databaseName,
userName, password);
} catch (Exception ex) {
String connectMsg = "Could not connect to the database: "
+ ex.getMessage() + " " + ex.getLocalizedMessage();
System.out.println(connectMsg);
}
return jdbcConnection;
}


public void runReport(String databaseName, String userName,
String password, String reportFile) {
try {
JasperDesign jasperDesign = JRXmlLoader.load(reportFile);
JasperReport jasperReport = JasperCompileManager
.compileReport(jasperDesign);
Connection jdbcConnection = connectDB(databaseName, userName,
password);
JasperPrint jasperPrint = JasperFillManager.fillReport(
jasperReport, null, jdbcConnection);
JasperViewer.viewReport(jasperPrint, isExitOnClose);
OutputStream ouputStream    = new FileOutputStream(new File("C:/catalog.xls"));
ByteArrayOutputStream byteArrayOutputStream    = new ByteArrayOutputStream();
JRXlsExporter exporterXLS = new JRXlsExporter();
exporterXLS.setParameter(JRXlsExporterParameter.JASPER_PRINT,jasperPrint);
exporterXLS.setParameter(JRXlsExporterParameter.OUTPUT_STREAM,byteArrayOutputStream);
exporterXLS.exportReport();
ouputStream.write(byteArrayOutputStream.toByteArray()); ouputStream.flush();ouputStream.close();
exporterXLS.setParameter(JRXlsExporterParameter.IS_ONE_PAGE_PER_SHEET, Boolean.TRUE); 
exporterXLS.setParameter(JRXlsExporterParameter.IS_AUTO_DETECT_CELL_TYPE, Boolean.TRUE); 
exporterXLS.setParameter(JRXlsExporterParameter.IS_WHITE_PAGE_BACKGROUND, Boolean.FALSE); 
exporterXLS.setParameter(JRXlsExporterParameter.IS_REMOVE_EMPTY_SPACE_BETWEEN_ROWS, Boolean.TRUE);


exporterXLS.exportReport(); 

catch(Exception ex) 
{
String connectMsg = "Could not create the report "
+ ex.getMessage() + " " + ex.getLocalizedMessage();
System.out.println(connectMsg);
}
}


}

Download link:-
    http://jasperforge.org/plugins/project/project_home.php?projectname=ireport


JFreeReport


JFreeReport is a free Java class library for generating reports (GNU LGPL). Includes support for headers, footers, grouping, report functions, print preview, export to PDF and more. Complete source code is included, subject to the GNU LGPL.
Download link:-












Wednesday, November 11, 2009

Java Tools


Java Tools:
              1.0 JProfiler 6.0:
JProfiler is an award-winning all-in-one Java profiler. JProfiler's intuitive GUI helps you find performance bottlenecks, pin down memory leaks and resolve threading issues.
                                                This release adds
  • Current locking and locking history graphs
  • Thread dumps view
  • Method statistics view
  • Exceptional method runs: Analyze the slowest executions of selected methods in detail
  • "Tree map" view mode in all call tree views and the biggest objects view of the heap walker
  • Auto-tuning for dynamic instrumentation: Methods with disproportional overhead will be suggested for a list of ignored methods
  • Simplified manual configuration of profiling with a single -agentpath VM parameter for Java 5+
  • Changing profiling settings without restarting the profiled JVM for Java 6+
  • Loading snapshots from IDE integrations
  • Support for FreeBSD x86 and Linux PPC
Download Link:-
                             http://www.ej-technologies.com/download/jprofiler/trial

     2.0 install4j 4.2    
                                     Install4j is a cross platform Java installer that produces native launchers and installers for all major platforms. Install4j offers an intuitive GUI that makes it easy to quickly define installation projects. A command line compiler and integration for Apache ANT are included.               



             This release adds
  • Support for including other .vmoptions files
  • Improved persistence of installer variables
  • Support for loading response files in the installer
  • Improved proxy handling and server side authentication
  • Console access for Windows GUI launchers
  • Visual progress for unattended execution
Download Link:-
                        http://download.cnet.com/install4j/3000-2069_4-10208786.html
                     http://www.ej-technologies.com/products/install4j/overview.html
See also…
                     Install Anywhere.
                     Launch4j.
                   3.0 exe4j
                                   Exe4j creates Windows executables that invoke your Java applications and integrates them into the Windows environment

       New features:
  • Added option in Executable info->Redirection step of the wizard to append output to existing redirection files
  • Command line argument -x / --require-license for exe4j command line compiler and attribute 'requirelicense' of exe4j ant task to avoid producing evaluation executables
  • Service launchers: Added the option non-interactive after /install to register services that should not allowed to interact with the desktop.
      Bugs fixed:
  • A listener registered with com.exe4j.Controller#registerStartupListener was not called reliably for a rapid succession of invocations
  • Added a workaround for an undefined TMP environment variable.
Download Link:-
4.0  Jclasslib
Jclasslib byte code viewer is a tool that visualizes all aspects of compiled Java class files and the contained bytecode. In addition, it contains a library that enables developers to read, modify and write Java class files and bytecode.
A module for NetBeans is available from nbextras.org. To download the module from within Netbeans, you can configure nbextras.org as an update center.
Jclasslib for Java is released under the GPL.
          5.0 JForm Designer
                                                JFormDesigner makes Swing GUI design a real pleasure. It decreases the time you spend on hand coding forms, giving you more time to focus on the real tasks. You'll find that JFormDesigner quickly pays back its cost in improved GUI quality and increased developer productivity

            Download:-
                                    http://www.formdev.com/



Tuesday, November 10, 2009

JNBridge Between Java and .NET

JNBridge, a company that makes tools to bridge Java and .NET applications, has announced new editions of its software that makes distributed transactions interoperable.

     Microsoft officials said the move makes it easier for its developer customers to work with a host of tools, not just those made by Redmond. Among the environments supported by Teamprise are Unix, the Mac OS, Linux, and Eclipse.

   It'll be interesting to see how much traffic heads in each direction.
No price was set on the purchase, but at least it gave Microsoft the chance to bang on about interoperability.

For more...
    http://www.sdtimes.com/link/33895           http://www.theregister.co.uk/2009/11/09/microsoft_teamprise/
   

Sunday, November 8, 2009

Java API

Below url gives online java specifications.
http://java.sun.com/j2se/1.5.0/docs/api/index.html
JDocs
JDocs is a collection of online javadocs for many popular packages. Includes search and user contributed notes.
It contains lot of features which will be integrated with most popular java IDEs like NetBeans,Eclipse,Intellij,Xpolog.

Difference Between Interface And Abstract Class

Difference between interface and abstract class.

1.Abstract classes can have implementations for some of its
members (Methods), but the inteface class can't have
implementation for any of its members.

2.Abstract class defines few or none of the methods, but
interface defines all the methods.

3 Abstract classes should have subclasses else that will
be useless.

4.Interfaces must have implementations by other classes else
that will be useless.

5.Only an interface can extend another interface, but any
class can extend an abstract class.

6.All variable in interfaces are final by default.

7.Accessibility modifier(Public/Private/internal) is
allowed for abstract class.Interface doesn't allow accessibility modifier







Export & Import Oracle 10g Tables Using Shell Scripts

#!/usr/bin/bash
Export Table:-
export ORACLE_SID=SNM
export ORACLE_HOME=/opt/app/oracle/product/10.2.0
#su – oracle -c /opt/app/oracle/product/10.2.0/bin/sqlplus ‘/ as sysdba’
echo ‘Enter UserName for DBConnection’
read userName
echo ‘Enter Password for DBConnection’
read password
echo ‘Enter the Export file Name’
read filename
su – oracle -c “
export ORACLE_SID=SNM
#create spfile from pfile
sqlplus / as sysdba <<- EOF
 CREATE OR REPLACE DIRECTORY test_dir AS ‘/tmp’;
 GRANT READ, WRITE ON DIRECTORY test_dir TO $userName;
 disconnect
exit

EOF

su – oracle -c “
export ORACLE_SID=SNM
export ORACLE_HOME=/opt/app/oracle/product/10.2.0
/opt/app/oracle/product/10.2.0/bin/expdp $userName/$password tables=table1,table2 directory=test_dir dumpfile=$filename.dmp logfile=expdpbackup.log

Import Table:-
#!/usr/bin/bash
export ORACLE_SID=SNM
export ORACLE_HOME=/opt/app/oracle/product/10.2.0
#su – oracle -c /opt/app/oracle/product/10.2.0/bin/sqlplus ‘/ as sysdba’
echo ‘Enter UserName for DBConnection’
read userName
echo ‘Enter Password for DBConnection’
read password
echo ‘Enter the Import file Name(File which has been exported earlier)’
read filename
fslash=’/’
snm=’@snm’
#/opt/app/oracle/product/10.2.0/bin/sqlplus omc_omc111/omc_omc111@snm <
#echo ${userName}${fslash}${password}${snm}
/opt/app/oracle/product/10.2.0/bin/sqlplus ${userName}${fslash}${password}${snm} <
spool /alcatel/databasedump.txt
drop table table1;
drop table table2;
commit ;
spool off;
disconnect
exit
EOF
su – oracle -c “
export ORACLE_SID=SNM
export ORACLE_HOME=/opt/app/oracle/product/10.2.0
/opt/app/oracle/product/10.2.0/bin/impdp $userName/$password tables=table1,table2 directory=test_dir dumpfile=$filename.dmp logfile=expdpbackup.log
disconnect
exit


Java - Out of Memory Exception


The out of memory issue shall be because of the following reasons.

  •          It can happen, particularly if your application involves a large amount of data processing, or is long lived – such as a server that responds to requests and is expected to run indefinitely
  •          The virtual machine  Java program is running on may have a limit to the amount of memory it will give access to, the system on which  program is running may have run out of physical and virtual memory
  •          Too many threads running
  •      An abnormal execution condition was synchronously detected by a Java Virtual Machine
Solutions for OutofMemoryException:-
1.Application redesign will give more effect.
2.Code codewise any memory leak is there i mean any of the collection classes creating 
number of times,reading huge records from database,unused objects cleanup.
3.Try to avoid collection classes like Vector,HashSet….

http://www.javacommerce.com/displaypage.jsp?name=java_performance.sql&id=18264 



Following also useful in some conditions. 
Code cleanup  using IntelliJIDEA tool.


1. Field Variable converted to local variables.

2. Removed Manual Array to collection copy (inside for loop)

3. Reduntant String.toString()

4. Reduntant string Constructor call

5. Replaced StringBuffer with StringBuilder

6.
equals (“”)
replaced with length()==0

7. Removed Filling Array inside the loop

8. Remove unused variables and Imports

9. Remove Unneccessary toString() conversion

10.Remove creating String object while adding into a ArrayList

Bookmark and Share
Hihera.com
Increase Page Rank Google
TopBlogDir.blogspot.com button
Best Indian websites ranking
Tips for New Bloggers
TopOfBlogs
The Link Exchange - Your ultimate resource for link exchange!

About This Blog

TopOfBlogs

FEEDJIT Live Traffic Feed

  © Blogger template Webnolia by Ourblogtemplates.com 2009

Back to TOP