Jython Beginner Learning

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.