Professional Documents
Culture Documents
Mykodes Mykodes: Home Home Java Java Javascript Javascript Oracle/ SQL Oracle/ SQL Others Others Forum Forum
Mykodes Mykodes: Home Home Java Java Javascript Javascript Oracle/ SQL Oracle/ SQL Others Others Forum Forum
public class EveryHour extends TimerTask { public void run() { Calendar date = Calendar.getInstance(); int n=date.getTime().getMinutes(); System.out.println("Generating report:"+n+":"+date.getTime()); //TODO generate report } public static void main(String[] args) { Timer timer = new Timer(); Calendar date = Calendar.getInstance(); // date.set( // Calendar.DAY_OF_WEEK, // Calendar.TUESDAY // ); date.set(Calendar.HOUR, 0); date.set(Calendar.MINUTE, 0); date.set(Calendar.SECOND, 0); date.set(Calendar.MILLISECOND, 0); // Schedule to run every Sunday in midnight timer.schedule( new sleep(), date.getTime(), 1000 * 60 * 60 );
} } I hope it will help you.Thanks for visiting this page. READ MORE
public class url { public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); shell.setLayout(new FillLayout()); Browser browser = new Browser(shell, SWT.NONE); browser.setUrl("http://www.mykodes.com"); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); } } Here we also use the static html file open using, browser.setUrl("C://mykodes.html");
READ MORE
public class readXML { public static void main(String argv[]) { try { File fXmlFile = new File("d://file.xml"); DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder dBuilder = dbFactory.newDocumentBuilder(); Document doc = dBuilder.parse(fXmlFile); doc.getDocumentElement().normalize(); System.out.println("Root element :" + doc.getDocumentElement().getNodeName()); NodeList nList = doc.getElementsByTagName("Value"); System.out.println("----------------------------"); System.out.println("node length:"+nList.getLength()); for (int temp = 0; temp < nList.getLength(); temp++) { Node nNode = nList.item(temp); System.out.println("\nCurrent Element :" + nNode.getNodeName()); if (nNode.getNodeType() == Node.ELEMENT_NODE) { Element eElement = (Element) nNode;
System.out.println("Value id : " + eElement.getAttribute("id")); System.out.println("tag1 : " + eElement.getElementsByTagName("tag1").item(0).getTextContent ()); System.out.println("tag2 : " + eElement.getElementsByTagName("tag2").item(0).getTextContent ()); System.out.println("----"); } } } catch (Exception e) { e.printStackTrace(); } } } Output: Root element :Root ---------------------------node length:5 Current Element :Value Value id : 1111 tag1 : check1 tag2 : 2 ---Current Element :Value Value id : 1122 tag1 : check2 tag2 : 12 ---Current Element :Value Value id : 1133 tag1 : check3 tag2 : 22 ---Current Element :Value Value id : 1441 tag1 : check4 tag2 : 32 ---Current Element :Value Value id : 1155 tag1 : check5
tag2 : 42 ---Similar Posts: Create XML file in Java using Loop READ MORE
import org.w3c.dom.Attr; import org.w3c.dom.Document; import org.w3c.dom.Element; public class createXML { public static void main(String argv[]) throws TransformerException { ArrayList<String> ar1=new ArrayList<String>(); ArrayList<String> ar2=new ArrayList<String>(); ArrayList<String> ar3=new ArrayList<String>(); ar3.add("1111");ar3.add("1122");ar3.add("1133");ar3.add("1441") ;ar3.add("1155");
ar1.add("check1");ar1.add("check2");ar1.add("check3");ar1.add(" check4");ar1.add("check5"); ar2.add("2");ar2.add("12");ar2.add("22");ar2.add("32");ar2.add("4 2");ar2.add("52"); DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder docBuilder; try { docBuilder = docFactory.newDocumentBuilder(); // root elements Document doc = docBuilder.newDocument(); Element rootElement = doc.createElement("Root"); doc.appendChild(rootElement); for(int i=0;i<ar1.size();i++){ // staff elements Element staff = doc.createElement("Value"); rootElement.appendChild(staff); // set attribute to staff element Attr attr = doc.createAttribute("id"); attr.setValue(ar3.get(i).toString()); staff.setAttributeNode(attr);
Element tag1 = doc.createElement("tag1"); tag1.appendChild(doc.createTextNode(ar1.get(i).toString())); staff.appendChild(tag1); Element tag2 = doc.createElement("tag2"); tag2.appendChild(doc.createTextNode(ar2.get(i).toString())); staff.appendChild(tag2);
} TransformerFactory transformerFactory = TransformerFactory.newInstance(); Transformer transformer; try { transformer = transformerFactory.newTransformer(); DOMSource source = new DOMSource(doc);
StreamResult result = new StreamResult(new File("d:\\file.xml")); // Output to console for testing // StreamResult result = new StreamResult(System.out); transformer.transform(source, result); System.out.println("File saved!"); } catch (TransformerConfigurationException e) { // TODO Auto-generated catch block e.printStackTrace(); } } catch (ParserConfigurationException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } } } Output:
<Root> <Value id="1111"> <tag1>check1</tag1> <tag2>2</tag2> </Value> <Value id="1122"> <tag1>check2</tag1> <tag2>12</tag2> </Value> <Value id="1133"> <tag1>check3</tag1> <tag2>22</tag2> </Value> <Value id="1441"> <tag1>check4</tag1> <tag2>32</tag2> </Value> <Value id="1155"> <tag1>check5</tag1> <tag2>42</tag2> </Value> </Root>
myTextToBeSplit ); ArrayList ar=new ArrayList(); while ( tok.hasMoreTokens()) { String word = tok.nextToken(); ar.add(word); } for(int i=ar.size()-1;i>=0;i--){ System.out.print(ar.get(i)+" "); } } } Output: Boy a is He 4) Find missing odd number in an sequence order of odd numbers Coding: import java.util.ArrayList; public class Odd { public static void main(String args[]){ int ar[]={1,3,5,9,13,17,25,35}; ArrayList ar1=new ArrayList(); System.out.println("Missing Odd Numbers:"); for(int i=0;i<ar.length-1;i++){ int k=ar[i+1]; int l=ar[i]; int n=k-l; if(n%2==0){ if(n!=2&&n>2){ for(int j=2;j<n;j+=2){ System.out.println(l+j); } } } else{ System.out.println("-----------------------"); System.out.println(ar[i+1]+"is even number"); } } } } Output:
READ MORE
SOCIAL PROFILE
Popular @Mykodes
Tag
Blog Archives
Pointel Solution Park,Chennai Ja Technical writte Interview Questi First round,Techn for java candidate questions. 1)Fibo series cli 2)Prime Numbe...
Differnce betwee and jdk 1.7 JDK 1.6 JDK 1.7 was released as Java SE1.6. JDK released as part
Convert Tiff Ima Jpeg using java Convert Tiff Imag using java We ne com.sun.media.ja for convert Tiff im The sun.media.ja
Create from .b exe file window Create Services f file or exe file 1.T
--------------------------
Windows NT user service, perform following steps: DOS comm... READ MORE
Home Older Posts
Write a program Number using ja A prime number ) is a natural num than 1 that has no divisors other tha itself. A natural nu
Look a Method java import j import java.awt.e import javax.swin class newlookAnd JFrame fr; JTex txtArea; public .
Disable refresh using javascript This coding is use disable refresh bu F5 button in brow the eb page is run <html> <head>
Write a program Fibonacci series in java import java.lang.S import java.util.*; class fib{ int i1=0,i2=0,i3=1,n; Scanne Scanner...
Highest common mathematics, also greatest common Now this program find the HCF for t numbers...
HTML File in Ecl Application View HTML File in Eclip Application ViewP article is show ho local html file in y rcp application.He
Powered by Blo
BLOG ARCHIVE
Op
Novem
Octob
Augus
July (2 June
May (3
April (1
March
Februa
TOTAL PAGEVIE