Part 13
Core java interview questions and answers for 3-5 years experience covered in this post:
What is the static method defined in
Function functional interface?
- There is only one static method defined inside the Function
interface.
- Identity() static method is defined in Function.
- Returns a function that always returns its input
argument.
- You will get the same output as your input.
- Please refer to the below example.
package simplifiedjava.crackedInterview.java8;
import
java.util.Arrays;
import
java.util.List; import java.util.function.Function; public class FunctionStaticMethodDemo {
public static void
main(String[] args) {
List<String> list
= Arrays.asList(".Net","Php","Java","C++","C","Database");
Function<String, String> f
= Function.identity();
for(String s: list) {
System.out.println(f.apply(s));
}
}
}
Output:
.Net
Php
Java
C++
C
Database |
What is the difference between
Predicate and Function interface?
|
Predicate |
Function |
1. |
The predicate can return only a Boolean value. |
The function can return any type of object. |
2. |
Predicate defined one abstract method. i.e. test() method. |
The function defined one abstract method. i.e. apply() method. |
3. |
Public Boolean test(T t); |
Public R apply(T t, R r); |
4. |
The predicate can take only one type of parameter which represent
the input argument. |
Function interface takes two parameters. The first one represents
input type and the second one represent return type. |
5. |
Predicate<T> |
Function<T,R> |
What is Consumer functional
interface?
- Consumer interface function just consumes a value, perform a certain
operation and doesn’t return anything.
- Syntax for Consumer interface is,
@FunctionalInterface public interface Consumer<T> {
} |
What is the abstract method defined in
Consumer functional interface?
- Consumer interface has only one abstract method.
- Consumer interface has accept() method which is abstract.
- Please refer to the below example.
@FunctionalInterface
public interface
Consumer<T> {
void accept(T t);
} |
What are the static methods defined in
Consumer functional interface?
- There is no static method declared inside the Consumer
interface.
- Consumer interface has only one abstract method and default
method.
What is the abstract method defined in
Supplier functional interface?
- Supplier interface has defined only one abstract method.
- Get() abstract method has defined the Supplier interface.
- Please refer to the below syntax.
@FunctionalInterface
public interface
Supplier<T> {
T get();
} |
What is Bi-Consumer functional
interface?
- Bi-Consumer interface function just consumes a couple of values, perform
the certain operation and doesn’t return anything.
- Syntax for Consumer interface is,
@FunctionalInterface
public interface
BiConsumer<T, U> {
} |
What are the default methods defined in Consumer functional interface?
- There is only one default method declared inside the Consumer
interface.
- The abstract method defined inside consumer is andThen().
- Please refer to the below example.
package simplifiedjava.crackedInterview.java8; import java.util.function.Consumer; public class ConsumerInterfaceDemo { public static void main(String[] args) {
Consumer<String> c1 = s
-> System.out.println("List 1 " +s);
c1.accept("Java");
Consumer<String> c2 = s
-> System.out.println("List 2 " + s);
c2.accept(".Net");
Consumer<String> c3 = c2.andThen(c1);//c2 calls first & then c1
c3.accept("Both");
}
}
Output:
List Item 1 Java
List Item 2 .Net
List Item 2 Both
List Item 1 Both |
1.
What are the static method defined in
Supplier functional interface?
- There is no static method declared inside the Supplier interface.
What is the difference between
Predicate and Bi-Predicate?
|
Predicate |
Bi-Predicate |
1. |
Predicate accepts only one argument. |
Bi-Predicate accepts two parameters. |
2. |
@FunctionalInterface
public interface
Predicate<T> {
} |
@FunctionalInterface
public interface
BiPredicate<T, U>{
} |
- Java interview questions and answers all MNC - Click here
- Basic core java interview questions and answers for freshers - Click here
- Core java interview questions for 3 years experience - Click here
- Core java interview questions and answers for 3-5 years exp - Click here
- Core java interview questions and Answers for 5 - 7 Years exp - Click here
- Basic Java Interview Questions and Answers - Click here
- Java interview questions and answers on oops - Click here
- Java interview questions and answers on Strings - Click here
- Java interview questions on exception handling - Click here
- Interview questions on multithreading in java for experienced - Click here
- Interview questions on serialization in java for experienced - Click here
- Interview questions on inner class in java for experienced - Click here
- Interview questions on Collections in java for experienced - Click here
Upcoming questions in next post:
131. What are the primitive function.
132. What is the difference between IntFunction, ToIntFunction and IntToDoubleFunction.
133. What is method Reference. How will you implements method reference.
134. Write a program to call static methods with method reference.
135. Can you call non-static method with method reference.
136. How does it different from Collection API.
137. What are the intermidiate operations. Can you list out some intermediate operations.
138. What are the terminal operations. Can you list out some terminal operations.
Thank you techies for visiting this blog. I hope you enjoyed this blog and got more technical knowledge. I have tried to cover all types of questions and provided examples tested on eclipse as much as I can. Guys, please don’t just mug up the questions and answers. Try to clear your concepts with examples. Try to write a code on eclipse once you read the concepts. It will help you to memorize the concepts for a very long time. Simultaneously you will be prepared for interview programs as well. It will help you to survive in the IT sector for a long time. It may be easy to crack an interview but it's really tough to survive in the IT industry with inadequate knowledge and skills. I have collected all the questions from actual interviews attended by my friends, colleagues, college mate and classmate. I have covered frequently asked questions as well as challenging questions. I have included many programs to understand the concept thoroughly. I will try to explain the concept with the help of a real-time program in eclipse. You can share more questions which are not covered in this blog or post. Always welcome your suggestions and queries. I will definitely try to resolve it. Please comment your queries and new set of questions under the comment sections. I will create a new post for those questions.
My total experience is 10. Initially I had worked on some support
projects and then I moved to java projects. I had worked with many
multi-national companies like R-Systems, Tata Consultancy Services,
Cybage Softwares. Fortunately, TCS and Cybage has given
me an opportunity to take interviews for experienced candidates. I
have conducted more than 1000 interviews by now. Mock sessions will be conducted for minimal charges. I will guide you personally on how to crack interviews. All sessions will be online sessions only. My interview book will be provided free of cost if you enroll for personal training. Once you have done practice then I assured you will definitely crack almost all java interviews. I have published my book named with "All MNC Java Interview" which is available on amazon. You can go through it or you can directly contact to me if you are interested to read the book. I will give you special discount. I have covered near about 550 questions and answers with program tested on eclipse and necessary diagram. I have covered interview questions asked in all reputed MNC like TCS, Infosys, Capgemini, Tech Mahindra, Cognizant, City Bank, Barclays, Amdocs, Mindtree etc. My purpose behind this book is, help you to get a job in your dream company. I can understand this is a struggling period for job seekers and freshers. Everybody must have gone from this phase. so never give up. Keep upgrading yourself. I am sure you will get a job in your dream company. All the best!!! Please reach out to me for personal training for interview preparation.
You can reach out to me at mncjavainterview@gmail.com.
|
0 Comments