Tutorial by Examples: er

To encode a string into a byte array, you can simply use the String#getBytes() method, with one of the standard character sets available on any Java runtime: byte[] bytes = "test".getBytes(StandardCharsets.UTF_8); and to decode: String testString = new String(bytes, StandardCharsets.U...
Functions can return tuples: func tupleReturner() -> (Int, String) { return (3, "Hello") } let myTuple = tupleReturner() print(myTuple.0) // 3 print(myTuple.1) // "Hello" If you assign parameter names, they can be used from the return value: func tupleReturner(...
If you want a function to be able to throw errors, you need to add the throws keyword after the parentheses that hold the arguments: func errorThrower()throws -> String {} When you want to throw an error, use the throw keyword: func errorThrower()throws -> String { if true { retur...
To load a properties file bundled with your application: public class Defaults { public static Properties loadDefaults() { try (InputStream bundledResource = Defaults.class.getResourceAsStream("defaults.properties")) { Properties defaults = new ...
Streams provide the most direct access to the binary content, so any InputStream / OutputStream implementations always operate on ints and bytes. // Read a single byte from the stream int b = inputStream.read(); if (b >= 0) { // A negative value represents the end of the stream, normal values ...
The quick start guide includes information about using Docker to stand up a Bosun instance. $ docker run -d -p 4242:4242 -p 80:8070 stackexchange/bosun This will create a new instance of Bosun which you can access by opening a browser to http://docker-server-ip. The docker image includes HBase/O...
There are two types of events emitted by a Preferences object: PreferenceChangeEvent and NodeChangeEvent. PreferenceChangeEvent A PreferenceChangeEvent gets emitted by a Properties object every time one of the node's key-value-pairs changes. PreferenceChangeEvents can be listened for with a Prefer...
Preferences objects always represent a specific node in a whole Preferences tree, kind of like this: /userRoot ├── com │   └── mycompany │   └── myapp │   ├── darkApplicationMode=true │   ├── showExitConfirmation=false │   └── windowMaximized=true └── org └...
All instances of Preferences are always thread-safe across the threads of a single Java Virtual Machine (JVM). Because Preferences can be shared across multiple JVMs, there are special methods that deal with synchronizing changes across virtual machines. If you have an application which is supposed...
Preferences nodes can be exported into a XML document representing that node. The resulting XML tree can be imported again. The resulting XML document will remember whether it was exported from the user or system Preferences. To export a single node, but not its child nodes: Java SE 7 try (Output...
Preferences nodes can be imported from a XML document. Importing is meant to be used in conjunction with the exporting functionality of Preferences, since it creates the correct corresponding XML documents. The XML documents will remember whether they were exported from the user or system Preferenc...
Event listeners can be removed again from any Properties node, but the instance of the listener has to be kept around for that. Java SE 8 Preferences preferences = Preferences.userNodeForPackage(getClass()); PreferenceChangeListener listener = evt -> { System.out.println(evt.getKey() + ...
A value of a Preferences node can be of the type String, boolean, byte[], double, float, int or long. All invocations must provide a default value, in case the specified value is not present in the Preferences node. Preferences preferences = Preferences.userNodeForPackage(getClass()); String som...
To store a value into the Preferences node, one of the putXXX() methods is used. A value of a Preferences node can be of the type String, boolean, byte[], double, float, int or long. Preferences preferences = Preferences.userNodeForPackage(getClass()); preferences.put("someKey", "...
Preferences can be used to store user settings that reflect a user's personal application settings, e.g. their editor font, whether they prefer the application to be started in full-screen mode, whether they checked a "don't show this again" checkbox and things like that. public class Exi...
Note that all bitwise operations operate on 32-bit integers by passing any operands to the internal function ToInt32. Bitwise or var a; a = 0b0011 | 0b1010; // a === 0b1011 // truth table // 1010 | (or) // 0011 // 1011 (result) Bitwise and a = 0b0011 & 0b1010; // a === 0b0010 // t...
Iterators and pointers pointing into an std::vector can become invalid, but only when performing certain operations. Using invalid iterators/pointers will result in undefined behavior. Operations which invalidate iterators/pointers include: Any insertion operation which changes the capacity of...
You can apply any kind of additional processing to the output by passing a callable to ob_start(). <?php function clearAllWhiteSpace($buffer) { return str_replace(array("\n", "\t", ' '), '', $buffer); } ob_start('clearAllWhiteSpace'); ?> <h1>Lorem Ipsum&l...
Useful for simple animations, the CSS transition property allows number-based CSS properties to animate between states. Example .Example{ height: 100px; background: #fff; } .Example:hover{ height: 120px; background: #ff0000; } View Result By default, hovering over an...
When creating animations and other GPU-heavy actions, it's important to understand the will-change attribute. Both CSS keyframes and the transition property use GPU acceleration. Performance is increased by offloading calculations to the device's GPU. This is done by creating paint layers (parts of...

Page 24 of 417