Wednesday, September 5, 2012

Melbourne - Dream place to visit

Melbourne is one of major cities in Australia and it very beautiful, greenery and specially for me it is more lovable place in the world. Even I couldn't get chance to visit Melbourne till today, I have observed many places in the web sites and TV channels and I loved it.

If I could get the chance to visit, the fist place I like to visit is the Cricket Ground. It is one of the biggest stadiums in the world with 100,000 seating capacity. Apart from the Cricket, it is very famous for the Foot ball. It's my dream place to visit since I habituated with watching and playing cricket.

The next place I would like to visit is the historical market i.e. QUEEN VICTORIA MARKET. I would like to taste the all the verities of Australian sea food items, vegetable food items and different fruits available in Australia and complete the shopping on lovable items.

One of my most lovable thing which I can't say by my mouth but just understand from below. Like to have one pe......g in Melbourne.

From childhood days I am hearing about 'Penguin', reading in books and watching in movies. So, I would like see the Penguins in Penguin Island and enjoy the moments.

You may have different taste than me or my like other things when compared to my interests. If you want to know more about Melbourne just visit :

Once you know more about Mebourne, I am sure you definately like to visit Melbourne and it will become a dream place to you. Finally I would like to say, "Melbourne is a city that knows how to live".


…it's your time to visit Melbourne NOW!!!

Create XML File in JAVA using DOM

package com.test;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import org.w3c.dom.Attr;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
public class CreateXMLInJava {
public static void main(String argv[]) {
        CreateXMLInJava createXml = new CreateXMLInJava();
public void createXML() {
    try {
         DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
         DocumentBuilder docBuilder = docFactory.newDocumentBuilder();
        // root elements
        Document doc = docBuilder.newDocument();
        Element rootElement = doc.createElement(“Company”);
       // staff elements
       Element staff = doc.createElement(“Dept”);
       // set attribute to staff element
       Attr attr = doc.createAttribute(“id”);
       // can be written as
       // staff.setAttribute(“id”, “1″);
       // firstname elements
      Element firstname = doc.createElement(“Firstname”);
      // lastname elements
      Element lastname = doc.createElement(“Lastname”);
        // salary elements
      Element salary = doc.createElement(“Salary”);
      // write the content into xml file
      TransformerFactory transformerFactory = TransformerFactory.newInstance();
      Transformer transformer = transformerFactory.newTransformer();
      DOMSource source = new DOMSource(doc);
      StreamResult result = new StreamResult(new File(“D:\\test.xml”));
     // Output to console for testing
     // StreamResult result = new StreamResult(System.out);
       transformer.transform(source, result);
      System.out.println(“File saved!”);
   } catch (ParserConfigurationException pce) {
  } catch (TransformerException tfe) {

Monday, September 3, 2012

Read .xls file in JAVA using POI API

import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;

import java.util.Iterator;

public class ReadExcelFileUsingPOI {
public static void main(String[] args) throws Exception {
String filename = "D:\\test.xls";

FileInputStream fis = null;
try {
fis = new FileInputStream(filename);

HSSFWorkbook workbook = new HSSFWorkbook(fis);
HSSFSheet sheet = workbook.getSheetAt(0);

Iterator rows = sheet.rowIterator();
while (rows.hasNext()) {
HSSFRow row = (HSSFRow);
Iterator cells = row.cellIterator();
while (cells.hasNext()) {
HSSFCell cell = (HSSFCell);

int type = cell.getCellType();
if (type == HSSFCell.CELL_TYPE_STRING) {
System.out.println("[" + cell.getRowIndex() + ", "+ cell.getColumnIndex()+"] = STRING; 
                        Value = " + cell.getRichStringCellValue().toString());
} else if (type == HSSFCell.CELL_TYPE_NUMERIC) {
System.out.println("[" + cell.getRowIndex() + ", "+ cell.getColumnIndex()+"]=NUMERIC;
                      Value = " + cell.getNumericCellValue());
} else if (type == HSSFCell.CELL_TYPE_BOOLEAN) {
System.out.println("[" + cell.getRowIndex() + ", "+ cell.getColumnIndex()+"]=BOOLEAN; 
                      Value = "+ cell.getBooleanCellValue());
} else if (type == HSSFCell.CELL_TYPE_BLANK) {
System.out.println("[" + cell.getRowIndex() +", "+cell.getColumnIndex()+"]=BLANK CELL");
} catch (FileNotFoundException e) {
} finally {
if (fis != null) {

Sunday, September 2, 2012

Percentage calculation Example in Java


public final class Percent {

public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(;
System.out.println("enter the total no.of sub");
int n = Integer.parseInt(br.readLine());
int marks[] = new int[n];
int i, tot = 0;
for (i = 0; i < n; i++) {
System.out.println("enter ur marks");
marks[i] = Integer.parseInt(br.readLine());
tot = tot + marks[i];
System.out.println("total marks: " + tot);
System.out.println("percentage of marks: " + (float) tot / n);