What I did was basically follow the OP's answer, but I had beforehand to create the .jar file. To do so, I just prepared my custom class in test.java:
import java.lang.System;
public class Test {
public static void main(String[] args) {
System.out.println("Hello, world!");
}
}
And then
javac Test.java
jar cf test.jar Test.class
Now you should see the .jar created. From this point, you are able to access it from Javascript:
let java= require('java');
java.classpath.push('test.jar');
let test = java.import("Test");
test.main(null) // should print "Hello, World!"
Answer from testing_22 on Stack OverflowWhat I did was basically follow the OP's answer, but I had beforehand to create the .jar file. To do so, I just prepared my custom class in test.java:
import java.lang.System;
public class Test {
public static void main(String[] args) {
System.out.println("Hello, world!");
}
}
And then
javac Test.java
jar cf test.jar Test.class
Now you should see the .jar created. From this point, you are able to access it from Javascript:
let java= require('java');
java.classpath.push('test.jar');
let test = java.import("Test");
test.main(null) // should print "Hello, World!"
After a lot of trying, this is what worked for me: (test.jar is in same directory as the other files)
let java= require('java');
java.classpath.push('test.jar');
let mySumTest= java.import("MySumClass");
/*
//this prints out undefined, don't know why
console.log(java.callStaticMethod("MySumClass", "sum", 2, 5, function(err, results){
if(err){
console.error(err);
return;
}
else return results;
}));
*/
var result= java.callStaticMethodSync("MySumClass", "sum", 2, 5)
console.log(result)
While implementing the custom LinkedList/Tree, we need Node. Here is demo of creating Node and LinkedList. I have not put in all the logic. Just basic skeleton is here and you can then add more on yourself.

I can give you a quick hint on how to do that:
Class Node{
//these are private class attributes, you need getter and setter to alter them.
private int item;
private Node nextNode;
//this is a constructor with a parameter
public Node(int item)
{
this.item = item;
this.nextNode = null;
}
// a setter for your item
public void setItem(int newItem)
{
this.item = newItem;
}
// this is a getter for your item
public int getItem()
{
return this.item;
}
}
You can create a Node object by calling:
Node newNode = Node(2);
This is not a complete solution for your problem, the two parameter constructor and the last node link are missing, but this should lead you in the correct direction.