JOBSEEKER?

Java Spring Interview Questions

Practice for Java Spring interviews by solving TestDome questions. Our interview questions are used by more than 7,000 companies and 450,000 individual test takers.

Jobseekers: Certify Your Knowledge

Take a Certification Test

Companies: Use Our Tests for Screening

Buy a Pack Of Candidates

Need to practice your Java Spring skills for an upcoming job interview? Try solving these Java Spring interview questions that test knowledge of Spring Framework concepts such as scheduling, configuration, database abstraction, and other skills. We’ll provide feedback on your answers, and you can use a hint if you get stuck.

These Java Spring interview questions are examples of real tasks used by employers to screen job candidates such as Java developers, web developers, Spring Framework developers, and others that require knowledge of the Java programming language and the Spring Framework.

1. Task Executor

Configuration
   
Easy  

Consider the following Spring bean:

@Component
public class TaskExecutor {

    @Value("${thread.count:10}")
    private int threadCount;
    @Value("worker.thread.name")
    private String threadNameTemplate;
    private AtomicInteger counter = new AtomicInteger();
    private ExecutorService executorService;

    @PostConstruct
    public void init() {
        ThreadFactory threadFactory = (runnable) -> new Thread(threadNameTemplate + counter.incrementAndGet());
        executorService = Executors.newFixedThreadPool(threadCount, threadFactory);
    }
}

Select the statements that are correct.

(Select all acceptable answers.)

Properties injected with @Value may, among other sources, come from system properties and JVM arguments.
As the values of threadCount and threadNameTemplate are private and have no setters, they cannot be set by Spring.
Initialization will fail because the counter and executorService fields are not managed by Spring.
If a property named "thread.count" is not made available to Spring (i.e. through property files), the value of threadCount field will be 10.
The value of the field threadNameTemplate will always be set to the same value regardless of properties provided to Spring.
   


2. Weather Forecast Service

Scheduling
   
Easy  

Edit the WeatherForecastService, FakeThermometer, and the Config classes so that:

  • The Spring container should always return a new instance of FakeThermometer.
  • Config class will configure Spring scheduling.
  • takeTemperatureMeasurement method should be executed every 50 milliseconds, using Spring scheduling.
Java SE 13  
 


  •   Spring returns a new instance of FakeThermometer every time it wires it: Wrong answer
  •   Spring scheduling is configured: Wrong answer
  •   takeTemperatureMeasurement is executed every 50 milliseconds: Time limit exceeded


3. Movie Repository

Database abstraction
   
Easy  

Modify the createMovie and findMoviesByName methods of the class MovieRepository.

  • Using JdbcTemplate, createMovie method should insert a new row into the movies table with the specified data.
  • Using JdbcTemplate, findMoviesByName should return a list of all movies from the 'movies' table, in which the name of the movie contains the likeName string, using the LIKE operator. The returned list should contain Movie objects with name, year, and rating fields correctly set.

For example, executing the following code:

AnnotationConfigApplicationContext config = new AnnotationConfigApplicationContext();
config.register(Config.class);
config.refresh();
MovieRepository repository = config.getBean(MovieRepository.class);

repository.createMovie("Some movie", 1974, 3);
repository.createMovie("Some other movie", 1993, 2);

List<Movie> movies = repository.findMoviesByName("Some%");
for(Movie movie : movies) {
    System.out.println(movie.name + " - " + movie.year + " - " + movie.rating);
}

should print:

Some movie - 1974 - 3
Some other movie - 1993 - 2
Java SE 13  
 


  •   Example case: Wrong answer
  •   createMovie method will create a movie with correct data: Wrong answer
  •   findMoviesByName method will return correct movies: Wrong answer


4. Logger AOP

Configuration
   
Hard  

In the LoggerAOP class, using Spring AOP, intercept all calls to the public methods annotated with the LogExecution annotation, and call the log method on the logger field with the intercepted method's name as the data argument.

Java SE 13  
 


  •   logger will be invoked on NameRepository getName method: Wrong answer
  •   logger will be invoked on methods annotated with LogExecution: Wrong answer
  •   logger will be invoked only on public methods annotated with LogExecution: Wrong answer


If you feel ready, take one of our timed public Java Spring Interview Questions tests:
Java

Java and Spring Framework Online Test (Easy / Hard)

Java, Hibernate, and Spring Framework Online Test (Easy / Hard)

Not exactly what you are looking for? Go to our For Jobseekers section.
Dashboard Start Trial Sign In Home Tour Tests Questions Pricing For Jobseekers