Get started with method references in Java

See the original posting on JavaWorld

Along with lambdas, Java SE 8 brought method references to the Java language. This tutorial offers a brief overview of method references in Java, then gets you started using them with Java code examples. By the end of the tutorial you will know how to use method references to refer to a class’s static methods, bound and unbound non-static methods, and constructors, as well as how to use them to refer to instance methods in superclass and current class types. You’ll also understand why many Java developers have adopted lambda expressions and method references as a cleaner, simpler alternative to anonymous classes.

Method references: A primer

My previous Java 101 tutorial introduced lambda expressions, which are used to define anonymous methods that can then be treated as instances of a functional interface. Sometimes, a lambda expression does nothing more than call an existing method. For example, the following code fragment uses a lambda to invoke System.out‘s void println(s) method on the lambda’s single argument–s‘s type is not yet known:

To read this article in full, please click here

C challenges Java in language popularity survey

See the original posting on JavaWorld

After nearly five years as the leader of the Tiobe index of programming language popularity, Java is now in a virtual dead heat with C. C trails Java by a mere fraction of a percent, according to the Tiobe Index of November 2019.

While Java is still ranked number one, with a rating of 16.246 percent, C is right behind it at 16.037 percent, a difference of just .209 percentage points. Tiobe reasons that C’s fortunes are on the upswing because of its use in Internet of Things development. The company speculates that C could have the number one ranking by the end of the year. Java has held Tiobe’s top spot since April 2015.

To read this article in full, please click here