# HG changeset patch # User Paul Boddie # Date 1106328148 -3600 # Node ID 9812fa1e481627293e4c239dfca9935532e29d9d # Parent e13633edd5f964f92a85a391ceafc11cdb92a5fd Worked on the documentation somewhat. diff -r e13633edd5f9 -r 9812fa1e4816 docs/index.html --- a/docs/index.html Fri Jan 21 18:22:18 2005 +0100 +++ b/docs/index.html Fri Jan 21 18:22:28 2005 +0100 @@ -1,29 +1,37 @@ - ClassFile + javaclass/ClassFile -

ClassFile

+

javaclass

+ +

The javaclass collection of packages and utilities (also known as +ClassFile) provides a means of importing Java classes and packages directly +into Python, without the need for a Java virtual machine, so that the classes +may be instantiated, accessed, run and manipulated just like Python classes, +and that the resulting objects and methods can be accessed and manipulated +just like Python objects and methods.

-

The ClassFile collection of packages and utilities provides a means of -importing Java classes and packages directly into Python, without the need -for a Java virtual machine, so that the classes may be instantiated, -accessed, run and manipulated just like Python classes, and that the -resulting objects and methods can be accessed and manipulated just like -Python objects and methods.

+

Quick Examples

+ +

It can be quicker to see what this is about by seeing some examples.

-

Quick Example

+

The Not Very Convincing Example

+ +

You can run Java classes by finding one with a main method and executing +it. Here's a comparison of a freshly prepared Java class being run in Python +and in a Java virtual machine:

cd tests/

javac Value.java

-

../runclass.py Value

+

runclass.py Value

v.getValue() correct: 123
v.getValue() correct: 456
@@ -49,6 +57,46 @@ v2.add(-123) correct: 0
v2.getValue() correct: 255

+

The Slightly More Credible Example

+ +

It can be more interesting to get into Python's interactive mode and then +start playing around with Java classes:

+ +

Python 2.2.2 (#2, Jan 21 2005, 16:16:57)
+[GCC 2.96 20000731 (Red Hat Linux 7.3 2.96-112)] on linux2
+Type "help", "copyright", "credits" or "license" for more information.

+ +

import javaclass.classhook

+ +

from __this__ import Value

+ +

dir()

+ +

['Value', '__builtins__', '__doc__', '__name__', +'javaclass']

+ +

dir(Value)

+ +

['__class__', '__delattr__', '__dict__', '__doc__', +'__getattribute__', '__hash__', '__init__', '__init______I_', '__module__', +'__new__', '__reduce__', '__repr__', '__setattr__', '__str__', '__weakref__', +'add', 'add____I_', 'compare', 'compare____I_', 'getClass', 'getClass___', +'getValue', 'getValue___', 'isPositive', 'isPositive___', 'main', +'main___java__lang__String_array_', 'newValue', 'newValue___', 'setValue', +'setValue____I_']

+ +

v = Value(20050121)

+ +

v.getValue()

+ +

20050121

+ +

v.setValue(20050401)

+ +

v.getValue()

+ +

20050401

+

Motivation

Pick one of the following:

@@ -62,6 +110,26 @@ bytecode on.
  • Experimentation around import hooks, bytecode generation; observation of different runtime and type systems interacting.
  • +
  • Using Python libraries from Java.
  • + + +

    Limitations

    + +

    It isn't all great, however. Here are some reasons why this might not do +what you want it to:

    + diff -r e13633edd5f9 -r 9812fa1e4816 docs/styles.css --- a/docs/styles.css Fri Jan 21 18:22:18 2005 +0100 +++ b/docs/styles.css Fri Jan 21 18:22:28 2005 +0100 @@ -58,3 +58,20 @@ color: black; margin-left: 1em; } + +p.python-prompt { +font-family: fixed; +background-color: silver; +color: black; +} + +p.python-prompt:before { +content: ">>> "; +} + +p.python-result { +font-family: fixed; +background-color: white; +color: black; +margin-left: 2em; +}