Skip to content
This repository was archived by the owner on Nov 17, 2022. It is now read-only.

Commit 563b42c

Browse files
committed
refactor: improved internal TOC structure
1 parent 6fea666 commit 563b42c

File tree

1 file changed

+12
-11
lines changed

1 file changed

+12
-11
lines changed

docs/core-concepts/android-runtime/marshalling/java-to-js.md

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@ position: 2
88
# Java to JavaScript Conversion
99
The article lists the available types in Java and how they are projected to JavaScript.
1010

11-
### String & Character
11+
## String & Character
1212
Both [java.lang.String](http://developer.android.com/reference/java/lang/String.html) and [java.lang.Character](http://docs.oracle.com/javase/7/docs/api/java/lang/Character.html) types are projected as JavaScript [String](http://www.w3schools.com/jsref/jsref_obj_string.asp):
1313

1414
```javascript
1515
var file = new java.io.File("/path/to/file");
1616
var path = file.getPath(); // returns java.lang.String, converted to JS String
1717
```
1818

19-
### Boolean & Primitive boolean
19+
## Boolean & Primitive boolean
2020
Both the primitive [boolean](http://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html) and reference [java.lang.Boolean](http://docs.oracle.com/javase/7/docs/api/java/lang/Boolean.html) types are projected as JavaScript [Boolean](http://www.w3schools.com/jsref/jsref_obj_boolean.asp):
2121

2222
```javascript
@@ -25,47 +25,47 @@ var button = new android.widget.Button(context);
2525
var enabled = button.isEnabled(); // returns primitive boolean, converted to JS Boolean
2626
```
2727

28-
### Byte & Primitive byte
28+
## Byte & Primitive byte
2929
Both the primitive [byte](http://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html) and reference [java.lang.Byte](http://docs.oracle.com/javase/7/docs/api/java/lang/Byte.html) types are projected as JavaScript [Number](http://www.w3schools.com/jsref/jsref_obj_number.asp):
3030

3131
```javascript
3232
var byte = new java.lang.Byte("1");
3333
var jsByteValue = byte.byteValue(); // returns primitive byte, converted to Number
3434
```
3535

36-
### Short & Primitive short
36+
## Short & Primitive short
3737
Both the primitive [short](http://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html) and reference [java.lang.Short](http://docs.oracle.com/javase/7/docs/api/java/lang/Short.html) types are projected as JavaScript [Number](http://www.w3schools.com/jsref/jsref_obj_number.asp):
3838

3939
```javascript
4040
var short = new java.lang.Short("1");
4141
var jsShortValue = short.shortValue(); // returns primitive short, converted to Number
4242
```
4343

44-
### Integer & Primitive int
44+
## Integer & Primitive int
4545
Both the primitive [int](http://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html) and reference [java.lang.Integer](http://docs.oracle.com/javase/7/docs/api/java/lang/Integer.html) types are projected as JavaScript [Number](http://www.w3schools.com/jsref/jsref_obj_number.asp):
4646

4747
```javascript
4848
var int = new java.lang.Integer("1");
4949
var jsIntValue = int.intValue(); // returns primitive int, converted to Number
5050
```
5151

52-
### Float & Primitive float
52+
## Float & Primitive float
5353
Both the primitive [float](http://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html) and reference [java.lang.Float](http://docs.oracle.com/javase/7/docs/api/java/lang/Float.html) types are projected as JavaScript [Number](http://www.w3schools.com/jsref/jsref_obj_number.asp):
5454

5555
```javascript
5656
var float = new java.lang.Float("1.5");
5757
var jsFloatValue = float.floatValue(); // returns primitive float, converted to Number
5858
```
5959

60-
### Double & Primitive double
60+
## Double & Primitive double
6161
Both the primitive [double](http://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html) and reference [java.lang.Double](http://docs.oracle.com/javase/7/docs/api/java/lang/Double.html) types are projected as JavaScript [Number](http://www.w3schools.com/jsref/jsref_obj_number.asp):
6262

6363
```javascript
6464
var double = new java.lang.Double("1.5");
6565
var jsDoubleValue = double.doubleValue(); // returns primitive double, converted to Number
6666
```
6767

68-
### Long & Primitive long
68+
## Long & Primitive long
6969
[java.lang.Long](http://docs.oracle.com/javase/7/docs/api/java/lang/Long.html) and its primitive equivalent are special types which are projected to JavaScript by applying the following rules:
7070

7171
* If the value is in the interval (-2^53, 2^53) then it is converted to [Number](http://www.w3schools.com/jsref/jsref_obj_number.asp)
@@ -92,7 +92,7 @@ var jsNumber = testClass.getLongNumber53Bits(); // result is JavaScript Number
9292
var specialObject = testClass.getLongNumber54Bits(); // result is the special object described above
9393
```
9494

95-
### Array
95+
## Array
9696
Array in Java is a special [java.lang.Object](http://docs.oracle.com/javase/7/docs/api/java/lang/Object.html) that have an implicit Class associated. A Java Array is projected to JavaScript as a special JavaScript proxy object with the following characteristics:
9797

9898
* Has length property
@@ -108,6 +108,7 @@ var singleFile = files[0]; // the indexed getter callback is triggered and a pro
108108

109109
>**Note:** A Java Array is intentionally not converted to a JavaScript [Array](http://www.w3schools.com/jsref/jsref_obj_array.asp) for the sake of performance, especially when it comes to large arrays.
110110
111+
### Array of Objects
111112

112113
Occasionally you have to create Java arrays from JavaScript. For this scenario we added method `create` to built-in JavaScript [`Array` object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array). Here are some examples how to use `Array.create` method:
113114

@@ -178,7 +179,7 @@ arr[0] = elements;
178179
SomeObject.myMethod(arr); // assuming the method is accepting a two-dimensional array of primitive types
179180
```
180181

181-
### Null
182+
## Null
182183
The Java [null literal](http://docs.oracle.com/javase/specs/jls/se7/html/jls-3.html#jls-3.10.7) (or null pointer) is projected to JavaScript [Null](http://www.w3schools.com/js/js_typeof.asp):
183184

184185
```javascript
@@ -187,7 +188,7 @@ var button = new android.widget.Button(context);
187188
var background = button.getBackground(); // if there is no background drawable method will return JS null
188189
```
189190

190-
### Android Types
191+
## Android Types
191192
All Android-declared types are projected to JavaScript using the Package and Class proxies as described in [Accessing APIs](../metadata/accessing-packages.md)
192193

193194
# See Also

0 commit comments

Comments
 (0)