Wednesday, July 10, 2013

Solution for server port is already in use

For developer while running server based application will get error like as

Starting of Tomcat failed, the server port 8080 is already in use.

This problem may occur in following reasons :

1. if another application used same port(then we need to select different port)

2. we already stopped application but port is still in used ,
then we need to stop port use and make it available for running application

goto command prompt

netstat -aon

it will show you something like

 TCP    192.1.200.48:8080     24.43.246.60:443       ESTABLISHED     248
 TCP    192.1.200.48:8080      24.43.246.60:443       ESTABLISHED     248
 TCP    192.1.200.48:2126      213.146.189.201:12350  ESTABLISHED     1308
 TCP    192.1.200.48:3918      192.1.200.2:8073       ESTABLISHED     1504
 TCP    192.1.200.48:3975      192.1.200.11:49892     TIME_WAIT       0
 TCP    192.1.200.48:3976      192.1.200.11:49892     TIME_WAIT       0
 TCP    192.1.200.48:4039      209.85.153.100:80      ESTABLISHED     248
 TCP    192.1.200.48:8080      209.85.153.100:80      ESTABLISHED     248

check which process has binded your port. here in above example its 248 now if you are sure that you need to kill that process fire

Linux:

kill -9 248

Windows:

taskkill /f /pid 248

it will kill that process

Friday, May 17, 2013

A Small Intro for Software Testing

What is software testing ?
  •  It is the process of evolution a software item to detect difference between given input and expected output , also to assess the feature of a software system.
  •  Testing assesses the quality of the product.
  •  It should be done in development phase.
  • It is a verification and validation process.

Verification :  
  • It is the process to make sure the product satisfies the conditions imposed at start of the development phase.
  • To make sure the product behaves the way we want.
Validation :  
  • It is the process to make sure the product satisfies the specified requirements at end of the development phase.
  • To make sure the product is built as per customer requirement.

There are two basics of software testing

1. Blackbox Testing :
  •    It is a testing technique that ignores internal mechanism of the system and focusses on the output generated against any input and execution of the system.
  •    It is often used for Validation.
  
2. Whitebox Testing  :
  •    It is a testing technique that takes into account the internal mechanism of the system.
  •    It is often used for Verification.
  
Types:

There are many types of testing like as below

Unit Testing :
  •   It is the testing of an individual unit or group of related units.
  •   It is done by programmer to test that the unit he has implemented is producing expected output against input.
  •   It falls under class of whitebox testing.

Integration Testing:
  •   It is testing in which the group of components are combined  to produce the output.
  •   It is also interaction between hardware and software is tested if hardware and software components have any relation.
  •   It may fall both blockbox and whitebox testing.

Functional Testing:
  •   It is the testing to ensure that the specified fuctionalities required in the system requirements works.
  •   It falls under class of Blackbox testing.

System Testing:
  •   It is the testing to ensure that by putting the software in different environments (diff OS) it still works.
  •   It is done with full system implementation and environments.
  •   It falls under class of Blackbox testing.

Performance Testing:
  •   It is the testing to assess the speed and effectiveness of the system and to make sure it's generating results in
  • specified time as an in performance requirements.
  •   It falls under class of Blackbox testing.

Usability Testing:
  •   It is performed to the perspective of the client , to evaluate how the GUI is user-friendly .How easily can the client learn? After learning how to use, how proficiently can the client perform? How pleasing is it to use its design?
  •   It falls under class of Blackbox testing.

Acceptance Testing
  •   It is often done by the customer to ensure that the delivered product meets the requirements and works as the customer expected.
  •   It falls under the class of black box testing.

Regression Testing
  •   It is the testing after modification of a system, component, or a group of related units to ensure that the modification is working correctly and is not damaging or imposing other modules to produce unexpected results.
  •   It falls under the class of black box testing.

Beta Testing
  •   It is the testing which is done by end users, a team outside development, or publicly releasing full pre-version of the product which is known as beta version. The aim of beta testing is to cover unexpected errors.
  •   It falls under the class of black box testing.

 

