TLDR;
This video features a mock interview for a Java and Spring Boot developer position. The interviewer assesses the candidate's knowledge and experience with Java fundamentals, Spring Boot concepts, and related technologies. The candidate demonstrates a good understanding of Java concepts and Spring Boot, but needs to improve practical application and hands-on experience, particularly in areas like Spring Security and testing.
- The interview covers topics such as project experience, Java fundamentals (packages, static keyword, generics, exception handling, method overloading, final keyword, inner classes, garbage collection), design patterns (Singleton), Spring Boot advantages, auto-configuration, database integration, security, actuator, and starters.
- The candidate shows strong theoretical knowledge but lacks practical experience in certain areas.
- The interviewer provides feedback and suggests creating mini-projects to gain hands-on experience.
Introduction [0:00]
The video introduces Raja Lakshmi Mohan, a Java and Spring Boot developer with four years of experience, who will be participating in a mock interview. Viewers interested in similar interviews are encouraged to fill out a form.
Candidate Introduction and Project Overview [0:13]
Lakshmi introduces herself, mentioning her computer engineering background and her experience with companies like TCS, Scal Ag, and Zebra Technologies since 2019. Her role primarily involves Java back-end development, with expertise in Spring MVC and Spring Boot. She describes her recent project as an end-to-end application involving data retrieval from the client through JSP and data storage in back-end database tables using Hibernate, utilising the Spring MVC framework with a model-view-controller architecture.
Database Interaction and Optimisation [1:30]
Lakshmi confirms that Hibernate was used as the framework for database interactions. Transactional annotations were not used directly; instead, Hibernate session objects and criteria were employed. To optimise queries, indexing was implemented where necessary to reduce back-end load during data fetching. The application was monolithic rather than microservice-based and was developed for a client. Lakshmi also mentions using JAXB libraries to convert Java objects to XML for interacting with third-party services.
Packages in Java [3:31]
Lakshmi explains the purpose of packages in Java, highlighting their role in preventing naming collisions when classes have the same name. Packages provide a structured way to organise code based on behaviour and hierarchy, making it easier for the compiler to differentiate between classes. If two packages contain classes with the same name, they can be accessed using package.className
after importing the specific package.
Static Keyword in Java [5:08]
The static keyword is associated with the class itself, not with instances of the class. When a variable is declared as static, memory is allocated only once, and all changes affect the same memory location. Lakshmi initially suggests that a static block can throw an exception if non-static data is incorporated, but then corrects herself regarding overriding static methods, acknowledging that it is not possible since static methods are related to the class and not its instances.
Execution Flow with Static and Non-Static Methods [6:48]
When a class is loaded, all static methods are loaded into memory at the same time and can be invoked without creating an object of the class. After that, when an object is created using the constructor, the methods called by the object are invoked.
Generics in Java [7:42]
Lakshmi admits to limited knowledge of generics, only being familiar with the optional class. She is unsure whether generics can be used with arrays.
Exception Handling [8:32]
Lakshmi explains that if an exception is thrown in a static initialisation block, it causes a runtime error and class loading fails, resulting in an ExceptionInInitializerError
. She initially believes that an exception cannot be thrown from a finally block, but the interviewer clarifies that it is possible, although it's not a good practice as it can suppress the original exception and lead to debugging issues.
Custom and Inbuilt Exceptions [10:42]
Custom exceptions are preferable because they allow developers to communicate error messages in a client-friendly manner. Lakshmi names several inbuilt exceptions, including ArithmeticException
, ArrayIndexOutOfBoundsException
, NullPointerException
, and ClassNotFoundException
.
Method Overloading [11:46]
Method overloading, which involves methods with the same name but different return types and arguments, is a compile-time polymorphism. Java resolves calls to overloaded methods using the return type, type, and number of arguments.
Final Keyword [12:42]
Lakshmi has limited experience with the final keyword in projects. She suggests a use case where employee IDs in an employee management system could be declared final to prevent modification. The interviewer clarifies that while the internal state of a final object can be modified if it is mutable, the reference of a final object cannot be changed once assigned. Declaring a method as final prevents it from being overridden in child classes, thus stopping inheritance.
Inner Classes, Java Memory Model, and Garbage Collection [15:41]
Lakshmi recalls reading about inner classes but doesn't remember much. She is unsure about the Java memory model but explains garbage collection as an automatic process that deallocates memory for objects no longer in use.
Investigating Memory Leaks [16:39]
When asked how to investigate and fix a memory leak in Java, Lakshmi suggests calling the System.gc()
method to free memory automatically, but doesn't provide a comprehensive approach to identifying the source of the leak.
Design Patterns: Singleton [17:19]
Lakshmi is aware of design patterns and has created a Singleton before. She describes a Singleton class as one with only one object.
Spring Boot vs. Traditional Spring [17:59]
Lakshmi highlights the advantages of Spring Boot over traditional Spring, including auto-configuration of dependencies and embedded servers like Tomcat and Jetty. In Spring Boot, dependencies are automatically configured, whereas in Spring, they must be manually configured.
Spring Boot Auto-Configuration [18:59]
The default server in Spring Boot is Tomcat, but it can be changed by modifying the pom.xml
file. Auto-configuration involves Spring Boot automatically creating objects at runtime based on annotations like @Configuration
and @Component
. Spring Boot uses classpath scanning to determine what to configure.
Overriding Default Auto-Configuration [20:51]
Lakshmi explains that default auto-configurations can be overridden to implement new functionality or modify existing behaviour. She provides an example of overriding the clone method in a Singleton class to prevent violating the Singleton pattern.
Integrating Database in Spring Boot [22:04]
To integrate a database, a class is created in the repository package and annotated with @Repository
. This class extends JpaRepository
, which internally calls @Repository
and @Transactional
. An entity class is created in the entity package, annotated with @Entity
and @Table
, with columns annotated with @Column
and the primary key with @Id
.
Securing a Spring Boot Application [23:37]
Lakshmi has heard of using JSON Web Tokens (JWT) to secure Spring Boot applications but hasn't implemented it. She expresses a willingness to learn and implement it in a personal project to gain hands-on experience. She defines Spring Security as a means to configure security, allowing only authorised profiles to access certain modules.
Authentication vs. Authorisation [25:37]
Lakshmi differentiates between authorisation (who can see what) and authentication (verifying user identity based on credentials). Method-level security can be achieved using annotations like @PreAuthorize
, @PostAuthorize
, and @Secured
.
Embedded Servers in Spring Boot [27:06]
The embedded server, such as Tomcat, hosts the Spring Boot application. Lakshmi confirms that Spring Boot applications can be deployed as traditional WAR files to external servers using specific commands.
Application Configuration in Spring Boot [28:15]
Application configuration is handled using @Configuration
classes and by taking properties from the application.properties
file. The order of precedence for configurations is command-line arguments, environment variables, and external configuration files. Lakshmi is not deeply involved in structuring configuration files in her current support role.
Optimising a Project [30:32]
To optimise a project, Lakshmi suggests removing unwanted methods and decreasing delays while calling APIs. The interviewer adds that reducing the complexity of loops (e.g., from O(n^2) to O(n)), avoiding multiple loops, implementing common DB queries in a parent method, using Stream API, and implementing efficient algorithms are all effective strategies.
Spring Boot Actuator [32:41]
Spring Boot Actuator provides health metrics for the application, making it production-ready. It offers endpoints for health, info, and metrics.
Testing Spring Boot Applications [33:51]
Lakshmi does not currently write unit test cases in her project but is open to doing so. She is not familiar with specific annotations for writing JUnit tests.
Spring Boot Starters [34:38]
Spring Boot starters are dependency bundles that simplify project setup. Examples include starter-web
for web applications, starter-jpa
for JPA configurations, starter-data-jpa
, and starter-data-hibernate
for including Hibernate.
Feedback and Conclusion [35:31]
The interviewer acknowledges Lakshmi's good theoretical knowledge but suggests focusing on practical experience, particularly in Spring Security and testing. He recommends creating mini-projects and adding them to GitHub for future reference. He rates her Java skills positively, noting that she only lacked in a few areas. Lakshmi clarifies that she has two years of development experience and two years in Java back-end support, expressing her intention to leverage her development skills when opportunities arise.