- Java code in java script
- Java to javascript converter
- Comment
- New Comment
- Saved searches
- Use saved searches to filter your results more quickly
- wyattades/java-to-javascript
- Name already in use
- Sign In Required
- Launching GitHub Desktop
- Launching GitHub Desktop
- Launching Xcode
- Launching Visual Studio Code
- Latest commit
- Git stats
- Files
- README.md
Java code in java script
Convert Java Classes to ES6 Classes.
Translates: classes, methods, variables, statics, and more!
(Originally created for converting Processing to p5.js)
class MyClassint x = 42;static String y = "Life";MyClass(String secret)final String result = MyClass.y + secret + x;if (result != null)purpose();>>>
class MyClassconstructor(secret)this.x = 42;const result = MyClass.y + secret + this.x;if (result !== null)purpose();>>>MyClass.y = 'Life';
$ npm install java-to-javascript
script src="https://unpkg.com/java-to-javascript@latest/build/java-to-javascript.min.js">/script>
Note: You can replace latest with the library’s version you want to use, e.g. v0.1.10 . The library will be exposed on the global window scope as javaToJavascript .
Module API (For Node and the browser)
javaToJavascript(javaString, options?, progress?)
Returns: string — — Converted JavaScript
// Node module:var javaToJavascript = require('java-to-javascript');// Browser script:var javaToJavascript = window.javaToJavascript;var jsString = javaToJavascript( /* params */ );
Param | Type | Description |
---|---|---|
javaString | string | Java file contents |
[options] | object | |
[options.globalVars] | object | Object keys are added to the globalScope object. If the value is a string, the variable is renamed to that string |
[options.globalScope] | string | If specified, variables in globalVars are appended to globalScope object |
[options.p5] | boolean | Sets globalScope to ‘p5’ , adds p5 variable mappings to globalVars , and allows for global methods and variables |
[options.ugly] | boolean | Don’t beautify JavaScript code |
[progress] | function | Callback on progress of conversion. Args are progress value (0.0 to 1.0), and a message string |
Usage: java-to-javascript [options] Options: -V, --version output the version number -o, --output Specifies the output filename. (Default is the input filename with a .js extension) -s, --scope If specified, variables in `globals` are appended to `scope` object -g, --globals JSON or JavaScript file containing a global variable mapping. See README --p5 Sets `scope` to "p5", adds p5 variable mappings to `globals`, and allows for global methods and variables --ugly Don't beautify JavaScript code -h, --help output usage information
- Parse Java code to create an AST (abstract syntax tree)
- Replace global variables that the user specifies
- Generate JavaScript code from the AST
- Beautify JavaScript
I’ve included some Java Class (partial) polyfills in polyfills.js that help in the conversion of Java to JS.
Included Polyfills: List (alias ArrayList ), Map (alias HashMap )
- Local variables or method parameters with the same name as a variable in their class will incorrectly be assigned to the this object. Example Input Java:
class Thingint x, y;myMethod(int x)int y = 20;this.x = x + y;>>
class ThingmyMethod(x)let y = 20;this.x = this.x + this.y;>>
/* I don't know the exact cause, but here's what I have found: */((testFunc())); // Normal(((testFunc()))); // Long parse time((((testFunc())))); // Infinitely hangs
- Nested classes aka anonymous classes
- Synchronized methods and statements
- Interfaces and abstract classes
- Enums
- Packages and imports
This is a work in progress! Not all Java features are supported, and some are too difficult to translate to JS, so make sure to doublecheck the resulting code (Also, it assumes you are passing in valid Java).
- Java lexical parser: Github user mazko (https://github.com/mazko/jsjavaparser/blob/master/src/Java.1.7.pegjs)
- Lexical Parser -> JS: peg.js
Java to javascript converter
This tool are designed to convert OOPS based javascript code.
- Online java to python converter
- Online java to c# converter
- Online Java To PHP Converter
- Online java to vb.net converter
- Online java to javascript converter
- Online java to swift converter
- Java to c++ converter online
- Java to typescript converter online
- Java to dart converter online
- Java to ruby converter online
- Java to scala converter online
- Java to groovy converter online
- Java to golang converter online
- Online java to rust converter
- Online python to php converter
Comment
Please share your knowledge to improve code and content standard. Also submit your doubts, and test case. We improve by your feedback. We will try to resolve your query as soon as possible.
New Comment
não funciona /*------------------------- Important Note 1 [Import missing java 8 package.] 2 [Check syntax error.] Or Servers are busy try after some time -------------------------*/ Test.java.java:3: error: package gnu.java.beans does not exist import gnu.java.beans.DefaultExceptionListener; ^ Test.java.java:4: error: package gnu.java.beans.encoder does not exist import gnu.java.beans.encoder.ArrayPersistenceDelegate; ^ Test.java.java:5: error: package gnu.java.beans.encoder does not exist import gnu.java.beans.encoder.ClassPersistenceDelegate; ^ Test.java.java:6: error: package gnu.java.beans.encoder does not exist import gnu.java.beans.encoder.CollectionPersistenceDelegate; ^ Test.java.java:7: error: package gnu.java.beans.encoder does not exist import gnu.java.beans.encoder.MapPersistenceDelegate; ^ Test.java.java:8: error: package gnu.java.beans.encoder does not exist import gnu.java.beans.encoder.PrimitivePersistenceDelegate; ^ Test.java.java:69: error: cannot find symbol delegates.put(Class.class, new ClassPersistenceDelegate()); ^ symbol: class ClassPersistenceDelegate location: class Encoder Test.java.java:71: error: cannot find symbol PersistenceDelegate pd = new PrimitivePersistenceDelegate(); ^ symbol: class PrimitivePersistenceDelegate location: class Encoder Test.java.java:80: error: cannot find symbol delegates.put(Object[].class, new ArrayPersistenceDelegate()); ^ symbol: class ArrayPersistenceDelegate location: class Encoder Test.java.java:82: error: cannot find symbol pd = new CollectionPersistenceDelegate(); ^ symbol: class CollectionPersistenceDelegate location: class Encoder Test.java.java:85: error: cannot find symbol pd = new MapPersistenceDelegate(); ^ symbol: class MapPersistenceDelegate location: class Encoder Test.java.java:135: error: cannot find symbol ? listener : DefaultExceptionListener.INSTANCE; ^ symbol: variable DefaultExceptionListener location: class Encoder Note: Test.java.java uses unchecked or unsafe operations. Note: Recompile with -Xlint:unchecked for details. 12 errors sendo que é a classe java.beans.Encoder.java da oracle me diz como é que está errado
Saved searches
Use saved searches to filter your results more quickly
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session.
Convert Java Classes to ES6 Classes
wyattades/java-to-javascript
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Sign In Required
Please sign in to use Codespaces.
Launching GitHub Desktop
If nothing happens, download GitHub Desktop and try again.
Launching GitHub Desktop
If nothing happens, download GitHub Desktop and try again.
Launching Xcode
If nothing happens, download Xcode and try again.
Launching Visual Studio Code
Your codespace will open once ready.
There was a problem preparing your codespace, please try again.
Latest commit
Git stats
Files
Failed to load latest commit information.
README.md
Convert Java Classes to ES6 Classes.
Translates: classes, methods, variables, statics, and more!
(Originally created for converting Processing to p5.js)
class MyClass < int x = 42; static String y = "Life"; MyClass(String secret) < final String result = MyClass.y + secret + x; if (result != null) < purpose(); > > >
class MyClass constructor(secret) this.x = 42; const result = MyClass.y + secret + this.x; if (result !== null) purpose(); > > > MyClass.y = 'Life';
$ npm install java-to-javascript
script src pl-s">https://unpkg.com/java-to-javascript@latest/build/java-to-javascript.min.js">script>
Note: You can replace latest with the library’s version you want to use, e.g. v0.1.10 . The library will be exposed on the global window scope as javaToJavascript .
Module API (For Node and the browser)
javaToJavascript(javaString, options?, progress?)
Returns: string — — Converted JavaScript
// Node module: var javaToJavascript = require('java-to-javascript'); // Browser script: var javaToJavascript = window.javaToJavascript; var jsString = javaToJavascript( /* params */ );
Param | Type | Description |
---|---|---|
javaString | string | Java file contents |
[options] | object | |
[options.globalVars] | object | Object keys are added to the globalScope object. If the value is a string, the variable is renamed to that string |
[options.globalScope] | string | If specified, variables in globalVars are appended to globalScope object |
[options.p5] | boolean | Sets globalScope to ‘p5’ , adds p5 variable mappings to globalVars , and allows for global methods and variables |
[options.ugly] | boolean | Don’t beautify JavaScript code |
[progress] | function | Callback on progress of conversion. Args are progress value (0.0 to 1.0), and a message string |
Usage: java-to-javascript [options] Options: -V, --version output the version number -o, --output Specifies the output filename. (Default is the input filename with a .js extension) -s, --scope If specified, variables in `globals` are appended to `scope` object -g, --globals JSON or JavaScript file containing a global variable mapping. See README --p5 Sets `scope` to "p5", adds p5 variable mappings to `globals`, and allows for global methods and variables --ugly Don't beautify JavaScript code -h, --help output usage information
- Parse Java code to create an AST (abstract syntax tree)
- Replace global variables that the user specifies
- Generate JavaScript code from the AST
- Beautify JavaScript
I’ve included some Java Class (partial) polyfills in polyfills.js that help in the conversion of Java to JS.
Included Polyfills: List (alias ArrayList ), Map (alias HashMap )
- Local variables or method parameters with the same name as a variable in their class will incorrectly be assigned to the this object. Example Input Java:
class Thing < int x, y; myMethod(int x) < int y = 20; this.x = x + y; > >
class Thing myMethod(x) let y = 20; this.x = this.x + this.y; > >
/* I don't know the exact cause, but here's what I have found: */ ((testFunc())); // Normal (((testFunc()))); // Long parse time ((((testFunc())))); // Infinitely hangs
- Nested classes aka anonymous classes
- Synchronized methods and statements
- Interfaces and abstract classes
- Enums
- Packages and imports
This is a work in progress! Not all Java features are supported, and some are too difficult to translate to JS, so make sure to doublecheck the resulting code (Also, it assumes you are passing in valid Java).