Top 27 Java J2ee Architect Interview Questions You Must Prepare 20.Jul.2024

Q1. What Are New Features Introduced With Java 8 ?

 Lambda Expressions , Interface Default and Static Methods , Method Reference , Parameters Name , Optional , Streams, Concurrency.

Q2. Difference Between Factory And Strategy Design Pattern ?

Factory is a creational design pattern whereas Strategy is behavioral design pattern. Factory revolves around the creation of object at runtime whereas Strategy or Policy revolves around the decision at runtime.

Q3. What Are Various Types Of Class Loaders Used By Jvm ?

Bootstrap - Loads JDK internal classes, java.* packages.

Extensions - Loads jar files from JDK extensions directory - usually lib/ext directory of the JRE

System  - Loads classes from system classpath.

Q4. What Is The Best Practice Configuration Usage For Files - Pom.xml Or Settings.xml ?

The best practice guideline between settings.xml and pom.xml is that configurations in settings.xml must be specific to the current user and that pom.xml configurations are specific to the project.

Q5. What Is Metaspace ?

The Permanent Generation (PermGen) space has completely been removed and is kind of replaced by a new space called Metaspace. The consequences of the PermGen removal is that obviously the PermSize and MaxPermSize JVM arguments are ignored and you will never get a java.lang.OutOfMemoryError: PermGen error.

Q6. Can You Provide Some Implementation Of A Dictionary Having Large Number Of Words ?

Simplest implementation we can have is a List wherein we can place ordered words and hence can perform Binary Search.

Other implementation with better search performance is to use HashMap with key as first character of the word and value as a LinkedList.

Further level up, we can have linked Hashmaps like ,

