Tutorial by Examples: al

"External" Storage is another type of storage that we can use to save files to the user's device. It has some key differences from "Internal" Storage, namely: It is not always available. In the case of a removable medium (SD card), the user can simply remove the storage. It i...
// Obtain an instance of JavaScript engine ScriptEngineManager manager = new ScriptEngineManager(); ScriptEngine engine = manager.getEngineByName("nashorn"); // Define a global variable engine.put("textToPrint", "Data defined in Java."); // Print the global var...
Static and member methods in Java can be marked as native to indicate that their implementation is to be found in a shared library file. Upon execution of a native method, the JVM looks for a corresponding function in loaded libraries (see Loading native libraries), using a simple name mangling sche...
Calling a Java method from native code is a two-step process : obtain a method pointer with the GetMethodID JNI function, using the method name and descriptor ; call one of the Call*Method functions listed here. Java code /*** com.example.jni.JNIJavaCallback.java ***/ package com.example....
You should be careful when comparing floating-point values (float or double) using relational operators: ==, !=, < and so on. These operators give results according to the binary representations of the floating point values. For example: public class CompareTest { public static void main...
Annotations @XmlElement, @XmlAttribute or @XmlTransient and other in package javax.xml.bind.annotation allow the programmer to specify which and how marked fields or properties should be serialized. @XmlAccessorType(XmlAccessType.NONE) // we want no automatic field/property marshalling public cla...
The == and != operators are binary operators that evaluate to true or false depending on whether the operands are equal. The == operator gives true if the operands are equal and false otherwise. The != operator gives false if the operands are equal and true otherwise. These operators can be used ...
PrinterJob pJ = PrinterJob.createPrinterJob(); if (pJ != null) { boolean success = pJ.showPrintDialog(primaryStage);// this is the important line if (success) { pJ.endJob(); } }
Overview In this example 2 clients send information to each other through a server. One client sends the server a number which is relayed to the second client. The second client halves the number and sends it back to the first client through the server. The first client does the same. The server st...
The JavaScriptSerializer.Deserialize<T>(input) method attempts to deserialize a string of valid JSON into an object of the specified type <T>, using the default mappings natively supported by JavaScriptSerializer. using System.Collections; using System.Web.Script.Serialization; // ....
internal class Sequence{ public string Name; public List<int> Numbers; } // ... string rawJSON = "{\"Name\":\"Fibonacci Sequence\",\"Numbers\":[0, 1, 1, 2, 3, 5, 8, 13]}"; Sequence sequence = JsonConvert.DeserializeObject<Seque...
Optional<String> optionalWithValue = Optional.of("foo"); optionalWithValue.ifPresent(System.out::println);//Prints "foo". Optional<String> emptyOptional = Optional.empty(); emptyOptional.ifPresent(System.out::println);//Does nothing.
There are many ways to create arrays. The most common are to use array literals, or the Array constructor: var arr = [1, 2, 3, 4]; var arr2 = new Array(1, 2, 3, 4); If the Array constructor is used with no arguments, an empty array is created. var arr3 = new Array(); results in: [] Note...
Variables can be accessed via dynamic variable names. The name of a variable can be stored in another variable, allowing it to be accessed dynamically. Such variables are known as variable variables. To turn a variable into a variable variable, you put an extra $ put in front of your variable. $va...
Given a list comprehension you can append one or more if conditions to filter values. [<expression> for <element> in <iterable> if <condition>] For each <element> in <iterable>; if <condition> evaluates to True, add <expression> (usually a function...
An array can be initialized empty: // An empty array $foo = array(); // Shorthand notation available since PHP 5.4 $foo = []; An array can be initialized and preset with values: // Creates a simple array with three strings $fruit = array('apples', 'pears', 'oranges'); // Shorthand no...
A single case in a switch statement can match on multiple values. let number = 3 switch number { case 1, 2: print("One or Two!") case 3: print("Three!") case 4, 5, 6: print("Four, Five or Six!") default: print("Not One, Two, Three, Four, F...
It is often necessary to generate a new array based on the values of an existing array. For example, to generate an array of string lengths from an array of strings: 5.1 ['one', 'two', 'three', 'four'].map(function(value, index, arr) { return value.length; }); // → [3, 3, 5, 4] 6 ['one...
Python lists are zero-indexed, and act like arrays in other languages. lst = [1, 2, 3, 4] lst[0] # 1 lst[1] # 2 Attempting to access an index outside the bounds of the list will raise an IndexError. lst[4] # IndexError: list index out of range Negative indices are interpreted as countin...
dictionary = {"Hello": 1234, "World": 5678} print(dictionary["Hello"]) The above code will print 1234. The string "Hello" in this example is called a key. It is used to lookup a value in the dict by placing the key in square brackets. The number 1234 is ...

Page 5 of 269