Archive for March 14th, 2012

Can I convert my WSP into a WAP, without starting from scratch?

Differences between Web Site Projects (WSP) and Web Application Projects (WAP) are highlighted in blogs such as this one. Based on that, if you feel a WAP would be better for your particular needs than a WSP, but have already created a WSP, you may be asking yourself, “Can I convert my WSP into a WAP, without starting from scratch?”.

This posting explains how to convert an existing Web Site Project to a Web Application Project in Visual Studio 2010. The most striking differences to a Web Site Project are that WAPs have a project file to include and exclude files, and compile to a single assembly.

The guidelines below include several of the basic steps detailed in the Walkthrough: Converting a Web Site Project to a Web Application Project in Visual Studio. This is an excellent topic to review as it discusses some specific issues you may encounter which were discovered in previous versions of Visual Studio (VS). Please keep in mind while reading it that it is based on a WSP to WAP conversion using previous versions of Visual Studio.

Let’s get started.

Open and Verify your Visual Studio Web Site Project
Before converting your WSP to a WAP, you should open it in Visual Studio and verify that is it working correctly.  This will help prevent the need to research errors that have nothing to do with the conversion process.

  1. In the File menu, click Open Web Site.

  2. The Open Web Site dialog box is displayed.

  3. Select the project folder that you want to open, and then click Open.

  4. In the Build menu, click Build Web Site.

  5. In the Debug menu, click Start Debugging. Alternatively, you can press F5.

  6. Verify your project compiles and runs as expected

Create a new, empty Visual Studio WAP
A good strategy for converting a WSP to a WAP is to create a new, blank Visual Studio Web Application Project in a separate directory, but in the same solution. This avoids changing any part of the existing Web site files. It also allows you to copy existing functionality and files into the new WAP easily, within the same Visual Studio instance.

  1. In the File menu, click Add, and then click New Project.

  2. The Add New Project dialog box is displayed.

  3. In the Installed Templates section of the Add New Project dialog box, expand the language that you want to use, and then select Web to display the Web-related templates.

  4. Select Empty ASP.NET Web Application.

  5. Type values for NameLocation, and then click OK to create the Web Application Project.

  6. After the project has been created, delete the Web.config file that is created automatically.

Set Project / Assembly References
If the WSP required additional project or assembly references, you need to add them to the WAP. You can see the list of default references associated with the new (empty) Visual Studio Web Application Project under the References node in Solution Explorer.

  1. In the Solution Explorer, make sure Show All Files is turned on.

  2. In the Solution Explorer, right-click References, and then click Add Reference.

  3. The Add Reference dialog box is displayed.

  4. Select the reference that you have already added in the Web Site Project and then click OK.

  5. Note: To help prevent errors, add references to the Web Application Project for assemblies that existed in the \bin folder of the WSP.


Copy and Convert the App_Code folder from the Web Site Project to the Web Application Project
In WSPs, the files in the App_Code folder are all compiled together and then referenced (automatically) as a “dll” by all other files in the WSP. In WAPs, this is not the case. All code is compiled together as one .dll. I’ve found that copying the App_Code folder over first and converting it to the WAP model helps to head off some dependency issues which could arise if one copied the entire site, converted, and then tried to compile.

  1. In the Solution Explorer, copy the entire App_Code folder from the WSP to the WAP

  2. In the Solution Explorerselect the WAP’s root node; right-click, select Convert to Web Application

  3. You will see our standard Convert to Web Application confirmation dialog.  Select “Yes” to this dialog.

  4. The App_Code folder should now be renamed to Old_App_Code folder

  5. Note: Do NOT name it back. As mentioned above, in the WAP model all code will be compiled into one assembly. At runtime, ASP.NET doesn’t know what type of project model you have created and will take anything in the “App_Code” folder and create a dynamic assembly for it, thereby causing “could not load type” exceptions as there would be duplicate types exists in two assemblies (the one for the VS web application and the one for App_Code).  Learn more about why App_Code folder does not work well with WAPs.

  6. Compile the WAP

  7. If you see an error, the most likely causes are:

    1. Missing assembly reference. See the section above to add missing references to your project.

    2. Files marked with Build Action = Content instead of Build Action = Compile. Any file you want compiled should be marked as such.

    3. To set the Build Action property:

      1. Select the file in the Solution Explorer

      2. Press F4 (Brings up the File’s Property Grid)

      3. Look at the Build Action property. Change as necessary.

Copy and Convert the remaining Files and Folders from the WSP to the WAP
Once your Old_App_Code folder is compiled (by compiling your WAP in the step above), your WAP will have an assembly in the \bin directory. This will make it easier for the remaining files you are copying over to successfully compile, especially if they reference or use code in the files contained within that folder.

  1. Select the remaining files / folders from the WSP project and copy them into the WAP.

  2. Make sure not to copy the App_Code folder again.

  3. In the Solution Explorer, right click the root node of the WAP and select Convert to Web Application.

    1. Don’t worry, this won’t affect (or try to reconvert) any files or the Old_App_Code folder you have already converted.

  4. Note: This will cause VS to automatically generate a .designer.cs (or .vb) file for each page, user-control, and master page in the project. Additionally, each .aspx/.ascx will be modified to use the ‘Codebehind’ instead of the ‘CodeFile’ attribute in the Page directive.

    1. Example of the ‘CodeFile’ to ‘Codebehind’ change

      1. WSP file:  <%@ Page Title=”Home Page” Language=”C#” CodeFile=”Default.aspx.cs” Inherits=”_Default” %>

      2. Converted WAP file:  <%@ Page Title=”Home Page” Language=”C#” Inherits=”_Default” Codebehind=”Default.aspx.cs” %>

Compile your WAP
After all the files have been added and converted, you should build your project again to see if there are any compilation errors. At this point, some of the most likely causes of errors are:

  1. Code files set with Build Action = Content. These should be changed to Compile. Refer to the above section.

  2. Missing project or assembly references. See above for steps for adding project or assembly references.

  3. Class name collisions. In the WSP model, each .aspx and associated codefile was compiled together as a separate, individual unit. Therefore, one could have files such as foo\widget.ascx.cs and bar\widget.ascx.cs where the classes were the same. Once these files are moved to a WAP and all compiled together, class name collisions occur with errors something like, “has multiple definitions with identical signatures”. If this occurs, unique class names should be created.

