Core Java - Interview Questions and Answers for 'Filter' | Search Java Interview Question - javasearch.buggybread.com

# Search Interview Questions

2426 questions in repository.
There are more than 200 unanswered questions.
Have a video suggestion.
Click Correct / Improve and please let us know.
Label / Company      Label / Company / Text

Core Java - Interview Questions and Answers for 'Filter' - 10 question(s) found - Order By Newest

Q1. Write a Program that gets a set of numbers , filters out the non prime numbers , calculate the factorial of each prime number and then finds the average of all factorials using Lambda expressions2017-05-14 14:02:57

public static void main(String args[]) {

// Declare and Initialize the Collection
Set<Integer> intSet = new HashSet<Integer>();

double averageOfNonPrimeFactorials = intSet.stream().filter(p->checkIfPrime(p)).collect(Collectors.averagingInt(p->calculateFactorial(p)));

System.out.println(averageOfNonPrimeFactorials );
}

static private boolean checkIfPrime(int num){
for(int count=2;count < num;count++){
if(num % count == 0){
return false;
}
}
return true;
}

static private int calculateFactorial(int num){
int factorial = 1;
for(int count=num;count > 0;count--){
factorial = factorial * count;
}
return factorial;
}
}

Help us improve. Please let us know the company, where you were asked this question :

java 8  lambda expressions  lambda  filter  Collectors  factorial  prime number

Q2. What is an IO Filter ?Core Java2017-01-12 14:17:53
Ans. It's an object that reads from one stream and writes to another.

Help us improve. Please let us know the company, where you were asked this question :

java io  io filter      intermediate

Q3. What is a Servlet Filter ?Java EE2017-01-19 11:33:37
Ans. It's an object that can intercept http request and response and hence we can take appropriate action on those requests.

There are different types of filters based on Specifications like

Authentication
Logging
Encryption
Tokenizing

etc

Help us improve. Please let us know the company, where you were asked this question :

servlets  servlet filters     Synechron  NexThoughts  Populus Group      basic        frequent

Q4. What is the difference between filter and filter-mappings xml tag within deployment descriptor ?Java EE2017-01-19 11:36:25
Ans. filter tag speficies the filter name and respective class for handling filter action whereas filter mapping maps the filter to the url patterns ( specifying the url that needs to be intercepted )

Help us improve. Please let us know the company, where you were asked this question :

deployment descriptor  web.xml  filters  filter mapping

Q5. What are the advantages of Spring interceptor over Servlet Filters ?Spring2017-01-30 10:30:32
Ans. Spring Interceptor are Spring beans and hence they can inject other beans and can be used with other Spring frameworks concepts like AOP.

Help us improve. Please let us know the company, where you were asked this question :

interceptors  servlet filters  spring interceptors vs servlet filters

Q6. Lets say we have a set "set1" with objects of Class A, Class has a non static string called element1, Write a code ( using lambda expression ) to see if there is any object in the set with element1 = "Hello". Core Java2017-08-06 11:51:10
Ans. set1.stream().filter(p->p.element1.equals("Hello")).findAny().isPreent();

Help us improve. Please let us know the company, where you were asked this question :

lambda expressions  java 8  java8  java 8 filter  findAny()

Q7. Write code to get count of every 5 letter word in a string using lambda expression

Core Java2018-04-18 13:06:13
Ans. String str = "I had been saying that he had been there";

Map<String,Long> countWords = Arrays.asList(str.split(" ")).stream().filter(p->p.length() = 5).collect(Collectors.groupingBy(p->p,Collectors.counting()));

System.out.println(countWords);

Help us improve. Please let us know the company, where you were asked this question :

Collectors  lambda  filter  coding  java 8

Q8. Can we capture the Request body within the interceptor or Filter and perform operations on it ?Spring2018-04-27 12:11:58
Ans. Yes, But with interceptor it will remove the body from the request and then we will have to explicitly add the attributes to the session to forward it to the handler.

Help us improve. Please let us know the company, where you were asked this question :

interceptor  filter

Q9. Can you explain filter and collectors in java 8 ?Core Java2018-05-03 08:27:26

Help us improve. Please let us know the company, where you were asked this question :

collector  filter

Do you think these are the Best Java Frameworks ?

 OpenXava SPRING MVC Apache Stripes Check everything that is Best in Java Click Here

Q10. Can you explain filter and collectors in java 8 ?Core Java2018-05-03 08:42:37

Help us improve. Please let us know the company, where you were asked this question :

collectors  filters  java 8

Subscribe to Java News and Posts. Get latest updates and posts on Java from Buggybread.com
Delivered by FeedBurner

## Help us and Others Improve. Please let us know the questions asked in any of your previous interview.

Any input from you will be highly appreciated and It will unlock the application for 10 more requests.