Thursday, April 10, 2008

Read XML File Using Java

Hi all ,
this is a simple program that uses java classes to read xml files.
If an html file is written without errors then that can also be parsed using this.


import java.io.File;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import org.w3c.dom.Document;
import org.w3c.dom.NodeList;

try {
File f = new File("filename");
// first obtain a parser that produces the DOM object tree from XML document
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();

// to obtain DOM document instances from XML document
DocumentBuilder db = dbf.newDocumentBuilder();

// Document represents xml or html documents
Document doc = db.parse(f);
doc.getDocumentElement().normalize();

// first get the root
NodeList root = doc.getChildNodes();

// children of root
NodeList nodes = root.item(0).getChildNodes();
for (int i = 0; i <>

// in case there are childs of nodes[i]
NodeList temp = nodes.item(i).getChildNodes();
System.out.println(nodes.item(i).getNodeName());
System.out.println(temp.getLength());

}
} catch (Exception e) {
e.printStackTrace();
}


Suggestion : to know more about this and for those who dont want to mug up the things use netbeans
thanks..

Cryptography: RSA : Java Implementation

hi all,
RSA is a well known encryption algorithm for encryption and decryption
this is public key cryptography

// choose tho prime number p and q
BigInteger p,q,n,phi;

p = prime(16);
q = prime(16);

// calculate modulus: n and totient: phi
n= p.multiply(q);
BigInteger temp1,temp2;
temp1=p.subtract(BigInteger.ONE);
temp2=q.subtract(BigInteger.ONE);
phi = (temp1).
multiply(temp2);

// choose a prime number and give it name private key.
// and using private key then compute public key

// actually public = private-1mod(phi)
BigInteger private, public;

private = prime(128);

public = private.modInverse(phi);

// now we have both keys private key and public key

//public key is known to anyone and is used to encrypt data
// private key is not disclosed to anyone.. and generally used for decryption



// encryption
BigInteger message;
BigInteger cypherText;

cypherText = message.modPow(public,n);
// cyphertext is encrypted message

// decryption
message =
cypherText .modPow(private,n);

more about cryptography you can get from wikipedia - RSA

JDBC : Easy Steps

hi all,
this is a sample program to show the jdbc connectivity( very simple and limited scopes but enough to create any program using jdbc)

Connection conn;
String driver = "XXXXXX.xxx.xx.xx";
String url = "xxx:XXX:xxx"; // remember the colon here
// url contains the database name

// loading the driver
Class.forName(driver);

// creating a connection
conn = DriverManager.getConnection(url);

Statement stmt = conn.createStatement();
String query = "xxxxxxx";

ResultSet result = null;

/*
* different queries need different methods to be executed
*/

/*
*
* in case of select
* result = stmt.executeQuery(query);
*
*/

/*
*
* in case of insert, update, delete
* stmt.executeUpdate(query);
*
*/

// Like if we use select query
result = stmt.executeQuery(query);

// initially curson is set before first row of the result
// so we need to make it at the desired row

result.next();
// we can use result.first() to get it at first row or result.last() to get it at the
// last row

String str = result.getString("attribute-name");

// finally
conn.close();

this was the very basic tute to implement jdbc.
if u want more then use javadocs.

thanks
Ravi Kumar Gupta ~A.K.A~ "D'Maverick"

Friday, April 4, 2008

Received My Ipod, T-shirts and Certi......

hi frnds,

it was my first achievement in any technical contest (actually it is first i took part.. :P)...

see this...
http://in.sun.com/communities/univ/codeforfreedom/winners.html

thanks for all the people who encouraged me for this.. and a great thanks goes to rahul my partner in this contest.

enjoy..

Saturday, March 8, 2008

Get more from your gmail account


hi frnds,

When you choose a Gmail address, you actually get more than just "yourusername@gmail.com." Here are two different ways you can modify your Gmail address and still get your mail:

* Append a plus ("+") sign and any combination of words or numbers after your email address. For example, if your name was hikingfan@gmail.com, you could send mail to hikingfan+friends@gmail.com or hikingfan+mailinglists@gmail.com.
* Insert one or several dots (".") anywhere in your email address. Gmail doesn't recognize periods as characters in addresses -- we just ignore them. For example, you could tell people your address was hikingfan@gmail.com, hiking.fan@gmail.com or hi.kin.g.fan@gmail.com.



enjoy..

Source : Google Blog

Monday, March 3, 2008

Student 2 Business [S2B] Program

hi frnds,
if u know anything about microsoft technologies like asp.net, c# etc. then u have an opportunity to get into S2B.
know more about this...
http://www.student2business.co.in/HomePage.aspx

enjoy.