RSS

Why Server Side Programming?

Server side programming is done to run the application on server from where all possible clients can access it whereas client side programming is done to run the application on client computers. Using Server Side Programming it is possible to make dynamic websites. Today we see a number of web-applications which are made using server side programming. This includes Google, Yahoo, Facebook and Wikipedia etc. Though there are hundreds of advantages of server side programming over client side, we will discuss here the most important of them.

Security: Server Side Applications are far better secure as compared to Client side applications. For eg: if a user is sending some sensitive information then the data is encrypted during transmission and decrypted at server side. Moreover all the code is on the server which is not accessible to any user. But in client side applications a user can decompile the application code to see the logic and security measures to use them for his benefit.

Maintainability: As all the code is on single machine it is easier to update or make any changes to the application whereas in Client Side Applications we have to update all the applications on each client machine. This saves a lot of cost and effort.

Browser Compatibility: In client side applications you have to make a different version for each type of OS. There are some platforms in market which provides the OS independence but then they also need an Interpreter which is OS specific. As the Server Side applications runs on server and browser is used for the data interchange there are no efforts applied to make it compatible. Moreover Ajax is a better technology that uses both client-side and server-side scripting. It can call a database without even refreshing the page at browser. The request made is transparent to the user since a new call to the server is done in the running window.

The most common scripting languages used to create server side applications are ASP.NET, Java Servlets, JSP, PHP and Ruby on Rails. There are various factors on which the choice of language used to develop application depends. With the advent of Cloud Computing the server side applications have grown faster.

Advertisements
 
Leave a comment

Posted by on July 5, 2010 in Programming

 

Spring Dependency Injection

Spring DI is the most fundamental feature that it provides. This feature has also been referred as Inversion of Control but after many discussions it was decided that DI is a better term.

Any application which is of practical use is composed of two or more Objects which communicate or use each other.  Traditionally each of those objects is responsible to get the reference of objects it uses but in DI objects are given references to the other objects when needed. All the bean creation and their injection are handled by Spring which acts as a container of beans. This provides loose coupling and also promotes programming to an Interface as the bean knows only about the type of bean but nothing about its implementation.

For Example: If the bean Store has declared Product property as an interface then the Product implementation becomes irrelevant.   The Product bean can be web-service implementation, an EJB or a mock test object.

Some other benefits of using DI:
• Reduction of boiler plate coding.
• As all metadata is in xml file and is easy to configure. This gives flexibility in testing and development.

 
Leave a comment

Posted by on July 5, 2010 in Java, Spring

 

Tags: ,

Java Example of Spring Dependency Injection

This tutorial uses the following:

    • Eclipse IDE
    • Spring Jars
    • commons-logging-api-1.1.jar
  1. Make a new Java Project in Eclipse.
  2. Add the following jars to its classpath:
    • commons-logging-api-1.1.jar
    • org.springframework.core-3.0.2.jar
    • org.springframework.beans-3.0.2.jar

The Spring jars can be taken from the dist folder of the expanded zip file. Here you have to include the two jars one for core and other for beans. Commons-logging is used for logging purpose.

  • Make a new class – Person.java. It is a 100% Java bean and has the proper getters and setters.
package com.spring.ioc.beans;

public class Person {

	private String name;

	private String address;

	/**
	 * @return the name
	 */
	public String getName() {
		return name;
	}

	/**
	 * @param name the name to set
	 */
	public void setName(String name) {
		this.name = name;
	}

	/**
	 * @return the address
	 */
	public String getAddress() {
		return address;
	}

	/**
	 * @param address the address to set
	 */
	public void setAddress(String address) {
		this.address = address;
	}

}

  • Make an XML file and name it context.xml and save it in the src folder.  This file contains all the meta information needed for bean creation. Here the bean id is person and class has the full qualified name of the class. The “name” property of the class Person is populated with the value Mac.

<?xml version="1.0" encoding="UTF-8"?>
xmlns="http://www.springframework.org/schema/beans"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
	xsi:schemaLocation="
       http://www.springframework.org/schema/beans
       http://www.springframework.org/schema/beans/spring-beans.xsd">
	<bean id="person" class="com.spring.ioc.beans.Person">
	<property name="name" value="Mac"></property>
	</bean>
</beans>

  • Make another class named Main.java.  Here an object of XmlBeanFactory loads the configurations from contect.xml file. Also its constructor takes an argument of ClassPathResource.
  • To get a bean from XmlBeanFactory object use its reference type to invoke the method getBean(<bean id>) and it will return the bean as defined in the spring context file.  The Object it returns is of type Object so you do have to cast it to the correct type.
