Click here to Skip to main content
11,497,795 members (37,461 online)
Click here to Skip to main content

Java.NET : Integration of Java and .NET

, 26 May 2008 CPOL 54.5K 1.1K 45
Rate this:
Please Sign up or sign in to vote.
A Approch To Integrate Java with .NET Web Application
Java_Net_Logo.gif Download IntegratedNETJavaWeb.zip - 4.21 KB

Introduction

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.

Background

I have used two IDE for this Application

  1. Visual Studio 2005
  2. Eclipse

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

Flow

The 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 data using 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.

JAVA_Tree.JPG

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.

Applet.JPG

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() 
{
MyJavaApplet.WelcomeToJava();
}
// Get Message From Java
function btnNetMessage_onclick() {
var message=MyJavaApplet.MessageForNetFromJava();
alert(message);
}
//Pass Argument To Java Methods
function btnServerValueSend_onclick()
 {
   var Message= document.getElementById(ID);
   var result=MyJavaApplet.MessageFromNETServerSide(Message.value);
  alert(result);
}

OutPut

Call Welcome Message

CallJava.JPG

Send Server Side Value To Java

ServerText.JPG

Get Message From Java

MessageForNet.JPG

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 .

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Abhijit Jana
Technical Lead
India India
.NET Consultant | Former Microsoft MVP - ASP.NET | CodeProject MVP, Mentor, Insiders| Technology Evangelist | Author | Speaker | Geek | Blogger | Husband

Blog : http://abhijitjana.net
Web Site : http://dailydotnettips.com
Twitter : @AbhijitJana
My Kinect Book : Kinect for Windows SDK Programming Guide
Follow on   Twitter

Comments and Discussions

 
You must Sign In to use this message board.
    Spacing  Noise  Layout  Per page   
QuestionBrowser hangs when I clicked on Call Java and In my defaul.aspx file under Applet tag code="myjava.net.MyApplet" shows was not found.
sachinsshelake27-Nov-12 21:35
membersachinsshelake27-Nov-12 21:35 
Abhijit I download your code and run locally.But,
browser hangs when I clicked on Call Java and In my defaul.aspx file under Applet tag code="myjava.net.MyApplet" shows was not found.
What "myjava.net.MyApplet" suggest.
GeneralMy vote of 5
Massimo Conti14-Jul-12 4:56
memberMassimo Conti14-Jul-12 4:56 
Very interesting!
Thank you!
GeneralMy vote of 2
Marcelo Lujan [El Bebe.Net ]22-Feb-12 16:56
memberMarcelo Lujan [El Bebe.Net ]22-Feb-12 16:56 
Its a good start, but interoperability is much more than calling an applet
QuestionThanks
sanya.fesak21-Sep-11 19:06
membersanya.fesak21-Sep-11 19:06 
Where to get Java?
Generaljava document
Tarık Murat18-May-10 1:53
memberTarık Murat18-May-10 1:53 
hi, ı tried your method on my project, however it did not work. also, ı create new project with your codes, and it did not work too. but your ".net project" worked correctly. can u put java document to JavaNet.jar. Thanks.
GeneralMy vote of 1
MeneDev10-May-10 7:50
memberMeneDev10-May-10 7:50 
This is not *integrating* Java and .Net
GeneralGreat
Brij23-Dec-08 2:58
memberBrij23-Dec-08 2:58 
Earlier,I haven't any Idea about .Net and java integration.Thanks

Cheers!!
Brij

GeneralRe: Great
Abhijit Jana18-Oct-09 11:25
mvpAbhijit Jana18-Oct-09 11:25 
Thanks Brij !

Abhijit Jana | Codeproject MVP
Web Site : abhijitjana.net
Don't forget to click "Good Answer" on the post(s) that helped you.

GeneralInteresting...
stevjhon17-Oct-08 5:37
memberstevjhon17-Oct-08 5:37 
Interesting Thoughts !!! Blush | :O
GeneralRe: Interesting...
Abhijit Jana18-Oct-09 11:25
mvpAbhijit Jana18-Oct-09 11:25 
Thnks Mate !

Abhijit Jana | Codeproject MVP
Web Site : abhijitjana.net
Don't forget to click "Good Answer" on the post(s) that helped you.

QuestionWhere is the .NET part?
Victor van Hagen26-May-08 9:47
memberVictor van Hagen26-May-08 9:47 
Excuse me but I somehow fail to see where any .NET technology comes into play here (other that serving the html and javascript).
AnswerRe: Where is the .NET part?
Abhijit Jana26-May-08 16:35
memberAbhijit Jana26-May-08 16:35 
check that article. i have read one server side text box value and passed it to applet.

Best Regards
-----------------
Abhijit Jana
Check Out My Latest Article

Java.NET : Integration of Java and .NET[^]
"Success is Journey it's not a destination"

GeneralRe: Where is the .NET part?
N a v a n e e t h26-May-08 17:51
memberN a v a n e e t h26-May-08 17:51 
I second the OP. I can't see any .NET code here. Am I missing something ?

All C# applications should call Application.Quit(); in the beginning to avoid any .NET problems.- Unclyclopedia

How to use google | Ask smart questions

GeneralRe: Where is the .NET part?
Victor van Hagen27-May-08 2:16
memberVictor van Hagen27-May-08 2:16 
Err yeah but... there's no server side communication going on anywhere. You're letting the browser take care of the communication using javascript.

This is the "server-side" code (from default.aspx) you're talking about I presume:
<input id="btnServerValueSend" style="width: 144px" 
    type="button" value="Send Sever Side Value" 
    language="<big>javascript</big>" 
    onclick="<big>return btnServerValueSend_onclick()</big>" />
I was expecting this article to go into a little bit more depth than just calling some javascript function.
Questioncan you do this without javascript?
mattvil26-May-08 4:15
membermattvil26-May-08 4:15 
I think this is just a Compromise solution.Use com+ object is maybe a better way.anyway,If this can help people this is valuable.
GeneralInteresting, but the Web Services are better solution
Stoyan K Petrov26-May-08 3:11
memberStoyan K Petrov26-May-08 3:11 
Your article is interesting, but the Web Services are better solution
GeneralSuperb !!!
ashu fouzdar21-May-08 3:31
memberashu fouzdar21-May-08 3:31 
Nice one Laugh | :laugh:

ashu fouzdar

GeneralRe: Superb !!!
Abhijit Jana21-May-08 6:07
memberAbhijit Jana21-May-08 6:07 
thanks boss !!!

Best Regards
-----------------
Abhijit Jana
Check Out My Latest Article

Java.NET : Integration of Java and .NET[^]
"Success is Journey it's not a destination"

GeneralGreat Effort!!!
SAMir Nigam 19-May-08 18:11
member SAMir Nigam 19-May-08 18:11 
Great Effort. Keep it up.

SAMir Nigam

GeneralRe: Great Effort!!!
Abhijit Jana19-May-08 18:39
memberAbhijit Jana19-May-08 18:39 
Thanks Samir Smile | :)

Best Regards
-----------------
Abhijit Jana
Check Out My Latest Article

Java.NET : Integration of Java and .NET[^]
"Success is Journey it's not a destination"

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

| Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.150520.1 | Last Updated 26 May 2008
Article Copyright 2008 by Abhijit Jana
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid