Tutorial by Examples: ad

Starting from a new Settings class and custom configuration section: Add an application setting named ExampleTimeout, using the time System.Timespan, and set the value to 1 minute: Save the Project Properties, which saves the Settings tab entries, as well as re-generates the custom Settings cl...
class Program { static void Main(string[] args) { // Run 2 Tasks. var task1 = Task.Run(() => PerformAction(1))); var task2 = Task.Run(() => PerformAction(2))); // Wait (i.e. block this thread) until both Tasks are complete. Task.WaitA...
1 - Create an empty folder, it will contain the files created in the next steps. 2 - Create a file named project.json with the following content (adjust the port number and rootDirectory as appropriate): { "dependencies": { "Microsoft.AspNet.Server.Kestrel": "1.0.0...
Set function inserts a cache entry into the cache by using a CacheItem instance to supply the key and value for the cache entry. This function Overrides ObjectCache.Set(CacheItem, CacheItemPolicy) private static bool SetToCache() { string key = "Cache_Key"; string value = &quo...
This code contains an overloaded method named Hello: class Example { public static void Hello(int arg) { Console.WriteLine("int"); } public static void Hello(double arg) { Console.WriteLine("double"); } public static vo...
We can create an ArrayList (following the List interface): List aListOfFruits = new ArrayList(); Java SE 5 List<String> aListOfFruits = new ArrayList<String>(); Java SE 7 List<String> aListOfFruits = new ArrayList<>(); Now, use the method add to add a String: ...
This is an example of a default build.gradle file in a module. apply plugin: 'com.android.application' android { compileSdkVersion 25 buildToolsVersion '25.0.3' signingConfigs { applicationName { keyAlias 'applicationName' keyPassword 'password...
To use a NavigationView just add the dependency in the build.gradle file as described in the remarks section Then add the NavigationView in the layout <?xml version="1.0" encoding="utf-8"?> <android.support.v4.widget.DrawerLayout xmlns:android="http://schema...
Dependencies can be added for a specific product flavor, similar to how they can be added for specific build configurations. For this example, assume that we have already defined two product flavors called free and paid (more on defining flavors here). We can then add the AdMob dependency for the ...
Resources can be added for a specific product flavor. For this example, assume that we have already defined two product flavors called free and paid. In order to add product flavor-specific resources, we create additional resource folders alongside the main/res folder, which we can then add resourc...
Addition Map<Integer, String> map = new HashMap<>(); map.put(1, "First element."); System.out.println(map.get(1)); Output: First element. Override Map<Integer, String> map = new HashMap<>(); map.put(1, "First element."); map.put(1, &quot...
We can use V put(K key,V value): Associates the specified value with the specified key in this map (optional operation). If the map previously contained a mapping for the key, the old value is replaced by the specified value. String currentVal; Map<Integer, String> map = new TreeMap&l...
// Create a new instance of a JSONArray JSONArray array = new JSONArray(); // With put() you can add a value to the array. array.put("ASDF"); array.put("QWERTY"); // Create a new instance of a JSONObject JSONObject obj = new JSONObject(); try { // Add the JSONAr...
Java 7 introduced the very useful Files class Java SE 7 import java.nio.file.Files; import java.nio.file.Paths; import java.nio.file.Path; Path path = Paths.get("path/to/file"); try { byte[] data = Files.readAllBytes(path); } catch(IOException e) { e.printStackTrace();...
From the documentation: The exception that is thrown when an application attempts to perform a networking operation on its main thread. This is only thrown for applications targeting the Honeycomb SDK or higher. Applications targeting earlier SDK versions are allowed to do networking on their ma...
public class MyActivity extends Activity { private static final String PREFS_FILE = "NameOfYourPrefrenceFile"; // PREFS_MODE defines which apps can access the file private static final int PREFS_MODE = Context.MODE_PRIVATE; // you can use live template "key"...
If you have many tasks to execute, and all these tasks are not dependent of the result of the precedent ones, you can use Multithreading for your computer to do all this tasks at the same time using more processors if your computer can. This can make your program execution faster if you have some bi...
A Toolbar is a generalization of ActionBar for use within application layouts. While an ActionBar is traditionally part of an Activity's opaque window decor controlled by the framework, a Toolbar may be placed at any arbitrary level of nesting within a view hierarchy. It can be added by performing t...
Using BufferedReader: System.out.println("Please type your name and press Enter."); BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); try { String name = reader.readLine(); System.out.println("Hello, " + name + "!"); } catch(I...
Following snippet shows an example of passing a method group (as opposed to a lambda) when a delegate is expected. Overload resolution will now resolve this instead of raising an ambiguous overload error due to the ability of C# 6 to check the return type of the method that was passed. using System...

Page 2 of 114