package com.spring.ioc.main;

import org.springframework.beans.factory.xml.XmlBeanFactory;
import org.springframework.core.io.ClassPathResource;

import com.spring.ioc.beans.Person;

/**
 * @author hgupta
 *
 */
public class Main {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		XmlBeanFactory beanFactory = new XmlBeanFactory(new ClassPathResource(
				"context.xml"));
		Person person = (Person) beanFactory.getBean("person");
		System.out.println(person.getName());
	}

}

  • Run the Main class as Java Application and you will see the following output: The output is the name of the person which you configured in the xml file.

Output:

May 27, 2010 6:54:04 PM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions

INFO: Loading XML bean definitions from class path resource [context.xml]

Mac

 
Leave a comment

Posted by on July 5, 2010 in Java, Spring

 

Tags: ,

Spring Framework Architecture

Spring framework is layered in architecture which consist several modules. All its modules are built on the top of its core container. These modules provide everything that a developer may use in the enterprise application development. He is always free to choose what all features he needs and eliminate the modules which are of no use. Its modular architecture enables integration with other frameworks without much hassle.


The Core Module: It provides the Dependency Injection (DI) feature which is the basic concept of spring framework. This module contains the BeanFactory an implementation of Factory Pattern which creates the bean as per the configurations provided by the developer in an XML file.

AOP Module: Its Aspect Oriented Programming module allows developer to define method-interceptors and point cuts to keep the concerns apart. It is configured at run time so the compilation step is skipped. It aims at declarative transaction management which are easier to maintain.

DAO Module: This provides an abstraction layer to the low level task of creating a connection, releasing it etc. It also maintains a hierarchy of meaningful exception rather than throwing complicated error codes of specific database vendors. It uses AOP to manage transactions. Transactions can also be managed programmatically.

ORM Module: Spring doesn’t provides its own ORM implementation but offers integrations with popular Object Relational mapping tools like Hibernate, iBATIS SQL Maps, Oracle TopLink and JPA etc.

JEE Module: It also provides support for JMX, JCA, EJB and JMS etc. In lots of cases, JCA (Java EE Connection API) is much like JDBC, except where JDBC is focused on database JCA focus on connecting to legacy systems.

Web Module: Spring comes with MVC framework which eases the task of developing web applications. It also integrates well with the most popular MVC frameworks like Struts, Tapestry, JSF, Wicket etc.

 
Leave a comment

Posted by on July 5, 2010 in Java, Spring

 

Tags: , ,

IP Locator

Recently I started learning Flex and AIR and was amazed to know about their features and ease of programming. To start with I decided to develop a widget which can be independently used in any web page. After much effort I made it but it was sad to now that flex applications need a policy file at the data server to communicate. As the data was coming from some third party I was not possible to place the policy file there. To make use of the efforts I decided this application to port to AIR platform. Though it was an easy task but there were some problems in integrating Google Maps in it. Thanks to Google Map API for AIR because of that it was done easily.

Screenshot of the Application

This IP Locator which is developed using Flex Builder needs Adobe Integrated Runtime to run. You can enter the IP in the input box and Hit Go. It connects to the internet to fetch the details of the IP given. It fetches the details in XML format. After parsing the XML response the view is updated.
Google Maps are located using longitude and latitude fetched. You should also be aware that it is not a commercial application and so there is no guarantee of the accuracy of data because the information is coming from some third server which is not maintained by us.

 
2 Comments

Posted by on May 21, 2010 in AIR

 

Tags: , , ,

Introducing ANT

ANT is an acronym for Another Neat Tool

It is a build tool. It is used to automate complicated repetitive tasks like setting classpath, compiling the code or packing the compiled files and many more things which you can ever imagine. ANT is developed in JAVA so it is platform independent. Ant accepts instructions in the form of XML documents thus is extensible and easy to maintain. You don’t need any special editor for writing ANT files a normal text editor is enough.

ANT Installation:

If you are using some IDE like Eclipse then there is no need to download anything as most of the IDE come with ANT libraries.

