Skip to main content

Notice: this Wiki will be going read only early in 2024 and edits will no longer be possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.

Jump to: navigation, search

Difference between revisions of "VJET/Java2Js Language Translation Reference mapping"

(Array type)
 
(9 intermediate revisions by 2 users not shown)
Line 680: Line 680:
  
 
=== Type Variables ===
 
=== Type Variables ===
 
 
Implemented in comment
 
Implemented in comment
 
  
 
{| style="background-color:#F9F9F9;border:1px solid #AAAAAA;border-collapse:collapse;color:black; margin:1em 0;"
 
{| style="background-color:#F9F9F9;border:1px solid #AAAAAA;border-collapse:collapse;color:black; margin:1em 0;"
Line 689: Line 687:
 
<source lang="java">
 
<source lang="java">
 
package com.ebay.dsf.javatojs.tests.operators;
 
package com.ebay.dsf.javatojs.tests.operators;
 
 
public class Pair<T, S>{
 
public class Pair<T, S>{
 
 
private T first;
 
private T first;
 
 
private S second;
 
private S second;
 
  
 
public Pair(T f, S s){  
 
public Pair(T f, S s){  
 
 
first = f;
 
first = f;
 
 
second = s;  
 
second = s;  
 
 
}
 
}
 
  
 
public T getFirst() {
 
public T getFirst() {
 
 
return first;
 
return first;
 
 
}
 
}
 
  
 
public S getSecond(){
 
public S getSecond(){
 
 
return second;
 
return second;
 
 
}
 
}
 
 
}
 
}
 
</source>
 
</source>
 
  
 
| style="border:1px solid #AAAAAA;padding: 0.2em;"|
 
| style="border:1px solid #AAAAAA;padding: 0.2em;"|
 
<source lang="javascript">
 
<source lang="javascript">
 
vjo.ctype("com.ebay.dsf.javatojs.tests.operators.Pair")
 
vjo.ctype("com.ebay.dsf.javatojs.tests.operators.Pair")
 
 
.protos({
 
.protos({
 
 
//> private T first
 
//> private T first
 
 
first:null,
 
first:null,
 
 
//> private S second
 
//> private S second
 
 
second:null,
 
second:null,
 
 
//> public constructs(T f,S s)
 
//> public constructs(T f,S s)
 
 
constructs:function(f,s){
 
constructs:function(f,s){
 
 
this.first=f;
 
this.first=f;
 
 
this.second=s;
 
this.second=s;
 
 
},
 
},
 
 
//> public T getFirst()
 
//> public T getFirst()
 
 
getFirst:function(){
 
getFirst:function(){
 
 
return this.first;
 
return this.first;
 
 
},
 
},
 
 
//> public S getSecond()
 
//> public S getSecond()
 
 
getSecond:function(){
 
getSecond:function(){
 
 
return this.second;
 
return this.second;
 
 
}
 
}
 
 
})
 
})
 
 
.endType();
 
.endType();
 
</source>
 
</source>
 
 
  
 
|}
 
|}
  
 
=== Parameterized type ===
 
=== Parameterized type ===
 
  
 
{| style="background-color:#F9F9F9;border:1px solid #AAAAAA;border-collapse:collapse;color:black; margin:1em 0;"
 
{| style="background-color:#F9F9F9;border:1px solid #AAAAAA;border-collapse:collapse;color:black; margin:1em 0;"
Line 779: Line 739:
 
! style="background-color:#F2F2F2;text-align:center;border:1px solid #AAAAAA;padding:0.2em;"| Java
 
! style="background-color:#F2F2F2;text-align:center;border:1px solid #AAAAAA;padding:0.2em;"| Java
 
! style="background-color:#F2F2F2;text-align:center;border:1px solid #AAAAAA;padding:0.2em;"| Vjo
 
! style="background-color:#F2F2F2;text-align:center;border:1px solid #AAAAAA;padding:0.2em;"| Vjo
 
 
|- style="vertical-align:top"
 
|- style="vertical-align:top"
 
| style="border:1px solid #AAAAAA;padding: 0.2em;"|  
 
| style="border:1px solid #AAAAAA;padding: 0.2em;"|  
 
<source lang="java">
 
<source lang="java">
 
Vector<String> vector = new Vector();
 
Vector<String> vector = new Vector();
 
 
Collection<Integer> collection = new ArrayList<Integer>();
 
Collection<Integer> collection = new ArrayList<Integer>();
 
</source>
 
</source>
 
| style="border:1px solid #AAAAAA;padding: 0.2em;"|  
 
| style="border:1px solid #AAAAAA;padding: 0.2em;"|  
 
 
<source lang="javascript">
 
<source lang="javascript">
 
//> Vector<String> vector
 
//> Vector<String> vector
 
 
vector:null,
 
vector:null,
 
 
//> Collection<Integer> collection
 
//> Collection<Integer> collection
 
 
collection:null,
 
collection:null,
 
 
//> private constructs()
 
//> private constructs()
 
 
constructs:function(){
 
constructs:function(){
 
 
this.vector=new this.vjo.Vector();
 
this.vector=new this.vjo.Vector();
 
 
this.collection=new this.vjo.ArrayList();
 
this.collection=new this.vjo.ArrayList();
 
 
},
 
},
 
</source>
 
</source>
Line 824: Line 773:
 
|- style="vertical-align:top"
 
|- style="vertical-align:top"
 
| style="border:1px solid #AAAAAA;padding: 0.2em;"|  
 
| style="border:1px solid #AAAAAA;padding: 0.2em;"|  
 
 
<source lang="java">
 
<source lang="java">
 
static Integer classVariableInteger = new Integer(10);
 
static Integer classVariableInteger = new Integer(10);
 
 
static Float classVariableFloat;
 
static Float classVariableFloat;
 
 
static int classVariableInt;
 
static int classVariableInt;
 
</source>
 
</source>
Line 835: Line 781:
 
<source lang="javascript">
 
<source lang="javascript">
 
.props({
 
.props({
 
 
//> Integer classVariableInteger
 
//> Integer classVariableInteger
 
 
classVariableInteger:null,
 
classVariableInteger:null,
 
 
//> Float classVariableFloat
 
//> Float classVariableFloat
 
 
classVariableFloat:null,
 
classVariableFloat:null,
 
 
//> int classVariableInt
 
//> int classVariableInt
 
 
classVariableInt:0
 
classVariableInt:0
 
 
})
 
})
 
 
.inits(function(){
 
.inits(function(){
 
 
this.vjo.Pair.classVariableInteger=new this.vjo.Integer(10);
 
this.vjo.Pair.classVariableInteger=new this.vjo.Integer(10);
 
 
})
 
})
 
</source>
 
</source>
 
|}
 
|}
 +
 
==== Instance variable ====
 
==== Instance variable ====
 
{| style="background-color:#F9F9F9;border:1px solid #AAAAAA;border-collapse:collapse;color:black; margin:1em 0;"
 
{| style="background-color:#F9F9F9;border:1px solid #AAAAAA;border-collapse:collapse;color:black; margin:1em 0;"
Line 863: Line 800:
 
<source lang="java">
 
<source lang="java">
 
package com.ebay.dsf.javatojs.tests.operators;
 
package com.ebay.dsf.javatojs.tests.operators;
 
 
public class Pair{
 
public class Pair{
 
 
Integer classVariableInteger = new Integer(10);
 
Integer classVariableInteger = new Integer(10);
 
 
Float classVariableFloat;
 
Float classVariableFloat;
 
 
int classVariableInt;
 
int classVariableInt;
 
 
}
 
}
 
</source>
 
</source>
Line 877: Line 809:
 
<source lang="javascript">
 
<source lang="javascript">
 
vjo.ctype("com.ebay.dsf.javatojs.tests.operators.Pair")
 
vjo.ctype("com.ebay.dsf.javatojs.tests.operators.Pair")
 
 
.needs("vjo.java.lang.Integer")
 
.needs("vjo.java.lang.Integer")
 
 
.needs("vjo.java.lang.Float")
 
.needs("vjo.java.lang.Float")
 
 
.protos({
 
.protos({
 
 
//> Integer classVariableInteger
 
//> Integer classVariableInteger
 
 
classVariableInteger:null,
 
classVariableInteger:null,
 
 
//> Float classVariableFloat
 
//> Float classVariableFloat
 
 
classVariableFloat:null,
 
classVariableFloat:null,
 
 
//> int classVariableInt
 
//> int classVariableInt
 
 
classVariableInt:0,
 
classVariableInt:0,
 
 
//> private constructs()
 
//> private constructs()
 
 
constructs:function(){
 
constructs:function(){
 
 
this.classVariableInteger=new this.vjo.Integer(10);
 
this.classVariableInteger=new this.vjo.Integer(10);
 
 
}
 
}
 
 
})
 
})
 
 
.endType();
 
.endType();
 
</source>
 
</source>
 
|}
 
|}
 +
 
==== Array components – are unknown variables - partially implemented ====
 
==== Array components – are unknown variables - partially implemented ====
 
{| style="background-color:#F9F9F9;border:1px solid #AAAAAA;border-collapse:collapse;color:black; margin:1em 0;"
 
{| style="background-color:#F9F9F9;border:1px solid #AAAAAA;border-collapse:collapse;color:black; margin:1em 0;"
Line 915: Line 833:
 
<source lang="java">
 
<source lang="java">
 
package com.ebay.dsf.javatojs.tests.operators;
 
package com.ebay.dsf.javatojs.tests.operators;
 
 
public class Pair{  
 
public class Pair{  
 
 
String[] stringArray = {new String(), new String()};
 
String[] stringArray = {new String(), new String()};
 
 
Integer[] intArray;  
 
Integer[] intArray;  
 
 
//Pair[] pairArrayInit = {new Pair(), new Pair()};
 
//Pair[] pairArrayInit = {new Pair(), new Pair()};
 
 
Pair(){
 
Pair(){
 
 
intArray = new Integer[2];
 
intArray = new Integer[2];
 
 
intArray[0] = new Integer(20);
 
intArray[0] = new Integer(20);
 
 
intArray[1] = 30;
 
intArray[1] = 30;
 
 
}
 
}
 
 
}
 
}
 
</source>
 
</source>
Line 939: Line 847:
 
<source lang="javascript">
 
<source lang="javascript">
 
vjo.ctype("com.ebay.dsf.javatojs.tests.operators.Pair")
 
vjo.ctype("com.ebay.dsf.javatojs.tests.operators.Pair")
 
 
.needs("vjo.java.lang.Integer")
 
.needs("vjo.java.lang.Integer")
 
 
.needs("vjo.java.lang.StringFactory")
 
.needs("vjo.java.lang.StringFactory")
 
 
.protos({
 
.protos({
 
 
//> String[] stringArray
 
//> String[] stringArray
 
 
stringArray:null,
 
stringArray:null,
 
 
//> Integer[] intArray
 
//> Integer[] intArray
 
 
intArray:null,
 
intArray:null,
 
 
//> constructs()
 
//> constructs()
 
 
constructs:function(){
 
constructs:function(){
 
 
this.stringArray=
 
this.stringArray=
 
                     [vjo.java.lang.StringFactory.build(),
 
                     [vjo.java.lang.StringFactory.build(),
 
                     vjo.java.lang.StringFactory.build()];
 
                     vjo.java.lang.StringFactory.build()];
 
 
this.intArray=new Array(2);
 
this.intArray=new Array(2);
 
 
this.intArray[0]=new this.vjo.Integer(20);
 
this.intArray[0]=new this.vjo.Integer(20);
 
 
this.intArray[1]=30;
 
this.intArray[1]=30;
 
 
}
 
}
 
 
})
 
})
 
 
.endType();
 
.endType();
 
</source>
 
</source>
Line 2,331: Line 2,223:
 
| style="border:1px solid #AAAAAA;padding: 0.2em;"|
 
| style="border:1px solid #AAAAAA;padding: 0.2em;"|
 
<source lang="javascript">
 
<source lang="javascript">
vjo.atype("j2jtest.AbstractClassTest")
+
vjo.ctype("j2jtest.AbstractClassTest")
 
.endType();
 
.endType();
 
</source>
 
</source>
Line 2,933: Line 2,825:
 
}</source>
 
}</source>
 