hashmap {

a ( key ) -> hashmap (key-aa , value (hashmap(key-aaa,value)

b ( key ) -> hashmap (key-ba , value (hashmap(key-baa,value)


z( key ) -> hashmap (key-za , value (hashmap(key-zaa,value)


upto n levels ( where n is the average size of the word in dictionary.

Q7. What Is Permgen Or Permanent Generation ?

The memory pool containing all the reflective data of the java virtual machine itself, such as class and method objects. With Java VMs that use class data sharing, this generation is divided into read-only and read-write areas. The Permanent generation contains metadata required by the JVM to describe the classes and methods used in the application. The permanent generation is populated by the JVM at runtime based on classes in use by the application. In addition, Java SE library classes and methods may be stored here.

Q8. If You Are Given A Choice To Implement The Code To Either Insert A Record Or Update If Already Exist, Which Approach Will You Follow ?

In first case, there would be 2 DB calls in worst case and 1 in best case. In 2nd approach there will be always 2 DB calls.

Decision on the approach should depend on the following considerations -

@How costly is the call to DB.  Are we using indices , hibernate etc

If calls to DB are costly , 1st approach should be the choice.

@Exception Book keeping load upon exception.

The benefit of saving 1st call in approach 1 should be bigger than the Book keeping for the exception.

@Probability of the exception in first apparoach.  

If the DB Table is almost empty, it makes sense to follow Approach 1 as majority of the 1st calls will pass through without exception.

Q9. Difference Between Adapter And Facade ?

The Difference between these patterns in only the intent. Adapter is used because the objects in current form cannot communicate where as in Facade , though the objects can communicate , A Facade object is placed between the client and subject to simplify the interface.

Q10. What Is Database Deadlock ? How Can We Avoid Them?

When multiple external resources are trying to access the DB locks and runs into cyclic wait, it may makes the DB unresponsive. 

Deadlock can be avoided using variety of measures, Few listed below:

  • Can make a queue wherein we can verify and order the request to DB.
  • Less use of cursors as they lock the tables for long time.
  • Keeping the traction smaller.

Q11. Difference Between First Level And Second Level Cache In Hibernate ?

  1. First level cache is enabled by default whereas Second level cache needs to be enabled explicitly.
  2. First level Cache came with Hibernate 1.0 whereas Second level cache came with Hibernate 3.@
  3.  First level Cache is Session specific whereas Second level cache is shared by sessions that is why First level cache is considered local and second level cache is considered global.

Q12. What Things You Would Care About To Improve The Performance Of Application If Its Identified That Its Db Communication That Needs To Be Improved ?

  1. Query Optimization ( Query Rewriting , Prepared Statements )
  2.  Restructuring Indexes.
  3. DB Caching Tuning ( if using ORM )
  4. Identifying the problems ( if any ) with the ORM Strategy ( If using ORM )

Q13. Why Web Services Use Http As The Communication Protocol ?

With the advent of Internet, HTTP is the most preferred way of communication. Most of the clients ( web thin client , web thick clients , mobile apps )  are designed to communicate using http only. Web Services using http makes them accessible from vast variety of client applications. 

Q14. Should We Create System Software ( E.g Operating System ) In Java ?

No, Java runs on a virtual machine called JVM and hence doesn't embed well with the underlying hardware. Though we can create a platform independent system software but that would be really slow and that's what we would never need. 

Q15. What Are The Ways To Avoid Lazyinitializationexception ?

  1. Set lazy=false in the hibernate config file.
  2.  Set @Basic(fetch=FetchType.EAGER) at the mapping.
  3. Make sure that we are accessing the dependent objects before closing the session.
  4. Using Fetch Join in HQL.

Q16. Difference Between Builder And Composite ?

Builder is a creational Design Pattern whereas Composite is a structural design pattern. Composite creates Parent - Child relations between your objects while Builder is used to create group of objects of predefined types.

Q17. What Are The Different Types Of Memory Used By Jvm ?

Class , Heap , Stack , Register , Native Method Stack.

Q18. Why Using Cookie To Store Session Info Is A Better Idea Than Just Using Session Info In The Request ?

Session info in the request can be intercepted and hence a vulnerability. Cookie can be read and write  by respective domain only and make sure that right session information is being passed by the client.

Q19. How Does Volatile Affect Code Optimization By Compiler?

Volatile is an instruction that the variables can be accessed by multiple threads and hence shouldn't be cached. As volatile variables are never cached and hence their retrieval cannot be optimized.

Q20. What Things Should Be Kept In Mind While Creating Your Own Exceptions In Java?

  • All exceptions must be a child of Throwable.
  • If you want to write a checked exception that is automatically enforced by the Handle or Declare Rule, you need to extend the Exception class.
  • You want to write a runtime exception, you need to extend the RuntimeException class.

Q21. Difference Between Proxy And Adapter Design Patterns ?

 Adapter object has a different input than the real subject whereas Proxy object has the same input as the real subject. Proxy object is such that it should be placed as it is in place of the real subject.

Q22. Which Uml Diagrams You Usually Use For Design ?

Use Case Diagram, Component Diagram for High level Design and Class Diagram , Sequence Diagram for low level design.

Q23. Shall We Use Abstract Classes Or Interfaces In Policy / Strategy Design Pattern ?

Strategy deals only with decision making at runtime so Interfaces should be used.

Q24. What Would You Do If You Have To Add A Jar To The Project Using Maven ?

If its already there in Maven local repository, We can add that as a dependency in the project pom file with its Group Id, Artifact Id and version.

We can provide additional attribute SystemPath if its unable to locate the jar in the local repository.

If its not there in the local repository, we can install it first in the local repository and then can add it as dependency.

Q25. How Do You Coordinate And Communicate With The Team Developers ?

We as a team of developers , testers , analyst , lead and architect sit close to each other. Most of the time I would just jump to their seat and talk to them ( if required ). We have daily stand up where we discuss things that needs team attention. 

Q26. What Kind Of Software Architecture Your Organization Follow ?

We have multi tier architecture with multiple layers , We have series of web servers and applications in application tier, infrastructure libraries at middle tier and Database servers at the lower tier. We are using Oracle as Database, ESB ( Enterprise service Bus ) for asynchronous communication and Rest Web Services.

Q27. What Are The Benefits Of Using Spring Framework ?

  1. Spring enables developers to develop enterprise-class applications using POJOs. The benefit of using only POJOs is that you do not need an EJB container product.
  2. Spring is organized in a modular fashion. Even though the number of packages and classes are substantial, you have to worry only about ones you need and ignore the rest.
  3. Spring does not reinvent the wheel instead, it truly makes use of some of the existing technologies like several ORM frameworks, logging frameworks, JEE, Quartz and JDK timers, other view technologies.
  4. Testing an application written with Spring is simple because environment-dependent code is moved into this framework. Furthermore, by using JavaBean-style POJOs, it becomes easier to use dependency injection for injecting test data.
  5. Spring’s web framework is a well-designed web MVC framework, which provides a great alternative to web frameworks such as Struts or other over engineered or less popular web frameworks.
  6. Spring provides a convenient API to trlate technology-specific exceptions (thrown by JDBC, Hibernate, or JDO, for example) into consistent, unchecked exceptions.
  7. Lightweight IoC containers tend to be lightweight, especially when compared to EJB containers, for example. This is beneficial for developing and deploying applications on computers with limited memory and CPU resources.
  8. Spring provides a consistent traction management interface that can scale down to a local traction