Git Product home page Git Product logo

java-8-lambdas-exercises's Introduction

java-8-lambdas-exercises

This git repository contains support material for the Java 8 Lambdas book.

Project Structure

The overall code layout is:

  • Code is in src/main/java
  • Tests are in src/test/java

Within these directories things are organised by package:

The sub-packages then correspond to the chapter number, so the examples for chapter 4 are in com.insightfullogic.java8.examples.chapter4.

Reporting Issues

If you find any issues with the exercises or examples then please submit them via the O'Reilly Errata Page.

java-8-lambdas-exercises's People

Contributors

algirdasrascius avatar arascius avatar consman avatar damiencharpentier avatar dhunziker avatar dololitingyu avatar herts avatar richardwarburton avatar soulxy1993 avatar szymonsadowski3 avatar tweimer avatar weebl2000 avatar yuqisun avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

java-8-lambdas-exercises's Issues

Testing, Debugging and Refactoring - logging example

Hello,

could you please exaplain once again what's the difference between non-lambda code and it's lambda version? (Chapter 7: Testing, Debugging and Refactoring, site 98)

non-lambda code:

Logger logger = new Logger();
if (logger.isDebugEnabled()) {
 logger.debug("Look at this: " + expensiveOperation());
}

lambda code:

Logger logger = new Logger();
logger.debug(() -> "Look at this: " + expensiveOperation());

What do we win by using the lambda version? We can hide the isDebugEnabled check in non-lambda code as well - don't we?

A point of confusion

Hi !

I am reading your book.
I am a little confused about the writing here.

src/main/java/com/insightfullogic/java8/examples/chapter1/Album.java

public Album(String name, List<Track> tracks, List<Artist> musicians) {
    Objects.requireNonNull(name);
    Objects.requireNonNull(tracks);
    Objects.requireNonNull(musicians);      
    this.name = name;
    this.tracks = new ArrayList<>(tracks);
    this.musicians = new ArrayList<>(musicians);
}

Is it correct to write like this:

public Album(String name, List&lt;Track&gt; tracks, List&lt;Artist&gt; musicians) {
    Objects.requireNonNull(name);
    Objects.requireNonNull(tracks);
    Objects.requireNonNull(musicians);      
    this.name = name;
    this.tracks = tracks;
    this.musicians = musicians;
}

or

public Album(String name, List&lt;Track&gt; tracks, List&lt;Artist&gt; musicians) {
    this.name = Objects.requireNonNull(name);
    this.tracks = Objects.requireNonNull(tracks);
    this.musicians = Objects.requireNonNull(musicians); 
}

chapter1——Artist#copy

Artist#copy
public Artist copy() {
List members = getMembers().map(Artist::copy).collect(toList());
return new Artist(name, members, nationality);
}

self invoke, and fall into an infinite loop

Cannot run OptimisationExampleFixed

Hi,
Recently I'm reading this book, and now encountered some problems. When I run com.insightfullogic.java8.answers.chapter6.OptimisationExampleFixed , it hint

No matching benchmarks. Miss-spelled regexp?
Use EXTRA verbose mode to debug the pattern matching.

What's wrong? how to solve it?

Fibonacci - exception

This code in chapter 5 is not correct:
public long fibonacci(int x) { return cache.computeIfAbsent(x, n -> fibonacci(n-1) + fibonacci(n-2)); }
because you are not allowed to change the cache when you are using computeIfAbsent()

Exception in thread "main" java.util.ConcurrentModificationException

Fibonacci HashMap

jdk8
f.fibonacci(15);
result:
{0=0, 1=1, 2=1, 3=2, 4=3, 5=5, 6=8, 7=13, 8=21, 9=34, 10=55, 11=89, 12=144, 13=233}

cache = new HashMap<>(); // Lack 14,15 why?
cache = new TreeMap<>(); // use TreeMap ok

oom caused by parallel()

this issues occurs when i calculate array size,
this array about three minion arays,i hava 2G heap.this file is only 40m,and if i use no parallel,this
program only uses 50m, Ask,what's the cause

static void useStream(){
    long uniqueWord = 0;
    try (Stream<String> lines =
                 Files.lines(Paths.get("D:\\nlp\\dictionary\\CoreNatureDictionary.ngram.txt"), Charset.defaultCharset())){
        long start = System.currentTimeMillis();
        uniqueWord = lines.flatMap(line -> Arrays.stream(line.split(" "))).parallel().distinct().count();

// uniqueWord = lines.flatMap(line -> Arrays.stream(line.split(" "))).distinct().count();
System.out.println(uniqueWord);
long end = System.currentTimeMillis();

        System.out.println( (end-start)+"ms");
    }catch (IOException e){
        e.printStackTrace();
    }
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.