Run your WAP
After completing the above steps and you have a WAP which successfully compiles, you are ready to try running your application. One of the most common problems I’ve seen encountered is the “Unknown server tag ‘SomeTag: Control’ (as it applies to user controls and such)”. This can be corrected in one of two ways.

  1. Add or modify the register directive on the page that is using the control. This will only register it for this specific page.

    1. <%@ Register Namespace”namespace the control is in” TagPrefix=”SomeTag” Assembly=”Name of dll compiled into the \bin folder” %>

  2. Register the control in the Web.config, making it available to all pages in the project

    1. In the <pages><controls> section add the following:

    2. <add tagPrefix=”SomeTag” namespace=”namespace the control is in” assembly=” Name of dll compiled into the \bin folder” />

Hope this helps!

Combining/Using Neural Networks Framework on the NetBeans Platform

Neural Networks on the NetBeans Platform

by Zoran Sevarac, Published February 2011

About this article by Denno secqtinstien

Since my post-graduation, i am a great fan of Neural technology and its techniques. during post graduation i got a change to be in touch with the subject, so making a publish of the article on demand

DownloadNetBeans Platform


The NetBeans Platform is a generic Java Swing application framework that provides GUI components and a module system for the development of custom desktop applications. The best known application on the NetBeans Platform is, of course, the NetBeans IDE, but there are also many other examples that can be seen at the NetBeans Platform Showcase.

Neuroph Studio is a Java neural network development environment built on top of the NetBeans Platform and Neuroph Framework. It is an IDE-like environment customized for neural network development. Neuroph Studio is a GUI that sits on top of Neuroph Framework. Neuroph Framework is a full-featured Java framework that provides classes for building neural networks.

In addition to providing easy-to-use neural network wizards and tools, Neuroph Studio also integrates basic Java development modules from the NetBeans IDE, so developers can create, test, and deploy various Java components based on neural networks in the same environment. Previously, developers usually needed two applications: one for neural network development and one for Java development.

Neural networks are artificial intelligence (machine learning technology) suitable for ill-defined problems, such as recognition, prediction, classification, and control. This article shows how to create some Java neural networks for classification. Note that Neuroph Studio also has support for image recognition, text character recognition, and handwritten letter recognition, which will be covered in future articles.

Note: If you want to install Neuroph Studio and Neuroph Framework so you can try the examples that are described in this article, downloadNeuroph Framework and Neuroph Studio (for Microsoft Windows, Linux, or Mac, depending on the operating system your system is running).

Brief Overview of Neural Networks with Neuroph Studio

Before I show how to create and use neural networks for real-world problems, I’ll first briefly explain what neural networks are and provide some general principles for how they work.

Neural networks are computational models inspired by the way the human brain works. Although they are very simplified models based on known principles about how the brain works, they exhibit some very interesting features, such as learning, generalization, and association capabilities. In addition, they are good at dealing with noisy or incomplete data.

Neural networks are graph-like structures that consist of a set of interconnected nodes called neurons. Each neuron has inputs through which it receives input from other neurons (connected to its inputs) and outputs through which it sends output to other neurons (connected to its outputs). The way in which the neurons are interconnected determines the type of neural network architecture.

In addition to the connection pattern among neurons, network behavior is determined by the processing inside the neurons and so-calledconnection weights. Connection weights are numerical values associated with connections among neurons, and by tweaking these values using an appropriate algorithm (called a learning rule), we can adjust the network behavior.

Typical neuron processing includes calculating the weighted sum of neuron inputs and connection weights and then feeding that value into some function (step, sigmoid, or tanh functions are commonly used). The output of that function represents the output of the neuron.

The Neuroph framework provides all of these neural network components out of the box, regardless of whether you want to create a common type of neural network or a custom neural network.

Neuroph Studio also provides samples that demonstrate the basic principles behind neural networks.

Basic Neuron Sample

The basic neuron sample demonstrates the basic components and processing for a single neuron.

1. To open the basic neuron sample, in Neuroph Studio, select File >New Project > Samples > Neuroph > Basic Neuron Sample.

Figure 1. New Project for Basic Neuron Sample

This basic neuron model consists of the following components:

  • Two inputs, x1 and x2, with corresponding weights, w1 and w2.
  • An input function, which calculates the weighted sum using the following formula: s = (x1*w1) + (x2*w2).
  • A transfer function, which takes the weighted sum as input and calculates the output of the neuron using a simple step function. If the weighted sum is greater then zero, the function outputs 1; otherwise, it outputs 0.

Figure 2. Basic Neuron Sample

2. Try to run this sample and play with the neuron by changing the input and weight values, and then click the Calculate output button.

During a learning procedure, a neuron’s weights are automatically adjusted in order to get the desired behavior. These are the basic principles of how artificial neurons work, but there are many variations depending on the type of neural network.

One neural network type commonly used for many different types of problems is the multilayer perceptron (MLP) network. This network consists of several layers of neurons (at least three) where each neuron from one layer is connected to every neuron in the next layer. The common transfer function for this type of network is the so-called sigmoid function. The architecture of this type of network is shown in Figure 3.

Figure 3. Architecture of a Multilayer Perceptron Network

This type of the network can be used for various machine learning tasks, such as recognition, prediction, approximation, and so on. Neuroph Studio provides a sample that shows how a multilayer perceptron network can be used for classification problems.

Multilayer Perceptron Classification Sample

This sample shows how a multilayer perceptron network can be used to learn complex classification tasks.

1. To run the sample, in Neuroph Studio, select File > New Project > Samples > Neuroph > Multi Layer Perceptron Classification Sample, as shown in Figure 4.

Figure 4. Multilayer Perceptron Network Sample

2. Create a classification task by clicking the feature space (x1, x2).

Left-clicking creates red dots, and right-clicking creates blue dots. Each dot represents an item with two features (x1 and x2).

These items represent data that the neural network should learn in such a way that for a given input (x1 and x2), it can decide whether the input belongs to the blue class or the red class.

Figure 5. Data for the Sample Multilayer Perceptron Network

The number of input features corresponds to the number of input neurons in the neural network, while the number of classification classes usually corresponds to the output neurons. In this example, since we have only two classes, we are using only one output neuron, which should output zero for the blue class and one for the red class.

We also need to set the number of hidden neurons (and layers), which depends on the classification complexity. Hidden neurons are neurons between the input and output layer, and MLP networks may have one or more hidden layers.

3. In the corresponding field, enter the number of neurons that are in the hidden layers. Separate the numbers with a space.

For this simple example, five hidden neurons will suffice.

Besides the number of hidden neurons, we can set some learning parameters, such as Learning Rate, Momentum, Max Error, and Max Iterations, which are typical settings used for Backpropagation (the learning algorithm for MLP).

Leave these as the default values for now, but keep in mind that for different problems, some other values might give better results. These values are always in the range [0, 1].

4. Click the Train button.

The neural network is created and the learning process starts. After a while, you can see the result in the Multi Layer Perceptron Classification Sample tab, as shown in Figure 6.

