Tuesday, October 9, 2012

Java Random number generation of 4 digits

import java.util.Random;System.out.println("***** Generating Random Number of 4 digit *****");Random random = new Random();for(int i=0;i<100;i++){    long fraction = (long)(1000 * random.nextDouble());    int PIN= (int)(fraction + 1000);    System.out.println(PIN); ...

Struts2 why more powerful than Struts1. Struts2 Vs Struts1 . Compare between Struts1 and Struts2

STRUTS2 = STRUTS1 + Interceptor (=XWork) + OGNL - FormBean1. Easy web.xmlSTRUTS1:<servlet><servlet-name>action</servlet-name><servlet-class>org.apache.struts.action.ActionServlet</servlet-class><init-param>   <param-name>config</param-name>   <param-value>/WEB-INF/struts-config.xml</param-value></init-param><load-on-startup>2</load-on-startup></servlet><servlet-mapping><servlet-name>action</servlet-name><url-pattern>*.do</url-pattern></servlet-mapping>STRUTS2:<filter><filter-name>webwork</filter-name><filter-class>  ...

First Example on Struts2, Struts2 Tutorial, Struts2 Easy Example

First Example on Struts2:1. Create one Dynamic Project in Eclipse Say Struts22. Put all these below jar file inside WEB-INF\lib folderstruts2-core-2.0.6.jarxwork-2.0.1.jarcommons-logging-1.1.jarfreemarker-2.3.8.jarognl-2.6.11.jar3. Change your web.xml (WEB-INF\web.xml) file as below:web.xml<?xml version="1.0" encoding="UTF-8"?><web-app id="WebApp_ID" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"><display-name>Struts2...

Struts2 example with Annotation. Struts 2 with annotation. First Struts 2 with annotation.

1. Create one Dynamic Project in Eclipse Say StrutsAnno2. Put all these below jar file inside WEB-INF\lib folderstruts2-core-2.1.6.jarxwork-2.1.2.jarcommons-logging-1.1.jarfreemarker-2.3.8.jarognl-2.6.11.jarstruts2-convention-plugin-2.1.6.jar3. Change your web.xml (WEB-INF\web.xml) file as below:<?xml version="1.0" encoding="UTF-8"?><web-app id="WebApp_ID" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"><display-name>Struts2...

Simple Ajax with JQuery

 First I will write code with native Ajax then will write same code using Ajax.The code below for add two number. There will be two text box on jps page and user has to enter first number and click on Add button then it will add first text box and second box number and will be showed to second text box. One clear button is also there to clear both text boxes.Back side (Server side) will be came in both ways.Pure (Native) Ajax:var request;function getRequest(){      if(window.ActiveXObject){       ...

AJAX Using DOJO Tutorial

It is very simple to develope Ajax application with DOJO. There is no any need to useActiveXObject or XMLHttpRequest. Here I am going to show a very simple application.1. Create one dynamic web project using your Eclipse IDE. (Say Project Name : Ajax_Dojo)2. Write one servlet in that project (Say AdmissionEnquiry.java)3. Write one jsp page inside WebContent (Say example1.jsp)4. Copy dojo.js inside WebContent5. Add any server like Apache or Jboss to your project6. Run the application http://localhost:8080/Ajax_Dojo/example1.jspAdmissionEnquiry.javaimport...

Easy explanation for Strategy design pattern using simple arithmetic calcuation

Strategy Design Pattern:Detail : http://en.wikipedia.org/wiki/Strategy_patternUse strategy when you need to define a family of algorithms, encapsulate each one, and make theminterchangeable. Strategy lets the algorithm vary independently from clients that use it.Strategy pattern are algorithms inside a class which can be interchanged depending on the class used.This pattern is useful when you want to decide on run time which algorithm to be used.Calculation.javapublic interface Calculation {int execute(int a, int b);}AddCalc.javapublic class AddCalc...

Command Design Pattern using simple example

Command Design Pattern:Detail : http://en.wikipedia.org/wiki/Command_patternUse strategy when you need to define a family of algorithms, encapsulate each one, and make theminterchangeable. Strategy lets the algorithm vary independently from clients that use it.Strategy pattern are algorithms inside a class which can be interchanged depending on the class used.This pattern is useful when you want to decide on run time which algorithm to be used.Calculation.javapublic interface Calculation {int execute(int a, int b);}AddCalc.javapublic class AddCalc...

Simple RMI and RMI with Spring

RMI (=Remote Method Invocation)The basic structure of an RMI-based method call involves a client, a server and a registry. To make a call to a remote object, the client first looks up the object it wishes to invoke a method on in the registry. The registry returns a reference to the object (assuming it exists) on the server, which the client can use to invoke any methods that the remote object implements.Step1 : HelloInterface.java  import java.rmi.Remote;import java.rmi.RemoteException;public interface HelloInterface extends Remote { ...

JSON Object With Servlet

ProjectStructure:     JarFiles:    package com.candidjava; import java.io.IOException;  import java.io.PrintWriter;  import java.util.Iterator; import javax.servlet.ServletException;  import javax.servlet.http.HttpServlet;  import javax.servlet.http.HttpServletRequest;  import javax.servlet.http.HttpServletResponse; import org.json.JSONException;  import org.json.JSONObject; public class JObject extends HttpServlet {  int...

Ajax and JSON example, How to use JSON with Ajax

In my previous post, I had explained easy example of JSON. In this post I am explaining how to use JSON with Ajax.No need to require any other software, just create one dynamic web project and paste below code.1. StudentInfo.java (This is a Servlet)import java.io.IOException;import java.io.PrintWriter;import javax.servlet.ServletException;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse; public class StudentInfo extends javax.servlet.http.HttpServlet implements javax.servlet.Servlet { protected void...

Monday, October 8, 2012

Chat application in java

This is my 3rd year project which is the initial state of any perfect chat application. It has also few bugs, but it can help any novice student to complete their java assignment. This application is developed in NetBeans IDE. There is two projects one is server and another is Client. To download this two projects click the link bellow. Download Chat Application How to run This application : After downloading two projects open this two projects in NetBeans IDE. At First run Server...

Emailtemplate

Download Source Code This application developed by using freemarker and ja...

struts 1x i18n internationalization tutorial with example program(Using Link)

This struts tutorial explains how to archive internationalization(i18n) without using or modifying any browser setting, Here we have loaded four different languages English, France, Germany and  Italy, by clicking a link in the webpage languages can be changed. Controller class will load the language for the  application based on their user request Project Structure: JAR Files:  TLD Files: Following is the list of required JAR files to be added...

Connect facebook using java

import javax.servlet.http.*;import java.io.IOException;import javax.servlet.*;import org.json.JSONException;import org.json.JSONObject;import java.io.PrintWriter;import com.facebook.api.*;import java.sql.Connection;import java.sql.DriverManager;import java.sql.ResultSet;import java.sql.SQLException;import java.sql.Statement;public class SocialJavaTutorial extends HttpServlet {    int count;    //Application API Key and application secret from creating app in FB    String appapikey = new String("7623a6ab94a7cc519b1fb73627afdda0");   ...