linkedin-skill-assessments-quizzes

Spring Framework

Q1. How filters are used in Spring Web?

HandlerInterceptors vs. Filters in Spring MVC. Also there is no such thing as DispatcherRequestServlet in Spring.

Q2. How is a resource defined in the context of a REST service?

Rest Service in Spring

Q3. Which of these is a valid Advice annotation?

Spring Advice Type Annotation

Q4. What does a ViewResolver do?

View Resolution in Spring MVC

Q5. How are Spring Data repositories implemented by Spring at runtime?

Explained QnA

Q6. What is SpEL and how is it used in Spring?

Spring Expression Documentation

Q7. The process of linking aspects with other objects to create an advised object is called

Q8. How are JDK Dynamic proxies and CGLIB proxies used in Spring?

Q9. Which of these is not a valid method on the JoinPoint interface?

Q10. In what order do the @PostConstruct annotated method, the init-method parameter method on beans and the afterPropertiesSet() method execute?

Q11. What is the function of the @Transactional annotation at the class level?

Q12. Which is a valid example of the output from this code (ignoring logging statements) ?

@SpringBootApplication
public class App {
     public static void main(String args[]) {
          SpringApplication.run(App.class, args);
          System.out.println("startup");
     }
}

public class Print implements InitializingBean {
     @Override
     public void afterPropertiesSet() throws Exception {
          System.out.println("init");
     }
}

Explanation: SpringApplication.run method returns the created Context, so main method will continue running and print “startup”. Class Print is not a Spring Bean, because it is not annotated with @Component, so it will not be initialized.

Q13. Which println statement would you remove to stop this code throwing a null pointer exception?

@Component
public class Test implements InitializingBean {
     @Autowired
     ApplicationContext context;
     @Autowired
     static SimpleDateFormat formatter;

     @Override
     public void afterPropertiesSet() throws Exception {
          System.out.println(context.containsBean("formatter") + " ");
          System.out.println(context.getBean("formatter").getClass());
          System.out.println(formatter.getClass());
          System.out.println(context.getClass());
     }
}

@Configuration
class TestConfig {
     @Bean
     public SimpleDateFormat formatter() {
          return new SimpleDateFormat();
     }
}

Q14. What is the root interface for accessing a Spring bean container?

Q15. Which annotation can be used within Spring Security to apply method level security?

Q16. What is the result of calling the map controller method using the HTTP request GET localhost:8080/map?foo=foo&bar=bar ?

@RestController
public class SampleController {

     @RequestMapping("/map")
     public String map(@RequestParam("bar") String foo, @RequestParam("foo") String bar) {
          return bar + foo;
     }
}

Q17. What is the purpose of the @Lazy annotation and why would you use it?

Q18. What is dependency injection?

Q19. What is a RESTful web service?

Q20. What happens when a class is annotated with the @Controller annotation?

Q21. Which property can be used to change the port of a Spring application?

Q22. What is the purpose of the @ResponseBody annotation?

Q23. How are mocking frameworks such as Mockito used with Spring?

Q24. What is the name of the central servlet that dispatches requests to controllers?

Q25. What is the purpose of the Spring IoC (Inversion of Control) container?

Q26. What is component scanning?

Q27. What does @SpringBootApplication do?

Q28. How does Spring Data facilitate queries against a datastore?

Q29. How does Spring generate bean names for classes annotated with @Component that do not specify a name?

Q30. What is the delegating filter proxy?

Overview and Need for DelegatingFilterProxy in Spring

Q31. What value does Spring Boot Actuator provide?

Spring Boot Actuator

Q32. What is the purpose of the @ContextConfiguration annotation in a JUnit Test?

@ContextConfiguration Example in Spring Test

Q33. How are authentication and authorization different?

Q34. What is the purpose of the @RequestBody annotation?

Q35. What is the DispatcherServlet and what is its function?

Q36. What is Spring Boot autoconfiguration?

Q37. Which are valid steps to take to enable JPA in Spring Boot?

Q38. What is a transaction in the context of Spring Data?

