How to install Apache Tomcat server on Ubuntu 11.04

29 07 2011

Hi, Today I’m going to tell you how to install Apache tomcat server on your Ubuntu (Linux) computer. You can install and use it as a portable installation on your pen drive too.Apache tomcat server is used to run .jsp file (Java Server Pages). So first you need to download Apache Tomcat 7.0 from Apache site.

DOWNLOAD Apache tomcat here!..

Ok let’s do it. Now extract the downloaded apache-tomcat-7.0.19.tar.gz file into desktop or to your pen drive.

Then rename it as tomcat (only for our convenience)

Open Terminal window (Ctrl+Alt+T)

Then go to this folder using this command : cd Desktop/tomcat/bin ( assuming you extracted on your Desktop )

Then run this command(run startup.sh shell script) : ./startup.sh

Now open firefox go to this URL : http://localhost:8080/ . Then you should see it like this!

Now try a jsp script to test the installation.

If you want to, copy this code and save it into tomcat–>webapps–>ROOT as hello.jsp  Then run it http://localhost:8080/hello.jsp  😀

<html>
<head>
<title>JSP Test page.</title>
</head>
<body>
<p align=”center”><font color=”#009900″ size=”7″><%=”gihansblog.com”%></font></p>
<p align=”center”><font color=”#FF0000″ size=”6″><%=”Hello JSP World!”%> </font></p>
<p><%= new java.util.Date()%></p>
</body>
</html>

To shut-down the Tomcat server use this command(run shutdown.sh shell script) : ./shutdown.sh

Thanks

Gihan





Moving to a new domain name… gihansblog.com

28 07 2011

Hi, A little Announcement for all the readers of Gihan’s Blog. That is gihansblog.wordpress.com moving to gihansblog.com :D. Now it’s been around two months that I’ve started this blog. There are lot of people who give me strength to carry on this blog by commenting, discussing and saying ‘Hi’.And I appreciate all those things.

I got this domian name form GoDaddy.com. And I forwarded it into my old wordpress domain name through their forwarding facilities.  And anyone interesting on more info about getting a domain, masking ,forwarding or anything regarding this , I’d like to share my experience. 😀

Now you can find my Blog on http://gihansblog.com/ . 😀

Thank you

Gihan Malan De Silva @ gihansblog.com/





Java 7 Released… (watch the video)

19 07 2011

Good and very Important News for all. That is Java 7 had released on 7th July 2011. Ceremony speech was given by Adam Messinger, vice president of development Fusion Middleware. According to dream team of Java , in the new version of Java has a big different comparing than the other versions of Java. And this is the first release of Java with Oracle company.And they has made it as MOVING JAVA FORWARD!

With Oracle, Java’s future  has goes with  the  new technology, the community, the Java Community Process (JCP), and the entire ecosystem focused on moving Java forward.

And they has categorised new Technical Breakout of Java 7

  1. Making Heads and Tails of Project Coin, Small Language Changes in JDK 7
  2. Divide and Conquer Parallelism with the Fork/Join Framework
  3. The New File System API in JDK 7
  4. A Renaissance VM: One Platform, Many Languages

Java 7 Released… from Gihan on Vimeo.

Just watch it. It’s worth to watch…

Thanks

Gihan Malan De Silva





Rotate an image with java Buffered image class..

14 07 2011

Hi, today I’m going to show you another image enhancing technique with Java’s Buffered image class. That is rotating an image. To rotate an image with Java we use classes called AffineTransform and AffineTransformOp. And let’s see how to rotate an image. It is very easy as previous things.

In this post I’m not going to describe basics like creating an buffered image, display a buffered image on a JLabel..  etc .. but to describe methods I wrote in my program.

1). public void rescale() {}

2). private void rorateImg() {}

Let’s consider one by one..

public void rescale() {

        tx = new AffineTransform();
        tx.rotate(angel,w / 2, h / 2);//(radian,arbit_X,arbit_Y)

        op = new AffineTransformOp(tx,AffineTransformOp.TYPE_BILINEAR);
        bufferedImage=op.filter(bufferedImage,null);//(sourse,destination)

       }//end rescale()

Before rotating the image...

In rescale() method I’ve created an AffineTransform object then called the rotate() method.