Figure 6. Results for the Sample Multilayer Perceptron Network

Figure 6 shows how the neural network sees the given data and how it will interpret any other data fed into the neural network.

We can also see how the network learned the given data by looking at the Total Network Error Graph tab. This graph, which is shown in Figure 7, shows how the learning rule tweaked the network weights in order to minimize misclassification (network error).

Figure 7. Total Network Error Graph Tab

We can also look at the neural network itself in the MlpSampleNet1 tab, as shown in Figure 8.

Figure 8. Neural Network Shown in the MlpSampleNet1 Tab

Note that in this image, there are three neurons in the input layer and six in the hidden layer. One neuron in both layers is the bias neuron, which always outputs 1. The bias neuron provides additional internal input.

The preceding example is the simplest possible, and we don’t need a neural network for it. However, we used this example just to show the basic principles when working with neural networks. Neural networks can actually do complex classifications, such as the one shown in Figure 9.

Figure 9. Example of a Complex Classification

You can experiment with different classification problems and learning settings to get a feel for how this works.

Once you train your neural network, you can serialize it as a Java class by clicking the Save button in Neuroph Studio. Then you can deploy it to your application by using Neuroph Framework. Here is the sample code:

// load serialized network from file
NeuralNetwork nnet = NeuralNetwork.load("MySavedNeuralNetwork.nnet");
// set network input which we want to classify
nnet.setInput(0.5, 0.9);
// process input/calculate network
// get networkoutput/classification result
double[] output = nnet.getOutput();

Note: You can create a Java project and run this code directly from Neuroph Studio, but you need to put a reference to the neuroph-2.5.jar file from your project to be able to use this code. The jar file is a Neuroph Framework class library and it is available, along with full Neuroph Framework documentation and source code, by downloading the file.

Creating and Training a Custom Neural Network

The previous examples were created using classification samples from Neuroph Studio. However, you can easily create and train custom neural networks using wizards. To create a neural network and teach the network a classification problem you perform the following tasks:

  • Create a new Neuroph Studio project.
  • Create a neural network using the New Neural Network Wizard.
  • Create a training set using the New Training Set Wizard.
  • Train the neural network using the created training set.

Here are the specific steps.

1. First, create a new Neuroph Studio project by selecting File > New Project > Neuroph > Neuroph Project.

Figure 10. Creating a New Neural Studio Project

2. Enter the name of your project and click Finish.

Figure 11. Specifying the Project Name

3. Create a multilayer perceptron neural network by selecting File > New File > Neuroph > Neural Network.

Figure 12. Creating a Multilayer Perceptron Network

4. Set the type of neural network to Multilayer Perceptron and enter a network name.

Figure 13. Setting the Network Type

You will be asked to set the network parameters.

5. Enter the network parameters values shown in Figure 14 and click Finish.

Figure 14. Setting the Network Parameters

This creates the neural network, as shown in the Figure 15.

Figure 15. Neural Network Is Created

6. Create the training set by selecting File > New File > Neuroph > Training Set.

Figure 16. Creating the Training Set

7. Specify the training set settings, as shown in the Figure 17.

For this example we’ll use the Iris classification data set, which is well-known classification problem data set.

In short, we have four properties and three classes of iris flowers and the classification is a bit tricky. See this Wikipedia article for more details. Note that number of properties corresponds to the number of network inputs, while number of outputs corresponds to the classification classes.

Figure 17. Specifying the Training Set Settings

8. Import the iris data set from this normalized file, which uses tab-separated-values (TSV).

Here we use a normalized data set, which simply means that original values are scaled to the interval [0, 1].

Figure 18. Importing the Iris Data Set

The training set will look like this:

Figure 19. Example Training Set

9. To train the network, click the neural network to open it, select the Iris training set from the training sets list, and click the Train button.

10. Use the default learning parameters in the Set Learning Parameters dialog, and click the Train button.

Figure 20. Using the Default Learning Parameters

In the Total Network Error Graph tab, you can watch how the network error is minimized during the learning procedure.

Figure 21. Total Network Error Graph Tab


This article showed how to use Neuroph Studio along with Neuroph Framework to easily create Java neural networks. More details about neural network theory and practice are beyond the scope of this article, but several resources are provided in the See Also section.

It is very convenient to have an integrated neural network and Java development environment, and Neuroph Studio is the first application to provide this type of environment. Because Neuroph Studio is open source, it is very suitable for education and research, but it is also helpful for Java developers who want to use neural networks as part of their projects.

See Also

About the Author

Zoran Sevarac is a teaching assistant at Belgrade University, Department for Software Engineering, and a researcher at the Laboratory for Artificial Intelligence at Belgrade University. He is also a member of GOAI Research Network. Through his research, he has been working on the development of a Java neural network framework, which was released as the open source project Neuroph. He holds a master’s degree in Information Systems, and he is a Ph.D. candidate. He is also the founder of the local NetBeans community Net Beans User Group Serbia.

Next Generation in Applet Java Plug-in Technology

The Article presented is a clone of the Original Article from sun java :-

Article :-

Applets are back!

It’s time to take another look at Java applet technology for delivering your programs over the web. The Next-Generation Java Plug-in Technology runs applets in a different, more efficient and more reliable way than ever before. Now you can reap the following benefits:

  • Improved reliability
  • Improved user experience
  • Applets launch in the background
  • Built-in JNLP support
  • Per-applet command line arguments
  • Heap size, Java 2D API acceleration options
  • Improved Java/JavaScript programming language integration
  • Improved Windows Vista support
  • Signed applets now work correctly in Protected Mode Internet Explorer

The next-generation Java Plug-in offers a completely redesigned architecture, and is available in the Java SE 6 Update 10. This plug-in provides powerful new capabilities to applets in the web browser, while improving the overall reliability and functionality of applets in a backward-compatible manner.

The most significant new feature of the next-generation Java Plug-in is built-in support for launching applets from JNLP files. Using the JNLP file format as the applet descriptor allows applets to instantly reuse JNLP extensions previously written for Java Web Start applications, and significantly expands the capabilities of applets in many other ways.

A New Way of Executing Applets

The new way of executing applets has architectural similarities to Java Web Start technology, but tighter browser integration. Applets no longer execute in a Java Virtual Machine (JVM) inside the web browser. Instead, a separate JVM machine process is launched to execute applets. By default, only one JVM machine is launched, but you have the opportunity to launch more than one JVM machine, and you get support per-applet command-line arguments, so you can affect heap size or other requests.

Applet Architecture

Figure 1. Applet Architecture