Q39. Modularization of a concern that cuts across multiple classes is known as a(n)____.

Q40. How do you inject a dependency into a Spring bean?

Q41. Consider the properties file application.properties. How would you load the property my.property?

my.property=Test
@Prop("${my.property}")
private String val;
@GetVal("my.property")
private String val;
@GetProperty("${my.property}")
private String val;
@Value("${my.property}")
private String val;

Q42. What is a bean in the context of Spring?

Q43. Which property is given precedence by Spring?

Q44. In the Spring Bean lifecycle pictured, what should the third step of the process be?

diagram

Q45. What Spring Boot property is used to set the logging level for the entire application in the application.properties file?

Logging in Spring Boot

Q46. What is a Spring bean uniquely identified?

Q47. What is the difference between a JAR and a WAR distribution in Spring Boot?

Q48. How does the transaction propagation setting impact the behavior of transactions?

Q49. What is printed when this code is run as a @SpringBootApplication?

@Component
public class Test implements InitializingBean {
     @Autowired
     ApplicationContext context;

     private TestService service;
     public void setService(TestService service) {
          this.service = service;
     }

     @Override
     public void afterPropertiesSet() throws Exception {
          System.out.print(context.containsBean("testService") + " ");
          System.out.println(service.getClass());
     }
}
@Service
class TestService {}

Explanation: missing @Autowired on private TestService service or on the setter

Q50. To register a custom filter that applies only to certain URL patterns, you should remove the _ annotation from the filter class and register a @Bean of type _ in Spring @Configuration.

Q51. What is the correct term for each definition bellow?

  1. A predicate that matches join points.
  2. A point during the execution of a program, such as the execution of a method or the handling of an exception.
  3. An action taken by an aspect at a particular join point.

Q52. How should passwords be stored?

Explanation: sha-1 is not considered secure anymore: https://en.wikipedia.org/wiki/SHA-1#Attacks . With bcrypt you can select more complex hashes https://en.wikipedia.org/wiki/Bcrypt

Q53. What methods does this Pointcut expression reference?

@target(com.linkedin.annotation.Loggable)

Difference between @target and @within (Spring AOP)

Q54. What is printed when this code is run as a @SpringBootApplication?

@Component
public class Test implements InitializingBean {
     @Autowired
     ApplicationContext context;

     @Autowired
     SimpleDateFormat formatter;

     @Override
     public void afterPropertiesSet() throws Exception {
          System.out.println(context.containsBean("formatter"));
          System.out.println(formatter.getClass());
     }
}
@Configuration
class TestConfig2 {
    @Bean
    public final SimpleDateFormat formatter() {
        return new SimpleDateFormat();
    }
}

Explanation: @Bean-method in @Configuration must be overridable. Remove the final keyword to fix.

Q55. What is the purpose of a web application context?

Q56. What is Spring AOP?

Q57. Assuming username and password authentication is in place, what method on the Authentication object can be used to obtain the username?

Q58. Assuming no additional configuration is provided, what is the first selection criteria Spring uses to choose a bean when autowiring a property?

Q59. What is the result of calling the map controller method using the following HTTP request?

POST localhost:8080/map
{"b" : "b", "d" : "d"}
@RestController
public class SampleController {
    @RequestMapping("/map")
    public String map(@RequestBody SampleObject sampleObject) {
        return sampleObject.getB() + sampleObject.getC();
    }
}
public class SampleObject {

    String b;
    String c;

    public String getB() { return b; }

    public void setB() { this.b = b; }

    public String getC() { return c; }

    public void setC() { this.c = c; }
}

Q60. What effect does private static have on the object service below?

@SpringBootApplication
public class Question14 {
    @Autowired
    private static Service service;

    public static void main(String[] args) {
        SpringApplication.run(Question14.class, args);
    }
}

@Component
class Service {}

Q61. What is a security context?

Q62. How might you map an incoming request to a controller method?

Spring RequestMapping. Spring does not use naming conventions for web requests (unlike e.g. for the Data Repositories)

Q63. What methods does the Pointcut expression below reference?

