diff --git a/README.md b/README.md index a2da9bf..002aff4 100644 --- a/README.md +++ b/README.md @@ -2,15 +2,33 @@ I've built on top of the [java-to-javascript](https://github.com/wyattades/java-to-javascript) transpiler by @wyattades and got inspiration from the JDK (Java Development Kit) implementation in [java2javascript](https://github.com/java2script/java2script) by @BobHanson, @zhourenjian, @abego, and others. -My purpose in creating this project is to allow intro level CS students to write Java code but still use my QuintOS library which is web based. Yes, I went to all this trouble just so some teenagers don't have to run their programs in a boring Java console! I made a barebones JDK implementation in modern Javascript to acheive this. +My purpose in creating this project is to allow intro level CS students to write Java code but still use my [QuintOS](https://github.com/quinton-ashley/quintos) retro game engine library which is web based. Yes, I went to all this trouble just so some teenagers don't have to run their programs in a boring Java console! I made a barebones JDK implementation in modern Javascript to acheive this. + +## API + +### jdk.init(root) + +- root is the local path or url to the parent folder of the jdk, by default it links to 'https://unpkg.com/java2js' (this package) so you don't need to change it + +This function imports much of the standard Java lang classes into the global scope. You must use it before translating or running files. + +### jdk.translate(javaFile) + +- javaFile is a string with contents of a Java file + +returns the Java file translated into JavaScript + +### jdk.run(translatedJSFile) + +- translatedJSFile is the translated JS class to run ## Known limitations - casting to int truncation workaround requires parenthesis around the number being cast -- no support for method overloading, though a workaround could be made by making a function with the og name route to each of the variations of the overloaded function +- no support for method overloading, though a workaround might be possible by making a function with the og name route to each of the variations of the overloaded function -- no support for private/public methods, though this could be done since they are included in modern JavaScript classes +- no support for private/public methods yet, though this could be done since they are included in modern JavaScript classes ## Contribute diff --git a/jdk.js b/jdk.js index e98ffa3..3c383b5 100755 --- a/jdk.js +++ b/jdk.js @@ -48,7 +48,7 @@ constructor() {} async init(root) { - this.root = root || '.'; + this.root = root || 'https://unpkg.com/java2js'; this.java = {}; let pkgs = ['com', 'lang', 'org', 'io', 'util']; for (let pkg of pkgs) { diff --git a/jdk/java/lang/String.js b/jdk/java/lang/String.js index 9882b5b..6fa4bf1 100755 --- a/jdk/java/lang/String.js +++ b/jdk/java/lang/String.js @@ -19,6 +19,9 @@ jdk.imports['java.lang.String'].load = async () => { String.prototype.contains = function (substr) { return this.includes(substr); }; + String.prototype.equals = function (o) { + return this == o; + }; // static methods String.valueOf = (c) => { return c.toString(); diff --git a/package.json b/package.json index 689a75d..654f714 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "java2js", - "version": "1.0.8", + "version": "1.0.9", "description": "Converts Java to JavaScript with support for p5.js and QuintOS.", "main": "jdk.js", "scripts": {