In Figure 1 above, the clouds represent JVM instances. There is a small, headless JVM inside the browser that is used to manage the connections to one or more client JVMs that actually run the applets. In the diagram the Dukes represent applets. One JVM instance is running two applets and the other is running one.

Applets launch directly from JNLP files, make use of the same descriptor used by Java Web Start software, and allow more powerful parameters than the classic “archive”, “code”, and “cache_archive” parameters.

The new plug-in provides:

  • access to advanced JNLP extensions previously available only to Java Web Start software applications. A small set was previously available, with restrictions, and these restrictions have now been removed.
  • access to the JNLP APIs from applets.
  • PersistenceService, DownloadService.
  • control over heap size, command-line arguments, JRE version selection, and auto-download. You have the same capabilities as Java Web Start software for applications.

Now, you use something like the following on the web page:

<applet width="500" height="500">
   <param name="jnlp_href" value="my_applet.jnlp">


Calls to the applet lifecycle methods initstartstop, and destroy are more deterministic, and cross-browser behavior has been improved. The applet class loader cache and the legacy applet lifecycle, required for backward compatibility, are fully supported and the behavior of both has been improved.

The applet behaves exactly like an application started with Java Web Start software. jnlp_href parameter bridges between the web page and the JNLP description of the applet. Applet tag and JNLP file have overlapping mechanisms for specifying things like the width and height.

In general you should use the Deployment Toolkit, also new in Java SE 6 Update 10, to automatically generate the HTML for the applet tag. The deployment advice guide shows how to easily and portably deploy applets using the Deployment Toolkit.

Configuring Applets

Now, it’s also much easier to configure applets in several areas, including heap size, the Java version that needs to be used, classloader cache, borders, and more.

The <applet> tag and the JNLP file have overlapping mechanisms for specifying certain parameters. These conflicts are resolved as follows:

  • width and height: these attributes are always taken from the <applet> tag and not from the JNLP file. The assumption is that the browser knows best how big the applet should be on the web page, and only the browser can support page-relative width and height (for example, width=”50%”).
  • codebase: if the JNLP file specifies an absolute codebase in the <jnlp> tag, then that is used. Otherwise, it is composed using the rules described in the codebase handling section.
  • code: when the jnlp_href parameter is specified, the applet’s main class name is taken from the main-classparameter to the applet-desc tag in the JNLP file, and the code attribute is ignored. Note that this feature allows you to write one applet tag which has a fallback case for the classic Java Plug-in, but which enables more advanced functionality with the new Java Plug-in. See the “Compatibility” section below.
  • Any applet parameters specified using the <param> tag are merged with those specified in the JNLP file. If the same parameter is specified through both the <applet> tag and the JNLP file, the <applet> tag’s version overrides the JNLP file’s version, except for the java_arguments and java_version parameters.
  • The new java_arguments and java_version parameters are unnecessary in JNLP applets. The mechanisms in the JNLP file for requesting a JRE version, or passing command-line arguments to the JVM, are used instead. Command-line arguments and JRE version requests from the JNLP file override those specified in the HTML for the applet.
  • Certain parameters, such as image, boxbgcolor, and so forth are useful early in the applet’s startup process. It may be advantageous to specify such parameters in the HTML instead of in the JNLP file so that they are available immediately upon loading of the web page rather than after the separate downloading of the JNLP file.

In the past, the maximum heap size that could be specified for applets through the Java Control Panel was limited. This limitation is fixed in the new Java Plug-in, and applets can now utilize as much heap space as command-line applications.

  • Specifying a larger-than-default maximum heap size:
    <APPLET archive="my_applet.jar" code="MyApplet" width="300" height="300">      
    <PARAM name="java_arguments" value="-Xmx128m">  
  • Specifying a non-default heap size and a Java 2D hardware acceleration option typically used for applets usingOpenGL through JOGL:
    <APPLET archive="my_applet.jar" code="MyApplet" width="300" height="300">      
    <PARAM name="java_arguments" value="-Xmx256m -Dsun.java2d.noddraw=true">  

An applet may force itself into its own JVM machine instance separate from all other applets if you like:

<param name="separate_jvm" value="true" />


This is useful when migrating certain kinds of desktop applications to work in the web browser.

You can also run a particular applet on a particular version of the JRE, as shown below:

<j2se version="1.4+" ...>
<j2se version="1.5*" ...>


This approach is useful for enterprises that want to QA an applet against a particular JRE version, or the applet supersedes earlier version selection mechanisms like CLSID in Internet Explorer. If a very old JRE version is requested, restrictions are enforced and the user will be prompted if the applet attempts to load unsigned code.

Note that since JNLP support is first available in Java Plug-in in the Java Platform, Standard Edition 6 (Java SE 6) Update 10, version specifications like “1.4+" are basically meaningless. This will have more meaning when “1.7+" is needed.

In addition, you can use the <update> tag in the JNLP file to drastically reduce startup time for second and subsequent launches:

<update check="background">


In this case, it will use the version of the applet that is already in the cache, and downloads updated versions of the applet in the background. At the next launch, the new version is picked up.

The new plug-in also offers better customization of the image, which is displayed before the applet is loaded. Animated GIFs are now supported as the target of the image parameter, as described in the Special Attributes section of the Java Plug-in Developers’ Guide. Additionally, the following new parameters are now supported:


A boolean parameter indicating whether a one-pixel border should be drawn around the edge of the applet’s area while displaying the image shown before the applet is loaded. Defaults to true. We recommend setting this value to false, in particular when using an animated GIF as the loading image, to avoid the possibility of flicker.


A boolean parameter indicating whether the loading image should be centered within the area of the applet instead of originating at the upper left corner. Defaults to false.

Example using the boxborder and centerimage parameters:

<APPLET archive="large_archive.jar"
	   width="300" height="300">
  <!-- Use an animated GIF as an indeterminate progress bar
	   while the applet is loading -->
  <PARAM NAME="image" VALUE="animated_gif.gif">
  <!-- Turn off the box border for better blending with the
	   surrounding web page -->
  <PARAM NAME="boxborder" VALUE="false">
  <!-- Center the image in the applet's area -->
  <PARAM NAME="centerimage" VALUE="true">



It’s now much easier to maintain backwards compatibility. You can author content that runs with earlier versions of Java Plug-in, but which takes advantage of new features by simply providing a fully-formed <applet> tag as well as thejnlp_href parameter. Earlier JRE versions ignore the jnlp_href parameter, and use the <applet> tag instead. The new Java Plug-in technology ignores the archive and code parameters and use only the JNLP file to launch the applet.

Example World Wind Applet

The NASA World Wind Java applet example, by the World Wind Java development team, illustrates how to deploy leading-edge libraries like NASA World Wind Java, as well as how to effectively combine HTML and content in a web page using JavaScript.