execution(* setter*(..))

baeldung

Q64. What pattern does Spring MVC implement to delegate request processing to controllers?

Q65. What methods does this Pointcut expression?

within(com.linkedin.service..*)

Q66. What is the output from invoking this Actuator endpoint in an unmodified Spring Boot application generated using Spring Intializr?

/shutdown

Reason: By default, all the endpoints are enabled in Spring Boot Application except /shutdown; this is, naturally, part of the Actuator endpoints.

Q67. How can you access the application context in a Spring integration test?

spring(dot)io

Q68. What interface can be specified as a parameter in a controller method signature to handle file uploads?

Q69. What is the purpose of this endpoint?

@GetMapping("api/v1/domain/resource/{id}")
public Pojo getPojo(@PathVariable("id") String id) {
  return testService.getPojo(id);
}

Q70. What property can be used to set the active Spring profiles

Q71. Which statement is true regarding loading and instantiation of Spring factories?

Q72. What methods does this Pointcut expression reference?

     execution(* com.linkedin.TestService.*(..))

Q73. When configuring an application, which configuration is given precedence by Spring?

Q74. What interface is used to represent a permission in Spring Security?

Q75. What is the difference between constructor injection and setter injection?

[Explanation] There are many key differences between constructor injection and setter injection.

Partial dependency: can be injected using setter injection but it is not possible by constructor. Suppose there are 3 properties in a class, having 3 arg constructor and setters methods. In such case, if you want to pass information for only one property, it is possible by setter method only. Overriding: Setter injection overrides the constructor injection. If we use both constructor and setter injection, IOC container will use the setter injection. Changes: We can easily change the value by setter injection. It doesn’t create a new bean instance always like constructor. So setter injection is flexible than constructor injection.

Q76. Which println would you remove to stop this code from throwing a null pointer exception?

@Component
public class Test implements InitializingBean {
     @Autowired
     ApplicationContext context;
     @Autowired
     static SimpleDateFormat formatter;

     @Override
     public void afterPropertiesSet() throws Exception {
          System.out.println(context.containsBean("formatter") + " ");
          System.out.println(context.getBean("formatter").getClass());
          System.out.println(formatter.getClass());
          System.out.println(context.getClass());
     }
}
@Configuration
class TestConfig {
     @Bean
     public SimpleDateFormat formatter() {
          return new SimpleDateFormat();
     }
}

Explanation: Here only one line can throw NPE. Calling getClass() from context.getBean(“formatter”) can potentially throw NPE if context.getBean(“formatter”) will return null.

Q77. What is the default rollback policy?

Q78. What is the difference between a CrudRepository and a JpaRepository?

Q79. What is the security filter chain?

Q80. Which is not a valid stereotype annotation?

Q81. Which statement is true regarding loading and instantiation of Spring factories?

Q83. What is a transaction isolation level?

Q84. What does the statement “Spring offers fully-typed advice” mean?

Q84. Which are considered to be typical, common, cross-cutting concerns that would be a good fit for AOP? (Choose 3)

- A. Creating SQL queries
- B. Logging
- C. Filtering, sorting and transforming data
- D. Transaction management
- E. Audit logging
- F. Business logic

Q85. Which of the Service implementations will be created first?

@SpringBootApplication
public class App {

     @Autowired
     Service service;

     public static void main(String[] args) {
          SpringApplication.run(App.class, args);
     }
}
@Primary
@Component
class Service2Impl implements Service {

    Service2Impl() {
        System.out.println("Service2");
    }
}

@Component("Service")
class Service1Impl implements Service {

    Service1Impl() {
        System.out.println("Service1");
    }
}

interface Service{}

Explaination: Primary indicates that a bean should be given preference when multiple candidates are qualified to autowire a single-valued dependency

Q86. What methods does this Pointcut expression reference?

     execution(* com.linkedin.service..*.*(..))

Q87. Which is not a core facet of Spring’s ecosystem?

Q88. A_ is a key-value map of data used to render the page, and the _ is a template of the page that is filled with data.