Why you should always be prepared for an interview!

The story repeats itself again…

You just landed this cool job, in which you are very proud of passing the interviews(not easy interviews at all).

The company values align with yours. They provide work from home, the office provides cool activities, the company owners were exceptional developers at the past(so they are familiar with the daily struggles).

They value knowledge sharing, they provide company trainings, people are happy and speak your language(similar values).

You want to give it your best at the beginning, so you spend time on the weekends to study the business logic, code and documents, of the customer you were just hired to help.

Not only that, in this “hypothetical” scenario, you were hired as a lead developer, so you need to make sure that the team is motivated, so you encourage them to study, be proactive, speak clear with the customer, be available and adaptable.

Still about the team, you need to blend in, because you just met this 5 or 6 other consultants, that are usually from another country, and have different egos, cultures, education levels. Sometimes they are lazy, sometimes they want to “measure dicks” with you, since you are the lead, sometimes the personalities just don’t match together.

But you overcame all of that, and after a few months, you managed a good balance with the team, and the team has a constant delivery improvement. They are communicating effective(even though they will never be best friends), they value their work together as a team, and help and protect each other, from external attacks(personal or work wise).

All of that said, we might say that we have a good development environment, working on a good consulting company. You might as well spend some years at this company! Right?

Not so fast little grasshopper!

I forgot(on purpose, in order to fulfill the plot) to mention about the client! This “hypothetical” client, is not really sure what they want, and seem not to have the most adequate people, to request for this software development.

So you spend months trying to guide the client, on the correct path, speaking things with a lot of care, because after all, they are the client, and you don’t want to sound arrogant.

The development is delayed a lot, because the client is starting to figure out, the things you mentioned three months ago were correct.

The development team(the ones that started with a lot of desire to work), are losing the development momentum, because they are tired of all the delay and every day bullshit.

All of the aforementioned, even though is frustrating, it is manageable, after all, we are resilient professionals.

But them, one thing that it is not manageable at all, is the lack of respect!!!

The client is getting frustrated, and even though they were never the most polite, they are treating the consulting team as vassals.

They are speaking with the team with a superiority, sometimes even threatening tone.

You as a seasoned professional, flag that with the customer, in the best transparent way, without letting the emotions fly, and expect the same cordiality, and the differences, to get resolved.

How naive are you? Now the client is attacking the team in different ways, micromanaging, lowering the communication standards on the meetings, and making the teams’s everyday a living hell.

Now here comes the big catch. You are a consultant right? Does the consultant company stays on your side? Try to solve the problem? Or postpone the problem until it is unbearable?

Either way it goes, here comes the importance of always practicing interviews. That is what will give you peace of mind, to know that if this client, or consultant company does not meet the levels you expect, you can always go somewhere else.

And even though there’s no perfect client or company, some low levels of education and treatment, no professional should have to deal with!

Keep the studies going! Good luck!

2018 Top Java + Spring Interview Questions

Every year, I train myself performing interviews. One never knows what might come along.

Some years, I participate on more interviews, and other years less.

The important aspects, of periodically participating on interviews, are:

  • Developing “thick skin”;
  • Getting to know what are the “trending” questions;
  • And just practicing having quick answers, for usual questions.

This year, at least for the companies I have tried out, the most common asked questions, for Java+Spring where:

1- SOLID principles.

SOLID is a set of design patterns in Object Oriented software development.
The important part here for the interview, is to remember and understand each principle:

Single Responsibility Principle
Open/Closed Principle
Liskov Substitution Principle
Interface Segregation Principle
Dependency Inversion

2- Describe a Singleton, and the different ways to write a Singleton class.

Singleton pattern, is one of the patterns discussed in the book Design Patterns: Elements of Reusable Object-Oriented Software (1994), and is the most common question asked for java developers.

In general, there is not just one way to write a Singleton, but the important in this question, is to understand when you should write a Singleton, and the basic ways to write it.

Basic rules:

  • Private constructor
  • Private static variable of the same class
  • Public static method, that returns the instance of the class

3- What design patterns do you know.

In this question, if you read the book Design Patterns: Elements of Reusable Object-Oriented Software (1994), you have an enormous advantage. But if you didn’t, don’t worry. The following are the 23 design patterns mentioned on the book:

Creational Patterns:

  • Abstract Factory:
  • Builder:
  • Factory Method:
  • Prototype:
  • Singleton:

