aboutsummaryrefslogtreecommitdiffstats
path: root/java/README
diff options
context:
space:
mode:
Diffstat (limited to 'java/README')
-rw-r--r--java/README63
1 files changed, 59 insertions, 4 deletions
diff --git a/java/README b/java/README
index 44f5a415162..3bce2556403 100644
--- a/java/README
+++ b/java/README
@@ -292,15 +292,15 @@ public class EmacsFrobinicator
292 } 292 }
293} 293}
294 294
295Java arrays are similar to C arrays in that they can not grow. But 295Java arrays are similar to C arrays in that they can not grow. But
296they are very much unlike C arrays in that they are always references 296they are very much unlike C arrays in that they are always references
297(as opposed to decaying into pointers in various situations), and 297(as opposed to decaying into pointers in only some situations), and
298contain information about their length. 298contain information about their length.
299 299
300If another function named ``frobinicate1'' takes an array as an 300If another function named ``frobinicate1'' takes an array as an
301argument, then it need not take the length of the array. 301argument, then it need not take the length of the array.
302 302
303Instead, it simply iterates over the array like so: 303Instead, it may simply iterate over the array like so:
304 304
305int i, k; 305int i, k;
306 306
@@ -339,10 +339,65 @@ struct emacs_array_container
339 339
340or, possibly even better, 340or, possibly even better,
341 341
342typedef int my_array[10]; 342typedef int emacs_array_container[10];
343 343
344Alas, Java has no equivalent of `typedef'. 344Alas, Java has no equivalent of `typedef'.
345 345
346Like in C, Java string literals are delimited by double quotes.
347Unlike C, however, strings are not NULL-terminated arrays of
348characters, but a distinct type named ``String''. They store their
349own length, characters in Java's 16-bit ``char'' type, and are capable
350of holding NULL bytes.
351
352Instead of writing:
353
354wchar_t character;
355extern char *s;
356size_t s;
357
358 for (/* determine n, s in a loop. */)
359 s += mbstowc (&character, s, n);
360
361or:
362
363const char *byte;
364
365for (byte = my_string; *byte; ++byte)
366 /* do something with *byte. */;
367
368or perhaps even:
369
370size_t length, i;
371char foo;
372
373length = strlen (my_string);
374
375for (i = 0; i < length; ++i)
376 foo = my_string[i];
377
378you write:
379
380char foo;
381int i;
382
383for (i = 0; i < myString.length (); ++i)
384 foo = myString.charAt (0);
385
386Java also has stricter rules on what can be used as a truth value in a
387conditional. While in C, any non-zero value is true, Java requires
388that every truth value be of the boolean type ``boolean''.
389
390What this means is that instead of simply writing:
391
392 if (foo || bar)
393
394where foo can either be 1 or 0, and bar can either be NULL or a
395pointer to something, you must explicitly write:
396
397 if (foo != 0 || bar != null)
398
399in Java.
400
346JAVA NATIVE INTERFACE 401JAVA NATIVE INTERFACE
347 402
348Java also provides an interface for C code to interface with Java. 403Java also provides an interface for C code to interface with Java.