| style="border:1px solid #AAAAAA;padding: 0.2em;"| <source lang="javascript">  
 
| style="border:1px solid #AAAAAA;padding: 0.2em;"| <source lang="javascript">  
vjo.atype("j2jtest.Pair2")
+
vjo.ctype("j2jtest.Pair2") //< abstract
 
.props({
 
.props({
 
//> void staticMethod()
 
//> void staticMethod()
Line 3,087: Line 2,979:
 
//> FinalClass fClass
 
//> FinalClass fClass
 
fClass:null,
 
fClass:null,
Abstractclass:vjo.atype()
+
Abstractclass:vjo.ctype() //< abstract
 
.endType(),
 
.endType(),
 
MyInterface:vjo.itype()
 
MyInterface:vjo.itype()
Line 4,509: Line 4,401:
  
  
[[Category:VJET]]
+
[[Category:VJET|Java2JS]]
 +
[[Category:JavaToJs]]

Latest revision as of 21:58, 28 January 2013

Contents

Lexical Structure

Comment

Not supported in AST parser

Identifier

Keywords

Below map shows java keyword mapping in JS/VJO

Java-keyword Js – keyword Vjo Js-reserved
break

case

catch

continue

default

do

else

finally

for

if

try

throw

instanceof

new

return

void

switch

this

while

break

case

catch

continue

default

do

else

finally

for

if

try

throw

instanceof

new

return

void

switch

this

while

boolean

char

short

int

double

float

long

short

public

protected

private

final


implements

extends

class

interface

import

static

enum

package

boolean

Int

short

int

double

float

long

short

public

protected

private

final


< satisfies >

< .inherits >

< .ctype >

<.itype>

< vjo.needs >

< .props({ }) >

< vjo.etype("pkg.Enum") >

< vjo.ctype("vjo.pkgname")>

boolean

char

short

int

double

float

long

short

public

protected

private

final


implements

extends

class

interface

import

static

enum

package

abstract

byte

const- reserved

goto -reserved

super

native

synchronized

transient


volatile

throws

assert

strictfp

abstract

byte

const

goto


super

native

synchronize

transient


volatile

throws


debugger

export

delete

function

in

var

with

typeof

Literals

java JS desc
Boolean literals


true, false

true. false Literals true/false are directly mapped in java script
null


null / false


Seperators

Java JS
( ) { } [ ] ; , . Directly mapped

Operators

All operators are directly mapped into js.

Java operators Java Js Description
# =
  1. >
  2. <
  3.  !
  4. ~
  5.  ?:
  6. ==
  7. <=
  8. >=
  9.  !=
  10. &&
  11. ||
  12. ++
  13. --
  14. +
  15. -
  16. *
  17. /
  18. &
  19. |
  20. ^
  21.  %
  22. <<
  23. >>
  24. >>>
  25. +=
  26. -=
  27. *=
  28. /=
  29. &=
  30. |=
  31. ^=
  32.  %=
  33. <<=
  34. >>=
  35. >>>=


a= b;

a = a+b;

a = a-b;

a = a * b;

a = a/b;

a = a&b;

if(a>b){}

if(a<b){}

if( !(a==b) && (x!=y) || (a<x) || (b>x) || (b<=a) || (x>=y) ){}

a= a++;

a= a--;

a = b^a;

a = a%b;

a +=b;

a -=b;

a *=b;

a /=b;

a &=x;

a ^= b;

a %= b;

a<<=b;

a>>=b;

a>>>=b;

a=b;

a=a+b;

a=a-b;

a=a*b;

a=parseInt(a/b);

a=a&b;

if(a>b){

}

if(a<b){

}

if( !(a==b)&&(x!=y)||(a<x)||(b>x)||(b<=a) || (x>=y)){

}

a=a++;

a=a--;

a=b^a;

a=a%b;

a+=b;

a-=b;

a*=b;

a=parseInt(a/b);

a&=x;

a^=b;

a%=b;

a<<=b;

a>>=b;

a>>>=b;

Direct translation

Types, Values and Variables

Primitive types and values

Java js

boolean

byte

char

short


int

long

double

float

boolean

int, indirectly supported , declared as int

int, indirectly supported, declared as int

short


int

long

double

float

Reference Types & Values

Class type

Java Vjo
package com.ebay.dsf.javatojs.tests;
 
public class A {
	int a=10;
	public int p=50;
	String city;
	String state;
	public void setCity(String c ){
		this.city=c;
	} 
	public String getCity(){
		return this.city;
	}
	protected void setState(String s){
		this.state=s;
	}
	protected String getState(){
		return this.state;
	}
	String foo(){
		return "foo";
	}
}
vjo.ctype("com.ebay.dsf.javatojs.tests.A")
.protos({
	//> int a
	a:10,
	//> public int p
	p:50,
	//> String city
	city:null,
	//> String state
	state:null,
	//> public void setCity(String c)
	setCity:function(c){
		this.city=c;
	},
	//> public String getCity()
	getCity:function(){
		return this.city;
	},
	//> protected void setState(String s)
	setState:function(s){
		this.state=s;
	},
	//> protected String getState()
	getState:function(){
		return this.state;
	},
	//> String foo()
	foo:function(){
		return "foo";
	}
})
 
.endType();

interface type

Java Vjo
package com.ebay.dsf.javatojs.tests.Inheritance;
public interface Interface3 {
	 String C3="c3";
	 String method3();
}
vjo.itype("com.ebay.dsf.javatojs.tests.Inheritance.Interface3")
.props({
	//> public String C3
	C3:"c3"
})
.protos({
	//> public String method3()
	method3:function(){
	}
})
.endType();

Array type

Java Vjo
long avg = 10;
long[] la = {1+avg,2,3}; 
int[][] twoDimArray = {{1,2,3}, {4,5,6}};
String[] sa = { "a", "b", "c"};
String[] sa2 = new String[2];
Employee[] sa3 = new Employee[2];
boolean boolArr1[] 
= new boolean[]{true};
boolean boolArr2[][] 
= new boolean[][]{{false}};
boolean boolArr11[] 
= new boolean[twoDimArray[0][0]];
boolean boolArr12[][] 
= new boolean[twoDimArray[0][0]] [twoDimArray[0][1]];
var avg=10;
var la=[1+avg,2,3];
var twoDimArray=[[1,2,3],[4,5,6]];
var sa=["a","b","c"];
var sa2=new Array(2);
var sa3=new Array(2);
var boolArr1=[true];
var boolArr2=[[false]];
var boolArr11=new Array(twoDimArray[0][0]);
var boolArr12=new Array;

Type Variables

Implemented in comment

package com.ebay.dsf.javatojs.tests.operators;
public class Pair<T, S>{
	private T first;
	private S second;
 
	public Pair(T f, S s){ 
		first = f;
		second = s; 
	}
 
	public T getFirst() {
		return first;
	}
 
	public S getSecond(){
		return second;
	}
}
vjo.ctype("com.ebay.dsf.javatojs.tests.operators.Pair")
.protos({
	//> private T first
	first:null,
	//> private S second
	second:null,
	//> public constructs(T f,S s)
	constructs:function(f,s){
		this.first=f;
		this.second=s;
	},
	//> public T getFirst()
	getFirst:function(){
		return this.first;
	},
	//> public S getSecond()
	getSecond:function(){
		return this.second;
	}
})
.endType();

Parameterized type

Java Vjo
Vector<String> vector = new Vector();
Collection<Integer> collection = new ArrayList<Integer>();
//> Vector<String> vector
vector:null,
//> Collection<Integer> collection
collection:null,
//> private constructs()
constructs:function(){
	this.vector=new this.vjo.Vector();
	this.collection=new this.vjo.ArrayList();
},

Sub-Typing

  1. Subtyping among primitive types
  2. Subtyping among class and interface
  3. Subtyping among array types

class type is defined using vjo .ctypas as

Variables

Class variable

static Integer classVariableInteger = new Integer(10);
static Float classVariableFloat;
static int classVariableInt;
.props({
	//> Integer classVariableInteger
	classVariableInteger:null,
	//> Float classVariableFloat
	classVariableFloat:null,
	//> int classVariableInt
	classVariableInt:0
})
.inits(function(){
	this.vjo.Pair.classVariableInteger=new this.vjo.Integer(10);
})

Instance variable

package com.ebay.dsf.javatojs.tests.operators;
public class Pair{
	Integer classVariableInteger = new Integer(10);
	Float classVariableFloat;
	int classVariableInt;
}
vjo.ctype("com.ebay.dsf.javatojs.tests.operators.Pair")
.needs("vjo.java.lang.Integer")
.needs("vjo.java.lang.Float")
.protos({
	//> Integer classVariableInteger
	classVariableInteger:null,
	//> Float classVariableFloat
	classVariableFloat:null,
	//> int classVariableInt
	classVariableInt:0,
	//> private constructs()
	constructs:function(){
	this.classVariableInteger=new this.vjo.Integer(10);
}
})
.endType();

Array components – are unknown variables - partially implemented

package com.ebay.dsf.javatojs.tests.operators;
public class Pair{ 
	String[] stringArray = {new String(), new String()};
	Integer[] intArray; 
	//Pair[] pairArrayInit = {new Pair(), new Pair()};
	Pair(){
		intArray = new Integer[2];
		intArray[0] = new Integer(20);
		intArray[1] = 30;
	}
}
vjo.ctype("com.ebay.dsf.javatojs.tests.operators.Pair")
.needs("vjo.java.lang.Integer")
.needs("vjo.java.lang.StringFactory")
.protos({
	//> String[] stringArray
	stringArray:null,
	//> Integer[] intArray
	intArray:null,
	//> constructs()
	constructs:function(){
		this.stringArray=
                    [vjo.java.lang.StringFactory.build(),
                    vjo.java.lang.StringFactory.build()];
		this.intArray=new Array(2);
		this.intArray[0]=new this.vjo.Integer(20);
		this.intArray[1]=30;
	}
})
.endType();

Method parameters

package com.ebay.dsf.javatojs.tests.operators;
public class Pair{ 
	public Pair myMethod(String s, Pair p){
		String paramString = s;
		Pair parameterPair = p;
		return parameterPair;
	}
}
vjo.ctype("com.ebay.dsf.javatojs.tests.operators.Pair")
.protos({
	//> public Pair myMethod(String s,Pair p)
	myMethod:function(s,p){
		var paramString=s;
		var parameterPair=p;
		return parameterPair;
	}
})
.endType();
Parameter s, and p exist only within the function

Constructor parameters

package com.ebay.dsf.javatojs.tests.operators;
public class Pair{ 
	String s;
	Integer i;
	Pair(String s, Integer i){
		 this.s =s;
		 this.i=i;
	}
}
vjo.ctype("com.ebay.dsf.javatojs.tests.operators.Pair")
.needs("vjo.java.lang.Integer")
.protos({
	//> String s
	s:null,
	//> Integer i
	i:null,
	//> constructs(String s,Integer i)
	constructs:function(s,i){
		this.s=s;
		this.i=i;
	}
})
.endType();

Exception-handler parameter

package com.ebay.dsf.javatojs.tests.operators;
public class Pair {
	public Integer getNumber(){
		Integer i = 10;
		String s = "20.9";
	try{
		i = new Integer(s);
	}catch(NumberFormatException nfe){
		i = 0;
	}
	return i;
	}
}
vjo.ctype("com.ebay.dsf.javatojs.tests.operators.Pair")
.needs("vjo.java.lang.Integer")
.needs("vjo.java.lang.NumberFormatException")
.protos({
    //> public Integer getNumber()
        getNumber:function(){
            var i=10;
            var s="20.9";
            try {
                i=new this.vjo.Integer(s);
            }
            catch(nfe){
                i=0;
            }
            return i;
        }
})
.endType();
Note: variable nfe only exists inside catch block.

Local variables

package com.ebay.dsf.javatojs.tests.operators;
public class Pair { 
    public void getNumber(){
        String s = new String();
        Integer i = 20;
        {
            String second = "2";
        }
    }
}
vjo.ctype("com.ebay.dsf.javatojs.tests.operators.Pair")
.needs("vjo.java.lang.Integer")
.needs("vjo.java.lang.StringFactory")
.protos({
    //> public void getNumber()
    getNumber:function(){
        var s=vjo.java.lang.StringFactory.build();
        var i=20;
        {
        var second="2";
        }
    }
})
.endType();

Conversions and Promotions

Note1: widening conversions do not require casts

Note2: narrowing conversions require explicit casts.

Identity conversions – conversion to a same type, straight forward

Widening primitive conversions

java js

byte b = 10;

short s = b;

int i = b;

long l = b;

float f = b;

double d = b;

var b=10;

var s=b;

var i=b;

var l=b;

var f=b;

var d=b;

# byte to short, int, long, float, or double
  1. short to int, long, float, or double
  2. char to int, long, float, or double
  3. int to long, float, or double
  4. long to float or double
  5. float to double
All conversions are straight forward in js

Narrowing primitive conversions

java vjo

long l = 100l;

byte b = (byte)l;

short s = (short)l;

char c = (char)l;

int i = (int)l;

var l=100;

var b=vjo.java.lang.Util.cast(l,'byte');

var s=vjo.java.lang.Util.cast(l,'short');

var c=l; // there is no casting to char

var i=vjo.java.lang.Util.cast(l,'int');

  1. short to byte or char
  2. char to byte or short
  3. int to byte, short, or char
  4. long to byte, short, char, or int
  5. float to byte, short, char, int, or long
  6. double to byte, short, char, int, long, or float
Note: Uses vjo util class to cast

Widening reference conversions

java vjo
String stringObj = new String();
Object object = new Object();
object = stringObj;
var stringObj=vjo.java.lang.StringFactory.build();
var object=new vjo.Object();
object=stringObj;
Note: Uses vjo reference implementation for all reference types

Narrowing reference conversions

Java Vjo
package com.ebay.dsf.javatojs.tests.operators;
import java.util.List;
public class Pair{ 
    public List getNumber(Object object){
        List list = (List) object;
        String str = (String) object;
        Object myObj = str;
        return list;
    }
}
vjo.ctype("com.ebay.dsf.javatojs.tests.operators.Pair")
.needs("vjo.java.util.List")
.protos({
    //> public List getNumber(vjo.Object object)
    getNumber:function(object){
        var list=object;
        var str=object;
        var myObj=str;
        return list;
    }
})
.endType();
Note:

Boxing conversions

Java vjo
package com.ebay.dsf.javatojs.tests.operators;
import java.util.List;
public class Pair{ 
    Byte ob = 0;
    Short os = 1;
    Integer oi = 10;
    Long ol = 20l;
    Character oc = 'C';
    Float of = 10.2f;
    Double od = 12.3;
    public void test(){
        Byte ob = 0;
         Short os = 1;
        Integer oi = 10;
        Long ol = 20l;
        Character oc = 'C'<nowiki>;</nowiki>
        Float of = 10.2f;
        Double od = 12.3;
    }
}
vjo.ctype("com.ebay.dsf.javatojs.tests.operators.Pair")
.needs("vjo.java.lang.Byte")
.needs("vjo.java.lang.Short")
.needs("vjo.java.lang.Integer")
.needs("vjo.java.lang.Long")
.needs("vjo.java.lang.Character")
.needs("vjo.java.lang.Float")
.needs("vjo.java.lang.Double")
.protos({
	//> Byte ob
	ob:0,
	//> Short os
	os:1,
	//> Integer oi
	oi:10,
	//> Long ol
	ol:20,
	//> Character oc
	oc:'C',
	//> Float of
	of:10.2,
	//> Double od
	od:12.3,
	//> public void test()
	test:function(){
		var ob=0;
		var os=1;
		var oi=10;
		var ol=20;
		var oc='C';
		var of=10.2;
		var od=12.3;
	}
})
.endType();
Type is declared in comment for jst translation
  1. From type boolean to type Boolean
  2. From type byte to type Byte
  3. From type char to type Character
  4. From type short to type Short
  5. From type int to type Integer
  6. From type long to type Long
  7. From type float to type Float
  8. From type double to type Double

Unboxing conversions

Java Vjo
package com.ebay.dsf.javatojs.tests.operators;
public class Pair{ 
	Byte ob = 0;
	Short os = 1;
	Integer oi = 10;
	Long ol = 20l;
	Character oc = 'C';
	Float of = 10.2f;
	Double od = 12.3;
 
	byte b = ob;
	short s = os;
	int i = oi;
	long l = ol;
	char c = oc;
	float f = of;
	double d = od;
}
vjo.ctype("com.ebay.dsf.javatojs.tests.operators.Pair")
.needs("vjo.java.lang.Byte")
.needs("vjo.java.lang.Short")
.needs("vjo.java.lang.Integer")
.needs("vjo.java.lang.Long")
.needs("vjo.java.lang.Character")
.needs("vjo.java.lang.Float")
.needs("vjo.java.lang.Double")
.protos({
	//> Byte ob
	ob:null,
	//> Short os
	os:null,
	//> Integer oi
	oi:null,
	//> Long ol
	ol:null,
	//> Character oc
	oc:null,
	//> Float of
	of:null,
	//> Double od
	od:null,
	//> byte b
	b:0,
	//> short s
	s:0,
	//> int i
	i:0,
	//> long l
	l:0,
	//> char c
	c:null,
	//> float f
	f:0,
	//> double d
	d:0,
	//> private constructs()
	constructs:function(){
		this.ob=new this.vjo.Byte(0);
		this.os=new this.vjo.Short(1);
		this.oi=new this.vjo.Integer(10);
		this.ol=new this.vjo.Long(20);
		this.oc=new this.vjo.Character('C');
		this.of=new this.vjo.Float(10.2);
		this.od=new this.vjo.Double(12.3);
		this.b=this.ob.byteValue();
		this.s=this.os.shortValue();
		this.i=this.oi.intValue();
		this.l=this.ol.longValue();
		this.c=this.oc.charValue();
		this.f=this.of.floatValue();
		this.d=this.od.doubleValue(); 
	}
})
.endType();
  1. From type Boolean to type boolean
  2. From type Byte to type byte
  3. From type Character to type char
  4. From type Short to type short
  5. From type Integer to type int
  6. From type Long to type long
  7. From type Float to type float
  8. From type Double to type double

Unchecked conversions – not supported

Capture conversions – not supported

String conversions - convert from any other type to String

String conversion applies only to the operands of the binary + operator when one

of the arguments is a String. When adding string to any object, java calls toString() and append to the string. This behavior is partially supported, ie., only with the user defined type with toString() implemented in it, other java objects are not supported.

Java js
package j2jtest.conversion;
import j2jtest.Out;
public class Conversion {
	public void method1(){
	AnotherClass obj = new AnotherClass();
	String simpleStr = " Simple String" + obj;
	Out.log("simpleStr = "+ simpleStr);
	}
}
vjo.ctype("j2jtest.conversion.Conversion")
.needs("j2jtest.Out")
.protos({
	//> public void method1()
	method1:function(){
	var obj=new this.vjo.AnotherClass();
	var simpleStr=" Simple String"+obj;
	this.vjo.Out.log("simpleStr = "+simpleStr);
	}
})
.endType();
Java Vjo
package com.ebay.dsf.javatojs.tests.operators;
import java.util.ArrayList;
import java.util.List;
 
public class Pair{ 
	List list = new ArrayList();
	String s<nowiki>= "a"+ list;
	public String getStringFromObject(List myList){
	String s = "Items in List "+ myList;
	return myList.toString();
	}
}
vjo.ctype("com.ebay.dsf.javatojs.tests.operators.Pair")
.needs("vjo.java.util.List")
.needs("vjo.java.util.ArrayList")
.protos({
	//> List list
	list:null,
	//> String s
	s:null,
	//> private constructs()
	constructs:function(){
	this.list=new this.vjo.ArrayList();
	this.s="a"+this.list;
	},
	//> public String getStringFromObject(List myList)
	getStringFromObject:function(myList){
	var s="Items in List "+myList;
	return myList.toString();
	}
})
.endType();
style="border:1px solid #AAAAAA;padding: 0.2em;"| Note: use toString() method on reference object

Value set conversions - not supported , Value set conversion is the process of mapping a floating-point value from one value set to another without changing its type.

Assignment conversion

Method invocation conversion

Java Vjo
package com.ebay.dsf.javatojs.tests.operators;
import java.util.ArrayList;
import java.util.List;
public class Pair{ 
	public void testMethod(){
		Integer integer = new Integer(10);
		int intValue = 20;
		ArrayList list = null;
		identityConversion(integer);
		wideningPrimitiveConversion(intValue);
		wideningReferenceConversion(list);
		boxingConversion(intValue);
		unboxingConversion(intValue);
	}
	public void identityConversion(Integer i){
	}
	public void wideningPrimitiveConversion(long l){
	}
	public void wideningReferenceConversion( List list){
	}
	public void boxingConversion(Integer i){
	}
	public void unboxingConversion(int i){
	}
}
vjo.ctype("com.ebay.dsf.javatojs.tests.operators.Pair")
.needs("vjo.java.lang.Integer")
.needs("vjo.java.util.ArrayList")
.needs("vjo.java.util.List")
.protos({
	//> public void testMethod()
	testMethod:function(){
	var integer=new this.vjo.Integer(10);
	var intValue=20;
	var list=null;
	this.identityConversion(integer);
	this.wideningPrimitiveConversion(intValue);
	this.wideningReferenceConversion(list);
	this.boxingConversion(new this.vjo.Integer(intValue));
	this.unboxingConversion(intValue);
	},
	//> public void identityConversion(Integer i)
	identityConversion:function(i){
	},
	//> public void wideningPrimitiveConversion(long l)
	wideningPrimitiveConversion:function(l){
	},
	//> public void wideningReferenceConversion(List list)
	wideningReferenceConversion:function(list){
	},
	//> public void boxingConversion(Integer i)
	boxingConversion:function(i){
	},
	//> public void unboxingConversion(int i)
	unboxingConversion:function(i){
	}
})
.endType();

String conversion

Casting conversion

Numeric promotion

Names

Declarations

declarations Java Vjo
package package com.ebay.dsf.javatojs.tests.operators;

vjo.ctype (“com.ebay.dsf.javatojs.tests.operators.Pair”)

import

Only single type import is supported. Import on demand would be converted into necessary single type import.

import java.util.ArrayList;
import java.util.List;
.needs("vjo.java.lang.Integer")
.needs("vjo.java.util.ArrayList")
import java.util.*;
.needs("vjo.java.lang.Integer")
.needs("vjo.java.util.ArrayList")
class public class Pair vjo.ctype("com.ebay.dsf.javatojs.tests.operators.Pair")
interface
package com.ebay.dsf.operators;
public interface PairInterface{ 
}
vjo.itype("com.ebay.dsf.operators.PairInterface")
.endType();
member class
package j2jtest;
public class Pair{ 
	private int p = 0;
	class PairInner{
	int iCanAccessParentPrivateToo(){
		return p;
	}
	}
	public void testMethod(){
 
	}
}
vjo.ctype("j2jtest.Pair")
.protos({
	//> private int p
	p:0,
	PairInner:vjo.ctype()
	.protos({
	//> int iCanAccessParentPrivateToo()
	iCanAccessParentPrivateToo:function(){
		return this.vjo.outer.p;
	}
	})
	.endType(),
	//> public void testMethod()
	testMethod:function(){
	}
})
.endType();
member interface
package j2jtest;
public class Pair{ 
	interface Colors {
	int ''WHITE'' = 0, ''BLACK'' = 1;
	int getColor();
	}
}
vjo.ctype("j2jtest.Pair")
.protos({
	Colors:vjo.itype()
	.props({
	//> public int WHITE
	WHITE:0,
	//> public int BLACK
	BLACK:1
	})
	.protos({
	//> public int getColor()
	getColor:function(){
	}
	})
	.endType()
})
.endType();
enum constant TODO: ERROR: Enum, not completely implemented. See the missing function for enum SUNDAY
package j2jtest;
public enum EnumTest {
	SUNDAY{
	int getIndex(){
	    return 0;
	}
	},
	MONDAY, 
	TUESDAY, 
	WEDNESDAY, 
	THURSDAY, 
	FRIDAY, 
	SATURDAY 
}
vjo.etype("j2jtest.EnumTest")
.values("SUNDAY, MONDAY, TUESDAY, 
WEDNESDAY, THURSDAY, FRIDAY, SATURDAY")
.endType();
field in class and interface

method in class and interface

local variable in block

local variable in for statement

parameter of a method in class and interface

parameter of an exception handler

package j2jtest;
public class Pair{ 
Integer fieldInClass = new Integer(10);
public void methodInClass
(String parameterOfaMethodInClass){
String sh = "shhhhhh!";{
Integer localVarInblock = 90; 
}
for( int i=0; i<20; i++){
String localVarInForStatement = ""+i;
try{
Integer k = new Integer(localVarInForStatement);
}catch (Exception parameterOfAnExceptionHandler){
}
}
}
interface Colors {
Integer ''fieldInInterface'' = 20;
int methodInInterface
(String parameterOfaMethodInInterface);
}
}
vjo.ctype("j2jtest.Pair")
.needs("vjo.java.lang.Integer")
.needs("vjo.java.lang.Exception")
.protos({
//> Integer fieldInClass
fieldInClass:null,
Colors:vjo.itype()
.props({
//> public Integer fieldInInterface
fieldInInterface:null
})
.protos({
//> public int methodInInterface
(String parameterOfaMethodInInterface)
methodInInterface:function
(parameterOfaMethodInInterface){
}
})
.inits(function(){
this.vjo.Colors.fieldInInterface=
new this.vjo.Integer(20);
})
.endType(),
//> private constructs()
constructs:function(){
this.fieldInClass=new this.vjo.Integer(10);
},
//> public void methodInClass
(String parameterOfaMethodInClass)
methodInClass:function(parameterOfaMethodInClass){
var sh="shhhhhh!"<nowiki>;</nowiki>
{
var localVarInblock=new this.vjo.Integer(90);
}
for (var <nowiki>i=0;i<20;i++)</nowiki>{
var localVarInForStatement=""+i;
try {
var k=new this.vjo.Integer
(localVarInForStatement);
}
catch(parameterOfAnExceptionHandler){
}
}
}
})
.endType();

Names and Identifiers

Scope of a Declaration

Shadowing Declaration

Java Vjo
package j2jtest;
public class Pair{ 
	int x = 20;
	void myMethod(){
		int x = 10;
		System.err.println("x ="+ x);
		System.err.println("thix.x="+ this.x);
 
	}
}
vjo.ctype("j2jtest.Pair")
.needs("vjo.java.lang.System")
.protos({
	//> int x
	x:20,
	//> void myMethod()
	myMethod:function(){
		var x=10;
		this.vjo.System.err.println("x = "+x);
		this.vjo.System.err.println("thix.x = "+this.x);
	}
})
.endType();
Above shows shadowing of a field x by a local variable x .

Obscured Declarations

Members and Inheritance

Java js
package j2jtest.member;
import j2jtest.Out;
public class Derived extends Base{
	String instanceMember;
	static String staticMember;
	public void method1(){
	    String local = inheritedMemberVar;
	    local = inheritedStaticMemberVar;
	    local = instanceMember;
	    local = staticMember;
	    local = "";
	    inheritedMemberMethod();
	    inheritedStaticMemberMethod();
	    override();
	    super.override();
	    overload();
	    overload(local);
	}
	public void memberMethod(){
	    Out.log("Derived.memberMethod");
	}
	public static void memberStaticMethod(){
	    Out.log("Derived.memberStaticMethod");
	}
	public void override(){
	    Out.log("Derived.override");
	}
	public void overload(String s){
	    Out.log("Derived.overload(String)");
	}
	public void abstractMethod(){
	    Out.log("Derived.abstractMethod");
	}
	public void abstractMethod(String value){
	    Out.log("Derived.abstractMethod(String)");
	}
}
 
package j2jtest.member;
import j2jtest.Out;
public abstract class Base {
	String inheritedMemberVar;
	static String inheritedStaticMemberVar;
 
	public void inheritedMemberMethod(){
	    Out.log("Base.inheritedMemberMethod");
	}
	public void inheritedStaticMemberMethod(){
	    Out.log("Base.inheritedStaticMemberMethod");
	}
	public void override(){
	    Out.log("Base.override");
	}
	public void overload(){
	    Out.log("Base.overload");
	}
}
vjo.ctype("j2jtest.member.Derived")
.needs("j2jtest.Out")
.needs("j2jtest.member.Base")
.inherits("j2jtest.member.Base")
.props({
	//> String staticMember
	staticMember:null,
	//> public void memberStaticMethod()
	memberStaticMethod:function(){
	    this.vjo.Out.log("Derived.memberStaticMethod");
	}
})
.protos({
	//> String instanceMember
	instanceMember:null,
	//> public void method1()
	method1:function(){
	    var local=this.inheritedMemberVar;
	    local=this.vjo.Base.inheritedStaticMemberVar;
	    local=this.instanceMember;
	    local=this.vjo.Derived.staticMember;
	    local="";
	    this.inheritedMemberMethod();
	    this.inheritedStaticMemberMethod();
	    this.override();
	    this.base.override();
	    overload();
	    this.overload(local);
	},
	//> public void memberMethod()
	memberMethod:function(){
	    this.vjo.Out.log("Derived.memberMethod");
	},
	//> public void override()
	override:function(){
	    this.vjo.Out.log("Derived.override");
	},
	//> public void abstractMethod()
	//> public void abstractMethod(String value)
	abstractMethod:function(){
	    if(arguments.length===0){
	    	this.abstractMethod_0_0_Derived_ovld();
	    }else if(this.base && this.base.abstractMethod){
		this.base.abstractMethod.apply(this,arguments);
	    }else if(arguments.length===1){
		if(arguments[0] instanceof String || 
		typeof arguments[0]=="string"){
	            this.abstractMethod_1_0_Derived_ovld(arguments[0]);
		}else if(this.base && this.base.abstractMethod){
		    this.base.abstractMethod.apply(this,arguments);
		}
	    }else if(this.base && this.base.abstractMethod){
		this.base.abstractMethod.apply(this,arguments);
	    }
	},
	//> private void abstractMethod_0_0_Derived_ovld()
	abstractMethod_0_0_Derived_ovld:function(){
	    this.vjo.Out.log("Derived.abstractMethod");
	},
	//> private void 
	//abstractMethod_1_0_Derived_ovld(String value)
	abstractMethod_1_0_Derived_ovld:function(value){
	    this.vjo.Out.log("Derived.abstractMethod(String)");
	},
	//> public void overload(String s)
	overload:function(s){
	    if(arguments.length===1){
		if(arguments[0] instanceof String || 
		typeof arguments[0]=="string"){
		    this.overload_1_0_Derived_ovld(arguments[0]);
		}else if(this.base && this.base.overload){
		    this.base.overload.apply(this,arguments);
		}
	    }else if(this.base && this.base.overload){
		this.base.overload.apply(this,arguments);
	    }
	},
	//> private void overload_1_0_Derived_ovld(String s)
	overload_1_0_Derived_ovld:function(s){
	    this.vjo.Out.log("Derived.overload(String)");
	}
})
.endType();

Access Control

Java vjo
package j2jtest;
public class Pair{ 
	int packageAccess;
	public int publicAccess;
	private int privateAccess;
	protected int protectedAccess;
	void packageMethod(){
 
	}
	public void publicMethod(){
 
	}
	private void privateMethod(){
 
	}
	protected void protectedMethod(){
 
	}
}
vjo.ctype("j2jtest.Pair")
.protos({
	//> int packageAccess
	packageAccess:0,
	//> public int publicAccess
	publicAccess:0,
	//> private int privateAccess
	privateAccess:0,
	//> protected int protectedAccess
	protectedAccess:0,
	//> void packageMethod()
	packageMethod:function(){
 
	},
	//> public void publicMethod()
	publicMethod:function(){
 
	},
	//> private void privateMethod()
	privateMethod:function(){
 
	},
	//> protected void protectedMethod()
	protectedMethod:function(){
 
	}
})
.endType();

Fully Qualified Names and Canonical Names

package j2jtest;
public class Pair{ 
	java.lang.Integer packageAccess;
	java.util.List l = new java.util.ArrayList();
	java.util.Date utilDate = new java.util.Date();
	java.sql.Date sqlDate = 
               new java.sql.Date(utilDate.getTime());
}
vjo.ctype("j2jtest.Pair")
.needs("vjo.java.lang.Integer")
.needs("vjo.java.util.List")
.needs("vjo.java.util.ArrayList")
.needs("java.util.Date")
.needs("java.sql.Date")
.protos({
	//> Integer packageAccess
	packageAccess:null,
	//> List l
	l:null,
	//> Date utilDate
	utilDate:null,
	//> Date sqlDate
	sqlDate:null,
	//> private constructs()
	constructs:function(){
		this.l=new this.vjo.ArrayList();
		this.utilDate=new java.util.Date();
		this.sqlDate=new java.sql.Date(this.utilDate.getTime());
	}
})
.endType();

Packages

Package Members

Compilation Units

No implicit imports (ex., java.lang package), imported only if it’s used.
package j2jtest;
public class Pair{ 
	Integer i = 10;
}
vjo.ctype("j2jtest.Pair")
.needs("vjo.java.lang.Integer")
.protos({
	//> Integer i
	i:null,
	//> private constructs()
	constructs:function(){
		this.i=new this.vjo.Integer(10);
	}
})
.endType();

Package Declarations

There is no explicit package declaration, package name is added to type declaration (name space of type)
package j2jtest;
public class Pair{ 
 
}
vjo.ctype("j2jtest.Pair")

Import

Does not support import on-demand, for ex., package.*;

All the compilation units needs to be imported separately .

package j2jtest;
import java.util.*; //
public class Pair{ 
    List list;
    HashMap map;
}
vjo.ctype("j2jtest.Pair")
.needs("vjo.java.util.List")
.needs("vjo.java.util.HashMap")
.protos({
    //> List list
    list:null,
    //> HashMap map
    map:null
})
.endType();

Top Level Type Declarations

All types should be imported explicitly even if the type belongs to the same package. For ex., from the below code, though Pair2 is defined in the same package of Pair, it requires import,
package j2jtest;
import java.util.*;
public class Pair{ 
	List list;
	HashMap map;
	Pair2 pair2OnSamePackage;
}
vjo.ctype("j2jtest.Pair")
.needs("vjo.java.util.List")
.needs("vjo.java.util.HashMap")
.needs("j2jtest.Pair2")
.protos({
	//> List list
	list:null,
	//> HashMap map
	map:null,
	//> Pair2 pair2OnSamePackage
	pair2OnSamePackage:null
})
.endType();

Classes

Class Declaration

Class Modifiers

Java Vjo
class
package j2jtest;
public class Pair{ 
	Integer i = 10;
}
vjo.ctype("j2jtest.Pair")
.needs("vjo.java.lang.Integer")
.protos({
	//> Integer i
	i:null,
	//> private constructs()
	constructs:function(){
		this.i=new this.vjo.Integer(10);
	}
})
.endType();
abstract class
package j2jtest;
public abstract class AbstractClassTest{ 
 
}
vjo.ctype("j2jtest.AbstractClassTest")
.endType();
final class
package j2jtest;
public final class AbstractClassTest{ 
 
}
vjo.ctype("j2jtest.AbstractClassTest")
.makeFinal()
.endType();
Sstrictfp class Not supported

Generic Classes and Type Parameters

Java Vjo
package j2jtest;
public class Pair<T>{
	T value;
	void set(T t){
		this.value = t;
	}
	T get(){
		return value;
	}
	Pair<String> testMethod(){
		Pair<String> pair = new Pair<String>();
		return pair;
	}
}
vjo.ctype("j2jtest.Pair")
.protos({
	//> T value
	value:null,
	//> void set(T t)
	set:function(t){
		this.value=t;
	},
	//> T get()
	get:function(){
		return this.value;
	}
})
.endType();
 
//> Pair<String> testMethod()
testMethod:function(){
	var pair=new this.vjo.Pair();
	return pair;
}

Inner Classes and Enclosing Instances

  1. Nested
    1. static
    2. inner
      1. anonymous
      2. local
Nested
Static
package j2jtest;
public class Pair2 {
	void anOuterMethod() {
 
	}
	public static class NestedStatic {
		void aNestedStaticMethod() {
 
		}
	}
}
vjo.ctype("j2jtest.Pair2")
.props({
	NestedStatic://> public NestedStatic
	vjo.ctype()
	.protos({
		//> void aNestedStaticMethod()
		aNestedStaticMethod:function(){
 
		}
	})
	.endType()
})
.protos({
	//> void anOuterMethod()
	anOuterMethod:function(){
 
	}
})
.endType();
inner –one level
package j2jtest;
public class OuterClass {
	int outerVar = 10;
	class InnerClass{
		void innerMethod(){
			Out.log("inner" +outerVar);
		}
	}
	static void testMethod(){
		OuterClass outerClass = 
		    new OuterClass();
		OuterClass.InnerClass innerClass = 
		    new OuterClass().new InnerClass();
		innerClass.innerMethod();
		innerClass = outerClass.new InnerClass();
		innerClass.innerMethod();
	}
}
vjo.ctype("j2jtest.OuterClass")
.needs("j2jtest.Out")
.props({
	//> void testMethod()
	testMethod:function(){
		var outerClass=new this();
		var innerClass=
		    new (new this()).InnerClass();
		innerClass.innerMethod();
		innerClass=
		    new outerClass.InnerClass();
		innerClass.innerMethod();
	}
})
.protos({
	//> int outerVar
	outerVar:10,
	InnerClass://> InnerClass
	vjo.ctype()
	.protos({
		//> void innerMethod()
		innerMethod:function(){
		this.vjo.Out.log(
		    "Inside inner class"+
			this.vjo.outer.outerVar);
		}
	})
	.endType()
})
.endType();
inner –two level

ERROR inInClass, not getting created

package j2jtest;
public class OuterClass {
	int outerVar = 10;
	class InnerClass{
		class InnerInnerClass{
		void innerInnerMethod(String mssg){
			Out.log("InnerInner " +mssg);
		}
		}
		void innerMethod(String mssg){
			Out.log("Inner " +mssg);
		}
	}
	static void testMethod(){
		OuterClass.InnerClass innerClass = 
		new OuterClass().new InnerClass();
 
		OuterClass.InnerClass.InnerInnerClass 
		inInClass = 
		   innerClass.new InnerInnerClass(); 
 
		innerClass.innerMethod("mssg1");
		inInClass.innerInnerMethod("mssg2");
	}
}
vjo.ctype("j2jtest.OuterClass")
.needs("j2jtest.Out")
.props({
	//> void testMethod()
	testMethod:function(){
		var innerClass=new (new this())
		.InnerClass();
		var inInClass;
		innerClass.innerMethod("mssg1");
		inInClass.innerInnerMethod("mssg2");
	}
})
.protos({
	//> int outerVar
	outerVar:10,
	InnerClass://> InnerClass
	vjo.ctype()
	.protos({
	InnerInnerClass://> InnerInnerClass
	vjo.ctype()
	.protos({
	//> void innerInnerMethod(String mssg)
	innerInnerMethod:function(mssg){
		this.vjo.Out.log("InnerInner "+mssg);
	}
	})
	.endType(),
	//> void innerMethod(String mssg)
	innerMethod:function(mssg){
		this.vjo.Out.log("Inner "+mssg);
	}
	})
	.endType()
})
.endType();
anonymous

ERROR Not getting created/initialized

package j2jtest.innerclass;
import j2jtest.Out;
import java.util.ArrayList;
import java.util.List;
 
public class AnonymousInnerclass {
	List list = new ArrayList(3) {
		{
		 add("One"); add("Two"); add("Three");
		 }
	};
	public void testMethod(){
		for(Object value: list){
			Out.log("value="+value);
		}
	}
}
vjo.ctype
("j2jtest.innerclass.AnonymousInnerclass")
.needs("vjo.java.util.List")
.needs("vjo.java.util.ArrayList")
.needs("j2jtest.Out")
.protos({
	//> List list
	list:null,
	//> private constructs()
	constructs:function(){
	this.list=
	vjo.make(this,vjo.java.util.ArrayList,3);
	},
	//> public void testMethod()
	testMethod:function(){
	this.vjo.Out.log("value=");
	for (var value,_$itr=this.list.iterator();
                      _$itr.hasNext();){
		value=_$itr.next();
		this.vjo.Out.log("value="+value);
	}
	}
})
.endType();

Superclasses and Subclasses

Please refer Names. Members and Inheritance

Superinterfaces

Java Js
package j2jtest.superinterface;
public interface BaseInterface{
	public void method1();
	public void method(int i);
 
	}
vjo.itype("j2jtest.superinterface.BaseInterface")
.protos({
	//> public void method1()
	method1:function(){
 
	},
	//> public void method(int i)
	method:function(i){
 
	}
})
.endType();
 
package j2jtest.superinterface;
public class ImplClass implements BaseInterface{
	public void method1(){
 
	}
	public void method(int i){
 
	}
}
 
vjo.ctype("j2jtest.superinterface.ImplClass")
.needs("j2jtest.superinterface.BaseInterface")
.satisfies("j2jtest.superinterface.BaseInterface")
.protos({
	//> public void method1()
	method1:function(){
 
	},
	//> public void method(int i)
	method:function(i){
 
	}
})
.endType();
 
package j2jtest.superinterface;
public interface SubInterface extends SuperInterface {
 
}
 
vjo.itype("j2jtest.superinterface.SubInterface")
.needs("j2jtest.superinterface.SuperInterface")
.inherits("j2jtest.superinterface.SuperInterface")
.endType();

Class Body and Member Declarations

Java js
 
package j2jtest.classbodyandmember;
public class ClassBody {
	String field1;
	static int staticField;
	static{staticField=12;}
	{field1="field1Str";}
 
	interface classinterface{
		void m1();
	}
	class classclass{
		void m1(){}
	}
	void m1(){}
	ClassBody(){}
	ClassBody(Integer a){}
}
 
vjo.ctype("j2jtest.classbodyandmember.ClassBody")
.needs("vjo.java.lang.Integer")
.props({
	//> int staticField
	staticField:0
})
.protos({
	//> String field1
	field1:null,
	classinterface://> public classinterface
	vjo.itype()
	.protos({
		//> public void m1()
		m1:function(){
		}
	})
	.endType(),
 
	classclass://> classclass
	vjo.ctype()
	.protos({
		//> void m1()
		m1:function(){
 
		}
	})
	.endType(),
 
	//> constructs()
	//> constructs(Integer a)
	constructs:function(){
		{
			this.field1="field1Str";
		}
		if(arguments.length===0){
			this.constructs_0_0_ClassBody_ovld();
		}else if(arguments.length===1){
			this.constructs_1_0_ClassBody_ovld(arguments[0]);
		}
	},
	//> void m1()
	m1:function(){
 
	},
	//> private constructs_0_0_ClassBody_ovld()
	constructs_0_0_ClassBody_ovld:function(){
 
	},
	//> private constructs_1_0_ClassBody_ovld(Integer a)
	constructs_1_0_ClassBody_ovld:function(a){
 
	}
})
.inits(function(){
	{
		this.vjo.ClassBody.staticField=12;
	}
})
.endType();

Class Members - see Class Body and Member Declarations

Field Declarations

Java Vjo
access modifier

public, private, protected

 
public Integer I =10;
private Integer j =20;
protected Integer k=0;
 
.protos({
	//> public Integer i
	i:null,
	//> private Integer j
	j:null,
	//> protected Integer k
	k:null,
	//> EnumTest etest
	etest:null,
	//> private constructs()
	constructs:function(){
		this.i=new this.vjo.Integer(10);
		this.j=new this.vjo.Integer(20);
		this.k=new this.vjo.Integer(0);
	},
static fields
class TestClass {
	public final Integer i = 10;
	private final Integer j = 20;
	protected static final Integer k = 0;
}
 
vjo.ctype("j2jtest.TestClass")
.props({
	//> public Integer i
	i:null,
	//> private Integer j
	j:null,
	//> protected Integer k
	k:null
})
.inits(function(){
	this.vjo.TestClass.i=new this.vjo.Integer(10);
	this.vjo.TestClass.j=new this.vjo.Integer(20);
	this.vjo.TestClass.k=new this.vjo.Integer(0);
})
.endType();
final fields
 
class TestClass {
	public static final Integer i = 10;
	private static final Integer j = 20;
	protected static final Integer k = 0;
}
 
vjo.ctype("j2jtest.TestClass")
.props({
	//> final public Integer i
	i:null,
	//> final private Integer j
	j:null,
	//> final protected Integer k
	k:null
})
.inits(function(){
	this.vjo.TestClass.i=new this.vjo.Integer(10);
	this.vjo.TestClass.j=new this.vjo.Integer(20);
	this.vjo.TestClass.k=new this.vjo.Integer(0);
})
.endType();
Transient –
 
class TestClass {
	transient Integer i = 10;
}
Not Supported

Method Declarations

method modifiers
abstract,

static, final methods

 
package j2jtest;
public abstract class Pair2{ 
	abstract void abstractMethod();
	static void staticMethod();
	public final void finalMethod(){
 
	}
	public native void nativeMethod();
	public synchronized void synchronizedMethod() {
 
	}
	strictfp void strictfpMethod(){
 
	}
}
 
vjo.ctype("j2jtest.Pair2") //< abstract
.props({
	//> void staticMethod()
	staticMethod:function(){
 
	}
})
.protos({
	//> abstract void abstractMethod()
	abstractMethod:function(){
 
	},
	//> final public void finalMethod()
	finalMethod:function(){
 
	},	
	//> public void nativeMethod()
	nativeMethod:function(){
 
	},
	//> public void synchronizedMethod()
	synchronizedMethod:function(){
 
	},
	//> void strictfpMethod()
	strictfpMethod:function(){
 
	}
})
.endType();


synchronized native strictfp

are not supported

Method throws not supported
 
public void method1() throws Exception {
 
}
 
//> public void method1()
method1:function(){
 
}
Overloading
 
package j2jtest;
public class Pair2{ 
	public void method1() {
 
	}
	public void method1(int i){
 
	}
	public void callMethod(){
		method1();
		method1();
	}
}
 
vjo.ctype("j2jtest.Pair2")
.protos({
	//> public void method1()
	method1:function(){
		if(arguments.length===0){
			this.method1_0_0();
		}else if(arguments.length===1){
			this.method1_1_0(arguments[0]);
		}
	},
	//> public void method1_0_0()
	method1_0_0:function(){
 
	},
	//> public void method1_1_0(int i)
	method1_1_0:function(i){
 
	},
	//> public void callMethod()
	callMethod:function(){
		this.method1();
		this.method1();
	}
})
 
.endType();

If a static field/method is accessed through instance object, it would be converted to use fully qualified class name to access.

Member Type Declarations

Java Vjo
 
package j2jtest;
public class Pair2{ 
	abstract class Abstractclass{
 
	}
	interface MyInterface{
 
	}
	protected class ProtectedClass extends Abstractclass{
 
	}
	private class PrivateClass implements MyInterface{
 
	}
	static class StaticClass {
 
	}
	final class FinalClass{
 
	}
	PrivateClass pclass = new PrivateClass();
	ProtectedClass prClass = new ProtectedClass();
	StaticClass sClass = new StaticClass();
	Abstractclass aClass = new ProtectedClass();
	MyInterface mInterface = new PrivateClass();
	FinalClass fClass = new FinalClass();
}
 
vjo.ctype("j2jtest.Pair2")
.props({
	StaticClass:vjo.ctype()
	.endType()
})
.protos({
	//> PrivateClass pclass
	pclass:null,
	//> ProtectedClass prClass
	prClass:null,
	//> StaticClass sClass
	sClass:null,
	//> Abstractclass aClass
	aClass:null,
	//> MyInterface mInterface
	mInterface:null,
	//> FinalClass fClass
	fClass:null,
	Abstractclass:vjo.ctype() //< abstract
	.endType(),
	MyInterface:vjo.itype()
	.endType(),
	ProtectedClass:vjo.ctype()
	.inherits("j2jtest.Pair2.Abstractclass")
	.endType(),
	PrivateClass:vjo.ctype()
	.satisfies("j2jtest.Pair2.MyInterface")
	.endType(),
	FinalClass:vjo.ctype()
	.makeFinal()
	.endType(),
	//> private constructs()
	constructs:function(){
		this.pclass=new PrivateClass();
		this.prClass=new ProtectedClass();
		this.sClass=new this.StaticClass();
		this.aClass=new ProtectedClass();
		this.mInterface=new PrivateClass();
		this.fClass=new FinalClass();
	}
})
.endType();

Instance Initializers

 
package j2jtest;
public class Pair2{ 
	Integer wrapperInteger = 10;
	Float wrapperFloat = 12.2f;
}
 
vjo.ctype("j2jtest.Pair2")
.needs("vjo.java.lang.Integer")
.needs("vjo.java.lang.Float")
.protos({
	//> Integer wrapperInteger
	wrapperInteger:null,
	//> Float wrapperFloat
	wrapperFloat:12.2,
	//> private constructs()
	constructs:function(){
		this.wrapperInteger=new this.vjo.Integer(10);
	}
})
.endType();

Static Initializers

 
package j2jtest;
public class Pair2 {
	public static Integer i = new Integer(20);
	private static Float f = new Float(23);
	static Pair2 pair;
	static{
		pair = new Pair2();
	}
}
 
vjo.ctype("j2jtest.Pair2")
.needs("vjo.java.lang.Integer")
.needs("vjo.java.lang.Float")
.props({
//> public Integer i
i:null,
//> private Float f
f:null,
//> Pair2 pair
pair:null
 
})
.inits(function(){
	this.vjo.Pair2.i=new this.vjo.Integer(20);
	this.vjo.Pair2.f=new this.vjo.Float(23);
	{
		this.pair=new this();
	}
})
.endType();

Constructor Declarations - see Class Body and Member Declarations

Enums

Java js
 
package j2jtest.enum1;
public enum EnumTest {
	SUNDAY{
		int getIndex(){
			return 0;
		}
	},
	MONDAY, 
	TUESDAY, 
	WEDNESDAY, 
	THURSDAY, 
	FRIDAY, 
	SATURDAY 
}
 
vjo.etype("j2jtest.enum1.EnumTest")
.values("SUNDAY, MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY")
.inits(function(){
	this.SUNDAY.getIndex=function(){
		return 0;
	};
})
.endType();

Initialization

 
package j2jtest;
public class Pair2 {
	public final int N = 10;
	private int[] x = new int[N];
	{
		for (int i = 0; i < N; i++)
			x[i] = i;
	}
	public static int L = 5;
	private static int[] y=new int[L];;
	static {
		for (int i = 0; i < L; i++)
			y[i] = i;
	}
}
 
vjo.ctype("j2jtest.Pair2")
.props({
	//> final public int L
	L:5,
	//> private int[] y
	y:null
})
.protos({
	//> final public int N
	N:10,
	//> private int[] x
	x:null,
	//> private constructs()
	constructs:function(){
		this.x=new Array(this.N);
		{
			for (var i=0;i<this.N;i++){
				this.x[i]=i;
			}
		}
	}
})
.inits(function(){
	this.vjo.Pair2.y=new Array(this.L);
	{
		for (var i=0;i<this.L;i++){
			this.y[i]=i;
		}
	}
})
.endType();

Interfaces

Interface Declarations

Instance Members

Field (Constant) Declarations

Abstract Method Declarations

Member Type Declarations


Java js
package j2jtest.interfaces;
public interface SuperInterface {
	String memberStr="";
	public int var1=1;
	public static int var2=2;
	public static final int var3 = 3;
	String var4 = ""+var3;
	void m1();
	void m1(int i);
	public void m2();
	abstract void m3();
	public abstract void m4();
}
vjo.itype("j2jtest.interfaces.SuperInterface")
.props({
	//> public String memberStr
	memberStr:"",
	//> public int var1
	var1:1,
	//> public int var2
	var2:2,
	//> final public int var3
	var3:3,
	//> public String var4
	var4:null
})
.protos({
	//> void m1()
	//> public void m1(int i)
	m1:function(){
		if(arguments.length===0){
			this.m1_0_0_SuperInterface_ovld();
		}else if(arguments.length===1){
			this.m1_1_0_SuperInterface_ovld(arguments[0]);
		}
	},
	//> private void m1_0_0_SuperInterface_ovld()
	m1_0_0_SuperInterface_ovld:function(){
 
	},
	//> private void m1_1_0_SuperInterface_ovld(int i)
	m1_1_0_SuperInterface_ovld:function(i){
 
	},
	//> public void m2()
	m2:function(){
 
	},
	//> public abstract void m3()
	m3:function(){
 
	},
	//> public abstract void m4()
	m4:function(){
 
	}
})
.inits(function(){
	this.vjo.SuperInterface.var4=""+this.var3;
})
.endType();
package j2jtest.interfaces;
public interface SubInterface extends SuperInterface{
	public static int memberInt=20;
	public static String var3 = ""+var2;
}
vjo.itype("j2jtest.interfaces.SubInterface")
.needs("j2jtest.interfaces.SuperInterface")
.inherits("j2jtest.interfaces.SuperInterface")
.props({
	//> public int memberInt
	memberInt:20,
	//> public String var3
	var3:null
})
.inits(function(){
	this.vjo.SubInterface.var3=""+this.vjo.SuperInterface.var2;
})
.endType();


Arrays

Java Vjo
long avg = 10;
long[] la = {1+avg,2,3}; 
int[][] twoDimArray = {{1,2,3}, {4,5,6}};
String[] sa = { "a", "b", "c"};
String[] sa2 = new String[2];
Employee[] sa3 = new Employee[2];
boolean boolArr1[] 
	= new boolean[]{true};
boolean boolArr2[][] 
	= new boolean[][]{{false}};
boolean boolArr11[] 
	= new boolean[twoDimArray[0][0]];
boolean boolArr12[][] 
	= new boolean[twoDimArray[0][0]] [twoDimArray[0][1]];


var avg=10;
var la=[1+avg,2,3];
var twoDimArray=[[1,2,3],[4,5,6]];
var sa=["a","b","c"];
var sa2=new Array(2);
var sa3=new Array(2);
var boolArr1=[true];
var boolArr2=[[false]];
var boolArr11=new Array(twoDimArray[0][0]);
var boolArr12=new Array;

ERORS/TO-DO List

1. FIXED. Field initialization should maintain the order. From the below example, initialization order is not maintained. myInt should be initialized before i.

package j2jtest;
public class Pair2{ 
    Integer myInt = 10;
    int i = myInt;
 
}
vjo.ctype("j2jtest.Pair2")
.needs("vjo.java.lang.Integer")
.protos({
	//> Integer myInt
	myInt:null,
	//> int i
	i:0,
	//> constructs()
	constructs:function(){
	this.i=this.myInt.intValue();
	this.myInt=new this.vjo.Integer(10);
	}
})
.endType();

2. DOCUMENTED. Overload with primitive and wrapper argument is not correctly transferred in js dispatcher function. From the below example, overLoad(Integer i) would be called regardless of parameter.


 
package j2jtest;
public class Pair2{ 
    void overLoad(int i){
	    System.out.println("called with primitive int");
    }
    void overLoad(Integer i){
        System.out.println("called with wrapper int");
    }
    void callOverLoad(){
        overLoad(10);
        overLoad(new Integer(12));
    }
}
 
vjo.ctype("j2jtest.Pair2")
.needs("vjo.java.lang.Integer")
.needs("vjo.java.lang.System")
.protos({
    //> void overLoad()
    overLoad:function(){
        if(arguments.length===1){
            if(arguments[0] instanceof vjo.java.lang.Integer){
                this.overLoad_1_0(arguments[0].intValue());
            }else if(arguments[0] instanceof vjo.java.lang.Integer){
                this.overLoad_1_1(arguments[0]);
            }
        }
    },
    //> void overLoad_1_0(int i)
    overLoad_1_0:function(i){
        this.vjo.System.out.println("called with primitive int");
    },
 
    //> void overLoad_1_1(Integer i)
    overLoad_1_1:function(i){
        this.vjo.System.out.println("called with wrapper int");
    },
    //> void callOverLoad()
    callOverLoad:function(){
        this.overLoad(new this.vjo.Integer(10));
        this.overLoad(new this.vjo.Integer(12));
    }
})
.endType();

3. FIXED. Instance initialization is not consistence. From the below example, float1 and double1 are not initialized in the init constructor.


 
package j2jtest;
public class Pair2{ 
    Integer integer2 = 20;
    Integer integer1 = new Integer(10);
    Float float1 = 12.2f;
    Float float2 = new Float(12);
    Double double1 = 30.5;
}
 
vjo.ctype("j2jtest.Pair2")
.needs("vjo.java.lang.Integer")
.needs("vjo.java.lang.Float")
.needs("vjo.java.lang.Double")
.protos({
    //> Integer integer2
    integer2:null,
    //> Integer integer1
    integer1:null,
    //> Float float1
    float1:12.2,
    //> Float float2
    float2:null,
    //> Double double1
    double1:30.5,
    //> private constructs()
    constructs:function(){
        this.integer1=new this.vjo.Integer(10);
        this.float2=new this.vjo.Float(12);
        this.integer2=new this.vjo.Integer(20);
    }
})
.endType();

4. NOT APPLICABLE: Don’t give function name starts with “constructs” ie., constructs_0_0. if you have then you’ll see unexpected result as shown below


 
package j2jtest;
public class Pair2{ 
    Integer integer1=12;
    Float f = 23.4f;
    Pair2(){
        System.out.println("No arg constructor");
        constructs_0_0();
    }
    Pair2(Integer initValue){
        System.out.println("One arg constructor");
    }
    void constructs_0_0(){
        System.out.println(" this is not a constructor");
    }
}
vjo.ctype("j2jtest.Pair2")
.needs("vjo.java.lang.Integer")
.needs("vjo.java.lang.Float")
.needs("vjo.java.lang.System")
.protos({
    //> Integer integer1
    integer1:null,
    //> Float f
    f:23.4,
    //> constructs()
    constructs:function(){
        this.integer1=new this.vjo.Integer(12);
        if(arguments.length===0){
            if(arguments.length==0){
                this.constructs_0_0_0_0();
            }else if(arguments.length==0){
                this.constructs_0_0_0_0();
            }
        }else if(arguments.length===1){
            this.constructs_1_0(arguments[0]);
        }
    },
 
    //> constructs_1_0(Integer initValue)
    constructs_1_0:function(initValue){
        this.vjo.System.out.println("One arg constructor");
    },
    //> constructs()
    constructs:function(){
        this.integer1=new this.vjo.Integer(12);
        if(arguments.length===0){
            if(arguments.length==0){
                this.constructs_0_0_0_0();
            }else if(arguments.length==0){
                this.constructs_0_0_0_0();
            }
        }else if(arguments.length===1){
            this.constructs_1_0(arguments[0]);
        }else if(arguments.length===0){
            if(arguments.length==0){
                this.constructs_0_0_0_0();
            }else if(arguments.length==0){
                this.constructs_0_0_0_0();
            }
        }else if(arguments.length===1){
            this.constructs_1_0(arguments[0]);
        }
    },
 
    //> constructs_0_0_0_0()
    constructs_0_0_0_0:function(){
        this.vjo.System.out.println("No arg constructor");
        constructs_0_0();
    },
 
    //> void constructs_0_0_0_1()
    constructs_0_0_0_1:function(){
        this.vjo.System.out.println(" this is not a constructor");
    }
})
.endType();

5. Need to have reserved/keyword that cannot be used while writing java that would be converted into js. For instance, use of base as method name in base class would cause calling wrong method/confusion


 
package j2jtest;
public class Pair{
    Integer i =10;
	Pair(Integer intValue){
 
	}
	void base(Integer i){
		System.out.println("Base method");
	}
}
 
package j2jtest;
public class Pair2 extends Pair{ 
	Pair2(){
		super(10);
	}
	Pair2(Integer intValue){
		super(intValue);
		base(intValue);
	}
}
 
vjo.ctype("j2jtest.Pair2")
.needs("j2jtest.Pair")
.needs("vjo.java.lang.Integer")
.inherits("j2jtest.Pair")
.protos({
	//> constructs()
	constructs:function(){
		if(arguments.length===0){
			this.constructs_0_0();
		}else if(arguments.length===1){
			this.constructs_1_0(arguments[0]);
		}
	},
 
	//> constructs_0_0()
	constructs_0_0:function(){
		this.base(10);
	},
 
	//> constructs_1_0(Integer intValue)
	constructs_1_0:function(intValue){
		this.base(intValue);
		this.base(intValue);
	}
})
 
.endType();

6. DOCUMENTED Don’t use class name, function name or package name for variables. It woks in java but not in javascript. For ex., below code display “test” in java but java script it display the whole java script object


class MyClass {
	String MyClass = "test";
	public void method1(){
		System.out.println(MyClass);
	}
}
 
vjo.ctype("j2jtest.abstract1.MyClass")
.protos({
	//> String MyClass
	MyClass:"test",
	//> public void method1()
	method1:function(){
		this.vjo.System.out.println(this.vjo.MyClass);
	}
})
.endType();


7. FIXED , Inner classes/second level inner classes are not getting created correctly

package j2jtest;
public class OuterClass {
	int outerVar = 10;
	class InnerClass{
		class InnerInnerClass{
			void innerInnerMethod(String mssg){
				Out.log("InnerInner " +mssg);
			}
		}
		void innerMethod(String mssg){
			Out.log("Inner " +mssg);
		}
	}
	static void testMethod(){
		OuterClass.InnerClass innerClass = 
		new OuterClass().new InnerClass();
 
		OuterClass.InnerClass.InnerInnerClass inInClass = 
		innerClass.new InnerInnerClass(); 
 
		innerClass.innerMethod("mssg1");
		inInClass.innerInnerMethod("mssg2");
	}
}
vjo.ctype("j2jtest.OuterClass")
.needs("j2jtest.Out")
.props({
	//> void testMethod()
	testMethod:function(){
		var innerClass=new (new this())
		.InnerClass();
 
		var inInClass;
		innerClass.innerMethod("mssg1");
		inInClass.innerInnerMethod("mssg2");
	}
})
.protos({
	//> int outerVar
	outerVar:10,
	InnerClass://> InnerClass
	vjo.ctype()
	.protos({
		InnerInnerClass://> InnerInnerClass
		vjo.ctype()
		.protos({
		//> void innerInnerMethod(String mssg)
		innerInnerMethod:function(mssg){
		    this.vjo.Out.log("InnerInner "+mssg);
		}
		})
		.endType(),
		//> void innerMethod(String mssg)
		innerMethod:function(mssg){
			this.vjo.Out.log("Inner "+mssg);
		}
	})
	.endType()
})
.endType();

8. DOCUMENTED. Inner class initialization is not translated correctly.

 
package j2jtest.innerclass;
import j2jtest.Out;
import java.util.ArrayList;
import java.util.List;
 
public class AnonymousInnerclass {
	List list = new ArrayList(3) {
	{add("One"); add("Two"); add("Three");}
	};
 
	public void testMethod(){
		for(Object value: list){
			Out.log("value="+value);
		}
	}
}
 
vjo.ctype("j2jtest.innerclass.AnonymousInnerclass")
.needs("vjo.java.util.List")
.needs("vjo.java.util.ArrayList")
.needs("j2jtest.Out")
.protos({
	//> List list
	list:null,
	//> private constructs()
	constructs:function(){
		this.list=
		vjo.make(this,vjo.java.util.ArrayList,3);
	},
	//> public void testMethod()
	testMethod:function(){
		this.vjo.Out.log("value=");
		for (var value,_$itr=
			this.list.iterator();_$itr.hasNext();){
			value=_$itr.next();
			this.vjo.Out.log("value="+value);
		}
	}
})
.endType();

9. FIXED Local inner class Class Out not imported and create

package j2jtest.innerclass;
import j2jtest.Out;
import java.util.ArrayList;
public class LocalInnerclass {
	public void testMethod() {
		//Out.log("asasas");
		 class Happy { 
			public void hi() {
			ArrayList list = new ArrayList();
			Out o = new Out();
			o.log("Hi");
			double d = Math.PI;
			} 
		}
		Happy h = new Happy();
		h.hi();
	}
}
 
vjo.ctype("j2jtest.innerclass.LocalInnerclass")
.needs("vjo.java.util.ArrayList")
.needs("vjo.java.lang.Math")
.protos({
	//> public void testMethod()
	testMethod:function(){
		//> Happy
		vjo.ctype("Happy")
		.protos({
			//> public void hi()
			hi:function(){
			var list=new this.vjo.ArrayList();
			var o;
			o.log("Hi");
			var d=this.vjo.Math.PI;
			}
		})
		.endType();
		var h=new Happy();
		h.hi();
	}
})
.endType();

10. FIXED method overload with super and base class as parameter

 
package j2jtest.constructor;
import j2jtest.Out;
public class MyClass extends MyClassBase{
	public void testMethod(MyClassBase base){
	Out.log("MyClass(MyClassBase)");
}
public void testMethod(MyClass myClass){
	Out.log("MyClass(MyClass)");
}
public void testMethod(){
	MyClass myClass = new MyClass();
	testMethod(myClass);
}
}
 
vjo.ctype("j2jtest.constructor.MyClass")
.needs("j2jtest.constructor.MyClassBase")
.needs("j2jtest.Out")
.inherits("j2jtest.constructor.MyClassBase")
.protos({
	//> public void testMethod()
	testMethod:function(){
		if(arguments.length===1){
			if(arguments[0] instanceof 
			  j2jtest.constructor.MyClassBase){
				this.testMethod_1_0(arguments[0]);
			}else if(arguments[0] instanceof 
			        j2jtest.constructor.MyClass){
				this.testMethod_1_1(arguments[0]);
			}
		}else if(arguments.length===0){
			this.testMethod_0_0();
		}
	},
	//> public void testMethod_1_0(MyClassBase base)
	testMethod_1_0:function(base){
		this.vjo.Out.log("MyClass(MyClassBase)");
	},
	//> public void testMethod_1_1(MyClass myClass)
	testMethod_1_1:function(myClass){
		this.vjo.Out.log("MyClass(MyClass)");
	},
	//> public void testMethod_0_0()
	testMethod_0_0:function(){
		var myClass=new this.vjo.MyClass();
		this.testMethod(myClass);
	}
})
.endType();

11. ERROR Default constructor. Default constructor is not getting created

package j2jtest.constructor;
public class MyClass 
        extends Base{
}
 
vjo.ctype("j2jtest.constructor.MyClass")
.needs("j2jtest.
   constructor.Base")
.inherits("j2jtest.
   constructor.Base")
.endType();
Generic object is not translated correctly if two typed parameters are same type

FIXED

// translate correctly
public static GenericClass<String,Integer>
                        testMethod(){
GenericClass<String,Integer> 
object2 = 
    new GenericClass<String, Integer>
	    ("String one",20);
Out.log(object2.one);
return object2;
}
 
GenericClass<String, String> testMethod1(){
GenericClass<String,String> object2 = 
    new GenericClass<String, String>("ss","ss");
return object2;
}
//> public GenericClass<String,Integer> 
                            testMethod()
testMethod:function(){
var object2=new this("String one",20);
this.vjo.Out.log(object2.one);
return object2;
}
 
//> GenericClass<String> testMethod1()
testMethod1:function(){
var object2=new 
    this.vjo.GenericClass("ss","ss");
return object2;
},

12. DOCUMENTED Super keyword not translated correctly

 
package j2jtest.inheritance;
import j2jtest.Out;
public class Derived extends Base {
	int i=20;
	public void method1(){
		Out.log(" i = "+super.i);
	}
}
 
vjo.ctype("j2jtest.inheritance.Derived")
.needs("j2jtest.Out")
.needs("j2jtest.inheritance.Base")
.inherits("j2jtest.inheritance.Base")
.props({
	//> public void touch()
	touch:function(){
	}
})
.protos({
	//> int i
	i:20,
	//> public void method1()
	method1:function(){
		this.vjo.Out.log(" i = "+this.i);
	}
})
.endType();

13. DOCUMENTED Cannt have variable name as class name

 
package j2jtest.conversion;
import j2jtest.Out;
public class Conversion {
	String Conversion = "Conversion string";
	String str = "str";
	public static void touch(){
	}
	public void method1(){
		Out.log("Conversion = "+ Conversion);
		Out.log("str = "+ str);
	}
}
 
vjo.ctype("j2jtest.conversion.Conversion")
.needs("j2jtest.Out")
.props({
	//> public void touch()
	touch:function(){
	}
})
.protos({
	//> String Conversion
	Conversion:"Conversion string",
	//> String str
	str:"str",
	//> public void method1()
	method1:function(){
		this.vjo.Out.log("Conversion = "+this.vjo.Conversion);
		this.vjo.Out.log("str = "+this.str);
	}
})
.endType();

14. FIXED Calling overload function from base class is not getting translated. Keyword this is missing

Eg.,

overload();

should be

this. overload();

 
package j2jtest.member;
import j2jtest.Out;
public class Derived extends Base{
	public void method1(){
		overload();
		overload("asasas");
		//overload(local);
	}
	public void override(){
		Out.log("Derived.override");
	}
	public void overload(String s){
		Out.log("Derived.overload(String)");
	}
}
 
package j2jtest.member;
import j2jtest.Out;
public class Base {
	public void override(){
		Out.log("Base.override");
	}
	public void overload(){
		Out.log("Base.overload");
	}
}
 
vjo.ctype("j2jtest.member.Derived")
.needs("j2jtest.Out")
.needs("j2jtest.member.Base")
.inherits("j2jtest.member.Base")
.protos({
	//> public void method1()
	method1:function(){
		overload();
		this.overload("asasas");
	},
	//> public void override()
	override:function(){
		this.vjo.Out.log("Derived.override");
	},
	//> public void overload(String s)
	overload:function(s){
		if(arguments.length===1){
			if(arguments[0] instanceof String 
			|| typeof arguments[0]=="string"){
			this.overload_1_0_Derived_ovld(arguments[0]);
			}else if(this.base && this.base.overload){
				this.base.overload.apply(this,arguments);
			}
		}else if(this.base && this.base.overload){
			this.base.overload.apply(this,arguments);
		}
	},
	//> private void overload_1_0_Derived_ovld(String s)
	overload_1_0_Derived_ovld:function(s){
		this.vjo.Out.log("Derived.overload(String)");
	}
})
.endType();


15. DOCUMENTED. Calling overloaded method with null is not handled correctly.

 
package j2jtest.member;
import j2jtest.Out;
public class Overload {
	public void method1(){
		String notWorking = null;
		//overload();
		overload("working");
		overload(notWorking);	
	}
	public void overload(){
		Out.log("Overload.overload()");
	}
	public void overload(String s){
		Out.log("Overload.overload(String)");
	}
	public void overload(Object s){
		Out.log("Overload.overload(Object)");
	}
}
 
vjo.ctype("j2jtest.member.Overload")
.needs("j2jtest.Out")
.protos({
	//> public void method1()
	method1:function(){
		var notWorking=null;
		this.overload("working");
		this.overload(notWorking);
	},
	//> public void overload()
	//> public void overload(String s)
	//> public void overload(vjo.Object s)
	overload:function(){
		if(arguments.length===0){
			this.overload_0_0_Overload_ovld();
		}else if(arguments.length===1){
		  if(arguments[0] instanceof String 
		  || typeof arguments[0]=="string"){
		    this.overload_1_0_Overload_ovld(arguments[0]);
		  }else if(arguments[0] instanceof vjo.Object){
			this.overload_1_1_Overload_ovld(arguments[0]);
		  }
		}
	},
	//> private void overload_0_0_Overload_ovld()
	overload_0_0_Overload_ovld:function(){
		this.vjo.Out.log("Overload.overload()");
	},
	//> private void overload_1_0_Overload_ovld(String s)
	overload_1_0_Overload_ovld:function(s){
		this.vjo.Out.log("Overload.overload(String)");
	},
	//> private void overload_1_1_Overload_ovld(vjo.Object s)
	overload_1_1_Overload_ovld:function(s){
		this.vjo.Out.log("Overload.overload(Object)");
	}
})
.endType();

16. Abstract method is not getting called correctly. From the example., callAbstractMethod() should call method in implementing class instead it calls from the abstract class method

 
package j2jtest.abstract1;
import j2jtest.Out;
public class Derived extends Base{
	public void method1(){
	callAbstractMethod();
	}
	public void abstractMethod(){
	Out.log("Derived.abstractMethod");
	}
	public void abstractMethod(String value){
	Out.log("Derived.abstractMethod(String)");
	}
}
 
package j2jtest.abstract1;
import j2jtest.Out;
public class Base {
	public String toString(){
	return " Hey i am Basie";
	}
	public void callAbstractMethod(){
	Out.log("Base.callAbstractMethod");
	abstractMethod("StrValue");
	}
	public void abstractMethod(){
	Out.log("Base.abstractMethod");
	}
	public void abstractMethod(String value){
	Out.log("Base.abstractMethod(String)");
	}
}
 
vjo.ctype("j2jtest.abstract1.Derived")
.needs("j2jtest.Out")
.needs("j2jtest.abstract1.Base")
.inherits("j2jtest.abstract1.Base")
.protos({
	//> public void method1()
	method1:function(){
		this.callAbstractMethod();
	},
	//> public void abstractMethod()
	//> public void abstractMethod(String value)
	abstractMethod:function(){
		if(arguments.length===0){
			this.abstractMethod_0_0_Derived_ovld();
		}else if(this.base && this.base.abstractMethod){
			this.base.abstractMethod.apply(this,arguments);
		}else if(arguments.length===1){
			if(arguments[0] instanceof String 
			|| typeof arguments[0]=="string"){
			this.abstractMethod_1_0_Derived_ovld(arguments[0]);
			}else if(this.base && this.base.abstractMethod){
			this.base.abstractMethod.apply(this,arguments);
			}
		}else if(this.base && this.base.abstractMethod){
			this.base.abstractMethod.apply(this,arguments);
		}
	},
	//> private void abstractMethod_0_0_Derived_ovld()
	abstractMethod_0_0_Derived_ovld:function(){
		this.vjo.Out.log("Derived.abstractMethod");
	},
	//> private void abstractMethod_1_0_Derived_ovld(String value)
	abstractMethod_1_0_Derived_ovld:function(value){
		this.vjo.Out.log("Derived.abstractMethod(String)");
	}
})
.endType();


Type Variables

A type variable (§4.4) is an unqualified identifier. Type variables are introduced

by generic class declarations (§8.1.2) generic interface declarations (§9.1.2)

generic method declarations (§8.4.4) and by generic constructor declarations

Things to Remember/TODO

1 Overloaded method and null parameter

Will get unexpected behaviour if overloaded method is called with null object. In java script, variable type is determined based on the value it has. If the variable has null value then ther is no way to determine the type value.

When passing result of an expression to overloaded method, make sure it’s not null.

2 Variable name as Class, Pakcage or function name

Do not overload variable name with Class, Pakcage or function name. In java it works fine, when it comes to java script, it evaluates as class or function.

3 Array components

Array components with custom object creation is not supported. For ex.,

Pair[] pairArrayWithInit = {new Pair(), new Pair()};

4 Inner class/ initialization.

Initializing object like shown below is not supported

List list = new ArrayList(3) {
 { add("One"); add("Two"); add("Three");}
};

5 Overload method with primitive and wrapper class

Overloading functions/constructor with primitive and wrapper class are not supported. For ex, below function method1 is overloaded using primitive type int and Integer. This type of overload is not supported.

public void method1(int intValue){
 
}
public void method1(Integer intValue){
 
}

6 Class loading and static initializer

In java a class is loaded only if it’s used or referenced and all staic fields/blocks will get executed only at that time of class loading.

In VJO there is no such thing called class loading. So all the reference and embedded class’s static variables/blocks are initialized along with the main class. This may cause unexpected bahaviour for ex.,

package j2jtest.todo;
import j2jtest.Out;
public class StaticInit {
    static int intValue = 10;
    public void display(){
        Out.log("intValue="+intValue);
        StaticInner staticInner = new StaticInner();
        Out.log("intValue="+intValue);
    }
    static class StaticInner{
        static{
            intValue = 20;
        }
    }
}

When running the above java class produces the result

intValue=10 intValue=20

but translated js file would result

intValue=20 intValue=20

as all static blocks run when the main class loads.


7 Overload method with super and derived class

When methods are overloaded based on super and derived class, java checks the variable type and calls the corresponding method with that type. In VJO, it doesn’t check the variable type, it checks the object type and call the corresponding method. For ex.,

package j2jtest.methodoverload;
import j2jtest.Out;
public class MyClass extends MyClassBase{
    public void testMethod(MyClassBase base){
        Out.log("testMethod(MyClassBase)");
    }
    public void testMethod(MyClass myClass){
        Out.log("testMethod(MyClass)");
    }
    public void testMethod(){
        MyClass myClass = new MyClass();
        MyClassBase myBaseClass = new MyClass();
        testMethod(myClass);
        testMethod(myBaseClass);
    }
}

Result from Java

testMethod(MyClass)

testMethod(MyClassBase)

Result from Vjo

testMethod(MyClass)

testMethod(MyClass)


8 Same variable names in super and derived class

Java maintains separate memory space for super and derived class so when variable is declared with same name in super and derived, both can have dirrerent value. VJO donesnt maintain separate memory space for super and derived, vjo shares one memory area for all variables (super and derived). So if a variable is declared with the same name in super and derived, only derived class variable would be available and would be refered as this.variablename. For ex.,

package j2jtest.inheritance;
import j2jtest.Out;
public class Derived extends Base {
    int i = 20;
    public void method1(){
        Out.log(" i = "+super.i);
    }
}
package j2jtest.inheritance;
public class Base {
    int i = 10;
}

Would be represented as

vjo.ctype('j2jtest.inheritance.Derived') //< public
.needs('j2jtest.Out')
.inherits('j2jtest.inheritance.Base')
.protos({
    i:20, //< int
    //> public void method1()
    method1:function(){
        this.vjo.Out.log(" i = "+this.i);
    }
})
.endType();

Java output

i = 10

JS output

i = 20


9 Avoid Circular references. For ex.,

public class Conversion {
    Conversion str = new Conversion();
}

10 Sub classes are not supported.

package j2jtest.member;
import j2jtest.Out;
public class MemberClass {
    void m1(){
        Out.log("in MemberClass");
        SubClass obj = new SubClass();
        obj.m1();
    }
}
class SubClass{
    public void m1(){
        Out.log("In MyInnerMemberClass.m1()");
    }
}

Back to the top