Java 7 Type Inference for Generic Instance Creation PRO

As of Java 7 we can take out the type arguments required to instantiate a generic class as long as the compiler can infer the type arguments from the context. Many developers name the remaining pair of angle brackets as ‘diamond’. package com.abelski.samples; import java.util.LinkedList; import java.util.List; public class GenericsTypeInference { public static void main(String[] […]

Java 7 Multiple Exception Types Catch PRO

As with Java 7 we can handle more than one type of exception using a single catch block. We should use the ‘|’ operator for putting them together in the same catch statement. When catch handles more than one type of exception the catch parameter is implicitly final. We won’t be able to assign it with […]

The Java 7 try-with-resources Statement PRO

As of Java 7 we can code a try statement that declares one or more resources. Each resource is an object that must be closed after the program is finished. The try-with-resources statement ensures that each resource is closed at the end of the statement. Each object considered as a resource must be instantiated from a class […]

Java 7 Binary Number System PRO

Java 7 allows us to express integral numbers using the binary numbers system. We just need to prefix our integral number with either ‘ob’ or ‘0B’. package com.abelski.samples; public class BinaryDemo { public static void main(String[] args) { int a = 0b101; int b = 0b011; int c = a | b; System.out.println(c); } } […]

Java 7 Switch Case PRO

As of Java 7 we can write a switch case statement that works on strings. This new capability might assist us with writing a shorter code. package com.abelski.samples; public class Demo { public static void main(String[] args) { String operator = args[1]; double numA = Double.parseDouble(args[0]); double numB = Double.parseDouble(args[2]); String result; switch(operator) { case […]

Java 7 Underscores in Numeric Literals PRO

As of Java 7, we can improve the readability of our code by adding underscores in between digits in numerical literals. package com.abelski.samples; public class SeparatorClass { public static void main(String[] args) { double num = 1_424_234.532; System.out.println(num); } } The following video clips overviews this code sample and shows its execution.

Pausing & Resuming Java Script Execution in Web View PRO

When executing code written in Java Script in our web view we would like to pause it when the user moves to another activity and resumes it when he returns. The following code sample includes two activities. The first activity includes a web view that executes code written in Java Script. The second activity is […]

Android Display Orientation PRO

When developing for the android platform we can create two versions for the same layout xml document and keep them separately within ‘layout’ and ‘layout-land’ folders. When the android platform executes our application it will automatically use the correct version in according with the display orientation. The following video clip shows that.

The sscanf Function in PHP PRO

This function allows us to extract values from a string that applies a specific pattern. Each place holder (e.g. %s) refers a specific value in our string. Each value that matches a specific place holder is assigned to a variable. We should pass over our variable to be assigned by the values that match the […]

The setlocale Function in PHP PRO

Calling this function we can apply a specific locale (combination of a language, a country and possible few more values) on our program. The first argument should be a constant that specifies on what do we want to apply the new locale (e.g. LC_NUMERIC will apply our locale on the decimal separator). The second argument […]

Skip to content Update cookies preferences