Quick revision
The short answer
Java 8 brought lambdas and method references, the Streams API, Optional, the java.time date and time API, CompletableFuture, and default and static methods in interfaces. Default methods were the key that made the rest fit into the existing libraries: they let the JDK add methods such as Collection.stream() and Iterable.forEach() to interfaces that millions of classes already implement, without breaking any of them. Java 8 also replaced PermGen with Metaspace in HotSpot and shipped the Nashorn JavaScript engine, which was removed in Java 15.
What to remember
In this answer, we toured Java 8's main features, lambdas, method references, streams, Optional, java.time, CompletableFuture and interface default and static methods, and saw why default methods were essential: they let the JDK add stream(), forEach() and many other methods to existing interfaces without breaking every class that implements them. We also covered the rules for conflicting defaults and the runtime changes, Metaspace replacing PermGen and Nashorn arriving in 8 and leaving in 15.
Your turn
Answer it aloud as you would in the interview, or type your answer below. Then show one part at a time and compare.
Java 8 brought lambdas and method references, the Streams API, Optional, the java.time date and time API, CompletableFuture, and default and static methods in interfaces. Default methods were the key that made the rest fit into the existing libraries: they let the JDK add methods such as Collection.stream() and Iterable.forEach() to interfaces that millions of classes already implement, without breaking any of them. Java 8 also replaced PermGen with Metaspace in HotSpot and shipped the Nashorn JavaScript engine, which was removed in Java 15.
Why this question is asked
Java 8 is the release that changed how everyday Java looks, and many codebases still live in its style. Interviewers ask this question less to hear a list of features and more to hear the reasoning about default methods, because it shows whether we understand how a language evolves without breaking compatibility. In this answer, we will recap the main features with a small example, look at the problem the stream methods created for existing interfaces, see how default methods solved it, and finish with the runtime changes that came with the release.
1A Quick Tour of the Main Features
A lambda is a short way to write an implementation of an interface that has a single abstract method, which Java calls a functional interface. A method reference, such as String::length, is an even shorter lambda that just calls an existing method. Streams use them to express operations on collections as a pipeline. Optional is a container that may hold a value or be empty, used as a return type instead of null. java.time replaced the old Date and Calendar classes with immutable types like LocalDate and Instant. CompletableFuture lets us combine asynchronous steps without blocking.
Notice how java.time handles the end of month correctly: January 31 plus one month is February 28, not an invalid date. Each line uses a different Java 8 feature, and together they read very differently from Java 7 code.
2The Problem: Adding Methods to Interfaces
To make streams usable, the JDK designers wanted every collection to offer a stream() method, and they wanted forEach, removeIf and similar methods on existing collection types. These are interfaces: Collection, List, Iterable, Map. Before Java 8, an interface could only declare abstract methods, and every class implementing it had to provide all of them.
So adding stream() as an abstract method to Collection would have broken every class in the world that implements Collection, including those in Guava, Hibernate, Apache Commons and countless private codebases. They would no longer compile, and old compiled classes would throw AbstractMethodError when the new method was called. For a platform that promises backward compatibility, that was not acceptable.
3How Default Methods Solved It
A default method is an interface method with a body. Classes that implement the interface inherit it automatically and may override it. That let the JDK add new behaviour to old interfaces while every existing implementation kept compiling and running.
| Feature | Depends on default methods? | Example |
|---|---|---|
Collection.stream() | Yes, added to an old interface | list.stream().filter(...) |
Iterable.forEach | Yes | list.forEach(System.out::println) |
Map.computeIfAbsent, merge | Yes | map.merge(k, 1, Integer::sum) |
Comparator.thenComparing | Yes, plus static comparing() | comparing(User::age).thenComparing(...) |
Lambdas, java.time, Optional | No, new types and syntax | LocalDate.now() |
Notice that Bag never mentions stream(), yet it has one. The default implementation is built on methods every collection already has. Java 8 also allowed static methods in interfaces, which let the JDK put factory and helper methods where they belong, such as Comparator.comparing(...) and Function.identity(), instead of in separate utility classes.
4What About Conflicts Between Default Methods?
Default methods raise an obvious question: what if a class implements two interfaces that both define the same default method? Java has clear rules. A method in the class or its superclass always wins over an interface default. Otherwise, a more specific interface wins over the one it extends. If two unrelated interfaces both provide the method, the class does not compile until it overrides the method and chooses, for example by calling A.super.hello().
5The Runtime Changes in Java 8
Two runtime changes are worth knowing. HotSpot removed PermGen, the fixed-size area that held class metadata, and replaced it with Metaspace, which is allocated from native memory and grows as needed. That ended the classic java.lang.OutOfMemoryError: PermGen space in application servers that redeployed often; we now cap it with -XX:MaxMetaspaceSize if needed. Java 8 also shipped Nashorn, a JavaScript engine reachable through the javax.script API, replacing the older Rhino engine. Nashorn was deprecated in Java 11 and removed in Java 15; it now lives on as a separate open-source project for those who still need it.
6Follow-up questions
Is a default method the same as an abstract class method?
Not quite. Interfaces still cannot hold instance state, so a default method can only call other interface methods; it cannot use fields. A class can implement many interfaces but extend only one class. Default methods were designed for evolving interfaces, not for turning interfaces into abstract classes.
Why is Optional not meant for fields or parameters?
It was designed as a return type that forces callers to think about the empty case. It is not Serializable, it adds an object per value, and as a parameter it makes callers wrap values. For fields and parameters, plain nullable references with clear documentation or overloads usually work better.
What else did Java 8 add that people forget?
Parallel streams, the StampedLock and LongAdder concurrency classes, Base64 encoding in java.util, type annotations, and repeating annotations. Base64 in particular replaced many uses of the internal sun.misc.BASE64Encoder.
7Conclusion
In this answer, we toured Java 8's main features, lambdas, method references, streams, Optional, java.time, CompletableFuture and interface default and static methods, and saw why default methods were essential: they let the JDK add stream(), forEach() and many other methods to existing interfaces without breaking every class that implements them. We also covered the rules for conflicting defaults and the runtime changes, Metaspace replacing PermGen and Nashorn arriving in 8 and leaving in 15.
Open with
The main Java 8 features are lambdas and method references, the Streams API, Optional as a return type, the java.time API that replaced Date and Calendar, CompletableFuture for composing asynchronous work, and default and static methods in interfaces.
Then, if they want more
Default methods are what made the others usable with existing code. The JDK wanted every collection to have stream(), and Iterable to have forEach, and Map to have computeIfAbsent and merge. Those are interfaces that millions of classes implement, in Guava, Hibernate and private code.
Before Java 8, adding an abstract method to an interface would break every implementation: they would stop compiling and old binaries would throw AbstractMethodError. A default method has a body, so every existing implementation inherits it automatically, and stream() can be written in terms of spliterator(), which every collection already has.
Static interface methods also let helpers like Comparator.comparing live on the interface itself. If two interfaces give the same default, the class must override it, and a class method always wins.
On the runtime side, Java 8 replaced PermGen with Metaspace in native memory, which ended the PermGen out of memory errors, and it shipped the Nashorn JavaScript engine, which was later removed in Java 15.
About this answer
- Last updated
- 12 November 2026
- Versions it names
- Java 8, Java 15, Java 7, Java 11
- Checked
- Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
- Where the question comes from
- Written by Scrivio for practice. It is not taken from an interview.
- Official documentation
- The Java Language Specification, Java SE 21, Java SE 21 API documentation
Report an issue with this answer
Copy the line below and send it to the author with what you found. It carries the address of this page.
Issue with "Name the main language and library features of Java 8 and explain why default methods...": https://scrivio-interview-library.netlify.app/java/java-versions/e262386909/