Jump to content

Repls available for Java programming


Recommended Posts

Posted

So, if repls have so many advantages, the next obvious question is what repls are available for the Java language?

 

[move]Jython[/move]

 

Jython (formerly known as JPython) is an implementation of Python (including a repl) in the Java programming language (certified 100% Pure). It actually compiles Python to (somewhat baroque) Java source code or directly to bytecode.

 

In the spirit of Python, every attempt was made to offer seamless Java interoperability with Jython. It gives you access to all of the Java standard libraries just as if you were programming natively in the language, as well as use of the existing Java class files. So you can use the repl to play not only with the standard libraries, but with your own Java (or Jython) classes that you've compiled to bytecode.

 

One significant consideration when using the Jython repl is that you are writing Python expressions, not Java expressions. The plus side of this is that you get the conciseness and beautiful syntactic sugar of Python.

 

For example, say I want to construct a new hash table that maps a to 1, b to 2, and c to 3. All I need to write in Jython is this:

>>> h = {'a':1, 'b':2, 'c':3}

 

 

The interpreter displays >>> before each new input line.

 

Jython syntax is also quite advantageous when exploring new GUI designs. For one thing, the various fields of a GUI element can be specified as keyword arguments to the constructor, like so:

>>> from javax.swing import *
>>> f = JFrame(visible=1)

 

This example illustrates some other differences between Jython and the Java language:

 

    - Import statements have a very different syntax.

 

    - ints are used instead of booleans (1 is true, 0 is false).

 

Here's another example where the Jython code saves you some typing -- adding action listeners to GUI elements. Normally, such listeners are specified as instances of anonymous inner classes using the Command Pattern. In Python (and many other "scripting" languages), such commands can be specified more succinctly using interactive function definitions. For example, let's build on the above interactive session and add a simple action listener to a JButton:

>>> def listener(event):
...   print 'thank you'
>>>

 

 

This is an example of a function definition in Jython. The interpreter lets us know when it expects a statement to be continued on the next line by printing ellipses for the caret. This function takes a single argument and prints "thank you" to standard out. We can use it as an action listener as follows:

 

>>> panel = JPanel()
>>> panel.add(JButton('press me', actionPerformed=listener))
>>> f.getContentPane().add(panel)
>>> f.pack()

 

 

Now we'll have a window displayed on the screen with a button labeled "press me" that, when pressed, will print "thank you" to standard out. Imagine how much more wordy this would be using Java code.

 

Of course, there are disadvantages. For example:

 

    - You lose static type checking (although static checking is arguably of little value in a repl).

 

    - Because the expressions you type in the repl are not Java code, you can't copy-and-paste expressions from the repl into your program without first translating them.

 

    - When using Jython with Java code, you have the added intellectual burden of juggling two languages in your head simultaneously (although some people consider that fun).

 

 

[move]DynamicJava[/move]

 

Another Java-usable repl is DynamicJava, a true Java-based (well, that's almost right) open-source tool with a few differences:

 

    - The repl language lets you get away without specifying the static types of variables when you declare them.

 

    - You don't have to add a semicolon at the end of a statement. The interpreter also (sloppily) returns null as the result of evaluating a statement. (It would have been better if statements didn't return values at all.)

 

    - You are not restricted from accessing the private fields of objects from within the repl.

 

For beginning Java programmers, these differences can be significant because they can cause confusion. More experienced programmers will probably welcome some of the relaxed restrictions. In either case, DynamicJava is a robust and very useful software product (and it helps that it's free).

 

Created:Krash

  • 1 month later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now


  • Posts

    • Same glitch or "technique" was working on Interlude L2Pride aswell.. only few knew about it!
    • 🌟 Need fast setup and guaranteed warranty? All products are fully tested and delivered instantly 24/7.
    • 7 DAYS TO CLOSED BETA!   WARFRONT Closed Beta begins in just 7 days!    If you're planning to participate and haven't registered yet, please make sure you [b]register now[/b]. If you're coming with friends or your clan, please make sure they register too — registration only takes a few seconds.   https://l2warfront.com/   Over the next couple of days I will begin sending emails to registered players containing: Account registration/access link WARFRONT Game Client WARFRONT Launcher Final Closed Beta instructions Important: Special Closed Beta participant rewards will also be distributed using the email address you registered with, so please make sure you've registered with a valid email you can access.   Closed Beta: 3 October 2026 — 19:00 GMT+0 We're almost there. 7 days. Angels vs Demons. See you on the battlefield.
    • No problem — it will decrypt AA (any chronicles). Text telegram
    • As the title says, we are an International group of players that currently play on Exiliumworld for arround 5 years now and we plan to keep on playing here long term now on. Exiliumworld its a server created on Fafurion client, with new skills added for each class and a completely different gameplay. All classes are good and do great damage, there are new exciting features and party compositions that are incredibly great to be played.   While most of us are Romanians, we also have people from different countrys so English is the main language we use on PvP/TW/Sieges or whenever objective pops on. Our  community runs on Discord, we try to keep it very simple in terms of rules : We dont flame each other, we try to respect each member of this group and overall we mentain a good atmosphere inside the group by always laughing, being positive in any situation and helping each other out with whatever it's needed.   If you also wish to be a part  of our community and play on a server that is opened for over a decade and continues running smooth, always gets updates and fixes, contact me in private on Discord because i won't be active in here. About what classes you can play, we will discuss more details like that when we get in contact. Have a great day, guys and remember : Having a good, stable server and a group of players that respect you and help you whenever you are in need might be the perfect environment for you to grow as a player and also as human being!    CONTACT  DISCORD : pqtestpq_97112 (Me) ash3s8354 (Leader) xmariusx (Subleader)   Whoever you choose to talk to, you will meet a friendly person ready to answer your all questions about our group, server features or explain you all the insights of the server.  P.S. : Don't hesitate to contact us. We also recruit CPs or group of players, not only single players. Have a nice day!   #SABOTAGEclan  
  • Topics

×
×
  • Create New...

Important Information

This community uses essential cookies to function properly. Non-essential cookies and third-party services are used only with your consent. Read our Privacy Policy and We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue..