CodeGym
Promotion
CodeGym University
Java FullStack
Learning
Courses
Tasks
Surveys & Quizzes
Games
Help
Schedule
Community
Users
Forum
Chat
Articles
Success stories
Activity
Reviews
Subscriptions
Light theme

Lessons

  • Reviews
  • About us
Start
Start learning
Start learning now
  • My Progress
  • Courses
  • University
  • Quest Map
  • Lessons
  • Using lambdas in collections and streams

    JAVA 25 SELF
    Level 48, Lesson 1
    Practice of lambda expressions in collections and Stream API: how to replace anonymous classes with compact lambdas, use collection methods ( forEach, removeIf, sort, replaceAll) and build data-processing pipelines ( stream → filter → map → sorted → collect). We will compare them with anonymous classes, discuss “effectively final” variables, provide a table of the main operations, and analyse common pitfalls.
    Available
  • Advantages and disadvantages of lambda expressions

    JAVA 25 SELF
    Level 48, Lesson 2
    In this lecture, we discuss why Java gained lambda expressions: conciseness and readability, passing behavior as a parameter, integration with collections and the Stream API ( filter, map, forEach), capture of “effectively” final variables, and convenient callback syntax via the -> operator. In parallel, we’ll look at pitfalls: debugging long chains, overload ambiguity ( Runnable vs Callable), closure limitations, serialization, and nested lambdas. We conclude with practical recommendations on when to use lambdas and a review of common mistakes.
    Available
  • Closures in Java: nuances

    JAVA 25 SELF
    Level 48, Lesson 3
    In this lecture, we break down what a closure is and how it works in Java: how lambdas and anonymous classes “capture” outer variables, why local variables must be final or effectively final, how capturing local variables differs from accessing class fields, and how this behaves in lambdas and anonymous classes. We’ll show function factories with IntSupplier, look into the internal capture implementation, and cover typical mistakes (for example, the compiler message Variable used in lambda expression should be final or effectively final).
    Available
  • Anonymous classes: how they differ from lambdas, with examples

    JAVA 25 SELF
    Level 48, Lesson 4
    In this lecture we unpack what an anonymous class is in Java and how it differs from a lambda expression: syntax, capabilities (fields, additional methods, overriding toString/ equals), scope and the behavior of this, variable capture (only final/“effectively final”). Practical examples with Runnable, Comparator, Predicate, plus recommendations — when to choose a lambda and when an anonymous class.
    Available
  • Functional interfaces: Predicate, Consumer, Supplier, Function

    JAVA 25 SELF
    Level 49, Lesson 0
    We break down the key functional interfaces from the java.util.function package: Predicate, Consumer, Supplier, Function—what they accept/return and where they are used in the Stream API ( filter, map, forEach, generate). We recall the “exactly one abstract method” rule and the @FunctionalInterface annotation, write lambdas, compare them with anonymous classes, practice with a User class example, and analyse common pitfalls when choosing between Predicate/ Function, etc.
    Available
  • Function composition: compose, andThen

    JAVA 25 SELF
    Level 49, Lesson 1
    This lecture is about building transformation pipelines from small functions using Function and its methods compose and andThen. We will cover execution order, type compatibility, examples with Predicate ( and, or, negate), Consumer ( andThen), build practical pipelines, and discuss common pitfalls: mixed-up order ( f.compose(g) vs f.andThen(g)), mismatched types, and “spaghetti” chains. You will learn to use apply, test, accept and to build readable, reusable transformations.
    Available
  • Passing Functions as Parameters: Examples

    JAVA 25 SELF
    Level 49, Lesson 2
    A practical introduction to passing behavior in Java: how to use lambda expressions ( ->) and method references ( ::) together with the Stream API and collections. We’ll cover the standard functional interfaces from java.util.function — Comparator, Predicate, Function, Consumer, Supplier — learn to write generic methods, accept behavior as parameters, and avoid common mistakes. We’ll practice with examples using Stream, Optional, and our own list-processing utilities.
    Available
  • Functional style with the Stream API

    JAVA 25 SELF
    Level 49, Lesson 3
    We move from imperative loops to declarative data-processing pipelines with the Stream API: we cover intermediate and terminal operations, lazy evaluation, collecting results via toList()/ collect, the key operations map, filter, sorted, flatMap, reduce, as well as checks anyMatch/ allMatch/ noneMatch. We’ll compare imperative and functional styles, walk through practical examples, and cover common mistakes, including misusing forEach for collecting and premature parallelStream().
    Available
  • Debugging errors in functional programming

    JAVA 25 SELF
    Level 49, Lesson 4
    The 10 most common mistakes when working with lambdas and the Stream API in Java: variable capture ( final/ effectively final), the behavior of this in lambdas, side effects and parallelism ( parallelStream()), type inference and generics, working with null and Optional, function composition ( compose/ andThen), as well as checked exceptions (for example, IOException). We show safe practices: filtering with Objects::nonNull, terminal operations ( sum(), collect(...)), thread-safe collections, and decomposing long chains.
    Available
  • Listeners and event interfaces

    JAVA 25 SELF
    Level 50, Lesson 0
    How the event model works in Java: a source generates an event, and subscribed listeners receive a notification and react. We will examine the key Swing listener interfaces — ActionListener, MouseListener, KeyListener, ChangeListener, DocumentListener — and show how to register handlers via addActionListener and implement the actionPerformed method. We will practice attaching listeners to JButton/ JFrame, compare anonymous classes and lambda expressions, and discuss common mistakes and practical tips.
    Available
  • Events in Swing and AWT: basics, examples

    JAVA 25 SELF
    Level 50, Lesson 1
    A brief hands-on introduction to the AWT/ Swing event model: we create a JButton, register a listener via addActionListener, and handle it in actionPerformed. We examine anonymous classes and lambda expressions, popular listeners ( MouseListener/ MouseAdapter, KeyAdapter, DocumentListener), build a mini application based on JFrame, JButton, JLabel, look at the call sequence and common mistakes (heavy work in a handler, variable finality in lambdas, a forgotten addActionListener, removing listeners, using SwingWorker).
    Available
  • Creating and handling custom events

    JAVA 25 SELF
    Level 50, Lesson 2
    In this lecture, we examine how to design custom events in Java: create an event class based on java.util.EventObject, define a listener interface via java.util.EventListener, add a subscribe/unsubscribe mechanism ( add...Listener/ remove...Listener) and notifications ( fire...). We’ll look at practical examples with DataLoader and a counter, discuss handlers with anonymous classes and lambda expressions, and also cover common mistakes (exceptions in listeners, memory leaks, ConcurrentModificationException).
    Available
  • 1
  • ...
  • 21
  • 22
  • 23
  • 24
  • 25
  • ...
  • 30
Learn
  • Registration
  • Java Course
  • Help with Tasks
  • Pricing
  • Java Syntax
Community
  • Users
  • Articles
  • Forum
  • Chat
  • Success Stories
  • Activity
  • Affiliate Program
Company
  • About us
  • Contacts
  • Reviews
  • Press Room
  • CodeGym for EDU
  • FAQ
  • Support
CodeGym CodeGym is an online course for learning Java programming from scratch. This course is a perfect way to master Java for beginners. It contains 1200+ tasks with instant verification and an essential scope of Java fundamentals theory. To help you succeed in education, we’ve implemented a set of motivational features: quizzes, coding projects, content about efficient learning, and a Java developer’s career.
Follow us
Interface language
English
Deutsch Español हिन्दी Français Português Polski বাংলা 简体中文 मराठी தமிழ் Italiano Bahasa Indonesia 繁體中文 Nederlands 日本語 한국어 Bulgarian Danish Hungarian Basa Jawa Malay Norwegian Romanian Swedish Telugu Thai Українська Filipino Turkish Azərbaycan Русский Vietnamese
Programmers Are Made, Not Born © 2026 CodeGym
MastercardVisa
Programmers Are Made, Not Born © 2026 CodeGym