Tutorial by Examples: c

Instance variables have an object wide scope, they can be declared anywhere in the object, however an instance variable declared on class level, will only be visible in the class object. A variable will be considered an instance variable when prefixed with @. Instance variables are used to set and g...
def results = [] (1..4).each{ def what = (it%2) ? 'odd' : 'even' results << what } assert results == ['odd', 'even', 'odd', 'even'] Here, the if-condition (in (parentheses)) is slightly more complex than just testing for existence/Groovy-Truth.
public void SaveNewEmployee(Employee newEmployee) { // best practice - wrap all database connections in a using block so they are always closed & disposed even in the event of an Exception // best practice - retrieve the connection string by name from the app.config or web.config (dep...
In Emacs M-x slime will start slime with the default (first) Common Lisp implementation. If there are multiple implementations provided (via variable slime-lisp-implementations), other implementations can be accessed via M-- M-x slime, which will offer the choice of available implementations in mini...
Examples ES6/ES2015 to ES5 (via Babel): This ES2015 syntax // ES2015 arrow function syntax [1,2,3].map(n => n + 1); is interpreted and translated to this ES5 syntax: // Conventional ES5 anonymous function syntax [1,2,3].map(function(n) { return n + 1; }); CoffeeScript to ...
C++17 namespace a { namespace b { template<class T> struct qualifies : std::false_type {}; } } namespace other { struct bob {}; } namespace a::b { template<> struct qualifies<::other::bob> : std::true_type {}; } You can enter both the a and b n...
Suppose the make fails: $ make Launch it instead with make VERBOSE=1 to see the commands executed. Then directly run the linker or compiler command that you'll see. Try to make it work by adding necessary flags or libraries. Then figure out what to change, so CMake itself can pass correct argum...
Example: Invoke different constructors by passing relevant parameters import java.lang.reflect.*; class NewInstanceWithReflection{ public NewInstanceWithReflection(){ System.out.println("Default constructor"); } public NewInstanceWithReflection( String a){ ...
Reflection is useful when it is properly used for right purpose. By using reflection, you can access private variables and re-initialize final variables. Below is the code snippet, which is not recommended. import java.lang.reflect.*; public class ReflectionDemo{ public static void main(St...
var baseType = typeof(List<>); var genericType = baseType.MakeGenericType(typeof(String)); var instance = Activator.CreateInstance(genericType); var method = genericType.GetMethod("GetHashCode"); var result = method.Invoke(instance, new object[] { });
If your enum class is required to have static fields, keep in mind they are created after the enum values themselves. That means, the following code will result in a NullPointerException: enum Example { ONE(1), TWO(2); static Map<String, Integer> integers = new HashMap<>(); ...
Compare two Strings ignoring case: "School".equalsIgnoreCase("school"); // true Don't use text1.toLowerCase().equals(text2.toLowerCase()); Languages have different rules for converting upper and lower case. A 'I' would be converted to 'i' in English. But in Turkish a 'I' ...
Once you installed Ubuntu, you might want to get the latest patches and updates. Using Ubuntu's easy to use package manager Aptitude, the OS along with all future packages that is installed using this manner can be kept up to date. Download the latest package lists by refreshing information from ...
public class InsertIntoConcurrentHashMap { public static void main(String[] args) { ConcurrentHashMap<Integer, SomeObject> concurrentHashMap = new ConcurrentHashMap<>(); SomeObject value = new SomeObject(); Integer key = 1; SomeObject ...
import java.io.FileReader; import java.io.IOException; import javax.script.ScriptEngine; import javax.script.ScriptEngineManager; import javax.script.ScriptException; public class InterfaceImplementationExample { public static interface Pet { public void eat(); } p...
An important principle for unit testing is to separate data access from business logic. One efficient technique for this is to define interfaces for data access. Your main class always use a reference to that interface instead of direct reading or writing data. in production code the main class wil...
GWT ships with a command line utility called webAppCreator that automatically generates all the files you’ll need in order to start a GWT project. It also generates Eclipse project files and launch config files for easy debugging in GWT’s development mode. You can create a new demo application in a...
You should already have your backend REST resource available. On the client side (GWT) your need to Add RestyGwt dependency to your project with maven <dependency> <groupId>org.fusesource.restygwt</groupId> <artifactId>restygwt</artifactId> <vers...
import java.util.ArrayList; import java.util.List; import static java.lang.System.out; public class PolymorphismDemo { public static void main(String[] args) { List<FlyingMachine> machines = new ArrayList<FlyingMachine>(); machines.add(new FlyingMachine())...
The way to do a JAX-WS call with basic authentication is a little unobvious. Here is an example where Service is the service class representation and Port is the service port you want to access. Service s = new Service(); Port port = s.getPort(); BindingProvider prov = (BindingProvider)port; ...

Page 342 of 826