tx = new AffineTransform();

double theta, double anchorx, double anchory parameters should be passed into the rotate() method. This method rotates an image around an anchor point which coordinates equals to anchorx,anchory . And the theta should be give in radians. And this procedure equal to these three operations.
translate(anchorx, anchory);      // final translation
rotate(theta);                                 // rotate around anchor
translate(-anchorx, -anchory);   // translate anchor to origin

double angel=Math.PI/2;

This Math.PI/2 equals to 90 degrees.

   int w;// width of buffered image
   int h;//height of buffered image

then Buffered Image’s getWidth() and getHeight() methods assigns image’s width and height into w and h.

  w= bufferedImage.getWidth();
  h=bufferedImage.getHeight();

tx.rotate(angel,w / 2, h / 2);

By assigning w/2 and h/2 into anchorx and anchory I made the image to rotate around it’s center point. Then AffineTransformOp object is created. When creating the object an AffineTransform object and Bilinear interpolation type are given as parameters.

op = new AffineTransformOp(tx,AffineTransformOp.TYPE_BILINEAR);

Then the filter() method is called with AffineTransformOp object. This public final BufferedImage filter(BufferedImage src, BufferedImage dst) method is more likely the filter() in RescaleOp which we discussed. And this method compares source and destination images then returns the filtered buffered image. 

bufferedImage=op.filter(bufferedImage,null);

After rotating the image...

private void rorateImg(){

        w= bufferedImage.getWidth();
        h=bufferedImage.getHeight();

        rescale();             

        icon = new ImageIcon(bufferedImage);          
        picLabel.setIcon(icon);

    }//end rotateImg()

In here I earlier discussed what happens with w= bufferedImage.getWidth(); and h=bufferedImage.getHeight(); . Then rescale() method is called and the other codes describes the displaying the buffered image on a JLabel. 😀 😀 ok that all.

And here is related Java docs.

1) AffineTransform

2) AffineTransformOp

Here is the source code of it and if you want you can DOWNLOAD my Netbeans project. And it has two classes Rotate.java and Main.java which is included the main method.

Main.java

/*
 * Main.java
 */
package rotate;

/**
 *
 * @author gihan
 */
public class Main {
     public static void main(String[] args) {
        Rotate obj=new Rotate();
    }

}

Rotate.java

/*
 * Rotate.java
 */
package rotate;

import java.awt.geom.AffineTransform;
import java.awt.image.AffineTransformOp;
import java.awt.image.BufferedImage;
import java.awt.image.RescaleOp;
import java.io.File;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.imageio.ImageIO;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JLabel;

/**
 *
 * @author gihan
 */
public class Rotate extends JFrame{

    // globel variables

    BufferedImage bufferedImage;
    RescaleOp rescale;
    ImageIcon icon;
    AffineTransformOp op;
    AffineTransform tx;
    int w;// width of buffered image
    int h;//height of buffered image
    double angel=Math.PI/2; /** angle should be given in radian and
                                        * this program rotates the image in 90 degrees */
    String path=”/home/gihan/Pictures/nfs_bmw.jpg”;// image file path  
    JLabel picLabel=new JLabel();

    public Rotate(){

         JFrame jf=new JFrame();
         JPanel jp=new JPanel();        

         jf.add(jp);
         jp.add(picLabel);

            jf.setVisible(true);
            jf.setSize(487, 640);
            jf.setLocation(200,200);
            jf.setTitle(“Gihan’s Image Processing Test Area.. “);
            jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

            File file = new File(path);

        try {           
            bufferedImage = ImageIO.read(file); // create a buffered image
        } catch (IOException ex) {
            Logger.getLogger(Rotate.class.getName()).log(Level.SEVERE, null, ex);
        }
            rorateImg();

         icon = new ImageIcon(bufferedImage);          
         picLabel.setIcon(icon);
    }

    private void rorateImg(){//rotates 90 degrees

        w= bufferedImage.getWidth();
        h=bufferedImage.getHeight();

        rescale();             

        icon = new ImageIcon(bufferedImage);          
        picLabel.setIcon(icon);

    }

