Jython is a combination of Python and Java. Jython syntax, like Python, can use not only the Python library, but also the Java library. Combines the advantages of Python and Java, which means that Jython has both the flexibility of dynamic language and the powerful class library of static languages. In fact, I understand that Jython is simply saying that the Python interpreter, implemented in the Java language, means that you can write programs in the Python language and use Java libraries at the same time. A simple example is shown below:
First create the Java class:
publicclass Foo{ private"Elegant"; publicgetName(){ return name; } publicvoidsetName(String name){ this.name = name; }}
And then Jython calls this class:
#导入Java标准类库#如果是jar包,需要sys.path.append(jar_file)fromimport Random #导入自定义类库import Foofoo = Foo()print foo.getName()foo.setName("change")print foo.getName()#调用Java标准类库random = Random()print random.nextInt(100)
Output:
Elegant change40
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Jython Beginner Learning