Thursday, April 25, 2013

AutoCompletionTestFieldDemo using Java

import java.awt.*;
import java.awt.event.*;
import java.util.*;

import javax.swing.*;
import javax.swing.event.*;
/**
 * Example for AutoCompletionTestFieldDemo
 * @author R.Amirtharaj
 */
public class AutoCompletionTestFieldDemo {

    public static void main(String[] args) throws Exception {
        UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
        JFrame frame = new JFrame();
        frame.setTitle("Auto Completion Test");
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setBounds(200, 200, 500, 400);

        ArrayList items = new ArrayList();
        // To get Locale
        Locale[] locales = Locale.getAvailableLocales();
        for (int i = 0; i < locales.length; i++) {
            String item = locales[i].getDisplayName();
            items.add(item);
        }
        JTextField txtInput = new JTextField();

        // set autocmplete
        setAutoComplete(txtInput, items);
        txtInput.setColumns(30);
        frame.getContentPane().setLayout(new FlowLayout());
        frame.getContentPane().add(txtInput, BorderLayout.NORTH);
        frame.setVisible(true);
    }

    private static boolean isAdjusting(JComboBox cbInput) {
        if (cbInput.getClientProperty("is_adjusting") instanceof Boolean) {
            return (Boolean) cbInput.getClientProperty("is_adjusting");
        }
        return false;
    }

    private static void setAdjusting(JComboBox cbInput, boolean adjusting) {
        cbInput.putClientProperty("is_adjusting", adjusting);
    }

    public static void setAutoComplete(final JTextField txtInput, final ArrayList items) {
        final DefaultComboBoxModel model = new DefaultComboBoxModel();
        final JComboBox cbInput = new JComboBox(model) {
            public Dimension getPreferredSize() {
                return new Dimension(super.getPreferredSize().width, 0);
            }
        };
        setAdjusting(cbInput, false);
        for (String item : items) {
            model.addElement(item);
        }
        cbInput.setSelectedItem(null);
        cbInput.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                if (!isAdjusting(cbInput)) {
                    if (cbInput.getSelectedItem() != null) {
                        txtInput.setText(cbInput.getSelectedItem().toString());
                    }
                }
            }
        });

        txtInput.addKeyListener(new KeyAdapter() {

            @Override
            public void keyPressed(KeyEvent e) {
                setAdjusting(cbInput, true);
                if (e.getKeyCode() == KeyEvent.VK_SPACE) {
                    if (cbInput.isPopupVisible()) {
                        e.setKeyCode(KeyEvent.VK_ENTER);
                    }
                }
                if (e.getKeyCode() == KeyEvent.VK_ENTER || e.getKeyCode() == KeyEvent.VK_UP || e.getKeyCode() == KeyEvent.VK_DOWN) {
                    e.setSource(cbInput);
                    cbInput.dispatchEvent(e);
                    if (e.getKeyCode() == KeyEvent.VK_ENTER) {
                        // User may enter Other than list
                        try {
                            txtInput.setText(cbInput.getSelectedItem().toString());
                        }
                        catch(Exception ex)
                        {
                        }
                        cbInput.setPopupVisible(false);
                    }
                }
                if (e.getKeyCode() == KeyEvent.VK_ESCAPE) {
                    cbInput.setPopupVisible(false);
                }
                setAdjusting(cbInput, false);
            }
        });

        txtInput.getDocument().addDocumentListener(new DocumentListener() {
            public void insertUpdate(DocumentEvent e) {
                updateList();
            }

            public void removeUpdate(DocumentEvent e) {
                updateList();
            }

            public void changedUpdate(DocumentEvent e) {
                updateList();
            }

            private void updateList() {
                setAdjusting(cbInput, true);
                model.removeAllElements();
                String input = txtInput.getText();
                if (!input.isEmpty()) {
                    for (String item : items) {
                        if (item.toLowerCase().startsWith(input.toLowerCase())) {
                            model.addElement(item);
                        }
                    }
                }
                cbInput.hidePopup();
                cbInput.setPopupVisible(model.getSize() > 0);
                setAdjusting(cbInput, false);
            }
        });
        txtInput.setLayout(new BorderLayout());
        txtInput.add(cbInput, BorderLayout.SOUTH);
    }
}

