Dec 29, 2008

How to install and run PHP 5 with Apache 1.x on Windows

Step 1 : Download PHP 5 from following link
PHP 5 Download

Step 2: Download Apache 1.3.x from following link
Apache 1.3.x Download

Step 3 : Install Apache 1.3.x download by running the msi file.

Step 4: On Server Information screen enter the following information
  1. Network Domain : localhost
  2. Server Name : localhost
  3. Administrator Email Address : abc@abc.com
  4. Select for All Users, on Port 80 radio button




Step 5 : Select Typical radio button and click next to install Apache Http Server.

Step 6 : Install PHP by clicking on the php msi installer

Step 7 : Select Apache 1.3.x Module as radio button option





Step 8 : Specify the location of the PHP installation.

Basic installation is done by following steps from 1 to 8. Now Apache needs to be configured for using PHP 5.

Step 1 : Open httpd configuration file which can be found at
\\Apache Software Foundation\Apache\conf

Step 2 : Enter the following LoadModule statement after series of LoadModule statement as shown below

LoadModule php5_module "c:/php/php5apache.dll"





Step 3 : Enter the following AddType statement after series of AddType statements as shown below

AddType application/x-httpd-php .php
AddType application/x-httpd-php .phtml





Step 4 : Enter the following ScriptAlias after ScriptAlias statement as shown below
ScriptAlias /php/ "c:/PHP/"





Step 5 : Test PHP configuration

Create PHP file as follows

test.php


Place this file under \\Apache Software Foundation\Apache\htdocs directory.

Start the Apache server and place http://localhost/test.php in browser.

If screen with php info is displayed then it mean that configuration is successful else there is something wrong somewhere.

Dec 26, 2008

Book Review : Jasper Report for Java Developers

I just finished reading Jasper Report for Java Developer written by David R. Heffelfinger and published by PACKT publishing and here is my review on the book.

The book is really a good read as far as I am concerned. I had never worked on the Jasper Reports earlier, so I can say that its a very good book for beginners . If you are a java developer and want to learn working on Jasper Reports fast I would recommend this as a first book about Jasper Reports.

For those who have never worked on java I would not recommend this as the first book as it requires some basic java understanding.

The book is divided into 11 chapters.

Chapter 1 and 2 are introductory chapter describing history of Jasper Report in general and what Jasper Report is all about. It also describes the environment setup required for using Jasper Reports.

Chapter 3 is the actually where you create your first report. It also provides some of the basics of Jasper Reporting.

Chapter 4 and 5 deals with generating reports by embedding sql queries in report and using different data sources like databases, XML, Java objects etc.

Chapter 6 is an important chapter of the book as provide knowledge about maintaining report layout and design. Sub reporting details are also provided in this chapter.

Chapter 7 and 8 details out step required for adding Chart and other graphic features to the report.

Chapter 9 is totally dedicated to export formats that are supported by Jasper Reports.

Chapter 10 describe how to create reports using IReport designer. IReport makes the designing of the report very easy and simpler. In earlier chapter whatever has been mentioned related to layout and designing of report are done by writing code in JRXML file of report, but using IReport designer its just drag and drop. Although its always good to know how its reflected at the actual jrxml file and how to create reports if designer is not available.

Chapter 11 is all about integrating of Jasper Report with other frameworks like Struts and Spring. These have been explained with simple example.

In the end I would like to recommend this book to all developers who want to learn or use Jasper Report. This book is written in easy to understand language with simple example which can be used for getting hands-on.

Book can be purchased from Packt publishing

Dec 16, 2008

Identifiers in Java

Some points about Identifiers
  1. A name in a program is called an identifier.
  2. An identifier is sequence of characters which can be a letter, digit, connecting characters (Underscore _) or a currency symbol ($, ¢, ¥ or £).
  3. Identifier cannot start with a digit, after first character digits are allowed.
  4. Identifiers in java are case sensitive i.e. test and Test are two different Identifiers.
  5. Identifier can be of any length
  6. Keywords cannot be used as an Identifier.

Illegal Identifier

  1. 45abcd – Starting with a digit
  2. abcd@efgh – @ is not allowed
  3. new – Keyword not allowed

Legal Identifier

  1. $$ – $ is allowed
  2. Ab88cd – Digits are allowed after first character.
  3. Abc_88 – Underscore is a valid connecting character.

Important Point about hash code

Important points about hash code
  1. Hash code is used for increasing the performance of large collection of data.
  2. Hash code is not always unique.
  3. Hash code only tell about the bucket to go into, but not how to locate the name once we are in that bucket.
  4. Collection use the hash code value of the object to decide in which bucket / slot the object should land.
  5. If two objects have same hash code value then it is not necessary that they are equal.
  6. Hashing is a two step process firstly search the right bucket using the hash code value, then search for the element in the bucket using equals()

equals() and ==

== operator evaluates to true, only when both references refer to the same object
e.g reference a------------> Object1
reference b------------> Object1
then a == b returns true.

  1. String class and Wrapper classes has override equals() method , so that two different objects could be compared to see if their contents are meaningfully equal.
  2. If classes equals() method is not overridden then it cannot be used as key in a Hashtable.
  3. equals() method in Object Class use only the == operator for comparison.
  4. If two objects are considered equal by using the equals() method then they should have identical hashcode values. So it is advisable to override hashCode() when equals() is overridden.

Dec 15, 2008

Basics of Java

Complexity can be handled by abstraction. In OOPS abstraction is modeled using Classes and objects.
A Class models abstraction by defining properties and behavior of an object.
Properties of an object are defined by the attributes, which are fields in java. A field in java is a variable that can hold value.
Behavior of an object is defined by the methods in java.

Object is an instance of the class. In java objects can only be manipulated using references.
Each Object created maintains its own copy of instance variables. Two objects can have same state if the values of their instance variable are same.
Object communicates with each other using message passing.

Static members/methods
  1. Certain members belong to Class only not to object these are called static members.
  2. A static member is initialized when the class is loaded at runtime.
  3. Certain methods that belong to the Class only and not to an object are called static methods.
  4. Client can access static methods using the class name.
  5. Static members of the Class can be accessed either using Object reference or using Class name.
Example of Class & Object
package Test;
//Class declaration
public class Example_Class {
//Attribute declaration - These variables defines the state of the object
private int first_attribute;
private int second_attribute;
//constructor
public Example_Class(int x, int y) {
//Initializing attributes of newly created object.
this.first_attribute = x;
this.second_attribute =y;
}
//Method - These methods define the behavior of the object
public int addResult() {
return first_attribute + second_attribute;
}
//Main method of Class
public static void main(String[] args) {
/* Object instantiation - Object is created using "new" keyword With new keyword Constructor of the class is called which returns the reference of the newly created object, which is assigned to
reference variable of appropriate Class.
*/
// objFirst ---------> Object1(1,2)
Example_Class objFirst = new Example_Class(1, 2);
//Both objFirst and objSecond object refernces will point to two different objects in heap
// objSecond ---------> Object2(1,2)

Example_Class objSecond = new Example_Class(1, 2);
int addResultFirst = objFirst.addResult();
System.out.println("Add Result First:" + addResultFirst);
//Calling method on second created Object
int addResultSecond = objSecond.addResult();
System.out.println("Add Result Second:" + addResultSecond);
}
}