This language joins two good tools into one. 🐍
Jython is an implementation of the Python language (https://terminalroot.com.br/2019/10/script-basico-de-python-para-learned.html) that generates bytecode for Java machines (JVM). With it is possible to develop hybrid applications that unite code in Java and Python.
This tool is also very useful for embedding a scripting language in applications that require this kind of functionality. It also includes a compiler that converts Python source code to Java bytecode, allowing Python programmers to write classes that can be used by a Java program.
Among its advantages are:
Procedure on Linux
Use your distribution’s package manager to install them, for example, as I installed here on Gentoo:
In this case I rejected the modules: cups and alsa and icedtea was installed automatically as it is a dependency.
Now download Jython at: https://sourceforge.net/projects/jython/. After downloading extract the package:
Create and enter a directory first so that files are not scattered
After this last command, it will open a ** wizard ** for you to follow, follow the images below:
In this 4th image ↓ part you could still choose a custom directory, for example from
~/.config/jython
, it would be the most ideal not to pollute your home directory.
After finish we will now edit your vim ~/.bashrc
and add the following line:
In this case my version and directory name is 2.5.2, check yours.
Then run the source ~/.bashrc
command or close and open the terminal so that the jython
command can be found.
A mini application that adds two numbers. Create a file named
vim sum.py
Save and run as follows:
No Shell will show the outputs of the program, but it does not mean that it is a problem, but it is sending the outputs correctly.
Note that in this case I added 8 + 8 and the result was as expected. 😁️
import javax.swing as libswing
- Imports the Java library.pnumero = libswing.JOptionPane.showInputDialog ("Enter an Integer: ")
- Shows the first dialog box and stores the value in the pnumero variable.snumero = libswing.JOptionPane.showInputDialog ("Enter an Integer: ")
- Displays the second dialog and stores the value in the snumero variable.sum = int (number) + int (number)
- Converts the number and number values to integers and adds both by storing the result in the sum variable.libswing.JOptionPane.showMessageDialog (None," The sum is% d "% sum)
- Shows the result of the sum on the screen, isn’t it?I particularly enjoyed Jython 🙌️ and I will dig deeper into it and there will probably be more tutorials here about it. Is that you ?! Liked ?! Tell us using the comment field. Hugs!
jython java python languages programming