Tutorial by Examples: a

The + symbol can mean three distinct operators in Java: If there is no operand before the +, then it is the unary Plus operator. If there are two operands, and they are both numeric. then it is the binary Addition operator. If there are two operands, and at least one of them is a String, then i...
The Java language provides 7 operators that perform arithmetic on integer and floating point values. There are two + operators: The binary addition operator adds one number to another one. (There is also a binary + operator that performs string concatenation. That is described in a separate e...
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 ...
While using the foreach loop (or "extended for loop") is simple, it's sometimes beneficial to use the iterator directly. For example, if you want to output a bunch of comma-separated values, but don't want the last item to have a comma: List<String> yourData = //... Iterator<Str...
To create your own Iterable as with any interface you just implement the abstract methods in the interface. For Iterable there is only one which is called iterator(). But its return type Iterator is itself an interface with three abstract methods. You can return an iterator associated with some coll...
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.
WebHistory history = webView.getEngine().getHistory(); The history is basically a list of entries. Each entry represents a visited page and it provides access to relevant page info, such as URL, title, and the date the page was last visited. The list can be obtained by using the getEntries() met...
import static java.awt.BorderLayout.*; import javax.swing.*; import java.awt.BorderLayout; JPanel root = new JPanel(new BorderLayout()); root.add(new JButton("East"), EAST); root.add(new JButton("West"), WEST); root.add(new JButton("North"), NORTH); root.add(...
import javax.swing.*; import java.awt.FlowLayout; public class FlowExample { public static void main(String[] args){ SwingUtilities.invokeLater(new Runnable(){ @Override public void run(){ JPanel panel = new JPanel(); pa...
PrinterJob pJ = PrinterJob.createPrinterJob(); if (pJ != null) { boolean success = pJ.printPage(some-node); if (success) { pJ.endJob(); } } This prints to the default printer without showing any dialog to the user. To use a printer other than the default you can use th...
PrinterJob pJ = PrinterJob.createPrinterJob(); if (pJ != null) { boolean success = pJ.showPrintDialog(primaryStage);// this is the important line if (success) { pJ.endJob(); } }
var person = new Person { Address = null; }; var city = person.Address.City; //throws a NullReferenceException var nullableCity = person.Address?.City; //returns the value of null This effect can be chained together: var person = new Person { Address = new Address { ...
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...
This is placed in a Windows Forms event handler var nameList = new BindingList<string>(); ComboBox1.DataSource = nameList; for(long i = 0; i < 10000; i++ ) { nameList.AddRange(new [] {"Alice", "Bob", "Carol" }); } This takes a long time to execute,...
BindingList<string> listOfUIItems = new BindingList<string>(); listOfUIItems.Add("Alice"); listOfUIItems.Add("Bob");
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...
Parentheses are now forbidden around named parameters. The following compiles in C#5, but not C#6 5.0 Console.WriteLine((value: 23)); Operands of is and as are no longer allowed to be method groups. The following compiles in C#5, but not C#6 5.0 var result = "".Any is byte; T...
Interfaces can be extremely helpful in many cases. For example, say you had a list of animals and you wanted to loop through the list, each printing the sound they make. {cat, dog, bird} One way to do this would be to use interfaces. This would allow for the same method to be called on all of th...
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...

Page 21 of 1099