Saturday, February 27, 2010

ThreadLocal Example in Java

To share a some object associated or linked with 1 thread at any point of time and do not want to modify this value by any other thread then ThreadLoal is useful.This also avoids no need to think about synchrniation,because each thread maintain's it's own copy.

public class ThreadLocalExample extends Thread {

private static int nextSerialNum = 0;
private static ThreadLocal serialNum = new ThreadLocal() {
protected synchronized Object initialValue() {
return new Integer(nextSerialNum++);
}
};

public static int get() {
return ((Integer) (serialNum.get())).intValue();
}

public void run() {
for(int i=1;i<30;i++)
    System.out.println("Name : " + Thread.currentThread().getName() +" Value : " + get());
  }

  public static void main(String[] args) {
    Thread t1 = new ThreadLocalExample();
    Thread t2 = new ThreadLocalExample();
    Thread t3=new ThreadLocalExample();
    t1.start();
    t2.start();
    t3.start();
  }
}

For more information on ThreadLocal class usage http://java.sun.com/j2se/1.4.2/docs/api/java/lang/ThreadLocal.html

To understand this concept more clearly execute the above program and observe the output.

Monday, February 22, 2010

Struts Layout Tree View Example

Struts Layout provide so many features for Struts developers,
so if you want to know about more information on struts-layout visit http://struts.improve-technologies.com/.

To know about what the features are there in practical some programming example requried.

To download struts layout tree view example click any of the bellow links
Mediafire  :   http://www.mediafire.com/?mzk2mcmw4bl

how to read excel file in java

To read Excel file in java using Jakarta POI  (or) JExcel API  visit the following url
http://blog.taragana.com/index.php/archive/how-to-read-write-excel-spreadsheet-from-java/.

To download POI Jar file Click Here

Sunday, February 21, 2010

How to Write and Read Some Content into (or from) File Using Java Script

To write some content into some file or read content from file and wants to store all file content in one variable and wants to dispaly this as a alert or some thing the following program will be helpful.This works in Internet Explorer.
Code:
<HTML>

<HEAD>


<SCRIPT language="JavaScript">


function WriteAndReadFile()

{

var fso = new ActiveXObject("Scripting.FileSystemObject");

var fh = fso.CreateTextFile("D:\\Test.txt", true);

fh.WriteLine("Text Example 1");

fh.WriteLine("Text Example 2");

fh.WriteLine("Text Example 3");

var f;

var str;

f = fso.OpenTextFile("D:\\Test.txt", 1);

var s=f.ReadAll();

alert(s);

f.Close();


}


</SCRIPT>

</HEAD>


<BODY>

<P>

<SCRIPT language="JavaScript"> WriteAndReadFile(); </SCRIPT>

</P>

</BODY>

</HTML>

Turbo C Software Free Download

To download Turbo C Software from official web site http://lmgtfy.com/?q=turbo+c+download+antique+software.In that you have to register and then you are able to download freely.

To install C software in Your Windows Operating System copy all Disk2,Disk3 files individually into Disk1 and click install.exe present in your Disk1 which came with your downloaded Zip file.
                                                 (OR)
Simply Click Here to Download

Ajax Tag Library for Server Side Java Applications

Ajax Tag Library from sourceforge.net is good to reduce the maintenance cost of our project developed in servlets,jsp or struts.To know more about this ajax tag library from sourceforge Click Here.

Thursday, February 4, 2010

How to Open Notepad through HTML File

The following program will launch the Notepad by Pressing button in web browser.This works in Internet Explorer only.

<html>
<head>
<script language="JavaScript" type="text/javascript">
function runReport()
{
var rep = new ActiveXObject("WScript.Shell");
rep.Run("C:\\Windows\\system32\\notepad.exe", 1, true);
}

</script>
</head>
<body>
<h1>Run a Program</h1>
This script launch the file >> c:\windows\system32\notepad.exe<p>
<button onclick="runReport()">Run Windows NotePad</button>
</body>
</html>