Category Archives: Java

Javascript and new way of thinking!

It’s been quite some time since I did any Javascript programming, and it’s hard to start thinking in an unstructured way again.  One of JS’s peculiar nuances is the ability to declare a property on an object by just assigning it! After working with C++/Obj C/C# and having to declare everything up front this takes a new way of thinking.

For instance, with the Cocos2D-X-JS the pattern of their script declaration didn’t make it obvious on where or how to declare variables that will persist between function calls.  Being used to pre-declaring everything, I stuck a few ‘var’ statements at the top of the file, before the ‘extends’ stuff starts.  This works, but looks a bit messy.

var self,canvas;

cc.Class({
extends: cc.Component,
...

Of course, with JS, there’s no need to declare variables, just assign them as a property and they’re created for you!  Of course, you’ll not get the benefit of type checking and even checking if the var you’re using is spelt the same as the one you declared, but you can’t have everything!

Time to expand my horizons!

I’m going to check out http://www.cocos2d-x.org/ as a cross platform language for some utility work that needs to be deployed on both Android & iOS.  I’d prefer to use Unity, but the client I’m talking with doesn’t want to spring for a full Unity license (turns out you can’t just buy the monthly sub for 4 months, release a product and then cancel…).

Can’t wait – especially given how much I love Javascript </sarcasm>.

 

JNI Type signatures

For my future reference, one of the things that will show up when you’re debugging your java stuff are functions with signatures.

The official documentation is here: http://docs.oracle.com/javase/6/docs/technotes/guides/jni/spec/types.html#wp16432

But for quicker access, here’s what matters:

Type Signature

Java Type

Z

boolean

B

byte

C

char

S

short

I

int

J

long

F

float

D

double

L fully-qualified-class ;

fully-qualified-class

[ type

type[]

( arg-types ) ret-type

method type

For example, the Java method:

long f (int n, String s, int[] arr); 

has the following type signature:

(ILjava/lang/String;[I)J