Monday, April 22, 2013

The Seven Phases of the Systems Development Life Cycle (SDLC):

The Seven Phases of the Systems Development Life Cycle :

1. Information Gathering : In this phase Bussiness Analyst will gather all the information from customer requirement and prepare BRS/CRS/URS(Buiseness/Customer/User Requirement Specification) document. Mainly this done by Buisness Anlayst as they are the one who are completely involved in SDLC.

2. Analysis : In this phase Senior Business Analyst will prepare SRS(Software Requirement Specification). The Features and functions are put in the project are determined.

3. Design : Actual flow of the project is done here. Deciding upto logical functionality, ER Diagram , Flow chart etc are made. Cheif Architect will prepare HLD and LLD(High Level Document and Low Level Document)
  • HLD : Defines the overall Hierarchy of the function.Example : Login into Net Banking. From the root level to the least level is defines in HLD.
  • LLD: Internal logic of the project is defined. Focuses on the internal functionality of the program. Each and every module logic is defined.

4. Code : Based on the design document , small-small modules are prepared . All the modules are summed together to form a .exe. Unit testing , integration testing & white box testing comes in this phase.       

5. Testing : Actuall system testing take place here.

6. Implementation : All sr.department will release the product .

7. Maintenance : In maintenance the maintenance team will change the software if necessary. 

Thursday, April 18, 2013

Java Collection loop throw elements

import java.util.*;

/**
 *
 * @author Amirtharaj
 */
public class CollectionLoopThroDemo {

    public static void main(String arg[]) {
        CollectionLoopThroDemo cd = new CollectionLoopThroDemo();

        List al = new ArrayList();
        al.add("C");
        al.add("A");
        al.add("B");
        cd.iterateList(al);

        Set setDet = new HashSet();
        setDet.add("B");
        setDet.add("A");
        setDet.add("C");
        cd.iterateSet(setDet);

        Map mapDet = new HashMap();
        mapDet.put("B", 2.0);
        mapDet.put("A", 1.0);
        mapDet.put("C", 3.0);
        cd.iterateMap(mapDet);

    }

    public void iterateList(List al) {
        //access via Iterator
        Iterator iterator = al.iterator();
        while (iterator.hasNext()) {
            String str = (String) iterator.next();
            System.out.println(str);
        }
        //access via new for-loop
        for (String str : al) {
            System.out.println(str);
        }
    }

    public void iterateSet(Set setDet) {

        //access via Iterator
        Iterator iterator = setDet.iterator();
        while (iterator.hasNext()) {
            String str = (String) iterator.next();
            System.out.println(str);
        }


        //access via new for-loop
        for (String str : setDet) {
            System.out.println(str);
        }
    }

    public void iterateMap(Map mapDet) {
        //access via Iterator
        Iterator iterator = mapDet.keySet().iterator();
        while (iterator.hasNext()) {
            String key = (String) iterator.next();
            Double value = (Double) mapDet.get(key);
            System.out.println(key + "," + value);
        }

        //access via new for-loop
        for (String key : mapDet.keySet()) {
            Double value = mapDet.get(key);
            System.out.println(key + "," + value);
        }

    }
}

Tuesday, April 2, 2013

To get Motherboard serial number, Hard disk serial number, IP Address and MAC Address from Java

import java.io.File;
import java.io.FileWriter;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.InetAddress;
import java.net.NetworkInterface;

public class MyPC {

