Java Spring Interview Questions

Want to become an expert in cracking Java Spring interview questions?

Start with practicing the questions below. Whether a question involves multiple choice or live coding, we will give you hints as you go and tell you if your answers are correct or incorrect.

After that, take our timed public Java Spring Interview Questions Test.

To use our service for testing candidates, buy a pack of candidates.


1. Task Executor

Java Spring Configuration Public

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.)

Easy  
5min
   


2. Movie Repository

Java Spring Database abstraction Public New

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
Easy 
10min
Java SE 8 
 


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


3. Weather Forecast Service

Java Spring Scheduling Public New

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.
Easy 
10min
Java SE 8 
 


  •   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


4. Logger AOP

Java Spring Configuration Public New

In the LoggerAOP class:

  • Add appropriate annotation, so that Spring will inject an instance of Logger in the logger field.
  • Using Spring AOP, intercept all calls to the public methods annotated with LogExecution annotation, and call log method on the logger field with the intercepted method's name as the data argument.
Hard 
20min
Java SE 8 
 


  •   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 and Spring Framework Online Test (Easy / Hard)
Not exactly what you are looking for? Go to our For Jobseekers section.