Saturday, April 19, 2014

Functional Programming in Java: Harnessing the Power Of Java 8 Lambda Expressions

Intermediate level, for programmers fairly familiar with Java, but new to the functional style of programming and lambda expressions.

Functional Programming in Java: Harnessing the Power Of Java 8 Lambda Expressions

Get ready to program in a whole new way. Functional Programming in Java will help you quickly get on top of the new, essential Java 8 language features and the functional style that will change and improve your code. This short, targeted book will help you make the paradigm shift from the old imperative way to a less error-prone, more elegant, and concise coding style that's also a breeze to parallelize. You'll explore the syntax and semantics of lambda expressions, method and constructor references, and functional interfaces. You'll design and write applications better using the new standards in Java 8 and the JDK.

Lambda expressions are lightweight, highly concise anonymous methods backed by functional interfaces in Java 8. You can use them to leap forward into a whole new world of programming in Java. With functional programming capabilities, which have been around for decades in other languages, you can now write elegant, concise, less error-prone code using standard Java. This book will guide you though the paradigm change, offer the essential details about the new features, and show you how to transition from your old way of coding to an improved style.

In this book you'll see popular design patterns, such as decorator, builder, and strategy, come to life to solve common design problems, but with little ceremony and effort. With these new capabilities in hand, Functional Programming in Java will help you pick up techniques to implement designs that were beyond easy reach in earlier versions of Java. You'll see how you can reap the benefits of tail call optimization, memoization, and effortless parallelization techniques.

Java 8 will change the way you write applications. If you're eager to take advantage of the new features in the language, this is the book for you.

What you need:
Java 8 with support for lambda expressions and the JDK is required to make use of the concepts and the examples in this book.

Thursday, April 17, 2014

Some examples of using Stream of Java 8

This post show some example of using Stream<String> of Java 8; such as splite String to Stream<String> of words, print all element in Stream, count number of element, sort Stream, convert to lower case, find the maximum, and Find the first word starts with.

package java8stream;

import java.util.Optional;
import java.util.stream.Stream;

/**
 * @web http://java-buddy.blogspot.com/
 */
public class Java8Stream {

    static String lyrics = "Hello darkness, my old friend,\n"
            + "I've come to talk with you again,\n"
            + "Because a vision softly creeping,\n"
            + "Left its seeds while I was sleeping,\n"
            + "And the vision that was planted in my brain\n"
            + "Still remains\n"
            + "Within the sound of silence.";

    public static void main(String[] args) {
        System.out.println("--- lyrics ---");
        System.out.println(lyrics);

        System.out.println("--- Some examples of using Stream ---");
        
        //print all element in Stream<String>
        Stream.of(lyrics.split("[\\P{L}]+"))
            .forEach((String element) -> System.out.println(element));
        
        //count number of element in Stream
        System.out.println("count of words = " + 
            Stream.of(lyrics.split("[\\P{L}]+")).count());
        
        System.out.println("--- Sorted Stream ---");
        Stream<String> sortedStream = Stream.of(lyrics.split("[\\P{L}]+")).sorted();
        sortedStream.forEach((String element) -> System.out.println(element));
        
        System.out.println("--- Convert to lower case ---");
        Stream<String> sortedStreamLower = Stream.of(lyrics.split("[\\P{L}]+"))
                .map(String::toLowerCase);
        sortedStreamLower.forEach((String element) -> System.out.println(element));
        
        System.out.println("--- Find the maximum, ignore case, in Stream<String> ---");
        Optional<String> max = Stream.of(lyrics.split("[\\P{L}]+"))
                .max(String::compareToIgnoreCase);
        if(max.isPresent()){
            System.out.println("max = " + max.get());
        }
        
        System.out.println("--- Find the first word starts with 'c' ---");
        Optional<String> startsWithC = Stream.of(lyrics.split("[\\P{L}]+"))
                .filter(s->s.startsWith("c")).findFirst();
        if(startsWithC.isPresent()){
            System.out.println("the first word starts with 'c' = " + startsWithC.get());
        }
    }

}



Tuesday, April 15, 2014

Java Programming Interviews Exposed

Java Programming Interviews Exposed

If you are a skilled Java programmer but are concerned about the Java coding interview process, this real-world guide can help you land your next position

Java is a popular and powerful language that is a virtual requirement for businesses making use of IT in their daily operations. For Java programmers, this reality offers job security and a wealth of employment opportunities. But that perfect Java coding job won't be available if you can't ace the interview. If you are a Java programmer concerned about interviewing, Java Programming Interviews Exposed is a great resource to prepare for your next opportunity. Author Noel Markham is both an experienced Java developer and interviewer, and has loaded his book with real examples from interviews he has conducted.


  • Review over 150 real-world Java interview questions you are likely to encounter
  • Prepare for personality-based interviews as well as highly technical interviews
  • Explore related topics, such as middleware frameworks and server technologies
  • Make use of chapters individually for topic-specific help
  • Use the appendix for tips on Scala and Groovy, two other languages that run on JVMs

  • Veterans of the IT employment space know that interviewing for a Java programming position isn't as simple as sitting down and answering questions. The technical coding portion of the interview can be akin to a difficult puzzle or an interrogation. With Java Programming Interviews Exposed, skilled Java coders can prepare themselves for this daunting process and better arm themselves with the knowledge and interviewing skills necessary to succeed.