World Wind Applet

Figure 2. NASA World Wind Applet


The web page contains information about the Cascade mountain range (thanks to Wikipedia) and embeds World Wind Java as an applet to illustrate the locations of the mountains in the range. Incorporating World Wind in a web page is remarkably easy. Here is the <applet> tag embedding it on the page:

<applet id="wwjApplet" width=600 height=380             
<param name="jnlp_href" value="WWJApplet.jnlp">     


The WWJApplet ships with the standard World Wind Java distribution. You might choose to write your own applet class and embed World Wind inside it, as described below:

Here are the relevant portions of the WWJApplet.jnlp file:

<jnlp href="WWJApplet.jnlp">
<resources os="Windows">         
<property name="sun.java2d.noddraw" value="true"/>       
<j2se href="" version="1.4+"/>         
<jar href="worldwind.jar" main="true" />         
<extension name="jogl"            
 href="" />       
<applet-descname="WWJ Applet"           
<!-- Overwritten by the surrounding web page -->           


Some items to note:

  • worldwind.jar is used as the main jar in this example. Ideally, it would be referenced as an extension JNLP from NASA’s web site, which allows many different applications or applets all embedding World Wind to share the same downloaded jar file. See below for more details.
  • World Wind Java uses the Java Binding to the OpenGL API, JOGL, for its hardware-accelerated 3D graphics. Note that the JOGL JNLP extension is incorporated into the application with a single line of code. Note also that on the Windows platform it is necessary to specify the system property -Dsun.java2d.noddraw=true due to driver-level conflicts between the OpenGL API and the DirectDraw/Direct3D APIs used by the Java 2D implementation by default on the Windows platform. This system property is needed on Windows for all applications and applets using JOGL.

The HTML links on the web page call JavaScript functions which interact with the applet to navigate it to the appropriate mountain. Here is an example of one of these links:

<a href="javascript:gotoLocation(MOUNT_RAINIER);">Mount Rainier</a>     
  (southeast of Tacoma, Washington) ...


When the link is clicked, the JavaScript function gotoLocation is called. It is defined on the same web page:

function gotoLocation(locationString) {        
 var params = locationString.split(';');        
 if(params.length == 3)	// Lat/lon         
 parseFloat(params[2]));        ...     }


The locations of the mountains are encoded as JavaScript strings in the HTML of the web page. The latitude, longitude, and other viewing information is parsed out of these strings and passed into the applet. The gotoLatLon method is defined on theWWJApplet class; the above call to this method initiates a JavaScript-to-Java call, passing the parameters from the JavaScript engine to Java. The World Wind applet takes in this notification and animates the viewpoint to the appropriate place. Note that the gotoLatLon method returns quickly, so that the browser is not waiting for it to complete; the animation is performed on a separate Java thread.

Mt. St. Helens

Figure 3. World Wind Applet with Mount St. Helen’s Clicked


As mentioned above, the preferred method of incorporating World Wind Java into your application or applet is as a JNLP extension. This allows the World Wind code resources to be shared among many applications or applets from around the web which incorporate it. To reference the World Wind JNLP extension, you would add the following lines to your application’s or applet’s JNLP file in the <resources> section:

<extension name="worldwind" href=""/>     
<extension name="jogl"       


Note that the World Wind extension JNLP is versioned, so you would need to consult the World Wind documentation or visit the forums to find the most current version to reference from your JNLP. The World Wind Central site is a useful source of up-to-date information on World Wind.

Using World Wind as an extension implies that you can not use the WWJApplet as your main-class directly. Due to the semantics of the JNLP file format, the main jar (main="true") must be defined in the main JNLP file. This is an easy restriction to satisfy, however. You can simply create your own subclass of WWJApplet (call it MyWWJApplet) which does nothing:

class MyWWJApplet extends WWJApplet {}


Compile this with worldwind.jar on the classpath, and then bundle this class into its own jar file. Reference that as your main jar and MyWWJApplet as your main-class, and then pull in World Wind as the extension JNLP.


The introduction of JNLP support in the Java Plug-in opens up many new possibilities for applet deployment and represents a large step forward in the unification of the deployment of Java content both in and out of the browser. Applets have come a long way since their inception, and now with the JNLP support, they’re faster and more customizable than ever.

Communicating with java using javascript

Downlaod Source Sample: – Here


  1. The ideas for the Demo Chat application included along with this article are from one of my pen-friend. All chat applications I’ve seen are either entirely Java based or HTML based.
  2. The technical information for communicating between Java and JavaScript has been gathered from reading numerous articles on the Netscape Developer site.
  3. He first came across the term ‘Faceless applet’ while reading an article by Danny Goodman (The JavaScript Apostle on the Netscape site). Thus he and I give credit to Danny for coining this very apt term.


  1. The techniques discussed in this article were tested using Internet Explorer 5.0 and Netscape Navigator 4.7 on a Windows 2000 Professional machine. To the best of my knowledge, these techniques should work using versions 4.0+ of either browser but cannot guarantee this since I did not have the time to test it out with all these versions.
  2. Since JavaScript is the only language that is supported out-of-the-box with both the major browsers, all scripting code fragments use this language. I have previously used a commercially available plug-in from that enables VBScript support within Netscape Navigator but when I went to their site to verify the information, the product is no longer listed there.


I have been living and breathing modern COM for over two years now as a technical lead on the toolkit team of my company’s eCommerce product. I have understood the significance of well-designed interfaces and of implementations that work well within various environments like Visual C++, Visual Basic as well as scripting. The power of interface-based programming is forever entrenched in my mind and I try to apply it to everything I am involved in as a software engineer.

Over the past one year, experience has taught our industry that all business logic should be encapsulated within COM objects while ASP + Scripting should be used only as glue for these objects. Designing and developing infrastructure and business objects typically requires a higher skillset as compared to what is required to actually use the same. The preferred environment for developing these objects (at least in my organization) is Visual C++ / ATL / STL. Microsoft is also promoting Visual Basic as an alternative development environment for these objects.

These objects are typically referred to as faceless because they implement a lot of logic but no user interface. The presentation tier is either a rich or thin client that has logic to present information to and gather information from the end user. Such a client then uses the faceless objects to do something meaningful with that information. The whole idea is that the presentation tier typically requires a lot of customization while the business objects do not change as frequently. The changes required for the presentation tier can also be implementedusing less experienced programmers.

Applying these same principles to the browser environment, it seems logical to encapsulate sophisticated client side logic within faceless, binary modules while using a scripting language to handle the presentation aspects. The options for these modules on the Windows platform are Java applets and ActiveX controls / servers. The focus of this article is on using Javaapplets for achieving this goal because applets are browser, platform and processor independent (for the most part).