If you are not using any IDE and doing all in notepad and you need to do these things:
Steps to set path cmd if you are not using any IDE:

  1. Download the files from http://jakarta.apache.org/ant/index.html and unzip them to some directory.
    In our case we are naming the folder as ant.
  2. Append /path/to/ant/bin to the PATH environment variable.
  3. Append the .jar files in /path/to/ant/lib/ to the CLASSPATH environment variable. Set JAVA_HOME to point to the location of the JDK installation on the machine that the software is being installed on. Append /path/to/jdk/lib/* to the CLASSPATH environment variable.

ANT file(build.xml) format:

ANT file is an XML file. As ANT is mostly used for building the project we name it as build.xml.
Here you can see a snapshot of the build file. It is written to complie the code present in src folder.

This is the declaration of the XML file with its version. All files must start by this.

This project element has three attributes.
1. name: Here you will write the name of your project for which you are writing this file.
2. default: This is the default target to be executed by ant file.
3. basedir: This is the base directory(root folder) of your project. Here . means current directory. If this is omitted the parent directory of the build file will be used.

This explanation is for you. DO IT YOURSELF.

This element allows you to write your own variable with their values. You can define as many properties as you need. This is a name-value pair where you can access the value of a property by writing it in $ {&ltproprtyNmae>}.
NOTE: THERE IS NO SPACE BETWEEN $ AND { }.

This point has two elements.
1. Target: This element can be treated as a function which has a set of instructions to do. It has an attribute name which is used to call the target of the specified name.
2. mkdir: This element is used to make directries. It has an attribute dir which takes the name of the directory to be made.

This target compiles the code. Here the depends attribute specifies that this target depends on init to be performed.javac uses the system java compliler if you have not given the classpath explicitly. So to run this you should have all the JAVA_HOME and PATH variables set.
srcdir is the source directory in which all the source file(.java) are present and destdir is the folder into which all the complied files(.class) will be created.

Writing Build Files for compiling the project:

Here we will write an ant file which will perform a clean build of the project. Below you can see snapshot of the build.xml file. In this project we have all the source files in src folder and we have only one file HelloWorld.java to be complied.

<?xml version="1.0" encoding="UTF-8"?>

<!--  Project name Declaration -->
<project name="HelloWorld" basedir="." default="compile">

	<!-- Setting the property here -->
	<property name="bin" value="bin" />

	<!-- This target makes a fresh directory if not present -->
	<target name="init" depends="clean">
		<mkdir dir="${bin}" />
	</target>

	<!-- Delete the old directory with all its files -->
	<target name="clean">
		<delete dir="${bin}" />
	</target>

	<!-- Compiles the source files -->
	<target name="compile" depends="init">
		<javac srcdir="src" destdir="${bin}" />
	</target>
</project>

As the code is self Explanatory we will leave all the dicussed topics and will bring new important thing called dependency.
depends:
When a target declares depends attribute then that target is only executed after the execution of the target on which it depends.

    In this case the dependency goes like this

  1. Compile is the default target which the file calls.
  2. Compile target depends on init so init target starts executing.
  3. Now init also depends on clean so the target names clean will be executed before the execution of init.
  4. So first of all target clean is executed, then init and then compile is executed.

Note: You can write more than one names of target in depends attribute like depends=”clean,init” and the execution is from left to right. So first clean will be executed and then init will get executed.Be careful while declaring dependency.

Running an ANT file

If you are using IDE like eclipse you can simply right click and select Run As –> ANT Build

If your classpath and code is all correct then you will see the following text in your console

If Environment variables like PATH and JAVA_HOME is not set in your system than you will get an error as shown below.

So if you get this error message forst set all the variables and then restart the eclipse and run the ant file again.


Note: In ant the error messages are well explained so error can be identified easily. If you set the verbose mode by giving the argument -v then you will get detailed log in the console.

 
Leave a comment

Posted by on April 22, 2010 in ANT, Java

 

Tags: ,

What is SMTP?

In simplest form an SMTP server is a computer that receives outgoing mail messages from users and routes them to their intended recipients. All SMTP servers implement some version of the Simple Mail Transport Protocol.


Electronic mail server software uses SMTP to send and receive mail messages, user-level client mail applications typically only use SMTP for sending messages to a mail server for relaying. SMTP is a “push” protocol that cannot “pull” messages from a remote server on demand. To retrieve messages only on demand, which is the most common requirement on a single-user computer, a mail client must use POP3 or IMAP. Here we have described a series of actions which happens when you hit Send button

  • The request goes to mail server where it connects to its port 25. Then it sends some command for its communication and if evrything works fine then the message is posted in to the network.
  • Server maintains a mail queue: it will save the mail locally and send it together with all the other queued mail in intervals (for example, every 30 minutes). This behavior depends on the configuration and the server may also deliver the mail instantly.
  • To get the mail POP3 or some other protocol is used.

 
Leave a comment

Posted by on April 21, 2010 in Protocols

 

Tags: , ,