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

Search Interview Questions


 More than 3000 questions in repository.
 There are more than 900 unanswered questions.
Click here and help us by providing the answer.
 Have a video suggestion.
Click Correct / Improve and please let us know.
Label / Company      Label / Company / Text

   



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

 Q1. What is a Servlet Filter ?Java EE
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 :   

   Like         Discuss         Correct / Improve     servlets  servlet filters     Asked in 3 Companies      basic        frequent


 Q2. What is an IO Filter ?Core Java
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 :   

   Like         Discuss         Correct / Improve     java io  io filter      intermediate


 Q3. What is the difference between filter and filter-mappings xml tag within deployment descriptor ?Java EE
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 :   

   Like         Discuss         Correct / Improve     deployment descriptor  web.xml  filters  filter mapping


 Q4. What are the advantages of Spring interceptor over Servlet Filters ?Spring
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 :   

   Like         Discuss         Correct / Improve     interceptors  servlet filters  spring interceptors vs servlet filters


 Q5. 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 Java
Ans. set1.stream().filter(p->p.element1.equals("Hello")).findAny().isPreent();

or

set1.stream().map(A::getElement1).anyMatch("Hello"::equals)

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

   Like         Discuss         Correct / Improve     lambda expressions  java 8  java8  java 8 filter  findAny()


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

Core Java
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 :   

   Like         Discuss         Correct / Improve     Collectors  lambda  filter  coding  java 8


 Q7. Can we capture the Request body within the interceptor or Filter and perform operations on it ?Spring
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 :   

   Like         Discuss         Correct / Improve     interceptor  filter


 Q8. Can you explain filter and collectors in java 8 ?Core Java
Ans. Filters are used to filter object in stream on certail criteria. And collector is used to collect outcome of the stream. Collector is a terminal operation.
List numbers = List.of(1,2,3,4,5,6,7);
List evenNumbers = numbers.stream().filter(n -> n%2==0).collect(Collectors.toList());
The above code will filter out odd numbers and return the list of even number.

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

   Like         Discuss         Correct / Improve     collector  filter


 Q9. Can you explain filter and collectors in java 8 ?Core Java
Ans. Filters are used to filter object in stream on certain criteria.
Collector is used to collect outcome of the stream. Collector is a terminal operation.
List numbers = List.of(1,2,3,4,5,6,7);
List evenNumbers = numbers.stream().filter(n -> n%2==0).collect(Collectors.toList());
The above code will filter out odd numbers and return the list of even number.

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

   Like         Discuss         Correct / Improve     collectors  filters  java 8



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.

Company Name:
Questions Asked: