Giter Club home page Giter Club logo

project-stream-api-initial's Introduction

Java Streams API Tutorial Starter Code

  1. Navigate to the following template in GitHub - https://github.com/UltimateSandbox/project-stream-api-initial
  2. Fork the repo into your account.
  3. In IntelliJ, clone the repo you just forked from your account. (File -> New -> Project From Version Control)
  4. Follow the instructions in the README.md file (this file) to complete the assignment.
  5. Turn in your assignment by the due date.

Tutorial Instructions

Java 8 Stream API Tutorial

  1. Navigate to the tutorial page below.
  2. Read the instructions/comments in the tutorial.
  3. As you come across code in the tutorial, copy/paste the code into the StreamAPITutorial class' main method.
  4. Complete the following sections of the tutorial to get full credit for this project:
  • How streams work
  • Different kind of streams
  • Processing Order
  • Why Order Matters
  • Reusing Streams
  1. For EXTRA CREDIT on this assignment, complete the following sections in addition to the sections listed above:
  • Advanced Operations
  • Collect
  • FlatMap
  • Reduce
  • Parallel Streams

Important Notes on the Tutorial

As with all tutorials, there are a few issues with this one you need to be aware of for it to run properly. These are listed below.

  1. In the section on reusing streams, there is a line that is marked as throwing an exception. Once you paste this and see the exception thrown, you'll need to comment out this line to be able to get your code to continue to work after that point. The line in question looks like this:
    stream.noneMatch(s -> true);   // exception
  • Comment out that line once you run it to get any of the following code to work.
  1. In the section labeled FlatMap, you'll see a code example with 2 classes in it. Those classes should be reversed in order so it matches the example below. Class Foo references class Bar and must be listed first to avoid an error.
        class Bar {
            String name;

            Bar(String name) {
                this.name = name;
            }
        }

        class Foo {
            String name;
            List<Bar> bars = new ArrayList<>();

            Foo(String name) {
                this.name = name;
            }
        }
  1. In the section labeled FlatMap, one of the sections of code which looks like this
    IntStream.range(1, 4)
        .mapToObj(i -> new Foo("Foo" + i))
        .peek(f -> IntStream.range(1, 4)
        .mapToObj(i -> new Bar("Bar" + i + " <- " f.name))
        .forEach(f.bars::add))
        .flatMap(f -> f.bars.stream())
        .forEach(b -> System.out.println(b.name));

should look like this

    IntStream.range(1, 4)
        .mapToObj(i -> new Foo("Foo" + i))
        .peek(f -> IntStream.range(1, 4)
        .mapToObj(i -> new Bar("Bar" + i + " <- " + f.name))
        .forEach(f.bars::add))
        .flatMap(f -> f.bars.stream())
        .forEach(b -> System.out.println(b.name));

There is a typo in it - can you find it? 4. In the section labeled FlatMap, you'll see a code example with 3 classes in it. Those classes should be reversed in order so it matches the example below.

        class Inner {
            String foo;
        }
        
        class Nested {
            Inner inner;
        }
        
        class Outer {
            Nested nested;
        }
  1. In the advanced section, you'll see a couple examples where they are reusing the same variable name more than once. This will cause a comple error so you'll need to rename these variables to avoid this. For example, ageSum and persons are reused and the instances of reuse will need to be changed to a name of your choice.

project-stream-api-initial's People

Contributors

grhooper avatar

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.