SIGN UP MEMBER LOGIN:    
ARTICLE

Calling Java Program from C#

Posted by Maheswara Rao Articles | Java and .NET July 18, 2001
This article shows you how to call a Java program from C#.
Reader Level:
Download Files:
 

Hi sharpers

This is Mahesh again after some break. In this article I am going to show how to call java program using C#. 

According Microsoft definition of C#:

C# is a simple, Modern. Object Oriented language and combine the high productivity of VB and the raw power of C++.

According Mahesh definition of C#:

C# is Simple, Modern, Object Oriented beautiful language and daughter (SHE-SHARP) of Java and Microsoft.

What I want to say SUN (sun) and MS (moon) both are very Important to IT WORLD (world) but both are now enemies now a days they are making languages to dominate each other.  This is sure without sun and moon there is no world like that with out SUN and MS there is no IT WORLD. I pry to god to make both are good friends they should work for IT PEOPLE.  

This application has 4 files

shesharp.cs
javasharp.java
comp.bat  //for compel
j.bat 

In this application I used Inner class for developing panel.

using System.Windows.Forms;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Diagnostics;
using System;
.
..
//for mixed background
public void format(object s,PaintEventArgs a)
{
Graphics g=CreateGraphics();
Rectangle rect=
new Rectangle(0,0,300,300);
Color nyc=Color.FromArgb(200,50,5,200);
LinearGradientBrush b=
new LinearGradientBrush(rect,Color.DarkOrange,nyc,LinearGradientMode.Vertical);
g.FillRectangle(b,rect);
}
//for calling java program
private void calljava(object ob,EventArgs arg)
{
Process.Start("j.bat");
}
//using Inner class for panel
public class pp:Panel
{
int x;
int y;
Timer t=
new Timer();
String s="Hi...\nyou Know?\nWe are good Friends\nI can call Java ...";
String mail="mail me..\nmallm_uma@rediffmail.com\nmahe_proj@rediffmail.com";
private Label l=null;
private Label maill=null;
Color nyc;
//Constructor
public pp()
{
x=10;
y=200;
this.Location=new Point(0,10);
nyc=Color.FromArgb(200,10,5,225);
this.Size=new Size(300,230);
maill=
new Label();
l=
new Label();
l.Text=s;
l.Size=
new Size(250,100);
l.ForeColor=nyc;
l.BackColor=Color.Transparent;
l.Font=
new Font("verdana",15,FontStyle.Bold);
l.TextAlign=ContentAlignment.MiddleCenter;
maill.Text=mail;
maill.Size=
new Size(160,40);
maill.Location=
new Point(10,192);
maill.Font=
new Font("verdana",7,FontStyle.Bold);
maill.ForeColor=Color.Yellow;
maill.BackColor=Color.Transparent;
this.Controls.Add(l);
this.Controls.Add(maill);
t.Interval=50;
t.Tick+=
new EventHandler(draw);
t.Enabled=
true;
}
protected override void OnPaint(PaintEventArgs a)
{
Graphics g=a.Graphics;
Rectangle rect=
new Rectangle(0,0,300,230);
LinearGradientBrush b=
new LinearGradientBrush
rect,Color.DarkOrange,nyc,LinearGradientMode.Vertical);
g.FillRectangle(b,rect);
Font ff=
new Font("Arial",14,FontStyle.Bold);
SolidBrush bb=
new SolidBrush(nyc);
StringFormat df=
new StringFormat();
}
//for animation
void draw(object ob,EventArgs a)
{
l.Location=
new Point(x,y);
--y;
if(y==-100)y=230;
}
}
public static void Main()
{
Application.Run(
new shesharp());
.
.

Remarks

OS: Win2000 and 98 with CLR and JAVA

This application is dedicated to SUN and MS. 

Login to add your contents and source code to this article
share this article :
post comment
 

Now I doing a mini project in C#.In this project I want to run a java program.If it is possible can u give some ideas to me....

Posted by vimal Jul 03, 2009

This is an example of using Process.Start() and not an example of calling a Java method from C#/.Net

Posted by Ian Mar 27, 2009
Nevron Gauge for SharePoint
Become a Sponsor
PREMIUM SPONSORS
  • Finally – a virtual platform that delivers next-generation Windows Server 2008 Hyper-V virtualization technology from a managed hosting partner you can truly depend on. Visit www.maximumasp.com/max for a FREE 30 day trial. Hurry offer ends soon. Climb aboard the MaxV platform and take advantage of High Availability, Intelligent Monitoring, Recurrent Backups, and Scalability – with no hassle or hidden fees. As a managed hosting partner focused solely on Microsoft technologies since 2000, MaximumASP is uniquely qualified to provide the superior support that our business is built on. Unparalleled expertise with Microsoft technologies lead to working directly with Microsoft as first to offer IIS 7 and SQL 2008 betas in a hosted environment; partnering in the Go Live Program for Hyper-V; and product co-launches built on WS 2008 with Hyper-V technology.
    ceTE software specializes in components for dynamic PDF generation and manipulation. The DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and new content to existing PDF documents from within your applications. Visit DynamicPDF here
6 Months Free & No Setup Fees ASP.NET Hosting!
Become a Sponsor