This Domain-Specific Language (DSL) lets you perform operations among different currencies,
by transparently doing all internal conversions. The conversion map is injected implicitly by the client code.
As you can see the client code just needs two simple imports and an implicit value of type Conversion
in order to use the DSL. The operations shown in the previous code are only a few among the available ones.
Have a look at the Money class for a complete coverage.
This API is a Java implementation of Scala Try API,
originally implemented by the guys at Twitter and later added to the Scala Standard Library.
The Try type represents a computation that may fail. If the computation is successful returns
the value wrapped in a Try.Success otherwise returns the
java.lang.Exception wrapped in a Try.Failure.
To use Try you need to call the Try.apply(FailableSupplier) method passing in a lambda with
the same signature used for a common java.util.function.Supplier.
Indeed FailableSupplier is just a java.util.function.Supplier with a
throws Exception added to its get method.
For example, Try can be used to perform division on a user-defined input, without the need to do explicit
exception-handling in all of the places that an exception might occur.
An important property of Try shown in the divide method of the MainExample class is its ability
to pipeline (chain if you prefer) operations, catching exceptions along the way thanks to its flatMap method.
If you are not a seasoned functional programming geek concepts such as flatMap/map might not be easy to grasp
at first. However you’ll get used to them and, in the end, you’ll love them. Moreover you’re going to encounter
these methods more and more often since some important Java 8 classes already implement them
(e.g. java.util.Optional and java.util.stream.Stream. Anyway for the moment just take for
granted that to pipeline more than two operations, say N, you just need to chain them by using N - 1
flatMap calls and a last call to map. E.g.: Suppose you have 3 variables (x, y and z) being
of type Try and you just want to sum them up. The code you need for doing that is the
Apart from map and flatMap, Try has many other useful methods. See the TryTest
class for a thorough coverage of all methods.
System.out.println("Integer division");System.out.println("Enter the dividend press Return and then enter the divisor: ");Scannerdividend=newScanner(System.in);Scannerdivisor=newScanner(System.in);Try<Integer>num=Try.apply(dividend::nextInt);Try<Integer>denom=Try.apply(divisor::nextInt);Try<Integer>result=num.flatMap(x->denom.map(y->x/y));Try<String>resultTryStr=result.map(i->"The result of division is: "+i);StringresultStr=resultTryStr.getOrElse("You must've divided by zero or entered something that's not an Int. Try again!");System.out.println(resultStr);
In the previous example if you enter two valid integers with the second one–the divisor–being different from zero
then the code prints out The result of division is: $RESULT, where $RESULT is the division between the first
and the second number. On the other hand, if you either enter non valid integers–such as a string–or the second
number is zero then you’ll get the message You must've divided by zero or entered something that's not an Int. Try again!
Anyway, as I already said, see the TryTest class for a thorough coverage of all methods.
Template engines (TEs) can be very useful in web development scenarios where you need to generate and format text automatically according to specific processing rules. These engines can also help you build your applications based on the Model-View-Controller (MVC) pattern, making them more robust and maintainable than applications based on spaghetti code. Most programming languages provide built-in or third-party TEs. Java, for example, has Velocity and FreeMarker, among others. For PHP, Smarty is the most used TE.
Learn how to integrate Script.aculo.us web controls into your web applications to make the end-user experience more pleasant.
Script.aculo.us is a pretty big library, so no single article can cover it completely. However, the knowledge you will gain will enable you to leverage the power of Script.aculo.us web controls to improve the end-user experience.
Go to DevX to read the rest of the article: Script.aculo.us Controls: Do Your Web Users a Favor.
Learn how to leverage the Google Gadget API to make your web applications more reachable. As an example, you’ll see how to build a real-world gadget that fetches and displays the DevX feeds.
Go to DevX to read the rest of the article: Will Your Next Web Application Be a Google Gadget?.
Go to DevX to read the rest of the article: The Productivity Perks Behind Prototype’s Popularity.
Go to DevX to read the rest of the article: Speed Up Your AJAX-based Apps with JSON.
In this article you’ll see how to make the three technologies work together by developing a simple and useful application that lets you update a multi-user blog and download the latest posts from it.
Write once, run anywhere. This Java motto seems to hold true even for mobile devices. Indeed, since it was born J2ME has had an ever-increasing impact on mobile development. Some may argue that J2ME is not as portable as other Java technologies, but even so, the result obtained on different mobile devices is, in most cases, still acceptable.
Go to DevX to read the rest of the article: Build Brilliant Client/Server Apps with J2ME, PHP, and MySQL.
Tired of trying to keep your documentation synchronized with the source? You can help alleviate the problem by creating professional documentation directly from the built-in XML documentation features of the C# language using the brilliant NDoc open-source application.
The .NET framework provides a nice way to insert XML documentation tags inside C# source code. These tags can then be extracted to an XML file, and using NDoc, transformed into fully-functional MSDN-style documentation.
Go to DevX to read the rest of the article: Producing Professional MSDN-style Documentation with .NET and NDoc.
J2ME and PHP are both powerful technologies used to develop applications for mobile devices and Web applications, respectively. In this article, you’ll see how to make them work together by developing a simple and useful application that retrieves the latest news from the Web and displays that on a mobile device.
The Java 2 Platform, Micro Edition (J2ME) is targeted at cell phones, smart cards, pagers, and other consumer devices. J2ME technology consists of a virtual machine and a set of APIs suitable for tailored runtime environments for these devices. PHP, on the other hand, is a widely used server-based language to build Web applications. But these two radically different technologies work very well together. In this article you’ll see how they can interact via HTTP (Hyper Text Transfer Protocol). Of course, this is not intended to be a thorough explanation of how HTTP works—you only need to know that HTTP is a request/response protocol. That simply means that the client application performs a request and the server application returns a response.
Go to DevX to read the rest of the article: Obtaining Wireless News with J2ME and PHP.