Tutorial by Examples: ad

Sometimes you may wish to read byte-input into a String. To do this you will need to find something that converts between byte and the "native Java" UTF-16 Codepoints used as char. That is done with a InputStreamReader. To speed the process up a bit, it's "usual" to allocate a b...
A common Executor used is the ThreadPoolExecutor, which takes care of Thread handling. You can configure the minimal amount of Threads the executor always has to maintain when there's not much to do (it's called core size) and a maximal Thread size to which the Pool can grow, if there is more work t...
The ScheduledExecutorService class provides a methods for scheduling single or repeated tasks in a number of ways. The following code sample assume that pool has been declared and initialized as follows: ScheduledExecutorService pool = Executors.newScheduledThreadPool(2); In addition to the nor...
To read an XML file named UserDetails.xml with the below content <?xml version="1.0" encoding="UTF-8" standalone="yes"?> <user> <name>Jon Skeet</name> <userID>8884321</userID> </user> We need a POJO class named U...
Buttons fire action events when they are activated (e.g. clicked, a keybinding for the button is pressed, ...). button.setOnAction(new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent event) { System.out.println("Hello World!"); } }); ...
Buttons can have a graphic. graphic can be any JavaFX node, like a ProgressBar button.setGraphic(new ProgressBar(-1)); An ImageView button.setGraphic(new ImageView("images/icon.png")); Or even another button button.setGraphic(new Button("Nested button"));
Scanner scanner = new Scanner(System.in); //Scanner obj to read System input String inputTaken = new String(); while (true) { String input = scanner.nextLine(); // reading one line of input if (input.matches("\\s+")) // if it matches spaces/tabs, stop reading b...
Scanner scanner = null; try { scanner = new Scanner(new File("Names.txt")); while (scanner.hasNext()) { System.out.println(scanner.nextLine()); } } catch (Exception e) { System.err.println("Exception occurred!"); } finally { if (scanner != nul...
Sometimes the same functionality has to be written for different kinds of inputs. At that time, one can use the same method name with a different set of parameters. Each different set of parameters is known as a method signature. As seen per the example, a single method can have multiple signatures....
Pagination p = new Pagination(10); Timeline fiveSecondsWonder = new Timeline(new KeyFrame(Duration.seconds(5), event -> { int pos = (p.getCurrentPageIndex()+1) % p.getPageCount(); p.setCurrentPageIndex(pos); })); fiveSecondsWonder.setCycleCount(Timeline.INDEFINITE); fiveSecondsWon...
When desired XML format differs from Java object model, an XmlAdapter implementation can be used to transform model object into xml-format object and vice versa. This example demonstrates how to put a field's value into an attribute of an element with field's name. public class XmlAdapterExample { ...
Add the dependency as described in the Remark section, then add a RecyclerView to your layout: <android.support.v7.widget.RecyclerView android:id="@+id/my_recycler_view" android:layout_width="match_parent" android:layout_height="wrap_content"/> ...
To add markers to a Google Map, for example from an ArrayList of MyLocation Objects, we can do it this way. The MyLocation holder class: public class MyLocation { LatLng latLng; String title; String snippet; } Here is a method that would take a list of MyLocation Objects and place a M...
WebView wv = new WebView(); WebEngine we = wv.getEngine(); we.load("https://stackoverflow.com"); WebView is the UI shell around the WebEngine. Nearly all controls for non UI interaction with a page are done through the WebEngine class.
You can use Scanner to read all of the text in the input as a String, by using \Z (entire input) as the delimiter. For example, this can be used to read all text in a text file in one line: String content = new Scanner(new File("filename")).useDelimiter("\\Z").next(); System.o...
BindingList<string> listOfUIItems = new BindingList<string>(); listOfUIItems.Add("Alice"); listOfUIItems.Add("Bob");
Spread operator 6 With ES6, you can use spreads to separate individual elements into a comma-separated syntax: let arr = [1, 2, 3, ...[4, 5, 6]]; // [1, 2, 3, 4, 5, 6] // in ES < 6, the operations above are equivalent to arr = [1, 2, 3]; arr.push(4, 5, 6); The spread operator also act...
The addition operator (+) adds numbers. var a = 9, b = 3, c = a + b; c will now be 12 This operand can also be used multiple times in a single assignment: var a = 9, b = 3, c = 8, d = a + b + c; d will now be 20. Both operands are converted to primitive types. ...
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 ...
At the command line, first verify that you have Git installed: On all operating systems: git --version On UNIX-like operating systems: which git If nothing is returned, or the command is not recognized, you may have to install Git on your system by downloading and running the installer. See...

Page 3 of 114