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. Movie Repository

Java Spring Database abstraction Public

Consider the following Spring bean:

public class MovieRepository {

    @Autowired
    private DataSource dataSource;

    public List<Movie> findMoviesByName(String name) {
        JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
        return jdbcTemplate.query("select name, year, rating from movies where name like ?",
                new Object[]{name},
                new RowMapper<Movie>() {
                    @Override
                    public Movie mapRow(ResultSet resultSet, int i) throws SQLException {
                        return new Movie(resultSet.getString("name"),
                                resultSet.getInt("year"), resultSet.getInt("rating"));
                    }
                });
    }

}

Select the statements that are correct.

(multiple correct answers possible)

Easy 
5min
   


2. Task Executor

Java Spring Configuration Multithreading 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.

(multiple correct answers possible)

Easy 
5min
   


3. Weather Forecast

Java Spring Components Public New

Consider the following two classes:

@Service
public class WeatherForecastService {

    private Thermometer thermometer;

    @Autowired
    public WeatherForecastService(Thermometer thermometer) {
        this.thermometer = thermometer;
    }

    @Scheduled(fixedDelay = 10000)
    public void takeTemperatureMeasurement() {
        thermometer.measure();
    }   
}

@Component
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public class FakeThermometer implements Thermometer {

    @Override
    public int measure() { return 10; };
}

Supposing Spring uses component scanning to discover beans, select the statements that are correct.

(multiple correct answers possible)

Hard  
5min
   


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.