Java Objects Executor (JOE) bridges the gap between Java applications and scripting by allowing methods of Java objects to be executed in sequence dynamically. With a syntax that mimics traditional scripting languages and full compatibility with Java, it simplifies the migration process of legacy applications while enhancing flexibility and functionality.
Java Objects Executor (JOE)
Java Objects Executor is a polymorphic script environment designed to streamline the migration of scripts to a Java context, facilitating the conversion of legacy applications. In many real-world applications, programs manage user interaction and calculations, while scripts handle administrative tasks, often communicating primarily with the operating system. Porting these applications into a Java ecosystem requires a flexible solution that incorporates the functionalities of scripts into a cohesive Java environment.
Key Features
JOE is engineered to address specific challenges encountered during such migrations. Its features include:
- Full Java Resource Access: Leverage the Java Virtual Machine (JVM) as a robust operating system, independent of the actual OS.
- Familiar Syntax: Easily adaptable to align closely with common scripting languages, enhancing capability and readability.
- Customization: Modifiable to accelerate access to frequently used operations.
- Extendability: Designed for future application enhancements, making it useful beyond migration tasks.
- Simplicity: User-friendly and easy to learn.
- Java Compatibility: Ensures 100% compatibility with existing Java resources.
Usage
JOE executes methods of Java objects in sequence on the fly, conveniently simulating various scripting language functionalities. Here's a quick overview of the syntax:
*message:* [var {`:=`|`<-`} ] obj [ method1 { `;` | obj-arg1-1 [`,`obj-arg1-2] ... } [ method2 { `;` | obj-arg2-1 [`,`obj-arg2-2] ...}] ... ].
*block:* `{` [[name]`:`[arg1 [`,`arg2] ...]`.`] [*message*] ... `}`
Examples
Arithmetic Expression
This snippet evaluates a basic arithmetic expression:
result := 2 * (3 + 4).
Factorial Calculation
The following script computes the factorial of 6:
fact <- {:n.
n > 1 ifTrue {
n * (fact exec (n - 1)).
},{
1.
}.
}.
!println (fact exec 6).
File Contents Printer
This example showcases how to read and print the contents of a file:
:args.
args length; > 1 ifTrue {
Paths <- !getClassRef"java.nio.file.Paths".
Files <- !getClassRef"java.nio.file.Files".
cs <- !getClassRef "java.nio.charset.Charset" defaultCharset.
!foreach (Files readAllLines (Paths get (args get 1),""),cs),{:line.
!println line.
}.
}.
Swing GUI Example
This script uses a simple Swing GUI for user interaction:
title <- "Think of a number".
answer := 0.
high := 1023.
low := 1.
ntry := 1.
PLAIN_MESSAGE <- !getStaticField "javax.swing.JOptionPane","PLAIN_MESSAGE".
QUESTION_MESSAGE <- !getStaticField "javax.swing.JOptionPane","QUESTION_MESSAGE".
OptionPane <- !getClassRef "javax.swing.JOptionPane".
OptionPane showMessageDialog (),("Think of a number between "+low+" and "+high+
": I can guess it using 10 tries at most"),
title, PLAIN_MESSAGE.
options <- !array "High","Low","Correct".
!while { answer <> 2 },
{
try := ((high - low) / 2 + low).
answer := OptionPane showOptionDialog (), ("My guess is " + try), title,
0, QUESTION_MESSAGE, (), options, (options get 0).
!switch answer
case 0,{
high := try.
ntry := (ntry + 1).
}
case 1,{
low := try.
ntry := (ntry + 1).
}
default {
OptionPane showMessageDialog (),
("I guessed the number using "+ntry+" guess(es)"),
title, PLAIN_MESSAGE.
}.
}.
For more detailed information, a tutorial is available here.
Additionally, a C language version of JOE has been developed for small devices, such as those used in automation, robotics, and the Internet of Things (IoT). This version is designed to maintain a small memory footprint while allowing for object-oriented interpretation with garbage collection and retains nearly all the features of the Java variant, though without the Java objects library. It can be compiled on Windows and Linux, with potential compatibility on other platforms.
No comments yet.
Sign in to be the first to comment.