    public void rescale() {

        tx = new AffineTransform();
        tx.rotate(angel,w / 2, h / 2);//(radian,arbit_X,arbit_Y)

        op = new AffineTransformOp(tx,AffineTransformOp.TYPE_BILINEAR);
        bufferedImage=op.filter(bufferedImage,null);//(sourse,destination)

       }

}//end class Rotate

 

If you have any doubt, feel free to ask. :D
Thank you

Gihan Malan De Silva @ gihansblog.wordpress.com





Contrast control with java Buffered image class..

11 07 2011

Hi, in this post I’m going to tell you how to change the contrast of an buffered image. And it will be very easy to you if you read my previous post on Brightness control with java Buffered image class... Here I’m going to explain only the key methods and others will be same as Brightness control.

In this program also here are two methods I’ve written.

1). public void rescale() {}

2). private void contrastChange() {}

Let’s consider them, one by one

An Image before change the Contrast...

        public void rescale() {

        rescale = new RescaleOp(scaleFactor,20.0f, null);
bufferedImage=rescale.filter(bufferedImage,null);//(sourse,destination)

       }//end rescale
In here, I’ve created RescaleOp object, and should pass parameters as in order sacleFactors, offsets,  hints .

By changing offsets value we can adjust the brightness of an image, and by changing sacleFactors value we can adjust contrast of an image and hints for the specified RenderingHints or can be kept as null. In my program scaleFactor is set to 1.0 in float for default image and for enhanced image it is set to 3.6 in float.

An Image after increasing the Contrast...

private void contrastChange(){

         rescale();
         icon = new ImageIcon(bufferedImage);          
         picLabel.setIcon(icon);
         System.out.println(“scaleFactor : “+scaleFactor  );

    }//end  contrastChange()

In the filter method filter(sourse_bufferedImage, destination_bufferedImage); should be given as like this, and it returns filtered buffered image. Then in the contrastChange() the rescale() method is called and as I mentioned in my previous post, the buffered image is printed on a JLabel. :D

Here is the source code of it and if you want you can DOWNLOAD my Netbeans project. And it has two classes Contrast.java and Main.java which is included the main method.

Main.java

/*

* Main.java

*/
package contrast;

/**
 *
 * @author gihan
 */
public class Main {
     public static void main(String[] args) {
        Contrast obj=new Contrast();
    }//end main()

}//end class Main

Contrast.java

/*
 * Contrast.java
 */
package contrast;

import java.awt.image.BufferedImage;
import java.awt.image.RescaleOp;
import java.io.File;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.imageio.ImageIO;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;

/**
 *
 * @author gihan
 */
public class Contrast extends JFrame{
       //globel variables
        BufferedImage bufferedImage;
        String path=”/home/gihan/Pictures/nfs_bmw.jpg”;// image file path     
        float scaleFactor=3.6f;//change scaleFactor to change contrast        
        /*keep the value scaleFactor = 1.0f; as for a normal image*/
        RescaleOp rescale;
        ImageIcon icon;
        JLabel picLabel=new JLabel();

     public Contrast() {

         JFrame jf=new JFrame();
         JPanel jp=new JPanel();        

         jf.add(jp);
         jp.add(picLabel);

            jf.setVisible(true);
            jf.setSize(740, 487);
            jf.setLocation(200,100);
            jf.setTitle(“Gihan’s Image Processing Test Area.. “);
            jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

            File file = new File(path);

        try {           
            bufferedImage = ImageIO.read(file); // create a buffered image
        } catch (IOException ex) {
            Logger.getLogger(Contrast.class.getName()).log(Level.SEVERE, null, ex);
        }

         contrastChange();   
         icon = new ImageIcon(bufferedImage);          
         picLabel.setIcon(icon);       

    }

     private void contrastChange(){

         rescale();
         icon = new ImageIcon(bufferedImage);          
         picLabel.setIcon(icon);
         System.out.println(“scaleFactor : “+scaleFactor  );

    }//contrastChange()

     public void rescale() {

        rescale = new RescaleOp(scaleFactor,20.0f, null);
        bufferedImage=rescale.filter(bufferedImage,null);//(sourse,destination)

       }//end rescale

}//end class contrast

If you have any doubt, feel free to ask. :D
Thank you

Gihan Malan De Silva @ gihansblog.wordpress.com





Brightness control with java Buffered image class..

10 07 2011

Hi, today I’m going to tell you how to change brightness of an image with Java’s Buffered image class. .. And consider this will be a series of posts regarding image processing/enhancement with Java  🙂 .

First we need to create an String variable to store the path of image file.

String path=”filepath_of_ your_image”;

for a example I used : String path=”/home/gihan/Pictures/nfs_bmw.jpg”;

Then create a file type object. And give our path as parameter.

File file = new File(path);

Then create a  buffered image.

BufferedImage bufferedImage = ImageIO.read(file);

If you want to, now you can preview your image using :

ImageIcon icon;
JLabel picLabel=new JLabel();

 icon = new ImageIcon(bufferedImage);          
 picLabel.setIcon(icon);

An Image before change the Brightness...

But we are going to process that image so let’s move to next point. There are two methods I’ve written in my programm.

1). public void rescale() {}

2). private void brighten() {}

Let’s consider them, one by one
     public void rescale() {

        rescale = new RescaleOp(1.0f,offset, null);
        bufferedImage=rescale.filter(bufferedImage,null);//(sourse,destination)

       }//end rescale
In here, I’ve created RescaleOp object, and should pass parameters as in order sacleFactors, offsetshints .

By changing offsets value we can adjust the brightness of an image, and by changing sacleFactors value we can adjust contrast of an image and hints for the specified RenderingHints or can be kept as null. In my program offset is set to 20 in float for default image and for enhanced image it is set to 170 in float.

An Image after change the Brightness...

Here you can look at the related java docs.

In the filter method filter(sourse_bufferedImage, destination_bufferedImage); should be given as like this, and it returns filtered buffered image.

Then in the private void brighten()  method I think there is nothing to describe. 😀 :D. I called the rescale() method and as I mentioned earlier, the buffered image is printed on a JLabel. 😀
private void brighten(){

         rescale();
         icon = new ImageIcon(bufferedImage);          
         picLabel.setIcon(icon);

    }//end  brighten()

Here is the source code of it and if you want you can DOWNLOAD my Netbeans project. And it has two classes Bright.java and Main.java which is included the main method.

Main.java
/*
 * Main.java
 */
package bright;

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

    public static void main(String[] args) {
        Bright obj=new Bright();
    }//end main()

}//end class Main

Bright.java

/*
 * Bright.java
 */
package bright;

import java.awt.image.BufferedImage;
import java.awt.image.RescaleOp;
import java.io.File;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.imageio.ImageIO;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;

/**
 *
 * @author gihan
 */
public class Bright extends JFrame{
       //globel variables
        BufferedImage bufferedImage;
        String path=”/home/gihan/Pictures/nfs_bmw.jpg”;// image file path         
        float offset = 170.0f;//change offset to brighten
        /*keep the value offset = 170.0f; as for a normal image*/
        RescaleOp rescale;
        ImageIcon icon;
        JLabel picLabel=new JLabel();

     public Bright() {

         JFrame jf=new JFrame();
         JPanel jp=new JPanel();        

         jf.add(jp);
         jp.add(picLabel);

            jf.setVisible(true);
            jf.setSize(550, 550);
            jf.setLocation(200,100);
            jf.setTitle(“Gihan’s Image Processing Test Area.. “);
            jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

            File file = new File(path);

        try {           
            bufferedImage = ImageIO.read(file); // create a buffered image
        } catch (IOException ex) {
            Logger.getLogger(Bright.class.getName()).log(Level.SEVERE, null, ex);
        }

         brighten();   
         icon = new ImageIcon(bufferedImage);          
         picLabel.setIcon(icon);       

    }

     private void brighten(){

         rescale();
         icon = new ImageIcon(bufferedImage);          
         picLabel.setIcon(icon);
         System.out.println(“offset : “+offset  );

    }//end  brighten()

     public void rescale() {

        rescale = new RescaleOp(1.0f,offset, null);
        bufferedImage=rescale.filter(bufferedImage,null);//(sourse,destination)

       }//end rescale

}//end class Bright

If you have any doubt, feel free to ask. 😀
Thank you

Gihan Malan De Silva @ gihansblog.wordpress.com