JavaMix

it`s all about JavaPrograming

Archive for March 2009

installing comport api in windows

comm.jar should be placed in:

    %JAVA_HOME%/lib

    %JAVA_HOME%/jre/lib/ext

win32com.dll should be placed in:

    %JAVA_HOME%/bin

    %JAVA_HOME%/jre/bin

JavaMix Blog


    %windir%System32

javax.comm.properties should be placed in:

    %JAVA_HOME%/lib

    %JAVA_HOME%/jre/lib

practice programs:

http://javamix.wordpress.com/2009/03/25/serialport-communication-using-java/


http://javamix.wordpress.com/2009/01/21/sending-sms-using-serialport-communication-api/

Written by katta vijay

March 30, 2009 at 10:32 am

output comment and hiddencomment in JSP

output comment:

A comment that is sent to the client in the viewable page source.The JSP engine handles an output comment as uninterpreted HTML text, returning the comment in the HTML output sent to the client. You can see the comment by viewing the page source from your Web browser.
JavaMix Blog
JSP Syntax
<!– comment [ <%= expression %> ] –>

Example 1

<!– This is a commnet sent to client on
<%= (new java.util.Date()).toLocaleString() %>
–>

Displays in the page source:
<!– This is a commnet sent to client on March 28, 2009 –>


hiddencomment

A comments that documents the JSP page but is not sent to the client. The JSP engine ignores a hidden comment, and does not process any code within hidden comment tags. A hidden comment is not sent to the client, either in the displayed JSP page or the HTML page source. The hidden comment is useful when you want to hide or “comment out” part of your JSP page.

You can use any characters in the body of the comment except the closing –%> combination. If you need to use –%> in your comment, you can escape it by typing –%\>.
JSP Syntax
<%– comment –%>

Example:
<%–
Document   : commenttest
Created on : Mar 28, 2009, 11:48:27 AM
Author     : vijay
–%>

<%@page contentType=”text/html” pageEncoding=”UTF-8″%>
<!DOCTYPE HTML PUBLIC “-//W3C//DTD HTML 4.01 Transitional//EN”
“http://www.w3.org/TR/html4/loose.dtd”>

<html>
<head>
<meta http-equiv=”Content-Type” content=”text/html; charset=UTF-8″>
<title>JSP Page</title>
</head>
<body>

<!– this is visible comment–>                          comment 1
<%– this comment is not visible  –%>          comment 2
<h1>Hello World!</h1>
</body>
</html>


output:

when you go for browser source code it will  displays the following :

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
   "http://www.w3.org/TR/html4/loose.dtd">

<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
    </head>
    <body>
        <!-- this is visible comment-->       comment 1 only displays

        <h1>Hello World!</h1>
    </body>
</html>


Written by katta vijay

March 28, 2009 at 6:41 am

Posted in j2ee, Jsp, tips

Tagged with , , , ,

Reading data from Excel sheet using JExcel API

using Java we can read the data from Excel sheets by creating type1 driver , but here

we are taking help of JExcelapi we can able to read data directly from the Excel sheets.
steps to be follow:
step 1:
download JExcel api from here

JavaMix Blog

step2:

after downloading extract the zip file.
make jxl.jar available to your class path.

step 3:

create a Excel sheet with some data

step 4:

in this step we are reading data from the Excel sheet.

use the below java code:

/*

* To change this template, choose Tools | Templates

* and open the template in the editor.

*/

// this is main java program

//describes how to read from the .xls and displays

package excelsheetreading; // my package name

import java.io.File;

import java.io.IOException;

import java.util.Date;

import jxl.*;

import jxl.read.biff.BiffException;

/**

*

* @author vijay

*/

public class Main // main is my class name

{

/**

* @param args the command line arguments

*/

public static void main(String[] args) throws IOException, BiffException {

// TODO code application logic here

Workbook workbook = Workbook.getWorkbook(new File(“C:/Documents and Settings/vijay/Desktop/contacts.xls”));

// my excel sheet name is contacts, iam given the complete path.

Sheet sheet = workbook.getSheet(0); // iam reading data from the sheet1

// here iam reading the data of 1st column data up three cells

Cell a1 = sheet.getCell(0,0);

Cell b2 = sheet.getCell(0,1);

Cell c2 = sheet.getCell(0,2);

//getting  the data from cells

String stringa1 = a1.getContents();

String stringb2 = b2.getContents();

String stringc2 = c2.getContents();

//printing the data

System.out.println(“a1–>”+stringa1);

System.out.println(“b2–>”+stringb2);

System.out.println(“c3–>”+stringc2);

}

}

JavaMix Blog


Written by katta vijay

March 26, 2009 at 12:15 pm

serialport communication using Java

before going to execute this program read how to install comport api for windows

In java there is no inbuilt support to access serial or parallel ports, to over come this we are taking support of  Java communication API.

after downloading the java communication api extract the folder then you can get the following…
in Commapi folder we require
comm.jar

javax.comm.properties

win32com.dll

after getting these files perform following operations….

  • Copy file comm.jar in <JAVA_HOME>\jre\lib\ext
  • Copy file javax.comm.properties in <JAVA_HOME>\jre\lib
  • Copy file win32com.dll in <JAVA_HOME>\lib

now you can able to access the commport by Java programm.

The following example displays the available ports(serial and parallel ports) and their type:

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/

package keyboardreader;

/**
*
* @author vijay
*/

import javax.comm.*;
import java.util.Enumeration;

public class ListPorts {
public static void main(String args[]) {
Enumeration ports = CommPortIdentifier.getPortIdentifiers();
while (ports.hasMoreElements()) {
CommPortIdentifier port = (CommPortIdentifier) ports.nextElement();
String type;
switch (port.getPortType()) {
case CommPortIdentifier.PORT_PARALLEL:
type = “Parallel”;
break;
case CommPortIdentifier.PORT_SERIAL:
type = “Serial”;
break;
default: /// Shouldn’t happen
type = “Unknown”;
break;
}
System.out.println(port.getName() + “: ” + type);
}
}
}

output is like this :

COM1: Serial
COM2: Serial
LPT1: Parallel
LPT2: Parallel

Written by katta vijay

March 25, 2009 at 7:30 pm

Follow

Get every new post delivered to your Inbox.