Wednesday, 31 July 2013

Spring 3.0 Hello World Example

Here I am posting my first very basic example on a very famous Java framework called Spring.

We need following requirements:-
1.Spring 3.0
2.Eclipse
3.JDK 1.6

5 Steps to create Hello World Example in Spring 3.0

 

1.First create a Java Project in Eclipse:



2.Include the Spring 3.0 jar in Project:

          Right Click on Project Then Goto
          Build Path->Configure Build Path
Then give the path of the jars where you have put it.

3.Create HelloWorld Class:

package com.tutorialjam.tutorial.beans;

public class HelloWorld {
 
 private String guestName;

 public void setGuestName(String guestName) 
 {
  this.guestName = guestName;
 }
 
 public String sayHello()
 {
  return "Hello "+guestName+"!!!";
 }

}

4.Create a xml file in root folder that includes:


 
 
  
 
 

5.Create A class that has main() method:

package com.tutorialjam.tutorial.app;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import com.tutorialjam.tutorial.beans.HelloWorld;

public class Main {

 /**
  * @param args
  */
 public static void main(String[] args) {
  
  ApplicationContext context= new ClassPathXmlApplicationContext("beans.xml");
  HelloWorld hello= (HelloWorld) context.getBean("helloworld");
  System.out.println(hello.sayHello());

 }

}

 

Here your first Spring application ready to run.You can run the main method and see output. Thanks.

Tuesday, 9 July 2013

Get IP address of an URL using Java


How to get an IP address of a URL using Java

It is often required to know the IP address of a website while building some applications, and it is very simple to know the IP of any URL using the Java. Java provides a class called InetAddress that can be used to get the IP.

Here is an example that shows that how we can get the IP address of an URL:

import java.net.InetAddress;
import java.net.UnknownHostException;


public class KnowIP {

 public static void main(String[] args) throws UnknownHostException {
  
  InetAddress address=InetAddress.getByName("www.google.com");
   
  String ipAddress=address.getHostAddress();
  
  System.out.println(ipAddress);
 }
}
My Daawat

Wednesday, 29 May 2013

How to Get CheckBox values in JSP


Example to get checkbox value:

The example shows how to get the multiple checkbox values from one page to another.

 To get the checkbox values we take the name of all the checkboxs same.
 Here we are taking name as hobbies, the values for all these will be different.

First Page:



Select Your Choice Here:-

Now at next page where we are getting these values we use request object's method getParameterValues(). This method take a string argument which is the name of the checkbox. at the first page. It returns an array of String, which contains the values of the checkboxes which are checked.

Second Page:

Your Hobbies are:-

<% String hobbies[] = request.getParameterValues("hobbies"); for (String hobby : hobbies) { out.println("" + hobby + ""); } %>

Start and Stop Process in windows using Java


Here is a simple Example to start and stop windows process using Java Program

To start a process we get a RunTime object through Runtime class method getRuntime().

Now we invoke the exec() method through this object that returns an object of started process.

This object can be used to stop the process by calling destroy() method of it.
import java.io.IOException;
public class StartAndStopProcess{

    public static void main(String[] args) throws IOException, InterruptedException {
   
   
        Runtime run = Runtime.getRuntime();
       
        //start process
        Process pro = run.exec("C:\\Program Files\\Mozilla Firefox\\firefox.exe");
   
        Thread.sleep(5000);
       
        //stop process
        pro.destroy();
    }

   
}
My Daawat

Tuesday, 28 May 2013

Menu Using CSS Sprites


Using CSS sprites we can make a menu using images. Here is a simple example which shows that how we can make a menu which requires 8 images that can be combined into 1 image.





CSS:-


HTML:-








Wednesday, 15 May 2013

CSS Sprites

Here is an example of CSS Sprites

CSS Sprites enable us to reduce the loading time of web page by decreasing the number of HTTP requests.

Sprite is a big image compressing of number of small images.

When a web page is requested by the browser and if that page contains let say 5 images then the number of HTTP requests to the server will be 5 in addition.

Using css sprites we can combine these five images into one and we can show on the page this one image portion accordingly.

This is done by the CSS background-position property.

The example shows the use of CSS Sprites


In this example a combined image of all images of buttons of a music player is used to show the buttons.
If we separate all the images then there would be 8 images for all the buttons so 8 http requests will be there, that increase the loading time.

CSS Code:

 
 

HTML Code:






Here is the Preview :







Monday, 13 May 2013

Dojo Dijit.InlineEditBox Make editable on dblclick

Example to make an dijit.InlineEditBox editable on double click.

 

 

 JavaScript code:-

 

         

    

HTML code:-

 
click me to edit