Tuesday, June 26, 2012

Comparison BetweenTwo Dates


Monday, June 11, 2012

Select Option Ops

<html>
<body>

<select id="slct" onchange="slct();">
  <option value="1">Volvo</option>
  <option value="2">Saab</option>
  <option value="3">Mercedes</option>
  <option value="4">Audi</option>
</select>

<script>
function slct(){

    var selObj = document.getElementById('slct');
    var selIndex = selObj.selectedIndex;

    alert(selIndex);
    alert(selObj.options[selIndex].value);
    alert(selObj.options[selIndex].text);
}
</script>


</body>
</html>

Tuesday, May 22, 2012

Codelets

#Convert String to Date in Java


java.util.Date = java.text.DateFormat.getDateInstance().parse(date String);
or


SimpleDateFormat format = new SimpleDateFormat( "dd.MM.yyyy" );
Date date = format.parse( myString );

Saturday, March 3, 2012

Read File In JAVA


import java.io.*;

class ReadFile{

    public static void main(String args[]) {
        try {

            FileInputStream fstream = new FileInputStream("c:/yash.txt");

            DataInputStream disobj = new DataInputStream(fstream);

            BufferedReader br = new BufferedReader(new InputStreamReader(disobj));

            String frst = br.readLine();
            String scnd = br.readLine();
            if (frst != null) {
                System.out.println(frst);
                System.out.println(scnd);
            }
            else{
                System.out.println("empty");
            }
            disobj.close();

        }
        catch (Exception ex) {
            System.out.println(ex.getMessage());
        }

    }
}

Sunday, February 19, 2012

In The Spring 3.0

Introduction-


To be very honest i am not some die hard geek coder or some sort of JAVA Guru writing some Bible. I am just a beginner who just started learning to work in JAVA but i am trying to note all the points i am covering while learning Spring 3.0. Just hoping, may be it will also help you. Have fun. :-)

Tuesday, December 13, 2011

Generate random string of certain length

function genRandomString()

{
$length = 10;
$characters = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
$string = null;
for ($p = 0; $p < $length; $p++) {
$string .= $characters[mt_rand(0, strlen($characters))];
}
return $string;
}



$x=genRandomString();
echo substr($x,0,6);

?>

Monday, December 5, 2011

XML Parser in JSP

/**
*
* @author yashx1@gmail.com
*/

import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.DocumentBuilder;
import org.w3c.dom.Document;
import org.w3c.dom.NodeList;
import org.w3c.dom.Node;
import org.w3c.dom.Element;
import java.io.InputStream;
import java.net.URL;
import com.ahoy.ubid.utils.ParseUtil;

public class XmlParserHelp {

public static void main(String argv[]) {
try {
ParseUtil p = new ParseUtil();
URL xmlURL = new URL("http://www.newsletter.uahoy.com:8081/WeBid/api.auctions.php");
InputStream xml = xmlURL.openStream();
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
Document doc = db.parse(xml);
xml.close();
doc.getDocumentElement().normalize();
NodeList nList = doc.getElementsByTagName("result");
for (int temp = 0; temp < nList.getLength(); temp++) {
Node nNode = nList.item(temp);
if (nNode.getNodeType() == Node.ELEMENT_NODE) {
Element eElement = (Element) nNode;
System.out.println("auctionTitle : " + p.getTagValue("auctionTitle", eElement));

//System.out.println("auctioneerId : " + p.getTagValue("auctioneerId", eElement));
}
}
} catch (Exception e) {
System.out.println(e);
}
}

}