Senior Java Developer Questions — Job Interview

Bayram EKER
5 min readJan 31, 2023

--

In this article we will answer SENIOR JAVA DEVELOPER job interview questions.

As a senior Java developer, you will have 5+ years of experience, a deep understanding of your business’s IT systems, and expertise on various projects. You will likely spend your work time:

  • Planning, consulting, and reviewing sophisticated Java projects
  • Overseeing work done by junior staff members
  • Working with vendors
  • Overseeing the financial side of development

We will answer:

  • What questions come up in a java developer job interview?
  • What should a java developer know ?
  • What are the critical questions in a job interview ?

Q-1 : Explain a use case for the Builder Design Pattern

Answer

The good example is a class hierarchy that adds more parameters as it goes down the chain. At the bottom, some of the classes can have up to N parameters, N-2 of which are just being passed into the super constructor. Instead of using a particular constructor with N params we could use the Builder Design Pattern.

Consider the following example:

public class StudentBuilder
{
private String _name;
private int _age = 14; // this has a default
private String _motto = ""; // most students don't have one

public StudentBuilder() { }

public Student buildStudent()
{
return new Student(_name, _age, _motto);
}

public StudentBuilder name(String _name)
{
this._name = _name;
return this;
}

public StudentBuilder age(int _age)
{
this._age = _age;
return this;
}

public StudentBuilder motto(String _motto)
{
this._motto = _motto;
return this;
}
}

This lets us write code like:

Student s1 = new StudentBuilder().name("Eli").buildStudent();
Student s2 = new StudentBuilder()
.name("Spicoli")
.age(16)
.motto("Aloha, Mr Hand")
.buildStudent();

Q-2 : Why is char[] preferred over String for passwords?

Problem

Why does String pose a threat to security when it comes to passwords? It feels inconvenient to use char[]?

Answer

Strings are immutable. That means once you’ve created the String, if another process can dump memory, there's no way (aside from reflection) you can get rid of the data before garbage collection kicks in.

With an array, you can explicitly wipe the data after you're done with it. You can overwrite the array with anything you like, and the password won't be present anywhere in the system, even before garbage collection.

Q-3 : Why is Spring MVC better than Servlets / JSP ?

Answer

Servlets are based upon a low-level API for handling requests and responses. Web frameworks like Spring MVC are designed to make building web applications, which handle HTTP requests and responses, easier. Most Java web frameworks, including Spring MVC, use servlets behind the scenes.

Not necessarily ‘better’ but Spring MVC is essentially a higher level abstraction built on top of Java Servlets centered around the Model View Controller design pattern. This pattern promotes seperation of concerns when building your web application.

The linch pin of the framework is the DispatcherServlet class which actually is a Servlet implementing the Front Controller design pattern.

Q-4 : What is the difference between concern and cross-cutting concern in Spring AOP?

Answer

  • Concern − Concern is behavior which we want to have in a module of an application. Concern may be defined as a functionality we want to implement. Issues in which we are interested define our concerns.
  • Cross-cutting concern − It’s a concern which is applicable throughout the application and it affects the entire application. e.g. logging , security and data transfer are the concerns which are needed in almost every module of an application, hence are cross-cutting concerns.

Q-5 : How do you ensure the scalability of a Java application?

Answer

Scalability is a critical aspect of any enterprise application. As a Senior Java Developer, I use various techniques to ensure scalability, such as designing the system in a modular way, using caching and load balancing mechanisms, and optimizing database queries. I also use technologies like Kubernetes, Docker, and Cloud Computing services like AWS or Google Cloud Platform to easily scale the application up or down based on demand.

Q-6 : What are the most challenging aspects of multi-threading in Java, and how do you deal with them?

Answer

The most challenging aspects of multi-threading in Java include synchronization issues, race conditions, and deadlocks. As a Senior Java Developer, I use tools like locks, synchronized blocks, and semaphores to manage concurrency issues. Additionally, I ensure that all shared resources are protected by locks, and I make use of thread-safe data structures such as ConcurrentHashMap.

Q-7 : What is Double Brace initialization in Java?

Answer

Double brace initialisation creates an anonymous class derived from the specified class (the outer braces), and provides an initialiser block within that class (the inner braces). e.g.

new ArrayList<Integer>() {{
add(1);
add(2);
}};

However, I’m not too fond of that method because what you end up with is a subclass of ArrayList which has an instance initializer, and that class is created just to create one object -- that just seems like a little bit overkill to me.

Q-8 : What is Materialized View pattern and when will you use it ?

Answer

Materialized View pattern is the solution for aggregating data from multiple microservices and used when we need to implement queries that retrieve data from several microservices. In this approach, we generate, in advance (prepare denormalized data before the actual queries happen), a read-only table with the data that’s owned by multiple microservices. The table has a format suited to the client app’s needs or API Gateway.

A key point is that a materialized view and the data it contains is completely disposable because it can be entirely rebuilt from the source data stores.

This approach not only solves the problem of how to query and join across microservices, but it also improves performance considerably when compared with a complex join, because you already have the data that the application needs in the query table.

Q-9 : What is Coupling in OOP ?

Answer

OOP Modules are dependent on each other. Coupling refers to level of dependency between two software modules. Two modules are highly dependent on each other if you have changed in one module and for supporting that change every time you have to change in the dependent module. Loose Coupling is always preferred.

Inversion of Control and Dependency Injection are some techniques for getting loose coupling in modules.

Q-10 : Is null check needed before calling instanceof ?

Problem

Will

null instanceof SomeClass

return false or throw a NullPointerException?

Answer

No, a null check is not needed before using instanceof. The expression

x instanceof SomeClass // return false if x is null

is false if x is null.

I hope the article was helpful. Don’t forget to follow to read our latest articles.

--

--