Wednesday, October 21, 2009

Struts

Struts  Framework was developed by Craig McLanahan in 2002 and subsequently handed over to Apache Jakarta project group.

Struts Frame work is the implementation of Model-View-Controller (MVC) design pattern for the JSP. Struts is maintained as a part of Apache Jakarta project and is open source. Struts Framework is suited for the application of any size. Latest version of struts can be downloaded from http://jakarta.apache.org/.


Before going to struts lets look what is Framework?
A software framework, in computer programming, is an abstraction in which common code providing generic functionality can be selectively overridden or specialized by user code providing specific functionality.  

Frameworks are similar to software libraries in that they are reusable abstractions of code wrapped in a well-defined API.

Struts is based on MVC Architecture ,Lets discuss about MVC

Model-View-Controller architecture is all about dividing application components into three different categories Model, View and the Controller.The main aim of the MVC architecture  is to separate the business logic and application data from the presentation data to the user. Components of the MVC architecture has unique responsibility and each component is independent of the other component. Changes in one component will have no or less impact on other component. Responsibilities of the components are:

Model: Model is responsible for providing the data from the database and saving the data into the data store. All the business logic are implemented in the Model. Data entered by the user through View are check in the model before saving into the database. Data access, Data validation and the data saving logic are part of Model.

View: View represents the user view of the application and is responsible for taking the input from the user, dispatching the request to the controller and then receiving response from the controller and displaying the result to the user. HTML, JSPs, Custom Tag Libraries and Resources files are the part of view component.

Controller: Controller is intermediary between Model and View. Controller is responsible for receiving the request from client. Once request is received from client it executes the appropriate business logic from the Model and then produce the output to the user using the View component. ActionServlet, Action, ActionForm and struts-config.xml are the part of Controller.  







Thursday, October 15, 2009

What is BIOS?

A BIOS (Basic Input/Output System) is an electronic set of instructions that a computer uses to successfully start operating. The BIOS is located on a chip inside of the computer and is designed in a way that protects it from disk failure.
BIOS or Basic Input/Output System is the first program accessed by the processor during start up to ensure that all the other basic programs, hard drives, ports, peripherals and the central processing unit are in good working condition. BIOS is different from the computer's operating system. The operating system resides in the hard drive and provides the user interface that can be seen on the screen after start up. The BIOS program, on the other hand, can be found right in a flash memory chip or ROM located in the motherboard. It is the basic requirement for booting a computer.
        BIOS has several functions in a computer but its most important task is to load the operating system. BIOS provides the microprocessor its first instructions upon activating the computer.

Wednesday, October 14, 2009

Operatin System Concepts




