Transcription
Hey guys, today we have Ashi, and she has a total of four years of experience in Java, Spring Boot, and microservices domains. And those who want to give a free mock interview, please fill out the form below in the description. So now, let's get started.
Hey, hello Ashi. How are you?
I'm good. How are you?
Yes, I'm also good. Shall we start?
Yes.
Okay. So Ashi, can you please introduce yourself and your recent project in brief?
Okay. So my name is Ashi Jaspal. I have an experience of four years. Uh, currently, I am working on a modernization project. It was a legacy application which we have converted into a uh, modern by doing the modernization of the project. Uh, so the project basically handles the policy issuance. I am working in the insurance domain. So I majorly handle the policy issuance, the process of policy issuance part.
Okay. Nice. So what's your day-to-day responsibilities Ashi there?
So right now, uh, so there are different types of products which has to be taken live. So right now, the legacy application is also working, and our modernization application is also working. So we have to maintain both the applications. And the second thing is we have to take the existing products live in our modernization project. So that development happens based on the requirement of the products and all. So we are, uh, migrating the products.
Okay. Nice. So this is based on completely Spring Boot, right?
Yes.
Okay. So, uh, like do you know the concept of dependency injection in Spring and how it is implemented?
Okay. So we can, there are three types of dependency injection: constructor, setter, and field. Uh, mostly, uh, constructor dependency injection is more prominent to be used. So basically, when we use dependency injection, it basically, uh, internally autowires our, uh, uh, the services that we are calling. For example, if we want to implement a method of the repository layer, so we can just autowire the, uh, class and we can then use the repository's methods.
Correct. Correct. So can you tell me a situation where constructor injection is preferred over setter injection?
Uh, that I'm not a little confused in that.
Uh, okay. Okay. Yeah. Yeah. So, yeah, that's fine. So constructor injection is preferred when dependencies are required for the object's functionality, and it ensures that the object is always in a valid state when created. Uh, it's also immutable and suitable for required dependencies.
Okay. Okay. Okay. Yeah. Yeah. Uh, so Sakshi, sorry, Ashi, can you, uh, tell me about Spring Beans? Like, what Spring Beans are and how do they work?
So Spring Beans are basically the entity class, we can say. So we create, uh, Spring Beans so that we can, for example, if we have a database, so we want to map the database columns with our Spring Boot application. So for that, we create beans so that our columns are mapped with the beans names, and we can access it in the Spring Boot application. It is a good practice to do that to make our code optimizable.
So guys, before moving ahead, I would like to share one important thing. Ashi purchased an interview preparation kit, and she was able to crack multiple interviews, and we also referred her in multiple companies. So, uh, let me brief what the interview preparation kit is. So actually, we had launched complete interview preparation material, structured step-by-step by myself, experts, and MNCs' interviews. And the best part is that no one need to go anywhere else to prepare for interviews. There is a 99% chance that the interview will ask questions from this material. So, the interview preparation kit contains this material plus one-on-one lifetime doubt sessions plus a video recorded session for project enterprise projects and referrals to the big MNCs. So, Ashi, can you please provide feedback like, is it helpful for you?
Uh, so yes, as per my experience, whatever questions were there, specifically in Spring Boot, it helped me a lot. Based on the scenario-based questions that are there, it helps a lot during the interviews to answer the questions.
Okay. Okay. Thank you. So guys, I'll provide both links below in the description, interview preparation kit as well as complete interview preparation material. Now, moving to our interview.
So, uh, like, as you know, there is an annotation, `@SpringBootApplication` annotation, right? So, it, it consists of three annotations internally, right? So, can you tell me in brief on this?
So there are three annotations: `@ComponentScan` and `@Configuration` and `@EnableAutoConfiguration`.
Okay. So what `@ComponentScan` does is basically, it will scan whatever components are needed for our application. Then we have `@EnableAutoConfiguration`, which will get all the configurations that are needed. For example, we have the database connectivity which we define in our `application.properties`. So for example, to get the configurations for that. And then we have `@EnableConfiguration`, that is based on the configurations that we have explicitly defined. So to use that, we can use `@EnableConfiguration`.
Okay. Okay. Got it. Uh, have you worked with Spring Profiles?
Spring Profiles? No.
Uh, like dev environment, prod environment, testing environment?
No, in your, no, we have just, we just do the definition in the `application.properties` for the different, different environments. We don't maintain the profiles.
Okay. Okay. Okay. So you guys don't maintain the profiles instead, you just, you are just mentioning the environments in the `application.properties`. So are you using properties or YAML files?
`application.properties` file.
So are you guys planning to migrate to YAML or not?
Yes, because we are planning to do that because, for example, we have `deployment.yaml` file. So it is very much structured and it helps us to, you know, understand the indentation more briefly and more properly.
Okay. Correct. Uh, okay. So moving ahead. Have you connected any database to the Spring Boot application by your own?
Uh, yes, means we use MySQL.
MySQL. Yeah. So, so how can we connect MySQL with Spring Boot?
First of all, we will have to include the dependency of MySQL in the `pom.xml`. Then we have to define the data source, the username, and the password in the `properties` or `yaml` file.
Okay. Okay. Got it. Uh, so do you know about Singleton design pattern, Ashi?
Yes.
So is there any relationship between Singleton design pattern and database connection?
Yes. So for, so what Singleton design pattern is, it maintains one instance. How many times we call it, it will always maintain one instance. So in that case, when we are doing a database connectivity, we will always require one instance. We can't have the same database connected two, three times. So that is why we use a singleton instance class implementation for database connectivity.
Okay. Okay. And, have you worked with `@Transactional` annotation?
Yes.
So basically, what the `@Transactional` annotation is, if we are having one process happening, but due to some reason, the process is stopped or corrupted in between, so the whole thing has to be rolled back. So for that, we use the `@Transactional` keyword.
Yes. Correct. Okay.
So tell me one thing. Uh, I mean, how would you, uh, Okay. No. So tell me a condition like, if you are working on `@Transactional` annotation, right?
Mhm.
And you mentioned the `@Transactional` annotation in both class and method level simultaneously. So what issues might arise?
So basically, `@Transactional` is used on the method level. Means, the best practice is it to use at the method level because, for example, if we are updating some resource in our database. So if we are using it at the class level, so it won't know that which method actually had the issue. So that is why it is the best practice to use it at the method level.
Choose a method level. Yeah. So, yeah, this is a best practice. But, uh, if we, if we add `@Transactional` annotation in both class and method, so the method one will override the class level settings. Okay. Yeah. But it would lead some unexpected behavior, right? As you already said.
Yes.
Okay. Uh, okay. So how would you handle a scenario where a transaction needs to be rolled back due to an operation on a remote service failing?
Remote service failing? No, this I'm not sure about.
Okay. Okay. So, have you heard about compensating transaction or distributed transaction pattern like Saga?
Okay. Okay.
Saga? Yes. Yeah. Yeah. We can, we could implement Saga pattern here.
Okay. Okay. Yeah. Yeah. Okay. Moving ahead. Uh, [Music] have you implemented any notification system in a Spring Boot application?
Notification system? No.
Uh, and have you worked with Java Mail?
Uh, no, we have a third party to send the emails.
And the third party? So what third party service?
Uh, so, uh, we have this thing called as Gupshop.
Gupshop. Yes. So we, uh, that is used, means our application sends the, uh, request and the whole body of the message to that. It would be an Indian, Indian, yes, uh, third-party service, right? Gupshop, as the name suggested.
Mhm.
Okay. Uh, okay. Got it. Moving ahead. Uh, so how you guys do deployments in your web applications? So tell me from, uh, scratch.
So what we do is, we have our deployments done through AWS. So we use the AWS Git, only the CodeCommit and the pipeline. Okay. So what we do is, we take the code on our local, the, we clone the repository. Whatever changes we have to do, we do the changes, then merge the code. But if there is any conflict during merge, we resolve them first by manually, the head and the arrows that are there. Based on that, we resolve the conflicts and then we push the code to the pipelines, and the pipeline deploys the code.
What's there in your pipeline? There are, there must be few steps in your pipelines, right? Uh, like build, check?
We have build, uh, then we have image creation, then we have, uh, we just have three steps.
Which is the three steps? Yeah.
Build and code review.
One is the code review. Okay. Okay. So, who reviews your code?
So, we have a TLs that reviews the code first.
And TLs. Yeah. Okay. And who reviews the code of your TL?
TL that I'm not sure about.
Okay. Fine. Okay. So, tell me how Spring Boot simplifies, uh, the web development.
So first of all, uh, Spring Boot is, uh, is used to first of all, reduce the boilerplate code. Then the annotations make it easier. Uh, then we have the, in annotations, for example, we have the `@Autowired` annotation, the `@SpringBootApplication` annotation itself. Uh, then have the, uh, Spring Actuators, which helps to maintain the code and the health of the, uh, of the API, everything on the, uh, production. Then we have Swagger, Swagger, which helps us to, uh, bifurcate our APIs, like how, what are the APIs, what are the request response.
Mhm. Okay. And it is more easier to maintain a web application using Spring Boot.
Okay. Okay. All right.
So, uh, tell me the servers that Spring Boot provides.
Uh, the Spring Boot have three embedded servers: Tomcat, Undertow, and Jetty.
And what's the default one?
Tomcat.
So, can we, I mean, remove the default one and include whatever we want?
Yes, we can do that.
So, how can we do that?
Uh, we can do that by excluding it, uh, through our `pom.xml`, the server.
Uh-huh. Okay. All right. [Music]
Okay. So, have you worked with database migration tools like Flyway or Liquibase?
No.
Okay. So, yeah, information like Spring Boot provides built-in support for Flyway and Liquibase. They are tools for migrating a database, right? And they have tools, they do some automatically initialize and run on application startup.
Okay. Okay. Okay.
What are Actuators in Spring Boot?
So Spring Boot Actuators is basically, we use it. It is like a checkup thing. Means, it is helpful for us to keep an eye on our Spring Boot application, how it is managed, how, what is the health of the APIs, if any API is running slow, all that information we can gather through Actuators.
Okay. Got it.
Tell me a few endpoints that Actuators provide.
Uh, one is `health`. Okay. Uh, one is, I think, `info` or something. I'm not sure, but I'm sure about `health`.
So, have you used the `health` endpoint?
Uh, no, we have. No.
Okay. Have you worked with Spring Boot Data JPA?
Yes.
What are the advantages Spring Boot Data JPA offers over standard JPA?
So first of all, it has the methods, uh, which are defined in the JPA, which is like `.save()`, `.flush()`, `.findAll()`. So that all helps us not to write the query or, not to, use the native queries or anything to write our, uh, database transactional query.
Okay. So suppose you have a requirement to dynamically fetch data with variable search criteria. How would you implement it using Spring Data JPA?
U searching. Yeah. Yeah. If I have to search, I think I can use here the native query, sorry, the `@Query` annotation, and then I can just write the query for it, like `SELECT * FROM table WHERE condition`. If I have to set something, so we will need a `WHERE` condition.
Okay. So do you prefer custom queries or like inbuilt queries?
Both have their advantages according to. Yeah. So according to the requirement, we should prefer which one has to. So tell me where, uh, we must write custom queries, like where we don't have any option for the default one. Tell me a scenario when we have to update something.
To update something, uh, based on some conditions. Yeah. Yeah. Correct. So that time, we can use custom queries.
Mhm.
So explain the concept of Repository in Spring Data JPA.
Uh, so Repository is basically for doing the database transactions. We add the `@Repository` annotation for that. Uh, now we have different types of repositories. We have `JpaRepository`, we have `CrudRepository`, we have `PagingAndSortingRepository`. So based on the requirement, we can use the repositories, whichever is for our requirement.
Mhm. Okay.
And what are the limitations of Spring Repositories?
Limitations means disadvantages. Disadvantages, I'm not sure about disadvantages.
Okay. Uh, there may have disadvantages as well, like naming conventions for query methods which can be confusing and limited in scope for complex queries.
Okay. Right. And, uh, custom implementations might be necessary for advanced querying.
Okay. Okay. Yeah. Okay.
So, uh, how do you handle transactions in Spring Data JPA?
Transaction as in the database transaction. Yeah. Yeah. Database transactions, uh, like internally, or yeah, yeah, yeah. I mean, how could we use `@Transactional` annotation here in Spring Data JPA?
Spring Data JPA, I'm not sure about that.
Okay. Okay. So I think it's the same. We already discussed. So we could use `@Transactional` annotation. We could, we can add this at method level, class level. Okay. We can do the rollback things and all.
Okay. Okay. Yeah. Okay.
So, uh, if you have a long batch operation, how would you manage transactions to optimize performance and consistency?
We can use our caching. Mhm. One is for enabling the caching because we are having caching, then it will just, if we store the data, so it will give the same output rather than going to the database and calling the APIs and everything. Yeah. Yeah. And we could also break the whole batch into the segments, right? And we could handle the transactions for each segment. Okay. Like if we segregate them into methods and we can just. Okay. Yeah. Okay.
So, moving ahead. Uh, uh. [Music] So, what's the difference between `==` and `.equals()` in Java?
Uh, `==` we use it to compare the references. Uh-huh. `.equals()` is used to compare the content. Means, if it is `String s1 = "hello"; String s2 = "hello";`
So, tell me a scenario where `==` gives a true result and `.equals()` gives a false result.
False. Okay. If it is `String s1 = "hello"; String s2 = "hello";` So we compare `s1 == s2`, that time we'll get the same, it as true. But if we write `String s1 = "hello"; String s2 = new String("hello");` So that time `.equals()` will give me true.
Okay. Okay. So how would you handle a situation where you need to compare the content equality of two custom object instances?
Content equality. M. Content equality, sorry. Uh, so what to be used, sorry. Uh, like how would you handle a situation where you need to compare the content equality of two custom object instances, like there are two objects and you have to compare their content, not the reference?
We can use `.equals()` method.
Then `.equals()` method. Okay.
Do you know about Java Memory Model?
Java Memory? Uh, the Java memory management part?
No, Java Memory Model.
Model? I'm not sure about.
Yeah, it is an abstraction that manages how threads interact through memory and how data is read from and written to main memory. Okay. It is related to thread management.
Yeah. Yeah. Thread management. Okay. Okay.
So tell me the use of the `final` keyword.
Uses of `final` keyword. Okay. So first of all, `final` keyword is used to make a class immutable. If we declare any variable as `final`, we cannot change its value. So it can be used in the immutability of a variable also. Okay. So basically, `final` is used for the implementation of immutability.
Okay. Got it.
And how can we create an immutable class?
Uh, first, we can declare the class as `final`. Then second, we can just implement the setter methods. Uh, sorry, only the getter methods and not the setter methods. We can declare the variables as `final`. Mhm. We can do these things.
Okay. So can you explain how `HashMap` works in Java?
So `HashMap` has three steps internally. First, it will do the hashing. That means it will first use the hash function to get the hash code. Then second, it will initialize the bucket. So that means it has the formula: hash code mod the array size, we will get the reference number. And then third step is storing in the bucket. That means whatever the hash code key we have found, the key, we will store it there, the value.
Okay. Got it. What happens when two different keys have the same hash code?
If two different keys have the same hash code, uh, I think it will give me an exception.
No, collision will occur. Okay. Yeah. Yeah. So when two keys have the same hash code, collision will occur. `HashMap` stores these keys in the same bucket. Okay. So what will happen before? Let me tell you first, what will happen before Java 8, all entries in the same bucket will be stored in a linked list. But post Java 8, all these entries will be stored in a balanced tree, okay, in a more efficient manner.
More efficient. Okay. Okay.
Uh, okay. So suppose you are storing user session data in a `HashMap`. How would you ensure thread safety?
We can use the `synchronizedMap`. Yeah. `synchronizedMap`. Or we can use `ConcurrentHashMap`.
Correct.
So, can you discuss exception handling and what are checked and unchecked exceptions?
Okay. So first of all, exception handling is a mechanism to handle errors and the exceptions that occur in our program. Then we have the checked and unchecked exceptions. Unchecked exceptions are the runtime exceptions, which can be handled using the `throw` keyword. Then we have the checked exceptions, which are the compile-time exceptions. This we can handle using the `try-catch` block.
Okay. Got it. How would you handle a scenario where a method throws multiple types of exceptions?
Multiple types of exception. We can use the `throws` keyword here. Uh-huh. And we can mention the different types of exceptions, or we can write multiple `catch` blocks.
Okay. Okay. Uh, so do you know about J-test cases?
Uh, no, I haven't.
Okay. So how you guys are doing test cases and like testing? How you guys are testing your application?
Uh, we perform the sanity testing or the unit testing that we do. So we have the document that we have the test cases based on that, we perform the testing for now.
Okay. But it's, so I mean, there will be a different team right for doing this and all?
Yes.
Okay. Okay. Got it. And, uh, uh, do you know about Maven? Like, what Maven is and why are we using Maven in our project? Why do we use?
Mhm.
So Maven is basically a central repository which has all the dependencies. We use Maven so that, uh, whatever dependencies we need, we mention it in our `pom.xml` file and then when we build our code, so that time Maven will first check into our remote repository if the dependencies are present or not. If it is not present, it will download it from the central repository for us. Mhm. So it makes our work easier.
So what's the difference between `mvn clean` and `mvn install`?
So first of all, `mvn clean` is used to clean the previous builds that we have had, and `mvn install` is basically to install and build the whole application again.
Mhm. Okay.
So, which editor are you using?
We use STS.
STS. Tell me a few shortcuts that you know about STS.
Uh, for when we are debugging the code, that time we can use `Ctrl+Shift+I` to know the value of the variables, what the values are assigned to a specific variable. Then we have `Ctrl+F` to make the code in a proper format. Then we have the `Ctrl+Click` we do to the method name so that we can reach the method directly rather than processing it through the packages and all.
Okay. Okay. And, um, which Git collaboration tool are you guys using?
We are using AWS.
AWS. Do you know about Git commands?
Yes.
Okay. So how do you resolve conflicts?
For resolving conflicts, we have to manually resolve them. So there is this process of doing it. So when a conflict occurs, what we have in our code is we have a `HEAD` written and the arrow. So whatever is between that, that is our previous code, and the down part which is in just the arrows, that is our current code. So based on whatever we want to remove or add, we accordingly manage it and then we add it.
Okay. Okay. Got it. What's the difference between `git rebase` and `git merge`?
So when we are merging, when we are merging, for example, two files, so that time the previous histories are also there for them, and the current ones are also there. But when we do `git rebase`, it gets on the top of the commit. It doesn't maintain the histories of the previous one. It maintains a linear history, basically.
What is `git cherry-pick`?
So `git cherry-pick` is basically when we have a lot of commits, and we have to just take a specific commit ahead. Mhm. So for that, we use `git cherry-pick`. So basically, it is like `git add` only if we have a lot of files to take. So we can use `git add` for that. So similarity.
Okay. Okay. Got it. Uh, so, uh, will you be able to solve a coding problem? Uh, Ashi?
Yeah.
By using Java Streams?
Okay. Okay.
Uh, like, will you know, like, are you in practice?
Not that much. Not that much. A normal coding or?
Okay. Yeah. Okay.
Please share your screen. Okay. So I will give you few questions, simple questions. Okay. So first question is, you are given a string, and you have to convert the string into the upper case. All, uh, characters of a string should be in upper case.
Okay. Sorry, this is getting handled. So I will, what I'll do here, I will stream it and then I will use the method reference to use the uppercase of the string method and then I will print it using the `forEach`. Mhm. Or do one thing, uh, take a list. Mhm. And enter two, three strings and then convert all those strings into the upper case. I think now it will.