    public static String getMotherBoardSerialNumber() {
        String result = "";
        try {
            File file = File.createTempFile("realhowto", ".vbs");
            file.deleteOnExit();
            FileWriter fw = new java.io.FileWriter(file);
            String vbs =
                    "Set objWMIService = GetObject(\"winmgmts:\\\\.\\root\\cimv2\")\n"
                    + "Set colItems = objWMIService.ExecQuery _ \n"
                    + "   (\"Select * from Win32_BaseBoard\") \n"
                    + "For Each objItem in colItems \n"
                    + "    Wscript.Echo objItem.SerialNumber \n"
                    + "    exit for  ' do the first cpu only! \n"
                    + "Next \n";

            fw.write(vbs);
            fw.close();
            Process p = Runtime.getRuntime().exec("cscript //NoLogo " + file.getPath());
            BufferedReader input =
                    new BufferedReader(new InputStreamReader(p.getInputStream()));
            String line;
            while ((line = input.readLine()) != null) {
                result += line;
            }
            input.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return result.trim();
    }

    public static String getHardDiskSerialNumber(String drive) {
        String result = "";
        try {
            File file = File.createTempFile("realhowto", ".vbs");
            file.deleteOnExit();
            FileWriter fw = new java.io.FileWriter(file);

            String vbs = "Set objFSO = CreateObject(\"Scripting.FileSystemObject\")\n"
                    + "Set colDrives = objFSO.Drives\n"
                    + "Set objDrive = colDrives.item(\"" + drive + "\")\n"
                    + "Wscript.Echo objDrive.SerialNumber";  // see note
            fw.write(vbs);
            fw.close();
            Process p = Runtime.getRuntime().exec("cscript //NoLogo " + file.getPath());
            BufferedReader input =
                    new BufferedReader(new InputStreamReader(p.getInputStream()));
            String line;
            while ((line = input.readLine()) != null) {
                result += line;
            }
            input.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return result.trim();
    }

    public static String getIPAddress() {
        String strIP = "127.0.0.1";
        try {
            InetAddress ip = InetAddress.getLocalHost();
            strIP = ip.getHostAddress();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return strIP;
    }

    public static String getMACAddress() {
        String strMAC = "127.0.0.1";
        try {
            InetAddress ip = InetAddress.getLocalHost();
            NetworkInterface network = NetworkInterface.getByInetAddress(ip);
            byte[] mac = network.getHardwareAddress();
            StringBuilder sb = new StringBuilder();
            for (int i = 0; i < mac.length; i++) {
                sb.append(String.format("%02X%s", mac[i], (i < mac.length - 1) ? "-" : ""));
            }
            strMAC = sb.toString();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return strMAC;
    }

    public static void main(String[] args) {
        System.out.println("Motherboard serial number : " + MyPC.getMotherBoardSerialNumber());
        System.out.println("Hard disk serial number : " + MyPC.getHardDiskSerialNumber("C"));
        System.out.println("IP Address : " + MyPC.getIPAddress());
        System.out.println("MAC Address : " + MyPC.getMACAddress());
    }
}

Tuesday, March 26, 2013

Hibernate and Oracle sequence

 For  Hibernate beginners using orcale db doing some examples then they will be confused over mapping file with auto increment . So for my experience I gave sample code as below to avoid 

1. Use Sequence increment in mapping File :

Create Tabele :

CREATE TABLE EMPLOYEE (
  ID          NUMBER        NOT NULL,
  FIRST_NAME  VARCHAR2 (20),
  LAST_NAME   VARCHAR2 (20),
  SALARY      NUMBER        DEFAULT null,
  CONSTRAINT EMPLOYEE_PK
  PRIMARY KEY ( ID ) ) ;

create sequence EMPLOYEE_ID_SEQ; 
 
In Mapping File :

Employee.hbm.xml


           


2. Mapping with Database trigger on sequence


Create table as like above

For trigger :

create sequence EMPLOYEE_ID_SEQ;

CREATE OR REPLACE TRIGGER EMPLOYEE_insert
before insert on EMPLOYEE
for each row
begin
    select EMPLOYEE_ID_SEQ.nextval into :new.id from dual;
end;
/

In Mapping File :

Employee.hbm.xml