A brief history of applets

SUN Microsystems introduced Java applets with much fanfare back in 1995. Applets immediately took the web world by storm because they added the ability to display dynamic web content within browsers in what was essentially a static HTML world.

During those initial days, it appeared that using Java applets was the best way to add dynamic content to web pages. Microsoft initially tried to counter SUN’s offering with their ActiveX Control technology but there are two primary issues with using controls within webpages:

  • These are binary modules that are processor specific and hence not very suitable for running as part of a web page. One of the primary reasons that the World Wide Web is so successful is the fact that web pages written using W3C standard HTML are (for the most part) browser and processor agnostic. ActiveX Controls just do not fit within this paradigm.
  • Security is a big problem because the control writer has full access to the resources on the client machine. Signed controls allow anyone viewing a web page to make intelligent decisions about whether a particular control should be downloaded on his / her machine but all it takes is an accidental (or blissfully ignorant) click of a button to leave the client machine vulnerable to the intentions of some malicious control writer.

When Dynamic HTML finally started taking shape, things changed drastically. The Document Object Model (DOM) exposes elements within a web page as programmable components with their own set of properties and methods. Even though the implementation of dynamic HTML within the Internet Explorer and Netscape Navigator browsers is vastly different, the underlying theme of programmatically changing content using scripting code within the displayed page itself was a BIG hit. Applets suddenly started to look old and primitive. The W3C’s endorsement of Dynamic HTML finally set the tone for the new breed of sophisticated, dynamic web pages.

There are several advantages to using Java applets within a browser as listed below

  • Applets work (for the most part) on multiple browsers, platforms and processors.
  • The Java language is a typed language with powerful constructs.
  • The JDK comes with many useful classes that are typically found only in a high-level class library.
  • Security is designed into the technology and applets run within a sandbox by default.Applets must be signed if they are to break the constraints of the sandbox.
  • Applets can communicate back to the web server for sending customized messages, uploading / downloading files etc. Signed applets can communicate to any server, not just the one that hosts them.
  • The applet code is not viewable using the browser’s ‘View Source’ option and thus protects intellectual property.
  • The Java .class files are very compact in size, resulting in faster downloads.

The disadvantages to using applets are

  • Within a browser session, applets are downloaded either the first time that a pageusing them is displayed or if the page is later refreshed. The applet code is not resident on the client machine between browser sessions. This can actually be considered as an advantage in most situations.
  • Applets take a long time to initialize.
  • Since the Java .class files are byte codes that are interpreted by the Java virtual machine (JVM), applets run slower than native code.
  • An applet is just a piece of real estate on the web page and does not appear seamlessly integrated into the page contents. Cascading style sheets do not directly affect the rectangular area occupied by an applet.
  • Netscape Navigator 4.x has a limitation of ten (10) active applets. I am not aware of any such limitation with Internet Explorer 4.0+.

A quick overview of using Java applets

Java applets are included in an HTML page with the applet tag. Section 13.4 of the HTML 4.01 Specification on the W3C site documents this tag in detail. It also mentions that this tag is deprecated in favor of the <object> tag.

A sample HTML page containing an applet is shown below:

<html><BR><head><BR><title>Calculator</title><BR></head><BR><body><BR><applet id="Calculator" width="300" height="500" code ="Calculator.class" codebase="."><BR><param name="InitialMode" value="Normal"><BR></applet><BR></body><BR></html>

The attributes used in the above example are explained below.

Id The identifier for the applet instance. Client side scripting code can refer to the applet using this id.
Width This attribute specifies the initial width of the applet’s display area (excluding any windows or dialogs that the applet creates). Even though I have successfully used a width of zero (0) with the browsers mentioned in the Disclaimers section, it is recommended to use a value of 1 as the smallest width possible.
Height This attribute specifies the initial height of the applet’s display area (excluding any windows or dialogs that the applet creates). Just like with the widthattribute, a value of 1 is recommended as the smallest height possible.
Code This attribute specifies either the name of the class file that contains theapplet’s compiled applet subclass or the path to get the class, including the class file itself. It is interpreted with respect to the applet’s codebase.
Codebase This attribute specifies the base URI for the applet. If this attribute is not specified, then it defaults the same base URI as for the current document.

Only the codewidth and height attributes are required.

The <param> tag contains name value pairs that allow the applet to be configured when it is first started up.

A sample JavaScript function that invokes a method on the above applet is shown below.

