~ubuntu-branches/ubuntu/trusty/monodevelop/trusty-proposed

« back to all changes in this revision

Viewing changes to external/ikvm/website/src/documentation/content/xdocs/devguide/java2net.xml

  • Committer: Package Import Robot
  • Author(s): Jo Shields
  • Date: 2013-05-12 09:46:03 UTC
  • mto: This revision was merged to the branch mainline in revision 29.
  • Revision ID: package-import@ubuntu.com-20130512094603-mad323bzcxvmcam0
Tags: upstream-4.0.5+dfsg
ImportĀ upstreamĀ versionĀ 4.0.5+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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">
 
3
<document> 
 
4
  <header> 
 
5
    <title>Developing .NET Applications in Java</title> 
 
6
    <authors><person name="Stephen Schaub" email="sschaub@bju.edu"/> 
 
7
    </authors> 
 
8
     <abstract>This section discusses information you need to know when you
 
9
     want to develop .NET applications in Java. </abstract>
 
10
  </header> 
 
11
  <body> 
 
12
 
 
13
      <section>
 
14
      <title>Overview</title>
 
15
      
 
16
      <p>IKVM makes it possible to develop .NET applications using the Java language. Here's how it works:</p>
 
17
      <ol>
 
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>
 
22
        </li>
 
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>
 
27
        </li>
 
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> 
 
31
      </ol>
 
32
      <p>For an example of this, see the <link href="ext:tutorial">tutorial</link>.</p>
 
33
      </section>
 
34
 
 
35
      <section>
 
36
      <title>Mapping .NET API's to Java</title>
 
37
 
 
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.
 
41
        </p>
 
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;        
 
48
</code>        </p>
 
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.
 
57
        </p>
 
58
    </section>
 
59
    
 
60
    <section>
 
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>
 
64
      <source>
 
65
    public <em>datatype</em> <em>property-name</em> {
 
66
        get { ... }
 
67
        set { ... }
 
68
    }</source>
 
69
      
 
70
      <p>would be translated to a pair of Java stub methods, like this:</p>
 
71
      
 
72
            <source>
 
73
    public <em>datatype</em> get_<em>property-name</em>( ) { ... }
 
74
    public void set_<em>property-name</em>(<em>datatype</em> value) { ... }</source>
 
75
      
 
76
      <p>Here is an example of C# code that uses a property, and how you would access the same property in Java:
 
77
      </p>
 
78
      
 
79
      <table>
 
80
      <tr>
 
81
         <th>C#</th>
 
82
         <th>Java</th>
 
83
      </tr>
 
84
      <tr>
 
85
        <td>
 
86
      <p xml:space="preserve"><code>
 
87
      int weight = bear.Weight;
 
88
      bear.Weight = 15;
 
89
      </code></p>
 
90
      </td>
 
91
      <td>      
 
92
      <p xml:space="preserve"><code>
 
93
       int weight = bear.get_Weight();
 
94
       bear.set_Weight(15);
 
95
      </code></p>
 
96
      </td>
 
97
      </tr>
 
98
      </table>
 
99
      
 
100
    </section>
 
101
    
 
102
    <section>
 
103
      <title>Enumerations</title>
 
104
      <p>TODO. For now, see the <link href="ext:ikvmweblogfull">IKVM Weblog</link>, March 20, 2004 entry.
 
105
      </p>
 
106
    </section>
 
107
 
 
108
    <section>
 
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>
 
112
    </section>
 
113
    
 
114
    <section>
 
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>
 
118
    </section>
 
119
  </body>
 
120
</document>