1
<?xml version="1.0" encoding="UTF-8"?>
2
<!DOCTYPE document PUBLIC "-//APACHE//DTD Documentation V1.2//EN" "http://apache.org/forrest/dtd/document-v12.dtd">
5
<title>Developing .NET Applications in Java</title>
6
<authors><person name="Stephen Schaub" email="sschaub@bju.edu"/>
8
<abstract>This section discusses information you need to know when you
9
want to develop .NET applications in Java. </abstract>
14
<title>Overview</title>
16
<p>IKVM makes it possible to develop .NET applications using the Java language. Here's how it works:</p>
18
<li>Identify .NET classes you want to use in your application.</li>
19
<li>Identify which .NET dll's contain the .NET classes you identified in step 1.
20
<p><strong>Tip:</strong> If you're developing on Windows, the Microsoft .NET SDK Class Reference documentation identifies the assembly / dll
21
for a .NET class at the bottom of each class overview page.</p>
23
<li>Use the <link href="ext:ikvmstub">ikvmstub</link> application to generate a Java jar file for each dll you identified in step 2.
24
<p>The ikvmstub tool analyzes the .NET classes in the designated dll
25
and generates a jar file containing Java interfaces and stub classes. This information is needed by the Java source compiler, which
26
knows nothing about .NET assemblies.</p>
28
<li>Compile your Java source code using javac or jikes, with the ikvmstub-generated jar files on the compiler classpath.</li>
29
<li>Compile the resulting Java classes using ikvmc. Use the -reference option to reference the dll's containing the
30
.NET classes you used; do <em>not</em> include the ikvmstub-generated jar files on the compiler classpath.</li>
32
<p>For an example of this, see the <link href="ext:tutorial">tutorial</link>.</p>
36
<title>Mapping .NET API's to Java</title>
38
<p>When ikvmstub generates a stub jarfile, it has to prevent namespace conflicts between Java API classes and
39
generated stub classes. It must also map .NET features such as properties, delegates, enumerations,
40
and variable-length argument lists to Java language equivalents.
42
<p>To prevent namespace conflicts, ikvmstub creates Java package names from .NET namespaces by
43
prefixing them with cli. For example, a .NET class in the <code>System.IO</code> namespace would have a stub generated
44
for it in a Java package named <code>cli.System.IO</code>. So, when writing Java code that uses the
45
System.IO.File class, you would use one of the following import statements in your Java code:</p>
46
<p xml:space="preserve"><code> import cli.System.IO.*;
47
import cli.System.IO.File;
49
<p>The following sections discuss how .NET features are mapped to the Java language. Some of the mappings,
50
such as properties and enumerations, are fairly straightforward. Others, such as delegates and event handling,
51
require a little more work. </p>
52
<p><strong>Tip:</strong> Java development tools that
53
provide code assist features are a great help when writing applications that use .NET API's.
54
If you install the ikvmstub-generated jar files into your favorite Java IDE, you can use code completion to help you
55
use the .NET methods, properties, and enumerations correctly. Note, however, that you will not be able to test
56
your applications using your Java IDE debugger.
61
<title>Properties</title>
62
<p>Since Java has no direct language support for properties, ikvmstub maps .NET properties to Java getter and
63
setter methods. A .NET property defined in C# like this:</p>
65
public <em>datatype</em> <em>property-name</em> {
70
<p>would be translated to a pair of Java stub methods, like this:</p>
73
public <em>datatype</em> get_<em>property-name</em>( ) { ... }
74
public void set_<em>property-name</em>(<em>datatype</em> value) { ... }</source>
76
<p>Here is an example of C# code that uses a property, and how you would access the same property in Java:
86
<p xml:space="preserve"><code>
87
int weight = bear.Weight;
92
<p xml:space="preserve"><code>
93
int weight = bear.get_Weight();
103
<title>Enumerations</title>
104
<p>TODO. For now, see the <link href="ext:ikvmweblogfull">IKVM Weblog</link>, March 20, 2004 entry.
109
<title>Delegates and Event Processing</title>
110
<p>TODO. For now, see the <link href="ext:ikvmweblogfull">IKVM Weblog</link>, March 20, 2004 entry.
111
Also, see the winforms sample.</p>
115
<title>Varargs</title>
116
<p>TODO. For now, see the <link href="ext:ikvmweblogfull">IKVM Weblog</link>, March 20, 2004 entry.
117
Also, see the usenetapi/CreateFile.java sample.</p>