<script language="Javascript"><BR>function SetCalculatorMode(Mode)<BR>{<BR>    document.Calculator.SetCalculatorMode (Mode);<BR>    <FONT
    COLOR="GREEN">// Alternative way to reference the applet.</FONT><BR><FONT
    COLOR="GREEN">    // document.applets[0].SetCalculatorMode(Mode);</FONT><BR>}<BR></script>

Division of labor

In the Introduction to this article, I suggested an approach wherein the sophisticated browser side processing is encapsulated within faceless Java applets while the presentation is managed by JavaScript code. This approach requires bi-directional communication betweenJava and JavaScript. The next few paragraphs investigate the available options.

Accessing public members and functions exposed by a Java applet from JavaScript code is straightforward as demonstrated in the SetCalculatorMode() function in the previous section. An applet within a document is referred to either using it’s Id / Name or using an index into the applets collection.

For example,

    document.Calculator.SetCalculatorMode(Mode);<BR>    <FONT
    COLOR="GREEN">// or</FONT><BR>    document.applets[0].SetCalculatorMode(Mode);

Communication in the other direction (Java to JavaScript) is achieved using thenetscape.javascript.JSObject and netscape.javascript.JSException classes. In order to find out where these .class files are located, I searched my hard-drive for all files that contained the text “JSObject”. To my surprise, these files are widely used in many different applications, including the Scripting Library that is part of any Visual Interdev project.

If Netscape Navigator 4.0+ is installed on your machine, these .class files are available in theJava40.jar file which itself is located in the <Navigator Installation Directory>\communicator\program\java\classes directory.

I also found these .class files in four different .zip files located in the <Windows Installation Directory>\Java\Packages directory. These .zip files were obviously installed by Microsoft products because they contain many packages. The point is that these two classes are available with either browser and you can set your CLASSPATH environment variable to any of the above paths. An alternative approach is to extract these files from the .jar or .zipfiles into your applet’s directory using a utility like WinZip.

The JSObject class

A brief description of the JSObject class’ member functions is included for better understanding the usefulness of this class.

public static JSObject getWindow (Applet applet )

This static method returns a JSObject for the window containing the givenapplet. For example,

JSObject MainWindow = JSObject.getWindow ( this );

public Object call ( String methodName, Object args[ ] )

This invokes a JavaScript method from within a Java applet. For example,

JSObject MainWindow = JSObject.getWindow ( this );<BR>String Arguments[ ] = {"90", "2"};       <FONT
     COLOR="GREEN">// {"Percent complete", "Time remaining"}</FONT><BR> ( "UpdateProgressIndicator", Arguments );

public Object eval ( String s )

This method evaluates a JavaScript expression. The expression is a string ofJavaScript source code, which will be evalauted in the context given by this. For example,

JSObject MainWindow = JSObject.getWindow ( this );<BR>JSObject UserName = MainWin.eval ( "document.UserInfoForm.UserName" );

public Object getMember ( String name )

This method retrieves an indexed member of a JavaScript object. Equivalent in JavaScript. For example,

JSObject MainWindow = JSObject.getWindow ( this );<BR>JSObject DocumentPage = (JSObject)MainWindow.getMember ( "document" );<BR>JSObject UserInfoForm = (JSObject) DocumentPage.getMember ( "UserInfoForm" );<BR>JSObject UserName = (JSObject) UserInfoForm.getMember ( "UserName" );

public Object getSlot ( int index)

This method retrieves an indexed member of a JavaScript object. Equivalent tothis [index] in JavaScript. For example,

JSObject MainWindow = JSObject.getWindow ( this );<BR>JSObject DocumentPage = (JSObject)MainWindow.getMember ( "document" );<BR>JSObject Applets = (JSObject) DocumentPage.getMember ( "applets" );<BR>Object theApplet = Applets.getSlot ( index );

public void removeMember ( String name )

This method removes a named member of a JavaScript object.

public void setMember ( String name, Object value )

This method sets a named member of a JavaScript object. It is equivalent = value in JavaScript. For example,

JSObject MainWin = JSObject.getWindow ( this );<BR>JSObject DocumentPage = (JSObject) MainWin.getMember ( "document" );<BR>JSObject UserInfoForm = (JSObject) DocumentPage.getMember ( "UserInfoForm" );<BR>JSObject UserName = (JSObject) UserInfoForm.getMember ( "UserName" );<BR>UserName.setMember ( "value", "Jeremiah S. Talkar" );

public void setSlot ( int index, Object value )

This method sets an indexed member of a JavaScript object. It is equivalent tothis[index] = value in JavaScript.

public String toString ()

This method converts a JSObject to a string.

As is clear from the examples presented above, the public methods of the JSObject class are not restricted to invoking JavaScript functions from within a JavaApplet. They also enable an applet to directly manipulate the Document Object Model (DOM) elements.

Full documentation on these classes is available at

The documentation also explains how data types are handled between Java and JavaScript.

Significance of the MAYSCRIPT attribute

Even if an applet uses the JSObject to invoke JavaScript functions or to directly access the Document Object Model, the JSObject methods will fail if the <applet> tag does not include the MAYSCRIPT attribute. This enables the page designer to determine if an applet can call out to JavaScript.

Communication between faceless applets

When using faceless, reusable Java applets within a web page, it is possible that oneapplet may need to directly communicate with another. Such a call could also be channeled through an intermediate JavaScript function but it is always better to know all the available options.

The AppletContext interface in the java.applet package gives an applet limited access to the applet’s context of execution like the browser that the applet is runing in, the webpage the applet is on as well as other applets on the same page.

For example, here is an HTML page that contains two applets.

<html><BR><head><BR><title>Communication between applets</title><BR></head><BR><body><BR><applet code="CircleArea.class" name="CircleArea" width=1 height=1><BR></applet><BR><applet code="PICalculator.class" name="PICalculator" width=1 height=1><BR></applet><BR>...<BR></body><BR></html>

The following code shows usage of the AppletContext object.

    AppletContext context = getAppletContext();<BR>    PICalculator PIApplet = (PICalculator) context.getApplet ( "PICalculator" );<BR>    PIApplet.getValueOfPI();

Another option is to use the AppletContext::getApplets() method which returns an enumeration to access all the applets within the document. Even though communications between applets is part of the standard Java applet API, it is not supported in all Javaenabled browsers. Hard-coding names of other applets is also inflexible. The best approach may well be to use an intermediate JavaScript function to handle such communication.

IUnknown::QueryInterface in Java

Class Object is the root of the class hierarchy. Every class has Object as a superclass. All objects, including arrays, implement the methods of this class. The Object::getClass()method returns ‘Class’ which has many useful functions to discover the details of the Javaclass itself. While a detailed explanation is beyond the scope of this article, I would like to point out the getInterfaces() method that enables dynamic discovery of the interfaces implemented by a Java class.

I have not tried invoking the getClass() method from within JavaScript and hence cannot comment on it’s feasibility. But using an infrastructure type applet, this functionality can be easily made available to scripting code.

Installing the sample files

The sample code for this article is packaged in the file. The sample files demonstrate a chat application that has been simplified to route messages on the client side itself. In real life, the users participating in a chat are on separate machines and a message is sent to a server that then broadcasts it to all the participants.

The files that comprise the sample are Source file that defines the ISession interface.
ISession.class Java byte-codes for the ISession interface. Source file for the demo ChatClient applet.
ChatClient.class Java byte-codes for the ChatClient applet class.
CompileChatClient.bat A primitive makefile for the java source files.
TestChatClient.htm HTML file that hosts the ChatClient applet.
JSObject.class Byte-codes for the JSObject class.
JSException.class Byte-codes for the JSException class.

The steps to install and run the sample program are

  • Unzip the file into a directory of your choice on a machine running an instance of either Personal Web Server or Internet Information Server.
  • Ensure that the JSObject and JSException class files are available in the netscape\javascript subdirectory under the installation directory.
  • Right-click on the installation directory and select ‘Properties’.
  • Click on the ‘Web Sharing’ tab and select the ‘Share this folder’ radio button, accepting the default ‘Virtual Directory’ shown in the dialog that pops up.
  • Finally, start an instance of either Internet Explorer 4.0+ or Netscape Navigator 4.0+ and enter the URL http:// <machine name>/<virtual directory>/TestChatClient.htm.

Enter some text into the two input fields and click on the corresponding ‘Send’ button to see the message displayed in the chat window.

Sample code explained

Chat applications are a popular collaboration mechanism on the web. The two types of chat applications that I have seen are

  • A Java applet that manages the user interface as well as all communication to the server.
  • An HTML page that is auto-refreshed every few seconds to display any new chat messages that have been sent since the last refresh.

Recently I had to implement a production quality chat application for our eCommerce product. After a lot of thought, I decided to use a hybrid approach. First and foremost, the Javaapplet is a faceless applet that implements the ISession interface.

public interface ISession<BR>{<BR><FONT
    COLOR="GREEN">    // Type is used to differentiate the actual message string </FONT><BR><FONT
    COLOR="GREEN">    // and can be set to ‘Text’, Hyperlink’ etc.</FONT><BR><BR><FONT
    COLOR="GREEN">    // Should be invoked first to indicate to the server that a </FONT><BR><FONT
    COLOR="GREEN">    // new person has joined the chat.</FONT><BR>    public int BeginSession(String strAuthor, String strOptions, String strType, String strMessage);<BR>    <BR><FONT
    COLOR="GREEN">    // Should be invoked when the author wants to exit the chat.</FONT><BR>    public int EndSession(String strAuthor, String strType, String strMessage);<BR><BR><FONT
    COLOR="GREEN">    // Used to send the chat messages.</FONT><BR>    public int SendMessage(String strAuthor, String strType, String strMessage);<BR>}

I have modified this interface slightly from the production version of the Chat application to include the Author parameter for both EndSession() as well as SendMessage(). This is because my demo uses one applet to channel chat messages from two different authors.

The file is the actual implementation of the ISession interface. The functionsinit()start() and stop() are invoked by the browser if they are implemented. The JSObject representing the document window is acquired during the init() method.

    COLOR="GREEN">    // Get the JavaScript window that will have the various scripts that this applet will call.</FONT><BR>    m_JScriptWin = JSObject.getWindow(this);

Since the Java applet calls out to two different JavaScript functions, I decided to enable the web developer to be able to specify the names of these functions as paramerters to theapplet, while providing defaults for the same.

m_strMessageHandler = getParameter("MessageHandler");<BR>m_strErrorHandler = getParameter("ErrorHandler");

BeginSession() and EndSession() are dummy implementations that just callSendMessage().

SendMessage() calls the JavaScript function whose name is specified in the m_strMessageHandler member variable. The default value is “HandleSessionMessage”. The relevant code is shown here.

if (m_JScriptWin != null)<BR>{<BR>    String Arguments[] = {strAuthor, strType, strMessage};<BR>, Arguments);<BR>}

HandleSessionError() invokes a JavaScript function whose name is specified in them_strErrorHandler member variable. The default value is “HandleSessionError”.

The TestChatClient.htm file deals with the presentation aspects of the chat. The applet is included on the page using the <applet> tag.

<applet id="ChatApplet" width="1" height="1" code="ChatClient.class" codebase="." VIEWASTEXT mayscript><BR><param name="MessageHandler" value="HandleSessionMessageEx"><BR><param name="ErrorHandler" value="HandleSessionErrorEx"><BR></applet>

The parameters specify names for the two JavaScript functions that the applet invokes. I’ve just indicated names other than the default to demonstrate how flexible this can be.

The two forms on the page simulate two people chatting with each other. The corresponding HTML is straightforward.

The actual messages themselves are displayed within the ChatMessages <DIV>. In the case of Internet Explorer, I use the Table Object Model to display each message in a separate row. Hence the ChatMessagesTable definition within the above DIV.

Finally, the HandleSessionMessagesEx() JavaScript function handles all the presentation aspects. Within Internet Explorer, a new row is added to the ChatMessagesTable table for every message that is sent. The scrollbar is displayed if required. Within Netscape Navigator, I append the new message to the Messages variable and use the latter to update the ChatMessages <DIV>. Since scrollbars cannot automatically be displayed within a Netscape <DIV> (which is really a LAYER), I display the last message received at the top. I have found articles on how to support scrollbars for LAYERs within Navigator, but that is not relevant for this demonstration.

Final Thoughts

This article attempts to present some (neat) techniques for implementing your browser side logic. As I have mentioned earlier in the article, the JSObject is widely used by many applications, including Microsoft Corporation. All the same, carefully consider your individual situation to determine if the techniques presented here are applicable.

As for the demonstration sample that accompanies this article, I feel that allowing the presentation of the chat to be implemented in JavaScript / DHTML enables this code to be maintained by an entry level / junior programmer. Customization of the user interface is also easier using DHTML / JavaScript. Additionally, it allows for more powerful presentation techniques that seem consistent with the rest of the page contents.

In the production version of this application, I’ve added support for exchanging hyperlinks that open up on the participant’s machine, dynamic selection of colors for messages usingcascading style sheets etc.

Java.NET : Integrating Java with DotNET

Download sample :- From Here


This article describes how we can integrate Java with Microsoft Technology. Sometimes we may need an application where we integrate both technologies. I am writing this article keeping all beginners in mind, so they can learn something from it. This article describes how we can call some Java methods from .NET code, and pass some values to Java or .NET and vice versa. This is a simple ASP.NET application, which interacts with Java Applets while performing another  operation. The application is very simple to do, but the main thing behind the scene is the idea and implementation logic.


I have used two IDE for this Application

  1. Visual Studio 2005
  2. Eclipse

This digaram describes the main flow between Java and .NET.

FlowThe main concept behind the scene is Applet, I have created a JAR file which contains one applet and I have called Java methods using applet from .NET. Once you get the datausing JavaScript, it is up to you to decide how you going to use it on the server side.

Using the Code

First of all, we have to create a JAR file using Java. As I already explained, I have used Eclipse, just take a look the hierarchy of my Java applet and function.


I have created these methods and created a “Jar” file, named JavaNet.Jar. Now I am going to interact with this using .NET. The following is the Java Applet code.

//Welcome Methods will call from .NET
public void WelcomeToJava()
  JOptionPane.showMessageDialog(null,"Hi .NET Welcome To Java");
//Return Value To .NET
public String  MessageForNetFromJava()
 return "Hi .NET, Nice To Meet you !!";
//Take Argument from .NET and Reply
public String MessageFromNETServerSide(String Message)
 return "From Java : " + Message ;

Now, in the ASP.NET page, I have used an Applet tag for invoking the applet. Now from the ID, MyJavaApplet, I can call any Java methods from file.


The following is the JavaScript I’m using to call all Java methods

var ID= "<%=txtnum1.ClientID%>"; //Read Client ID of TextBox
//Call Java Welcome Message
function btnCallJava_onclick()
// Get Message From Java
function btnNetMessage_onclick() {
var message=MyJavaApplet.MessageForNetFromJava();
//Pass Argument To Java Methods
function btnServerValueSend_onclick()
   var Message= document.getElementById(ID);
   var result=MyJavaApplet.MessageFromNETServerSide(Message.value);


Call Welcome Message


Send Server Side Value To Java


Get Message From Java


Points of Interest

.NET and Java, both are leading the world’s technology, and by integreting both of them we can do anything we want to do .

%d bloggers like this: