Videos
Google App Engine is the one, which one can you help to set up Free online Java Compiler, But for that you need to have an account to proceed.
Few other places you can defnitely Check http://compilr.com/
If you have Applets, http://www.innovation.ch/java/java_compile.html
EDIT : As Stephen Suggests, Download JRE and JDE and use it from oracle website http://www.oracle.com/technetwork/java/javase/downloads/index.html
With http://www.browxy.com you can compile and run java console application and applets
Functional interface
StringFunction is a functional interface. In other words it is an interface with a single abstract method.
An abstract method is a method without definition (without body).
Such interfaces can be implemented using a lambda expression. As it is done in your example.
So StringFunction exclaim = (s) -> s + "!" is an implementation of StringFunction and an instance of that implementation.
You can think of StringFunction exclaim = (s) -> s + "!" as a short version of following:
class ExclamationAppender implements StringFunction {
@Override
public String run(String s) {
return s + "!";
}
}
StringFunction exclaim = new ExclamationAppender();
The other Answers are correct about your StringFunction being a functional interface because it defines only a single abstract method. You later implement that functional interface by way of a lambda. (See tutorial by Oracle.) Iโll add one more thought.
java.lang.FunctionalInterface
If you were intending for StringFunction to be a functional interface, you can communicate that intent by annotating with FunctionalInterface.
@FunctionalInterface // (a) Communicates your intent. (b) Protects against later adding more methods.
interface StringFunction {
String run(String str);
}
Besides communicating intent, this annotation protects you in the future. If a programmer later adds another method to your interface, the compiler reports an error. The error explains how the additional method violates the contract promised by that annotation.
However, note that use of the FunctionalInterface annotation is optional. Your code so demonstrates. To quote the Javadoc:
โฆ the compiler will treat any interface meeting the definition of a functional interface as a functional interface regardless of whether or not a
FunctionalInterfaceannotation is present on the interface declaration.
While technically optional, I do recommend using this annotation.
For a complete definition of a functional interface, see this page of the Java Language Specification.