javaclass

Changeset

139:9812fa1e4816
2005-01-21 Paul Boddie raw files shortlog changelog graph Worked on the documentation somewhat.
docs/index.html (file) docs/styles.css (file)
     1.1 --- a/docs/index.html	Fri Jan 21 18:22:18 2005 +0100
     1.2 +++ b/docs/index.html	Fri Jan 21 18:22:28 2005 +0100
     1.3 @@ -1,29 +1,37 @@
     1.4  <?xml version="1.0" encoding="iso-8859-1"?>
     1.5  <html xmlns="http://www.w3.org/1999/xhtml">
     1.6  <head>
     1.7 -  <title>ClassFile</title>
     1.8 +  <title>javaclass/ClassFile</title>
     1.9    <meta name="generator" content="amaya 8.1a, see http://www.w3.org/Amaya/" />
    1.10    <link xmlns:xlink="http://www.w3.org/1999/xlink" href="styles.css"
    1.11    rel="stylesheet" type="text/css" />
    1.12  </head>
    1.13  
    1.14  <body>
    1.15 -<h1>ClassFile</h1>
    1.16 +<h1>javaclass</h1>
    1.17 +
    1.18 +<p>The javaclass collection of packages and utilities (also known as
    1.19 +ClassFile) provides a means of importing Java classes and packages directly
    1.20 +into Python, without the need for a Java virtual machine, so that the classes
    1.21 +may be instantiated, accessed, run and manipulated just like Python classes,
    1.22 +and that the resulting objects and methods can be accessed and manipulated
    1.23 +just like Python objects and methods.</p>
    1.24  
    1.25 -<p>The ClassFile collection of packages and utilities provides a means of
    1.26 -importing Java classes and packages directly into Python, without the need
    1.27 -for a Java virtual machine, so that the classes may be instantiated,
    1.28 -accessed, run and manipulated just like Python classes, and that the
    1.29 -resulting objects and methods can be accessed and manipulated just like
    1.30 -Python objects and methods.</p>
    1.31 +<h2>Quick Examples</h2>
    1.32 +
    1.33 +<p>It can be quicker to see what this is about by seeing some examples.</p>
    1.34  
    1.35 -<h2>Quick Example</h2>
    1.36 +<h3>The Not Very Convincing Example</h3>
    1.37 +
    1.38 +<p>You can run Java classes by finding one with a main method and executing
    1.39 +it. Here's a comparison of a freshly prepared Java class being run in Python
    1.40 +and in a Java virtual machine:</p>
    1.41  
    1.42  <p class="prompt">cd tests/</p>
    1.43  
    1.44  <p class="prompt">javac Value.java</p>
    1.45  
    1.46 -<p class="prompt">../runclass.py Value</p>
    1.47 +<p class="prompt">runclass.py Value</p>
    1.48  
    1.49  <p class="result">v.getValue() correct: 123<br />
    1.50  v.getValue() correct: 456<br />
    1.51 @@ -49,6 +57,46 @@
    1.52  v2.add(-123) correct: 0<br />
    1.53  v2.getValue() correct: 255</p>
    1.54  
    1.55 +<h3>The Slightly More Credible Example</h3>
    1.56 +
    1.57 +<p>It can be more interesting to get into Python's interactive mode and then
    1.58 +start playing around with Java classes:</p>
    1.59 +
    1.60 +<p class="python-result">Python 2.2.2 (#2, Jan 21 2005, 16:16:57)<br />
    1.61 +[GCC 2.96 20000731 (Red Hat Linux 7.3 2.96-112)] on linux2<br />
    1.62 +Type "help", "copyright", "credits" or "license" for more information.</p>
    1.63 +
    1.64 +<p class="python-prompt">import javaclass.classhook</p>
    1.65 +
    1.66 +<p class="python-prompt">from __this__ import Value</p>
    1.67 +
    1.68 +<p class="python-prompt">dir()</p>
    1.69 +
    1.70 +<p class="python-result">['Value', '__builtins__', '__doc__', '__name__',
    1.71 +'javaclass']</p>
    1.72 +
    1.73 +<p class="python-prompt">dir(Value)</p>
    1.74 +
    1.75 +<p class="python-result">['__class__', '__delattr__', '__dict__', '__doc__',
    1.76 +'__getattribute__', '__hash__', '__init__', '__init______I_', '__module__',
    1.77 +'__new__', '__reduce__', '__repr__', '__setattr__', '__str__', '__weakref__',
    1.78 +'add', 'add____I_', 'compare', 'compare____I_', 'getClass', 'getClass___',
    1.79 +'getValue', 'getValue___', 'isPositive', 'isPositive___', 'main',
    1.80 +'main___java__lang__String_array_', 'newValue', 'newValue___', 'setValue',
    1.81 +'setValue____I_']</p>
    1.82 +
    1.83 +<p class="python-prompt">v = Value(20050121)</p>
    1.84 +
    1.85 +<p class="python-prompt">v.getValue()</p>
    1.86 +
    1.87 +<p class="python-result">20050121</p>
    1.88 +
    1.89 +<p class="python-prompt">v.setValue(20050401)</p>
    1.90 +
    1.91 +<p class="python-prompt">v.getValue()</p>
    1.92 +
    1.93 +<p class="python-result">20050401</p>
    1.94 +
    1.95  <h2>Motivation</h2>
    1.96  
    1.97  <p>Pick one of the following:</p>
    1.98 @@ -62,6 +110,26 @@
    1.99      bytecode on.</li>
   1.100    <li>Experimentation around import hooks, bytecode generation; observation
   1.101      of different runtime and type systems interacting.</li>
   1.102 +  <li>Using Python libraries from Java.</li>
   1.103 +</ul>
   1.104 +
   1.105 +<h2>Limitations</h2>
   1.106 +
   1.107 +<p>It isn't all great, however. Here are some reasons why this might not do
   1.108 +what you want it to:</p>
   1.109 +<ul>
   1.110 +  <li>It runs on the Python runtime which does not have the security,
   1.111 +    threading and just-in-time compiler features that people enjoy about Java
   1.112 +    runtimes, so if what you like to do is to run one big servlet container
   1.113 +    with lots of classes and threads from different people floating around,
   1.114 +    this isn't going to protect them from doing all sorts of things to each
   1.115 +    other and to your system. However, you may take the unfashionable view
   1.116 +    that the operating system is supposed to do that kind of thing.</li>
   1.117 +  <li>It works by generating Python bytecode from the Java bytecode in class
   1.118 +    files (and .jar archives). Generally, anyone who is anyone in the Python
   1.119 +    pantheon has largely recommended against doing anything with the
   1.120 +    bytecode, despite noble efforts to make exciting things happen by
   1.121 +    transforming it, optimising it, and so on - </li>
   1.122  </ul>
   1.123  </body>
   1.124  </html>
     2.1 --- a/docs/styles.css	Fri Jan 21 18:22:18 2005 +0100
     2.2 +++ b/docs/styles.css	Fri Jan 21 18:22:28 2005 +0100
     2.3 @@ -58,3 +58,20 @@
     2.4  color: black;
     2.5  margin-left: 1em;
     2.6  }
     2.7 +
     2.8 +p.python-prompt {
     2.9 +font-family: fixed;
    2.10 +background-color: silver;
    2.11 +color: black;
    2.12 +}
    2.13 +
    2.14 +p.python-prompt:before {
    2.15 +content: ">>> ";
    2.16 +}
    2.17 +
    2.18 +p.python-result {
    2.19 +font-family: fixed;
    2.20 +background-color: white;
    2.21 +color: black;
    2.22 +margin-left: 2em;
    2.23 +}