Structural Patterns:

  • Adapter:
  • Bridge:
  • Composite:
  • Decorator:
  • Facade:
  • Flyweight:
  • Proxy:

Behavioral Patterns:

  • Chain of Responsibility:
  • Command:
  • Interpreter:
  • Iterator:
  • Mediator:
  • Memento:
  • Observer:
  • State:
  • Strategy:
  • Template Method:
  • Visitor:

4- AOP and Spring

Aspect Oriented Programming is a key component of Spring Framework.

Spring AOP modules provide interceptors for an application. When a method is executed, you can add additional functionality before or after the method execution.

Types of advice:

  • before
  • after
  • after-returning
  • after-throwing
  • around

5- What’s the difference between @Factory and @AbstractFactory

The Factory Method pattern uses inheritance and relies on a subclass to handle the desired object instantiation.

The Abstract Factory pattern, a class delegates the responsibility of object instantiation to another object via composition.

6- What’s the relation between Reflection and Frameworks such as Spring?

First, let’s understand the basic reflection concept. Reflection allows us to inspect or/and modify runtime attributes of classes, interfaces, enum, fields and methods. Very useful, when we don’t know their names at compile time.

Not only Spring, but most of J2EE frameworks, use Java Reflection. The following are some examples:

  • JUnit
  • Struts
  • Spring
  • Hibernate

And the list goes on, since those frameworks have no knowledge of the user defined classes, interfaces, methods, enums, etc…

7- What is dependency injection?

Dependency Injection (DI) is a concept used in many programming languages, and is based on the Inversion Of Control(Ioc). This concept states that a class should not configure or instantiate its dependencies, rather, the dependencies should be configured from the outside.
Classes should be as independent as possible from other classes.
In Java, one can use dependency injection through annotation such as @Inject and @Named, or using frameworks such as Spring, with the @Autowired annotation, as an example.

7.1- What ways can you inject a bean in Spring?

  • Spring Constructor Injection
  • Spring Setter Injection
  • Spring Field Injection

7.2 – What’s the best recommended way to use dependency injection in Spring?

The answer is: DEPENDS. There is no correct answer for this question. What the interviewer really wants to know, is whether you have the correct arguments, for each of the ways, one can inject a bean in Spring.

Some of the arguments are:

  • Readability
  • Immutability
  • State Safety
  • Too many instance fields

When we start to analyse all of the above, in general Field and Constructor injection, are the winners. Although at the end, it will be your choice, depending on your program, and the dependencies involved.

8- What Spring annotations do you know?

Spring has a lot of annotations, depending on the module you are working with. The following are the most common annotations you most probably work with, although there are much more.

  • Core Spring
    • @Required
    • @Autowired
    • @Qualifier
    • @Configuration
    • @ComponentScan
    • @Bean
    • @Lazy
    • @Value
  • Stereotype
    • @Component
    • @Controller
    • @Service
    • @Repository
  • SpringBoot
    • @EnableAutoConfiguration
    • @SpringBootApplication
  • SpringMVC and Rest
    • @Controller
    • @RestController
    • @RequestMapping
    • @CookieValue
    • @CrossOrigin
    • @GetMapping
    • @PostMapping
    • @PutMapping
    • @DeleteMapping
    • @ExceptionHandler
    • @PathVariable
    • @RequestAttribute
    • @RequestBody
    • @RequestHeader
    • @RequestParam
    • @ResponseBody
    • @ResponseStatus
    • @ControllerAdvice
    • @RestControllerAdvice
    • @SessionAttribute

9- Have you worked with Lambdas(Java 8)? Please describe.

What the interviewer wants from you with this question, is to know some basic concepts of Java 8. And one of the main changes about Java 8, is working with lambdas.

You can start describing the problems of working with anonymous classes, and the heavy syntax they leave on your code.

Lambda expressions let you express instances of single-method classes more compactly.

Lambda expressions are considered the first step to Java functional programming.

The following is an example of a Lambda expression, with zero parameters:

() -> System.out.println("Print something");

Note that it has a parenthesis, followed by the new “arrow” operator.

10- What are the OOP concepts in Java?

As straightforward as possible, the following are the concepts:

  • Abstraction
  • Encapsulation
  • Polymorphism
  • Inheritance
  • Association
  • Aggregation
  • Composition

It is recommended that you study all of the above concepts.

That is it! The interviews are becoming more and more difficult, depending on the company you are applying to. So, besides studying language especifc paradigms, you need to study the most common interview questions, so you don’t get caught off guard.

Good luck!