Select the right Java scripting language

xiaoxiao2021-03-06  16

Select the right Java scripting language

- If you are considering integrating scripting interpreters in Java applications, it is hard to decide to use that

Summary: The scripting language has proved its value to Java developers. It allows customers to implement the extension of application and personalization of the interface, so that the programs have improved. In addition, they can significantly simplify the design tasks of the program developer, and deliver and evaluate dynamic definitions. The task of developers, integrated one or more scripting languages ​​is simple, and select a more difficult in the increasingly long optional list. This article describes some issues supporting scripted language in Java applications, comparing Groovy, Judoscript, PNUTS, JRUBY, JACL, JYTHON, RHINO, and Beanshell from different angles to help readers can make the correct decision.

Three years ago, I wrote a "Java Scripting language in JavaWorld, which is the article that suits you?" When I collect the interpreter and compare, I try to choose those who seem to meet harsh business needs. Ideally, I hope that the interpreter can easily extend the user interface of the application, and have easy-to-read script code, high reliability, fast, good support and documentation, and is complete. At that time, I restricted the list to JaCl, Jython, Rhion and Beanshell.

A lot of changes have occurred in the past three years. Options are no longer few, whether dynamic development or direct selection, optional scripting languages ​​have one strike. A reliable selection list is more than three years ago, and now you also include Groovy, Judoscript, PNUTS, and Beanshell. We can also consider other interpreters in this list, but in this list, it is already enough to develop people's own needs.

I am preparing to standardize all interpreses, see JACL, JYTHON, RHION and Beanshell have improved in 2002, and look at Groovy, Judoscript, Jruby and PNUTs how to compare them. I think it is very interesting about what special strength and weakness in different scripting languages.

Business risk

In the previous article, I talked about the information of some famous excellent script interpreters and explained the risk you may encounter when combined with a scripting interpreter. In this article, I simplified these content into some points, and improved according to my experience after writing those articles. The advantages of the Java script interpreter are unquestionable. Using scripting language code than using Java simple; step language makes the program's application logic and user interface push (Drive / Drive?) And extension become possible; scripting code can be run in violation of Java applications, this is very powerful . This makes it easier to write program test drivers, which is faster than encoding and compiling unit tests for Java classes. In addition, if the user spends time to expand your application using the script, they make investments on your tool, which makes you more than one weapon in the competition.

However, when you integrate a JIAVA script interpreter in your application, you must face a certain risk. The two main risks are that the interpreter may become an orphan, or when you put the product, you may find the fatal defect of the interpreter. Most interpresers are dynamically maintained and updated by open source model. In this case, you can seek help to study the experts you find, to make the interpreter, or contain the bug you need in the future. FIX (bug repair?). This is a safe gambling, but it does not get enough guarantees. If you seriously consider adopting a specific interpreter, first look at its development site, look at its code evolution, look at the speech board above, and the user's question has an answer. No. This can help you understand the actual situation of code support. Another measures for self-protection are fully tested for the ruins you prepare. Some interpreters contain a unit test set when publishing. These unit tests can be used as part of your greater test set when taking an interpreter that is integrated into your application. When the integration between test interpreters and applications, you can take your own work because the script interpreter has sufficient flexibility and exposes sufficient features to developers. You guarantee the time in early quality, not the application has become a product, and it is only considered when the user needs an urgent bug fix.

New competitor list

If you are looking for a scripting interpreter, you have a lot of choices. Some interpreters support already existing languages, such as Ruby, Python, JavaScript, Java, and TCL. Some interpreters, such as Judoscript, Groovy, and PNUTS, choose their own similar language syntax. In a comparison of different interpreters, the biggest choice to do is that the syntax of the scripting language can be suitable for your application. The technique choice such as such personal preferences can cause fierce arguments in different developers team. Perhaps this article can help solve some arguments.

I collected eight different script interpreters that were recently released. The interpreter and its version are listed in the table below. If you are not familiar with these interpreters, I also give a summary of each interpreter function and development activity (A thumbnail Sketch).

Scripting language

version number

Brief description

JaCl

1.3.1

Java implementation of the TCL interpreter. If you want to use the toolkit to create a user interface class in the script to see the class set of the package (WRAP) Java Swing tool in the SWANK project. JACL already has a long time and is still continuously improved.

Jython

2.1

The Java implementation of the Python interpreter. One question I noticed is that I haven't seen the new version of this interpreter for a long time. But on Jython's website, the plan for changing this status quo and has fund support.

Rhino