The most important program that runs on a computer. Every general-purpose computer must have an operating system to run other programs. Operating systems perform basic tasks, such as recognizing input from the keyboard, sending output to the display screen, keeping track of files and directories on the disk, and controlling peripheral devices such as disk drives and printers.
For large systems, the operating system has even greater responsibilities and powers. It is like a traffic cop -- it makes sure that different programs and users running at the same time do not interfere with each other. The operating system is also responsible for security, ensuring that unauthorized users do not access the system.
Operating systems can be classified as follows:

  • multi-user : Allows two or more users to run programs at the same time. Some operating systems permit hundreds or even thousands of concurrent users. 

  • multiprocessing : Supports running a program on more than one CPU.

  • multitasking : Allows more than one program to run concurrently.

  • multithreading : Allows different parts of a single program to run concurrently.

  • real time: Responds to input instantly. General-purpose operating systems, such as DOS and UNIX, are not real-time.

  • Operating systems provide a software platform on top of which other programs, called application programs, can run. The application programs must be written to run on top of a particular operating system. Your choice of operating system, therefore, determines to a great extent the applications you can run. For PCs, the most popular operating systems are DOS, OS/2, and Windows, but others are available, such as Linux.
    As a user, you normally interact with the operating system through a set of commands. For example, the DOS operating system contains commands such as COPY and RENAME for copying files and changing the names of files, respectively. The commands are accepted and executed by a part of the operating system called the command processor or command line interpreter. Graphical user interfaces allow you to enter commands by pointing and clicking at objects that appear on the screen.

    3 Things which Microsoft can never explain

     
        MAGIC #1
           An Indian found that nobody can create a FOLDER anywhere on the Computerr
          which can be named as "CON". This is something funny and inexplicable.
          TRY IT NOW, IT WILL NOT CREATE A "CON" FOLDER
         
       MAGIC #2
          For those of you using Windows, do the following:
          1....) Open an empty notepad file
          2.) Type "Bush hid the facts" (without the quotes)
          3.) Save it as whatever you want.
          4.) Close it, and re-open it.
          Noticed the weird bug? No one can explain!
         
      MAGIC #3
          Again this is something funny and can't be explained.
          It was discovered by a Brazilian. Try it out yourself.
          Open Microsoft Word and type
          =rand (200, 99)
          And then press ENTER
          And see the magic.

    Monday, October 12, 2009

    What is a Kernal?

    The kernel is the central part of an operating system, that directly controls the computer hardware. Usually, the kernel is the first of the user-installed software on a computer, booting directly after the BIOS. Operating system kernels are specific to the hardware on which they are running, thus most operating systems are distributed with different kernel options that are configured when the system is installed. Changing major hardware components such as the motherboard, processor, or memory, often requires a kernel update. Additionally, often new kernels are offered that improve system security or performance. The two major types of kernels competing in today's computer markets are the Windows kernel and the unix-like kernels.
    The Windows kernel is available only with the Microsoft Windows series of operating systems. It is proprietary software, developed and distributed by Microsoft Corporation. Introduced in Windows/386, it's many incarnations have since gone by several different names, and some had no names at all. The latest version of the Windows kernel was introduced in Windows NT, and has had many of it's functions removed and placed in user-mode software for Windows Vista. This leads to increased system stability and security. In Vista, application-level software exploits have much less access to the core functions of the operating system, and application crashes will not bring down the OS.

    Unix-like kernels are a family of operating system kernels that are based upon, or operate similar to, the original Bell Labs UNIX operating system. Common examples of unix-like kernels are the Linux kernel, BSD, Mac OS, and Solaris. While many of these kernels were developed with original Bell Labs code as part of the software, not all of them have direct lineage to Bell. Linux, for instance, was developed as a free alternative to Minix, itself an independently developed variation of UNIX. Although originally running an original kernel design, Mac OS was outfitted with a unix-like kernel in 1988 with the introduction of A/UX. All subsequent Apple operating systems have unix-like kernels, including the current Mac OS-X's BSD-derived kernel.

    JASPER REPORT

    Generating reports is a common, if not always glamorous, task for programmers. In the past, report generation has largely been the domain of large commercial products such as Crystal Reports. Today, the open source JasperReports report generating library gives Java developers a viable alternative to commercial software.

    The open source JasperReports uses XML templates for your reporting needs

    JasperReports provides the necessary features to generate dynamic reports, including data retrieval using JDBC (Java Database Connectivity), as well as support for parameters, expressions, variables, and groups.

    Note: The documentation and code featured in this article are based on JasperReports version 0.3.3.


    Architecture

    As shown in the above figure JasperReports architecture is based on declarative XML files which by convention have an extension of jrxml that contains the report layout. A lot of third-party design tools were produced to generate your jrxml file in a smooth way (like iReport or JasperAssistant) Design file is supposed to be filled by report's result which is fetched from database, XML files, Java collection, Comma-separated values or Models. Jasper can communicate with those data-sources and more, it can merge any number of data-sources together and manipulates the results of any combinations. This communication goes through JDBC, JNDI, XQuery, EJBQL, Hibernate or existing Oracle PL/SQL. You also can define your own data-source class and pass it to jasper engine directly. After defining your report design layout in jrxml format and determining your data source(s) jasper engine does the rest of work. It compiles your design file and fills it with results fetched from data-source and generates your report to the chosen exporting format (PDF, Excel, HTML, XML, RTF, TXT …, etc.)


    Report Definition file structure (jrxml):

    Jasper design file –jrxml- contains the following elements:
    • - the root element.
    • - its contents are printed at the beginning of every page in the report.
    • - contains the body of the report, repeated by n number of results
    • - its contents are printed at the bottom of every page in the report.
    • - defines a report section, all of the above elements contain a band element as its only child element.

    Only the root element is mandatory, the rest of elements are optional.


    Environment

    To set up working environment we need to download JasperReport jar file from the following URL: http://sourceforge.net/project/showfiles.php?group_id=36382&package_id=28579
    And add the following jars to your project classpath:
    • jasperreports-2.0.4.jar
    • commons-digester-1.7.jar
    • commons-collections-2.1.jar (commons-collections.jar)
    • commons-logging-1.0.2.jar
    • commons-beanutils.jar
    • iText-2.0.7.jar (used infor PDF exporting

    Sample Application

    At this section we'll introduce a sample application that generates PDF, HTML and Excel files contain the results of our report which is built over Oracle database contains the following table:
    ITEM

    ITEM_ID ---- NUMBER(5) --- NOT NULL
    CATEOGRY_ID ---- NUMBER(5) --- NOT NULL
    ITEM_NAME ---- VARCHAR2(50) --- NOT NULL
    ITEM_DESCIPTION ---- VARCHAR2(200)

    ITEM_AMOUNT ---- NUMBER(5) ---- NOT NULL

    Result: Report should retrieve the items with amount less than or equal 100 item.

    We're going to divide the work into two steps:

    1. Generate the report design (jrxml file).
    2. Implement application that assigns data source, compiles jrxml file and exports result in the chosen format.


    Designing The Report

    First we create new text file and rename it to sample_report.jrxml, this file should contain the following XML tags.

    01.
    02."//JasperReports//DTD Report Design//EN"
    04.
    05.<jasperReport name="sample_report" >
    06.<queryString>
    07.
    09.queryString>
    10.<field name="ITEM_NAME" class="java.lang.String"/>
    11.<field name="ITEM_AMOUNT" class="java.math.BigDecimal"/>
    12.<columnHeader>
    13.<band height="28" isSplitAllowed="true">
    14.<staticText>
    15.<reportElement x="40" y="11" width="193" height="15" key="staticText-1"/>
    16.<text>
    17.
    18.text>
    19.staticText>
    20.<staticText>
    21.<reportElement x="330" y="11" width="193" height="15" key="staticText-2"/>
    22.<text>
    23.
    24.text>
    25.staticText>
    26.band>
    27.columnHeader>
    28.
    29.<detail>
    30.<band height="27" isSplitAllowed="true">
    31.<textField>
    32.<reportElement x="47" y="6" width="173"
    33.height="18" key="textField"/>
    34.<textFieldExpression class="java.lang.String">
    35.
    36.textFieldExpression>
    37.textField>
    38.<textField >
    39.<reportElement x="330" y="6" width="100"
    40.height="18" key="textField"/>
    41.<textFieldExpression class="java.math.BigDecimal">
    42.
    43.textFieldExpression>
    44.textField>
    45.band>
    46.detail>
    47.jasperReport>

    The above XML file consists of the following main sections that defining report behavior and layout:

    • : contains the SQL statement which retrieves the report result.
    • : defines the resulted fields from the query, and give them name to reuse them into the report body [they are case-sensitive].
    • : contains the header titles "Item Name" in tag format.
    • : defines the appearance of result field.
    • $F{ITEM_NAME}: is a variable contains the value of Query result predefined field in the tag .

    Once we finished the report design file, save it in C:\ directory.

    Implementing The Report Service:

    - Create a new java project.
    - Import the jars listed in environment section to your project libraries.
    - Create new class and import the following packages

    01.import java.sql.Connection;
    02.import java.sql.DriverManager;
    03.import java.sql.SQLException;
    04.import java.util.HashMap;
    05.
    06.import net.sf.jasperreports.engine.JRException;
    07.import net.sf.jasperreports.engine.JRExporterParameter;
    08.import net.sf.jasperreports.engine.JasperCompileManager;
    09.import net.sf.jasperreports.engine.JasperExportManager;
    10.import net.sf.jasperreports.engine.JasperFillManager;
    11.import net.sf.jasperreports.engine.JasperPrint;
    12.import net.sf.jasperreports.engine.JasperReport;
    13.import net.sf.jasperreports.engine.export.JRXlsExporter;


    - Define the data source, in my case it's an oracle connection and established by JDBC as following:

    01.public static Connection establishConnection()
    02.{
    03.Connection connection = null;
    04.try
    05.{
    06.Class.forName("oracle.jdbc.driver.OracleDriver");
    07.String oracleURL = "jdbc:oracle:thin:@localhost:1521:mySID";
    08.connection = DriverManager.getConnection(oracleURL,"username","password");
    09.connection.setAutoCommit(false);
    10.}
    11.catch(SQLException exception)
    12.{
    13.exception.printStackTrace();
    14.}
    15.return connection;
    16.
    17.}

    Finally, the core code for compiling, filling and exporting the results in the following sequence:

    - Define jasper objects that will hold report template, compiled files, and result files.

    1./* JasperReport is the object
    2.that holds our compiled jrxml file */
    3.JasperReport jasperReport;
    4.
    5.
    6./* JasperPrint is the object contains
    7.report after result filling process */
    8.JasperPrint jasperPrint;

    - Create a connection to my data-source; initialize the report parameter into empty HashMap then compile our jrxml file into JasperReport object and finally fill the JasperPrint object by data from data-source connection.

    01.// connection is the data source we used to fetch the data from
    02.Connection connection = establishConnection();
    03.// jasperParameter is a Hashmap contains the parameters
    04.// passed from application to the jrxml layout
    05.HashMap jasperParameter = new HashMap();
    06.
    07.// jrxml compiling process
    08.jasperReport = JasperCompileManager.compileReport
    10.
    11.// filling report with data from data source
    12.
    13.jasperPrint = JasperFillManager.fillReport(jasperReport,jasperParameter, connection);

    - Last segment of code is responsible for exporting the result files into different formats

    01.// exporting process
    02.// 1- export to PDF
    03.JasperExportManager.exportReportToPdfFile(jasperPrint, "C://sample_report.pdf");
    04.
    05.// 2- export to HTML
    06.JasperExportManager.exportReportToHtmlFile(jasperPrint, "C://sample_report.html" );
    07.
    08.// 3- export to Excel sheet
    09.JRXlsExporter exporter = new JRXlsExporter();
    10.exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);
    11.exporter.setParameter(JRExporterParameter.OUTPUT_FILE_NAME, "C://simple_report.xls" );
    12.
    13.exporter.exportReport();

    You have just managed to generate your first jasper report in 3 different file formats at C:\\ directory (shown in the image below):

    - sample_report.html
    - sample_report.pdf
    - sample_report.xls


    Here we reach the end of today's article, next article we will cover the following points:
    1- Using design tool (iReport) to generate robust and smooth jrxml file.
    2- Create run-time search criteria and pass them to report.

    Note: this Article was first published in FCI-H Blog, here

    References:
    http://www.jasperforge.org/jaspersoft/opensource/business_intelligence/jasperreports/index.html
    http://en.wikipedia.org/wiki/Jaspersoft
    http://www.javaworld.com/javaworld/jw-09-2002/jw-0920-opensourceprofile.html