DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING
Experiment 6
Student Name: Md Zaka Al Shahariar Tanvir UID: 23BCS10438
Branch: B.E CSE Section/Group:23BCS 605-B
Semester: 05 Date of Performance:03.11.25
Subject Name: Project-Based Learning in Java Subject Code: 23CSH-304
1. Aim: Develop Java programs using lambda expressions and stream
operations for sorting, filtering, and processing large datasets efficiently:
a. Write a program to sort a list of Employee objects (name, age, salary)
using lambda expressions.
b. Create a program to use lambda expressions and stream operations to
filter students scoring above 75%, sort them by marks, and display their
names.
c. Write a Java program to process a large dataset of products using
streams. Perform operations such as grouping products by category, finding the
most expensive product in each category, and calculating the average price of
all products.
2. Objective:
• Understand the concept and use of lambda expressions in Java.
• Apply Stream API for filtering, sorting, and processing data efficiently.
• Learn to use built-in stream collectors for grouping and aggregation.
• Enhance code readability and performance using functional-style programming.
3. Implementation/Code:
a. import [Link].*;
public class Easy {
public static void main(String[] args) {
List<Employee> e = new ArrayList<>([Link](
new Employee("zaka", 25, 60000), new
Employee("shan", 28, 75000), new
Employee("akm", 30, 50000)
));
[Link]([Link](Employee::n));
Name: MD ZAKA AL SHAHARIAR TANVIR UID: 23BCS10438
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING
[Link]("--- By Name --- \n" + e);
[Link]([Link](Employee::a));
[Link]("\n--- By Age --- \n" + e);
[Link]([Link](Employee::s));
[Link]("\n--- By Salary --- \n" + e);
}
}
record Employee(String n, int a, double s)
{} Output:
[Link]: import [Link].*; import
[Link].*;
public class Medium {
public static void main(String[] args) { [Link](
new Student("Ravi", 101, 80), new Student("Sunil", 104, 70),
new Student("Aditi", 102, 92), new Student("Kiran", 103,
85), new Student("Meera",
105, 75)
).stream()
.filter(s -> s.m() > 75)
.sorted([Link](Student::m))
.map(Student::n)
.forEach([Link]::println);
}
} record Student(String n, int id, double m)
{}
Name: MD ZAKA AL SHAHARIAR TANVIR UID: 23BCS10438
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING
Output:
C.
import [Link].*; import
[Link].*; public
class Hard {
public static void main(String[] args) {
List<Product> p = [Link](
new Product(1, "Laptop", 80000, "Electronics"),
new Product(2, "Phone", 65000, "Electronics"), new
Product(3, "Office Chair", 12000, "Furniture"),
new Product(4, "Desk", 9000, "Furniture"), new
Product(5, "Monitor", 10000, "Electronics") );
[Link](
[Link]()
.collect([Link](Product::c,
[Link]([Link](Product::p))))
);
[Link]("Average Price: " +
[Link]().collect([Link](Product::p))
);
} }
record Product(int id, String n, double p, String c) {}
Name: MD ZAKA AL SHAHARIAR TANVIR UID: 23BCS10438
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING
OUTPUT:
4. Learning Outcome:
• Use lambda expressions to simplify sorting logic for collections.
• Apply stream operations like filter, sorted, and map to process lists of objects.
• Perform advanced data aggregation using stream Collectors like groupingBy
and averagingDouble.
Name: MD ZAKA AL SHAHARIAR TANVIR UID: 23BCS10438