1.6.1

JavaScript interpreter's Java implementation. It also supports compiling scripts into class files. Its latest version is released a few months and adds XML support.

JRUBY

0.8

The Java implementation of the Ruby interpreter. It is developing, and its beta version 0.8 is good.

Beanshell

2.0 Beta 2

It is a Java source file interpreter that is continuous development and new features. 2.0 Version provides full ordinary Java source file interpretation support.

Groovy

1.0 Beta 9

Groovy is the feature of Python and Ruby to Java similar spells, which is made up of many exciting features. You can compile the script to class files, for different IDEs, and many Groovy plugins are available, and the JSR Committee is developing Groovy specification.

Judoscript

0.9

It has a similar programming grammar similar to JavaScript, learning and use easier. A clear goal is mentioned in its FAQ: "Support for object level, operating system level and application level script". I have a good run in version 0.9. PNUTS

1.1 Beta 2

PNUTS has a programming syntax similar to Java and remains continuously updated. It can compile scripts into Java class files.

First indicator: performance

In the future, the first indicator, I wrote an equivalent script code for each interpreter, allowing them to complete the simple task set and record the time spending them to perform scripts. My test script focuses on basic operations, such as cycling, integer comparison and large one-dimensional, two-dimensional array assignment, and initialization. The test script for each interpreter and the Java program running them can be downloaded in the original resource section.

The most useful information in the benchmark test is, the interpreter completes the apples-to-apples comparison of simple task speeds. If you focus on throughput, the reference number will be very important. For each script language, I try my best to write acquaintance test code. Test use Java

1.4.2

Running on Toshiba Tecra8100 notebook, CPU is PIII700MHz, memory 256MB. The default stack size is used when the JVM is started. For more and more slow interest to your display interpreter, I wrote the Java code of the test case and run on Java1.4.2. Test sets include:

1 to 1,000,000 count

1,000,000 integers

Assign and initialize an array containing 100,000 elements

Assign and initialize a 500 * 500 two-dimensional array

Is there improved after 2002?

When telling you which interpreter is the fastest, let's take a look at Figure 1, this bar chart lists the results of a lot of time-consuming tasks: 1 million integers. Comparison. I have given the four scripting interpreters described in the 2002 article. I gave it in Java.

1.3.1

The time required to run on JVM and Java1.4.2. Very interesting is that test Jython is used by the same version of the script interpreter, indicating that the new version of JVM has increased by 25%. In addition, I use the exact same hardware as the previous test, so I can affirm that JVM1.4.2 reduces the time required to run the underlying test. Now look at Rhino, Beanshell and Jacl what happened: The new version of Rhino is 86% of the old version of the old version of the 1.4.2 JVM, and the number of JACL is 76%. It can be seen that performance has improved a lot.

Total time for four tasks

Since the interpreter is very similar (at least for my benchmark test), I calculate the total time consumed by each interpreter to calculate and give it in FIG.

Variable sign

For these simple tests, RHINO, PNUTS and JYTHO are always the fastest, followed by Groovy, then Judoscript, then other. These performance parameters are useful for you, depending on what you want scripting languages. If your scripting function contains a lot of iterations, and the user wants the result, you need to pay attention to the fastest interpreter, or you should consider implementing high-performance requirements with Java, not scripting code. If your script requires a lot of duplicate operations, these interpreter speeds are not that important, and fast hardware will make problems different.

It is also necessary to point out that even if the fastest interpreter, the time used to complete the above test is also approximately 40 times the time used by the same function Java code. If the speed is your most important issue, you must clear, the most meaningful thing is to use Java instead of the script code to implement critical algorithms.

Some script interpreters support script code to directly compile the zoning code. I am very curious about this will have a lot of performance differences, so I have conducted another test. I used the Rhino script interpreter to compile the benchmark script into a zona code, and then I run 10 times for the entire benchmark set script and script. Surprisingly, the script code compiles the script compiled by the script to save only 10% of the time compared to direct operation scripts. My initial task, JVM's curse occupies most of the time running test set, but further inspections have found that JVM curse itself only accounts for 20% of the total test set. Simple script code compiles that the zoning code seems to have positive significance, but this does not necessarily improve the performance of a silver bomb. Different results can be seen in longer or more, more computing centers. Second standard: integrated difficulty

Third Standard: License

English Original:

http://www.javaworld.com/javaworld/jw-03-2005/jw-0314-scripting.html

转载请注明原文地址:https://www.9cbs.com/read-45090.html

New Post(0)