JavaRush /Java Blog /Random EN /Coffee break #21. Integrating Python with Java. Getting t...

Coffee break #21. Integrating Python with Java. Getting to know Jakarta EE and Eclipse MicroProfile

Published in the Random EN group

Python integration with Java? Why not!

Source: Jaxenter Coffee break #21.  Integrating Python with Java.  Getting to know Jakarta EE and Eclipse MicroProfile - 1 Actually, combining systems programming and scripting languages ​​is not a strange new concept: it's just rarely used. For programming languages ​​that have a common binary application interface, it is entirely possible to combine them into a single library or executable. While this makes things a little more difficult, there are tools that can help. Python and Java actually complement each other. For example, you can use one of them for typical subtasks, and the other as a scripting language to extend the settings of your application. When it comes to integrating other languages, JavaScript, for example, is not typically used outside of web browsers, at least compared to other scripting languages ​​such as Perl, Tcl, Visual Basic, and Python. However, all these languages ​​are usually combined with other languages. Python has traditionally been combined with C and C++, while Visual Basic is often the scripting language of choice for C++ on the Windows platform. And Perl, like Tcl, is commonly used on C/Unix. Python is used a little more often on Windows as it integrates easily with the Microsoft Scripting Host architecture as well as COM. Plus, it's also great for macOS tools.

Why Java and Python?

Python is an object-oriented scripting language, making it a good match for Java. Combined with a Python interpreter written entirely in Java, such as Jython, you can write entire applets in Python, which can then run in any JDK-compatible browser, with code execution almost as fast as C/CPython. The Jython interpreter translates Python source code directly into Java bytecode, giving it incredible speed. But other Java scripting solutions (Java/TCL, Java/Perl, etc.) attach the JVM to the C implementation in these languages, which not only creates a portability problem, but these solutions themselves are not as easy as we would like.

What's the best way to use Java and JPython together?

There are a number of proven tools that implement Python in Java or vice versa, so you can run commands from one language in another. Here is a short list of some of the best tools for integrating Python with Java:
  • Jython is Python implemented in Java.
  • JPype - Allows you to run Java commands using Python.
  • Jepp - Java built into Python.
  • JCC is a C++ code generator for calling Java from C++/Python.
  • Javabridge is a package for running and interacting with the JVM from CPython.
  • Py4j - Allows you to run Java commands in Python.
  • Voc is an element of the BeeWare tool . Converts Python code to Java bytecode.
  • p2j - Converts Python code to Java. No longer in development.
There are several approaches to using these tools. Each has its own advantages and disadvantages. For example, you can prototype an entire application in Jython, and after several rounds of testing and redesign, rewrite everything in Java. This allows you to take advantage of the increased flexibility and speed of developing scripting languages ​​early in your project. However, your final product will need to be a little more detailed than if you just started writing in Java only. And if you're worried about UI libraries, Jython can hook into the same UILs as regular Java, so converting Java should be a breeze. However, things are not so simple if you are trying to build a large project. You'll likely run into the disadvantage of various components and layers having independent development cycles, such as top-level components. Of course, you can rewrite individual components in Java as you get closer to a stable release, or simply write some of your components exclusively in Java from the start. Another option is to rewrite only those components for which performance is important. This way, you can leave the high-level components in Jython, which means you only need to rewrite the lower-level components, and in some cases you won't have to rewrite anything at all.

Introducing Jakarta EE and Eclipse MicroProfile

Source: DZone Haven't heard of Jakarta EE and Eclipse MicroProfile yet? So, it's time to get acquainted with how the Java Enterprise standard developed. Both of these technologies are sure to be useful to you in the future, as they are great for building cloud-native and modern enterprise applications.

What is Jakarta EE?

Jakarta EE is a set of specifications (JAX-RS, CDI, JPA, JSON-P, etc.) for writing enterprise applications in Java. These specifications are documents that define the API and how the technology interacts. Coffee break #21.  Integrating Python with Java.  Getting to know Jakarta EE and Eclipse MicroProfile - 2Specification documents are like interfaces with formal definitions, and the actual implementation of these interfaces depends on the application server vendor (e.g. WildFly, Open Liberty, Payara, TomEE). To prevent a vendor from implementing a specification incorrectly, each specification provides a Technology Compatibility Kit (CTS). This is a set of tests to verify compliance of an implementation of a particular specification. Once the application server transmits the CST for all specifications, it complies with the entire standard. For many years, Java EE has been the standard way to write enterprise applications. Java EE (formerly called J2EE) has been supported by Oracle for a long time. In 2017, Oracle decided to no longer develop the corporate standard under its auspices and transferred it to the Eclipse Foundation. For legal reasons, they had to rebrand and decided to call the product Jakarta EE. You can find all the Jakarta EE specifications on the official website , and you can get more information about how the specification process currently works on the Eclipse Foundation website.

What is Eclipse MicroProfile?

Since the process of releasing and adapting new features for Java EE was quite slow, a group of vendors and community members decided to create MicroProfile in 2016. The main goal of this project was to help developers keep up with the times and also to optimize the existing platform for microservices architecture. Currently, Eclipse MicroProfile contains twelve specifications. Four of them are also part of Jakarta EE. This allows you to create standalone applications exclusively with MicroProfile. All specifications are vendor independent and the implementation comes with the application server. The Jakarta EE specifications can be considered a solid foundation for building enterprise applications. In addition to this, Eclipse MicroProfile fills a gap in building distributed systems as the technology follows the Twelve-Factor application methodology .
Comments
TO VIEW ALL COMMENTS OR TO MAKE A COMMENT,
GO TO FULL VERSION