0% found this document useful (0 votes)
4 views2 pages

Lambdas Function 8

JAVA LAMBDAFUNCTION ASSIGNMENT

Uploaded by

coyef88168
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
0% found this document useful (0 votes)
4 views2 pages

Lambdas Function 8

JAVA LAMBDAFUNCTION ASSIGNMENT

Uploaded by

coyef88168
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 2

Assignment on

Lambdas and Functional Programming


Subject: CSW2 (CSE3141) Branch: CSE&CSIT
Session: Feb 2024 to April 2024 Section : All

Q1. Create a functional interface Calculator with methods for addition,


subtraction, multiplication, and division. Implement these methods using
lambda expressions. Define the Calculator functional interface with methods for
arithmetic operations. Implement the interface methods using lambda
expressions for basic arithmetic operations.

Q2. Write a program that sorts a list of strings based on their lengths in
descending order. Define a custom comparator using a lambda expression that
compares strings based on their lengths. Use the custom comparator to sort the
list of strings in descending order of length.

Q3. Write a program that demonstrates lazy evaluation by creating a lazy


sequence of prime numbers. Define a lazy sequence using lambda expressions
that generates prime numbers. Demonstrate lazy evaluation by printing the first
few prime numbers from the lazy sequence.

Q4. Create a functional interface Shape with a method double area() and a
default method void printArea(). Implement the interface using lambda
expressions for different shapes. Define the Shape functional interface with an
area method. Implement the interface for shapes like circle, square, and
rectangle using lambda expressions. Use the default method to print the area of
each shape.

Q5. Write a program that reads a list of strings, converts them to uppercase,
filters out the strings starting with a vowel, and then prints the remaining
strings.

Q6. Write a program that demonstrates a function returning another function,


where the inner function calculates the square of a number. Define a function
that returns another function. The inner function should calculate the square of a
given number. Demonstrate the use of the returned function to calculate squares.
Q7.Write a program that calculates factorial using a recursive lambda
expression. Define a recursive lambda expression to calculate factorial. Use the
lambda expression to calculate factorial of a given number.

Q8. Write a program that creates a thread using a lambda expression as the
Runnable and prints "Hello, CSW2!" from the thread. Define a lambda
expression that implements the Runnable interface and prints "Hello, CSW2!".
Create a thread using the lambda expression and start the thread.

Q9. Write a program that implements the producer-consumer problem using


lambda expressions and threads. Define a bounded buffer class that implements
a queue. Create producer and consumer classes that use lambda expressions to
produce and consume items from the bounded buffer. Create and start multiple
producer and consumer threads to demonstrate the producer-consumer problem.

Q10. Write a Java program that takes a LocalDateTime object and formats it to
a custom string format ("yyyy-MM-dd HH:mm:ss"). Define a LocalDateTime
object representing a specific date and time. Use DateTimeFormatter to format
the LocalDateTime object to the desired string format.

Q11. Write a Java program that converts a given date and time in UTC to the
local date and time of a specific time zone (e.g., "America/New_York"). Parse a
string representing a date and time in UTC format. Convert the parsed Instant to
a ZonedDateTime using a specific ZoneId.

You might also like