LD for Job Interviews

. . .

LD refers to Little Dinosaur.

BQ

  • “id”: 1,
    • “question”: “Introduce yourself and talk about your most recent project”,
      • “answer”: “

        Self Introduction

        1. Hi, my name is X, i have over X years of experience as a [title] in software development, design and deployment. My main skills are in Java, XX etc. I have been working in Both frontend and backend.
        2. For frontend end, i used [Angular, React, Jquery, Bootstrap, Html, ES6, CSS] etc
        3. For backend, I used Spring boot, Rest API, GraphQL, Spring Dependency Injection, JPA, Scheduler etc
        4. For security, I am familiar with Oauth2, Basic Authentication, JWT Token, Asymmetric Key pairs etc
        5. For database, I have worked with both SQL and NoSQL, like Oracle, Postgres, SQL Server, MongoDB, Cassandra etc
        6. For cloud, I have used AWS cloud, like EC2, RDS, S3, EBS, lambda, ECS container etc
        7. I also have experience in distributed systems, like MicroServices, Kafka Message queue, Redis distributed cache, Load Balancer, Circuit Breaker, API Gateway etc.
        8. More, i have written a lot of test cases, like JUNIT, Mockito, PowerMock, Selenium, TestNG, Cucumber, Gatling etc
        9. I am also familiar with CICD using Jenkins or Bamboo with maven or gradle.
        10. For monitor tools, i used Grafana, AWS cloudwatch, Jmeter(load test), JProfiler, Splunk, Datadog etc.


        Project Introduction:

        1. Talk pure business and list 2-5 entries to talk about, make it the way everyone can understand. Talk from how users use your app or how data flows in your app.
        2. Then talk about pure technical skills used. Frontend, security, backend, microservice, message queue, cloud, testing, monitoring etc
        3. Make it as long/detailed as possible.
        “,
      • “keyword”: “BQ”,
      • “frequency”: 5,
  • “id”: 2,
    • “question”: “Talk about the team structure and how your team works when everyone is working remotely”,
      • “answer”: “

        Team structure

        Business Team: responsible for determine the functions of application

        Dev Team: responsible for developing the functions (where developers in)

        QA team: test the functions developed by Dev team:

        DevOps team: deploy the functions to production.


        Dev team size: safe to say any number from 4 - 15, good range is a number in 5-10. Like, our team has 8 developers. We all work on both frontend and backed and We all write the test cases.. We also joined the DevOps deployment process, but we have a dedicated DevOps team. Remember to say: whenever you have question about the function, you can talk with business team.


        Jira: a tool to track all the tickets that you need to work on in each sprint

        Confluence: a tool to document everything, like functional documents, technical documents etc


        Communications: Email, Zoom Meetings, Slack messaging.


        “,
      • “keyword”: “BQ”,
      • “frequency”: 5,
  • “id”: 4,
    • “question”: “Describe a bug you met and how you deal with it?”,
      • “answer”: “

        Think of one in your most recent project

        Key thing to mention:

        1) How was the bug found in production - monitor tools like Splunk OR customer feedback to your support team

        2) you try to reproduce it in your local and DEBUG it, test with postman, put breakpoint, write new test case to cover it.

        3) CICD and release it, customer is happy.

        “,
      • “keyword”: “BQ”,
      • “frequency”: 5,
  • “id”: 5,
    • “question”: “How do you coordinate with QA?”,
      • “answer”: “

        Agile with sprint: Sprint is usually 2 or 3 weeks length

        Sprint Begin: planning meeting, business, dev, and QA sit together to discuss what to do in the sprint.

        Then: grooming meeting: Dev team members only to get everyone familiar with their own tickets

        Daily standup: report status of everyone ticket and discuss issues

        Spring End: retrospective meeting to review what have been done.


        In 2 weeks sprint, every ticket is mark as dev completed will be tested by QA, if any issue, QA feedback to developer and get it fixed immeidately.

        “,
      • “keyword”: “BQ”,
      • “frequency”: 3,
  • “id”: 11,
    • “question”: “What’s the architecture of your project? How many layers are there?”,
      • “answer”: “

        For big web based application:

        Overall: Microservice, Load Balancer, Circuit Breaker, Kafka, Docker, Cloud etc

        Each service: Frontend -> security -> controller -> service with helper and utils -> repository, model, DTO etc.

        “,
      • “keyword”: “BQ”,
      • “frequency”: 4,
  • “id”: 14,
    • “question”: “How did you start with a new job/project?”,
      • “answer”: “

        Some general steps:

        1. Get code to local and try to run it
        2. Read documents about the workflows
        3. Try to solve some simple tickets
        “,
      • “keyword”: “BQ”,
      • “frequency”: 4,
  • “id”: 15,
    • “question”: “Talk about your daily work, what’s your typical day looks like”,
      • “answer”: “

        We follow Agile methodology, we have 2 weeks sprint. So at beginning of each sprint, we have a planning meeting which we sit together to discuss all the tickets we need to work in in the whole sprint, and after that we have grooming meeting which is for developers to get familiar their own tickets. Then in each day, we have daily standup meeting in the morning at around 10am when we discuss our progress on each ticket and any blockers (need to wait on others work) we have. After meeting, we go back to work on our tickets and sometimes, we have meeting with business team to discuss the detailed problems, we also have design meetings for each big stories and we also have developer meetings to discuss our common issues. AT the end of each sprint, we have retrospective/retro meeting to review what we have done.

        Percentage of daily time: 60-70% on coding including development and test cases, 10-20% on meetings, 10-20% on leading junior people or system design meeting

        You need to say 60-70% on coding because they are hiring you as a software developer who writes code all the time.

        “,
      • “keyword”: “BQ”,
      • “frequency”: 4,
  • “id”: 20,
    • “question”: “When you have conflicts with your colleague, how do you deal with it?”,
      • “answer”: “
        1. Conflicts is normal, everyone has their own ideas, and not everyone familiar with every part of the project, so conflicts is common
        2. Communication is the key to solve conflicts, never hide my idea, i always explain and spread out
        3. I reach out to the person and explain my ideas and I try best to understand his ideas. And we choose the better one regardless whose idea that is. we only want the best solution goes to the code
        4. If conflicts cannot be solved between us, we escalate it to tech lead or team manager.
        “,
      • “keyword”: “BQ”,
      • “frequency”: 5,
  • “id”: 21,
    • “question”: “Tell a time you have conflicts with your team and how you resolved it”,
      • “answer”: “

        Conflicts <find a particular conflicts >

        How do you solve it: The key thing is communication, I will first open communication, i will explain my idea. I will also try my best to understand his idea. We will discuss and keep it transparent and try to choose the best solution. It does not matter who comes up with that solution, because our goal is to make best product for customers.

        If we cannot really agree on each other, we will escalate to manager and let manager decides, we should all agree on the final decision.

        “,
      • “keyword”: “BQ”,
      • “frequency”: 4,
  • “id”: 24,
    • “question”: “Do you like Pair programming or coding on your own”,
      • “answer”: “

        Both has pros and cons

        Pair programming:

        1. Good to learn from the leader and good for new members to get familiar with project
        2. Good to trigger new ideas, when you discuss, new ideas come out more often then you just think by yourself
        3. Bad: coding is very slow.

        Work independent:

        1. I am senior and experienced, so i can quickly get things done.
        2. Sometimes I get stuck, it can take a long while to find solution

        Overall: I am experienced, so I can solve most of the tickets just by working on my own. But I also did pair programming with team members, like when we have POC (proof of concept) or Demo or Design meetings, or when I do knowledge transfer for some new team memebers, I do pair programming to help them.

        “,
      • “keyword”: “BQ”,
      • “frequency”: 2,
  • “id”: 26,
    • “question”: “During middle of sprint, your manager suddenly add a new task to you, what do you do?”,
      • “answer”: “
        1. There must be a reason why manager added that ticket, it could be urgent issues. so i understand him, i will take it
        2. I will explain what I have left in my ticket list, I will put that urgent ticket as top priority to fix it, and other tickets will be pushed after
        3. I will still try to fix other tickets according to their priority, i can work extra hours
        4. If i really cant finish the other tickets, i will ask to move to next sprint or to share to other team members.
        “,
      • “keyword”: “BQ”,
      • “frequency”: 5,
  • “id”: 27,
    • “question”: “How do you debug?”,
      • “answer”: “

        First, we check the application log, like Splunk Log can tell where it has exception. Then we can try to reproduce it in our local environment. Put a breakpoint, and start application in debug mode, when program stop at the breakpoint, we can step into, step over, jump to next breakpoint, check variable values, do expression evaluation.

        REPRODUCE is always the best way to find the bug root cause.

        If it is not an exception, if it is something like performance issue, like page loads slowly, we have many tools to find the reason, like DataDog, Splunk, CloudWatch etc.

        “,
      • “keyword”: “BQ”,
      • “frequency”: 5,
  • “id”: 338,
    • “question”: “Do you have any leader experience”,
      • “answer”: “

        YOU DONT SAY: YOU WERE A LEADER! BUT YOU SAY, YOU HAVE SOME LEADING EXPERIENCE.

        Answer: I was not a leader of the entire team, but I do have some leading experience. Whenever our team have new hires or juniors, I was always the person who onboard them and guide them. I need to assign easy tasks to them and do pair programming with them to help them know more about the applications. I also answer their questions. Basically I was the person who make sure they will be able to catch up with the team pace.

        Also I review our team PR on a regular basis. In [client], I was one of the small group who reviews code for all team members. we have a checklist to go through when we review the code


        “,
      • “keyword”: “BQ”,
      • “frequency”: 2,
  • “id”: 339,
    • “question”: “What do you need to look when you review others code”,
      • “answer”: “
        1. Syntax error
        2. Possible duplicate logic
        3. Method possibilities to split to reusable methods.
        4. Make sure having unit test that covers the part
        5. Check performance improvements, like try to improve the time and space complexity.
        6. Check performance, like try to use cache or eliminate duplicate database calls.
        “,
      • “keyword”: “BQ”,
      • “frequency”: 4,
  • “id”: 428,
    • “question”: “Have you ever worked in a situation where you are on your own, with no other developer and no other infrastructure, just you and PM?”,
      • “answer”: “

        Hint: Key to this problem is show you can work independently. Some project only has 1-2 people and some projects can have 20-40 people.

        Answer: Yes, actually I have worked purely by myself for the project at XXX. I was the only person who worked on the project from scratch, from design the service, to write implementation and test code and even to production release. The project is about XXXX (description). It could me about 3 ( to 6) months to complete the entire project. My manager was very satisfied and customers are still using the application now.

        The project actually helped me a lot as well. It gives me confidence that I can work on independently and solve the entire project by myself. I can learn things quickly and write code fast etc…

        “,
      • “keyword”: “BQ”,
      • “frequency”: 3,
  • “id”: 429,
    • “question”: “Describe a task that you did by yourself”,
      • “answer”: “

        Key: Pick a medium size task and explain it clearly.

        Example 1: While in project XXX, i was given task to write stored procedures for the data transfer in different inventory databases. I was the only person responsible for writing all the database programming. I wrote many triggers, stored procedures, functions, views and database links. I feel it was a great experience to me because I gained all the SQL experiences.

        Example 2: I remember a task at XXXX, we were previously returning all the data in string format and fields are separated with semi colons. However, in some cases, the result string may contain semi colon as part of the contents which we should not parse it as delimiter. Initially, we solve it case by case, but later on, we see it happens more when customer increases. So I proposed and created this task by myself to refine all the logic to use json format instead of the string format. I have to revise all the related logics and have to update about 100 java classes which return this result string. It is a big task but it is also one of the most impacted task to the project.

        Example 3: When I was working on migrating the legacy system to new angular spring boot based system, I was given a task to rewrite the payment flow. Instead of just rewrite, I actually redesigned it and created a template for this workflow migration, i created several base classes and typescript files. With this case, all the future workflow migration just need to extend my template and the base classes. It becomes a new format and rule to the entire project. I become the expert in that project and I created a lot of documentations for that as well.

        “,
      • “keyword”: “BQ”,
      • “frequency”: 5,
  • “id”: 430,
    • “question”: “Describe a time you made a big mistake, what lesson you learnt from it”,
      • “answer”: “

        Key: find a mistake, clearly explain it, and then say how your solve it in a positive way and the lesson you learned in a positive way.

        Example: Mistake: Accidently deleted some data in database and there is no backup. Solve: try to put data back via 1) asking others help 2) reproduce data with some code etc. Lesson learnt: 1) Always backup 2) Always be careful with Update, Delete. etc.

        “,
      • “keyword”: “BQ”,
      • “frequency”: 5,
  • “id”: 431,
    • “question”: “Tell me about a time you have difficulty with a project or with a team member. How you solve it. What strategy did you use to solve them? “,
      • “answer”: “

        For conflicts, always prepare something technical related.

        Answers should always be: When (which project) -> What (what conflicts) -> How (how do you solve it) -> Result (what is the good consequences)

        When: I remember when I was at XXX project, I had a conflict with my team member (from another team).

        What: The conflict is about a ticket/story, the ticket is about XXX, My idea is XXX, his idea is XXX, he does not agree with me. We argue about it.

        How: I think communication is key, so I explain my idea to him and listen to him carefully. As long as it is not personal, it is all about work, I have to be professional. I even write POC/demo to show my idea.

        Result: Finally, 1) if two people cannot reach the same agreement, we escalate to our manager to make a decision and we should all listen to managers OR 2) we both things our ideas have some good parts, so together we make a better plan that combines the goodness of both ideas and it turned out working very well.


        “,
      • “keyword”: “BQ”,
      • “frequency”: 5,
  • “id”: 432,
    • “question”: “Talk about your experience working in a small team and a large team, which one do you prefer”,
      • “answer”: “

        Small team: Pro: 1) efficiency - easy communication, fast communication 2) every one can have chance work on every part of the project, can learn a lot. Cons: 1) limit resources, due to lack of people, many things can be blocked

        Large team: Pro: 1) large project, more users, more traffic, more challenge 2) big family, more culture part. Cons: 1) low efficiency 2) only work on small portion of the entire whole project.

        “,
      • “keyword”: “BQ”,
      • “frequency”: 3,
  • “id”: 433,
    • “question”: “Tell a time you faced a hard deadline, how do you solve it”,
      • “answer”: “
        1. provide detailed example in the project
        2. Solution: 1) Make priority order of the tasks and focus on high priority first, the low priority may be pushed to backlog or next sprint. 2) Work extra time, commit fully to the tasks 3) if still cannot finish or extra time is not allowed in the company, I will request manager to push to next sprint or extend the deadline.
        “,
      • “keyword”: “BQ”,
      • “frequency”: 5,
  • “id”: 434,
    • “question”: “What are the key things you care about in a new team/project?”,
      • “answer”: “

        Some points to mention:

        1. Good team culture, nice working environment
        2. Good skills and new technologies used in the team
        3. You feel you can grow in the team, someday you may become a senior or leading some juniors
        4. You feel being important to the project, you can make contributions and be needed by others as well.
        “,
      • “keyword”: “BQ”,
      • “frequency”: 4,
  • “id”: 435,
    • “question”: “Do you need to work with a business team ever? Describe your daily work with them.”,
      • “answer”: “

        Yes, I need to work with business team pretty much all the time.

        1) we have agile sprint, so at the beginning of each sprint, the entire team of developers and business team need to sit together to discuss about the work to be done in the sprint

        2) whenever I am unclear about the tickets, I would reach out to the business team members directly to discuss about it.

        “,
      • “keyword”: “BQ”,
      • “frequency”: 5,
  • “id”: 436,
    • “question”: “How do you learn something new? How do you start the process?”,
      • “answer”: “

        !! Never mention \”Google\”, \”GPT\”, \”ChatGPT\”, \”Youtube\”


        1. read official documents and tutorial guidelines, they are the most accurate and first-hand study materials.
        2. follow some tutorials or courses on Udemy etc.
        3. Most importantly, I always try the examples, try to implement by myself. The best way to learn new technologies is to implement with it.
        “,
      • “keyword”: “BQ”,
      • “frequency”: 4,
  • “id”: 437,
    • “question”: “What is your team size? What methodology was used?”,
      • “answer”: “

        Team size: developers (in real world, it could be 2 - 20, when you answer, safe to say any number in 4-10)

        Mostly we don’t business and QA inside the team, when refer to \”team\”, we refer to \”dev team\”, but when having scrum meetings, project manager, scrum master, dev, QA all join the meetings, including daily standup meeting

        Methodology: Agile Sprint.

        “,
      • “keyword”: “BQ”,
      • “frequency”: 4,
  • “id”: 438,
    • “question”: “Do you have experience working in a global team? “,
      • “answer”: “

        Yes. We have team members in different countries, we have part of the team in India. So i often need to have meetings with them in late night or early mornings. It is very common to have global team nowadays.

        “,
      • “keyword”: “BQ”,
      • “frequency”: 3,
  • “id”: 439,
    • “question”: “Your degree is in XXX; why do you switch to a developer?”,
      • “answer”: “

        Just tell your personal story.

        Some points to consider 1) I always like programming 2) original degree is hard to find a job 3) I learnt programming when i was pursuing my degree in XXX etc.

        “,
      • “keyword”: “BQ”,
      • “frequency”: 4,
  • “id”: 441,
    • “question”: “How do you debug (in your IDE)?”,
      • “answer”: “

        Java IDE

        1. put breakpoints in the code
        2. run project
        3. code will stop at the breakpoints, we can choose to step into/over/skip the breakpoint
        4. check variable values Or evaluate expressions.

        Frontend

        1. open chrome browser DevTools
        2. \”Sources\” tab will list the file and we can put breakpoints in the code.
        3. \”Network\” tab will show traffic, we can check the request status, payload and response
        4. \”Elements\” tab will show the html structure, we can locate the html elements
        5. \”Console\” tab will show the logs and also can be used to evaluate the local variables and expressions.


        “,
      • “keyword”: “BQ”,
      • “frequency”: 3,
  • “id”: 442,
    • “question”: “Have you used task management tools like Jira, Rily, and Confluence?”,
      • “answer”: “

        YES.

        The task management tools like Jira can be used to run the scrum meetings, it will list the sprint tickets (task, story, issue etc), each ticket can have status like \”TO DO\”, \”In Progress\”, \”Done\” etc

        “,
      • “keyword”: “BQ”,
      • “frequency”: 3,
  • “id”: 443,
    • “question”: “Can you share the most enjoy point in your current company, or what you really expect for your next role? “,
      • “answer”: “

        Same as the \”what your look for in the new team\”

        1. New skills/technologies
        2. Good team culture, open communication etc


        “,
      • “keyword”: “BQ”,
      • “frequency”: 5,

CICD

  • “id”: 30,
    • “question”: “Can you talk about CI/CD?”,
      • “answer”: “

        KeyPoints:

        1. CICD is continuous integration and continuous deployment. In the project, we usually use Jenkins with its pipeline scripts to implement CICD.
        2. The script contains multiple parts. The \”stages\” parts list each stage and the steps inside. For example, stage one is \”checkout\” and steps in this stage are like using git clone to checkout the code from repository and then use maven to package it etc. Another part of the script is \”post\” part which handles different result. For example, what to do when the build is success or failure, what to do when the test cases failed etc.
        3. CICD usually starts from when the code is pushed to the target branch, and then it includes checkout and package the code, deploy the jar/war, run the test cases and send reports etc. It could cover from dev to QA/Staging environment, but usually does not cover production.
        “,
      • “keyword”: “CICD”,
      • “frequency”: 5,

Cloud AWS

  • “id”: 297,
    • “question”: “How to deploy microservice in AWS container”,
      • “answer”: “

        MicroService is mostly deployed to AWS EKS service (Elastic Kubernetes Service). To deploy we need to

        1) Use eksctl to create the cluster and update the kubeconfig file to use new EKS cluster.

        1) Create a cluster and define the deployment.yaml and service.yaml. Deployment.yaml is a file that specify the metadata for deployment, including apiVersion, number of replications and container image and port etc. The service.xml defines the details of each service pods and how to access them, aka, how to communicate between pods/services.

        2) Use \”kubectl\” command to apply the deployment and service configurations: kubectl apply -f deployment.yaml kubectl apply -f service.yaml



        “,
      • “keyword”: “Cloud AWS”,
      • “frequency”: 4,
  • “id”: 317,
    • “question”: “AWS difference between parameter store and secret manager”,
      • “answer”: “

        Parameter Store: 1) mainly store configurations. 2) Does not support auto rotation. 3) Use hierarchy structure to store parameters

        Secret Manager: 1) mainly store database credentials, API keys and other sensitive information. 2) Auto rotation support 3) Not using hierarchy structure.

        “,
      • “keyword”: “Cloud AWS”,
      • “frequency”: 1,
  • “id”: 318,
    • “question”: “AWS where to store certificate file”,
      • “answer”: “

        For SSL/TLS related certification, we can use AWS Certificate Manager(ACM) or AWS Identity and Access Management(IAM) directly

        For customized certificate data, we can store it in the Parameter Store.


        “,
      • “keyword”: “Cloud AWS”,
      • “frequency”: 1,

Docker

  • “id”: 235,
    • “question”: “How to use docker in the Spring Boot?”,
      • “answer”: “

        Docker is a container with flexible memory management and has dockerHub that you can upload or download images

        To use with Spring boot, 1) include docker dependency 2) add a Dockerfile

        “,
      • “keyword”: “Docker”,
      • “frequency”: 2,

ElasticSearch

  • “id”: 347,
    • “question”: “ElasticSearch why do you use it”,
      • “answer”: “

        Elastic Search is an engine to make search data very faster. It is usually put between backend application and database, it works like a cache or a database. Some people think it is a databse, but it is actually defined to only optimize search.

        ElasticSearch use index to cache out all the fields you want to search, just like the database Non-Cluster Index.

        For example, you have JSON:

        Product{\n   \”id\” : \”234323423434\”,\n   \”name\” : \”a complete guide to java\”,\n   \”description\” : \”This is a book as a complete description to java, it is mainly focused on java, spring, java 8, jdbc, spring framework. the author is intended to help any one with no or strong experience in java or any programming language, I am very long..\”,\n   \”many other fields\”\n}\n

        You can add the fields or the description texts as the index so you can search any text match in the name or description. It is very fast.

        “,
      • “keyword”: “ElasticSearch”,
      • “frequency”: 3,
  • “id”: 348,
    • “question”: “How do you use elasticSearch in your java application”,
      • “answer”: “

        Spring boot project:

        If using JPA: (https://www.baeldung.com/spring-data-elasticsearch-tutorial)

        • We need to add elastic search to our configuration class, Elastic Search has many clients, we can use the RestHighLevelClient to work with JPA.
        • Entity need to add @Document(indexName = \”XXX\”, type = \”XXX\”) to do ORM mapping.
        • Repository needs to extend ElasticSearchRepository

        When it is complex that can not be handled by JPA repository: (https://reflectoring.io/spring-boot-elasticsearch/)

        • Use ElasticsearchOperations object, it has many method, like index() and search() methods.
        • Use NativeSearchQueryBuilder object to build a complex query and run it directly with JPA @Query


        “,
      • “keyword”: “ElasticSearch”,
      • “frequency”: 2,

Git

  • “id”: 41,
    • “question”: “Git command you used in the project”,
      • “answer”: “

        There are 2 common repositories working with git: Github and Bitbucket

        • Clone from repository as new project: git clone URL
        • Steps to commit change to remote repository: git add (files), git commit (-m message), git push
        • get remote data: git pull or git fetch (git fetch just read remote repository, git pull is git fetch + push to current local branch)
        • rebase and merge: git rebase, git merge
        • create a branch: git checkout branchName
        • delete a branch: git branch -d branchName
        • to override current branch with remote: git reset –hard remoteHead


        “,
      • “keyword”: “Git”,
      • “frequency”: 2,
  • “id”: 358,
    • “question”: “How do you release from the git reposiotry”,
      • “answer”: “

        Use git tag.

        In Git, a tag is a named pointer to a specific commit. It is used to mark specific points in Git history, such as release versions, significant milestones, or any other notable events. Tags are lightweight and can be created quickly and easily without affecting the repository’s history.

        Git tags are typically used to:

        1. Mark a specific point in history: You can create a tag to mark a specific commit as a significant point in the repository’s history, such as a release version or a major milestone.
        2. Identify releases: You can use tags to identify releases, which are specific versions of your software that have been tested and are ready for production use. This makes it easy to track which version of your software is deployed in production and to roll back to a specific version if necessary.


        “,
      • “keyword”: “Git”,
      • “frequency”: 1,
  • “id”: 367,
    • “question”: “How do you combine several commits together”,
      • “answer”: “

        Use squash. Example to use:

        1. If you need to combine the last N commits together: git rebase -i HEAD~N (N is the number of commits)
        2. If you have a branch F which contains many commits, you want to merge F branch into your current branch: git merge –squash F
        “,
      • “keyword”: “Git”,
      • “frequency”: 1,
  • “id”: 368,
    • “question”: “What is git cherry-pick”,
      • “answer”: “

        Cherry-pick is to pick a particular commits into your current branch.

        For example, if you have two branches with commits (DEV: a -> b -> c -> d) and (FEATURE: b -> x -> y -> z)

        if you are currently on DEV branch, but you want to have the y commit from FEATURE onto DEV too, you can do git cherry-pick y

        “,
      • “keyword”: “Git”,
      • “frequency”: 1,
  • “id”: 369,
    • “question”: “difference between git and svn”,
      • “answer”: “

        Both are used to maintain work repository (where your code will stay)

        Git is a distributed model, good for large team collaboration. You have a main branch, for every ticket, you can create feature branch out from the main branch, once you are down, you can merge the feature back to the main branch.

        SVN is a centralized model, good for small team or straightforward projects. You have a main repository called trunk, all developers will commit to this trunk

        “,
      • “keyword”: “Git”,
      • “frequency”: 2,
  • “id”: 370,
    • “question”: “difference git merge and rebase”,
      • “answer”: “

        Suppose you have 2 branches: f1 and f2 bot derived from main branch and both have some commits. now you are on f1 and you want the commits from f2.

        Merge: combine all commits from f1 and f2 as a new commit and put on f1. so merge will create a new commit.

        Rebase: your f1 is based on main, rebase is to let your f1 branch based on f2. it will make f2 as the new base for f1.

        link: https://www.atlassian.com/git/tutorials/merging-vs-rebasing

        “,
      • “keyword”: “Git”,
      • “frequency”: 2,

Java

  • “id”: 43,
    • “question”: “Abstract class vs. Interface. When to use abstract class and when to use interface?”,
      • “answer”: “

        Abstract Class: 1) still a class, so you can only extend one abstract class. 2) Have both concrete method and abstract method.

        Interface: 1) you can implement many interfaces 2) Only has abstract method. 3) In java 8, interface can have default and static method

        Usage:

        Most of the places, interfaces are preferred, but if you need some common method to inherit automatically, you can use abstract class.


        FOLLOW UP:

        since java 8 allows default and static method in interface, what is the essential difference between abstract class and interface?

        A: abstract class can have fields, the fields can hold value and track the status of the object itself. Interface cannot have fields, it can only have constants.

        “,
      • “keyword”: “Java”,
      • “frequency”: 5,
  • “id”: 44,
    • “question”: “New feature of Java 8. Give an example of how you use them in your project”,
      • “answer”: “

        Top of java 8 features:

        • Functional interface: is an interface that only has ONE abstract method. We can use lambda expression to implement that method
        • Lambda expression: () -> {}. It is to implement functional interface and anonymous class. You can pass a lambda function to a method as argument
        • Optional: to prevent NullPointerException in runtime. for example, Optional<Employee>, it has methods like isPresent(), isEmpty(), get(), orElse() etc.
        • Default method in interface:
        • Why need it: When a interface has 10 children classes, all children classes need the same method, before java 8, you need to implement this same method in every child class, but with default method, you just write it once as default method in interface, all children will automatically inherit it.
        • If a class implements 2 interfaces and both interfaces has same \”default\” method, then there will be exception because the class does not know which on to use, the class then has to override them.
        • Stream API: a group of methods to handle collections easily. like, filter, map, flatmap, sorted, reduce, groupingBy, joining etc.
        • Intermediate operator vs terminator operator
        • flatmap vs map
        • Java Date Time API update: new date time API has default timezone, so developer does not need to set it.
        “,
      • “keyword”: “Java”,
      • “frequency”: 5,
  • “id”: 45,
    • “question”: “Comparable vs. Comparator”,
      • “answer”: “

        Comparable is an interface. (In java, \”able\” is mostly an interface). You use a object class to implement comparable interface and implement its compareTo method. int compareTo(Object B)

        Comparator is a class, many times used as anonymous class, like in Collections.sort(list, comparator), you need to implement the compare(Object A, Object B) method.

        “,
      • “keyword”: “Java”,
      • “frequency”: 3,
  • “id”: 46,
    • “question”: “Types of Exceptions and how do you deal with exceptions in your project?”,
      • “answer”: “
        • Java Exception hierarchy:

        throwable – error + exception.

        error is like system error which can NOT be handled by program, like OutOfMemoryError, StackOverflowError etc.

        Exception – compile/checked exception + runtime/unchecked exception. Checked exception can be handled using try catch block, like the SQLException, Thread InterrupttedException; Unchecked exception happens in runtime, like NullPointerException, IndexOutOfBoundException etc.

        • self defined exception: Just extend the java Exception class and define your own constructor and message
        • How to deal with exception
        • Java: use Try/Catch/Finally block or use Throws on method level.
        • Spring: use @ExceptionHandler @ControllerAdvice on the controller level to catch exception in whole application



        “,
      • “keyword”: “Java”,
      • “frequency”: 5,
  • “id”: 47,
    • “question”: “Generics and how do you use generics in your project?”,
      • “answer”: “

        Generics is used to prevent the error when converting data from one type to another type or just to make a method work for multiple type of data.

        public V getFirstElement(List<T> list) {\n    return list.isEmpty() ? null : list.get(0);\n}\n

        Usually T is used to present Type and V is used to represent Value.

        With generics, we can 1) make sure the type is safe at compile time. 2) make a method or class work for different type of data.

        “,
      • “keyword”: “Java”,
      • “frequency”: 3,
  • “id”: 48,
    • “question”: “Java OOP 4 principles, and explain each of them”,
      • “answer”: “

        PIEA:

        Polymorphism: 2 types, static polymorphism/overload and dynamic polymorphism/override. overload is you have 2 methods in the same class, they have SAME method name but different type or numbers of parameters . They can have different access modifier too (they are basically just 2 different methods happening to have the same name).

        Override: 2 methods with same method signature(method name, parameters) in Parent and Child class, but different implementations. The child method must have same or broader access modifier than parent method.

        Inheritance: One class can only inherit one parent class, one class can implement many interfaces

        Encapsulation: This is about who can access your method or fields, Access modifer: Public, Private, Protected, Default.

        Abstraction: abstract class and interfaces.

        “,
      • “keyword”: “Java”,
      • “frequency”: 5,
  • “id”: 49,
    • “question”: “If java 8 allows default method in interface, so what is the real difference between interface and abstract class?”,
      • “answer”: “

        abstract class can have regular fields which can host the data, but interface cannot, interface can only have constants.

        “,
      • “keyword”: “Java”,
      • “frequency”: 4,
  • “id”: 52,
    • “question”: “Serialization, What is Serializable and SerialVersionUID?”,
      • “answer”: “

        Serialization is to convert the java object into byte stream so you can save it to file system or database or send across network.

        To implement serialization, just implement serializable interface. private and final fields can be serialized, but static field cannot, because static field does not go with objects.

        When a \”serialVersionUID\” is presented, it is used to match the byte stream with current java object, if they match, the object can be de-serialized, otherwise, exception will be thrown.

        “,
      • “keyword”: “Java”,
      • “frequency”: 4,
  • “id”: 53,
    • “question”: “HashMap: how does it work internally, what is hash collision”,
      • “answer”: “

        VERY IMPORTANT!!!

        HashMap has 2 key important methods, equals() and hashcode()

        Think there is a list of buckets, each bucket is identified by a hashcode.

        When you call get(key), the key will first be passed to hashcode() method and a hashcode is returned, Use this hashcode, you can locate the corresponding bucket. Inside that bucket, it is a tree structure of all key-value pairs that share the same hashcode. so to find the target key-value pair, the equals() method will be called, and once found, the value will be returned.

        Hash collision: all the key-value pair that shares the same hashcode stays in same bucket, that is called hash collision. It is preferred in hashmap, because if there is NO hash collsion, each key-value pair will stay in one bucket, then there will be too many buckets, causing too much memory. If all entries in one bucket, then it is hard to search the target. The hash collision makes the time complexity of hashmap to O(1) because of hashing.

        Why hashmap use Tree structure in bucket: Previously it is a list, but then changed to tree, because tree has left node smaller than root and root smaller than right. So the search is O(logn), much faster than list.


        “,
      • “keyword”: “Java”,
      • “frequency”: 5,
  • “id”: 59,
    • “question”: “What is the Functional Interface? Java 8 built in functional interface?”,
      • “answer”: “

        Function interface is in java 8, it can only contain Single Abstract Method. You can use lambda to implement it.

        Java built-in function interface:

        Consumer: the method takes input but NO output. Example: System.out.println(input)

        Supplier: the method takes NO input but HAS output. Example: RandomNumberGenerator.

        Predicate!: the method return boolean type, true or false, it is widely used in stream().filter(predicate) to filter out collections

        Function: the method takes INPUT and RETURN output. it is used to convert data, like stream().map(function)

        Binary Operator: the method has 2 input and 1 same type output: like int add(int a, int b)

        there are other types, but you only need to anser, the top 4.

        “,
      • “keyword”: “Java”,
      • “frequency”: 5,
  • “id”: 62,
    • “question”: “HashTable vs. HashMap”,
      • “answer”: “

        HashTable: thread safe, synchronized, low performance

        HashMap: not thread safe, good performance

        Simliar group:

        Vector vs ArrayList.

        “,
      • “keyword”: “Java”,
      • “frequency”: 3,
  • “id”: 67,
    • “question”: “Implement a singleton”,
      • “answer”: “

        REMEMBER THIS:

        import java.io.Serializable;\n\n\npublic class Singleton implements Cloneable, Serializable {\n\n\n    private static Singleton instance;\n\n\n    private Singleton() {}\n\n\n    public static Singleton getInstance() {\n        if (instance == null) {\n            synchronized (Singleton.class) {\n                if (instance == null) {\n                    instance = new Singleton();\n                }\n            }\n        }\n        return instance;\n    }\n\n\n    @Override\n    protected Object clone() throws CloneNotSupportedException {\n        throw new CloneNotSupportedException(\”Cloning of Singleton is not allowed.\”);\n    }\n\n\n    protected Object readResolve() {\n        return getInstance();\n    }\n}\n\n\n
        “,
      • “keyword”: “Java”,
      • “frequency”: 5,
  • “id”: 68,
    • “question”: “Do you know about the Executor Service and Future?”,
      • “answer”: “

        Executor Service has thread pool. It can be used run multi threads in parallel.

        Thread Pool:

        • Fixed Thread Pool: create fixed number of threads no matter you will use it or not
        • Cached Thread Pool: create threads based on needs, if new task is coming and no threads available, it will create new thread. If a thread idle for some time, it will be terminated.
        • Scheduled Thread Pool: can be used to set delays and schedule tasks
        • Fork Join Pool: It uses a work-stealing algorithm, the tasks are break into many small pieces. If some threads are done with their tasks, they can steal other threads task to run. This will have better performance.

        When the task has return (callable tasks)

        Use Future object to host the return. The tasks are like async process, they are submitted, and later on, if there is a return comes back, the return will be stored in Future object.

        Future has method like get() to get result or isDone() to check if task is completed.

        “,
      • “keyword”: “Java”,
      • “frequency”: 5,
  • “id”: 69,
    • “question”: “Explain the Factory design pattern”,
      • “answer”: “

        A factory is a method that if you pass an input, it can return the corresponding objects:

        REAL PROJECT Example:

        1. Credit card payment, if enter \”MasterCard\”, will return mastercard payment object, if enter \”Visa\”, will return visa payment etc.
        2. Database Connection, if pass in \”oracle\”, will return oracle connection object, if pass \”mysql\”, will return mysql payment object.


        Example:

        public interface DatabaseConnection {\n    void connect();\n}\npublic class MySqlConnection implements DatabaseConnection {\n    @Override\n    public void connect() {\n        // Implementation details for connecting to MySQL\n    }\n}\n\npublic class PostgreSqlConnection implements DatabaseConnection {\n    @Override\n    public void connect() {\n        // Implementation details for connecting to PostgreSQL\n    }\n}\npublic class DatabaseConnectionFactory {\n    //driver method takes dbType and will get the corresponding type\n    public static DatabaseConnection createDatabaseConnection(String dbType) {\n        if (dbType.equalsIgnoreCase(\”MySQL\”)) {\n            return new MySqlConnection();\n        } else if (dbType.equalsIgnoreCase(\”PostgreSQL\”)) {\n            return new PostgreSqlConnection();\n        }\n        // Handle other database types or throw an exception for unknown types\n        throw new IllegalArgumentException(\”Unsupported database type: \” + dbType);\n    }\n}\n\n\n\n\n
        “,
      • “keyword”: “Java”,
      • “frequency”: 4,
  • “id”: 70,
    • “question”: “What design patterns did you worked on before?”,
      • “answer”: “

        Singleton, Factory + One more (You pick the 3rd one, You need to know how to explain and how to write it)

        “,
      • “keyword”: “Java”,
      • “frequency”: 5,
  • “id”: 71,
    • “question”: “How to custom an Exception?”,
      • “answer”: “

        Just extend the \”Exception\” class

        public class CustomException extends Exception {\n    \n    String message;\n\n    public CustomException(String message) {\n        super(message);\n        //other logic if needed.\n    }\n}\n
        “,
      • “keyword”: “Java”,
      • “frequency”: 4,
  • “id”: 72,
    • “question”: “OutOfMemoryError vs StackOverflowError vs Memory Leak”,
      • “answer”: “

        OutOfMemoryError:

        • Cause: JVM Heap memory is all used. Like read too large file into memory OR infinite loop keep creating objects.
        • Prevent: batch read file; avoid creating unused object; increase heap memory with XmX setting etc

        Memory Leak:

        • Cause: objects are not used anymore, but still not garbaged collected. Like \”static\” objects.
        • Prevent: avoid creating too many static objects and clean unused objects
        • !!! Heap dump can show if there is memory leak. (WebSphere or JProfiler can do heap dump)

        StackOverflowError:

        • cause: Too many references in stack causing stack memory out
        • Prevent: avoid recursive calls without proper terminations, avoid too many references not deleted.


        “,
      • “keyword”: “Java”,
      • “frequency”: 3,
  • “id”: 75,
    • “question”: “java 8: Different types of \”method reference\””,
      • “answer”: “

        In java 8, functional interface just has one abstract method, so we can use method reference to refer to it because the method input is fixed.

        There are 4 types of method references:

        1. Reference to a Static Method:

        \t\t\t\t\t– Syntax: ClassName::staticMethodName

        \t\t\t\t\t– Example: Math::max refers to the max method of the Math class.

        1. Reference to an Instance Method of a Particular Object:
        2. Syntax: object::instanceMethodName
        3. Example: list::size refers to the size method of the list object.
        4. Reference to an Instance Method of an Arbitrary Object of a Particular Type:
        5. Syntax: ClassName::instanceMethodName
        6. Example: String::toUpperCase refers to the toUpperCase method of the String class.
        7. Reference to a Constructor:
        8. Syntax: ClassName::new
        9. Example: ArrayList::new refers to the constructor of the ArrayList class.
        “,
      • “keyword”: “Java”,
      • “frequency”: 2,
  • “id”: 78,
    • “question”: “What is Optional?”,
      • “answer”: “

        Optional is introduced in java 8, to prevent null pointer exception.

        For example, if you have employee.getAddress().getCity(), in runtime, if employee is null, getAddress() will throw exception.

        Wen can use Optional<Employee>, optional has method like ifPresent(), isPresent(), get(), orElse() etc.

        “,
      • “keyword”: “Java”,
      • “frequency”: 4,
  • “id”: 90,
    • “question”: “ArrayList vs LinkedList, which one to choose?”,
      • “answer”: “

        Structural: Arraylist has index and get(index) method. LinkedList: has only header and next pointer.

        For TIME complexity,

        if you know the index of target element in arraylist, arraylist is best O(1), if you dont know index, arraylist and linkedlist are the same O(n)

        For Space complexity,

        ADD element ArrayList is O(n) because you have to shift all elements after. But linkedlist is O(1) because you just change the pointer.




        “,
      • “keyword”: “Java”,
      • “frequency”: 4,
  • “id”: 91,
    • “question”: “How does Java class loader work?”,
      • “answer”: “

        When java loads a class, it has to load the parent first, but one class is only loaded once.

        Bootstrap class loader: is parent of all class loaders. it loads the core java in jre/lib.

        Extension class loader: it loads all java standard extensions or 3rd party extensions

        Application class loader: it loads java classes from class path, like the class developer wrote.

        It is a tree like hierarchical structure.

        “,
      • “keyword”: “Java”,
      • “frequency”: 2,
  • “id”: 92,
    • “question”: “Java 8: Intermediate operator and terminal operator in stream api”,
      • “answer”: “

        Intermediate operator:

        • refer to operators that return another stream which can be appended by another operator. like stream().map(), the map is an intermediate operator because we can chain it with more operations.
        • Example: filter, map, sorted

        Terminal operator:

        • refer to final operators in stream api. We cannot append more operations after terminal operator.
        • Example: forEach, collect, count, findAny
        “,
      • “keyword”: “Java”,
      • “frequency”: 5,
  • “id”: 95,
    • “question”: “How do you create a thread?”,
      • “answer”: “

        There are 2 ways: extend the Thread class or Implement the Runnable interface

        “,
      • “keyword”: “Java”,
      • “frequency”: 4,
  • “id”: 98,
    • “question”: “How does arraylist work internally?”,
      • “answer”: “

        Internally ArrayList is implemented by Array. Initial size is 10. When the array is filled about to full size, it will create a large array (default double size) and copy old data into new array so there will be more space to add elements

        “,
      • “keyword”: “Java”,
      • “frequency”: 4,
  • “id”: 104,
    • “question”: “How does thread communicate/interact/share data with each other?”,
      • “answer”: “

        Communicate/Interact:

        1. Wait() and Notify() method: wait() method will let current thread pause and release lock to other threads, this current thread will only be waken up and get lock if other threads call notify() or notifyAll().
        2. Executor service in java concurrent package can interact threads, like the WorkStealingPool use join and fork to interact between threads to improve performance. CompletableFuture also can chain threads.


        If asking how to share data between threads:

        1. Let threads visit same data memory, like same object, same database table, same file or cache
        2. Use message queues. one thread sending data, another thread consume data
        “,
      • “keyword”: “Java”,
      • “frequency”: 3,
  • “id”: 106,
    • “question”: “What are the meaning of thread methods: join, wait, sleep, yield”,
      • “answer”: “

        JOIN: to let current thread wait until another thread finishes. So it is used to let threads run in order.

        WAIT: wait is to RELEASE lock and let other threads run. this thread will resume only when other threads call notify(), notifyAll()

        SLEEP: this thread will NOT RELEASE the lock, it lets current thread to sleep for given time and then it will restart by itself. Different from wait method, the sleep will not release lock and will resume by itself.

        YIELD: if some threads share the same priority, yield method is to hold current thread and let others run first.

        “,
      • “keyword”: “Java”,
      • “frequency”: 3,
  • “id”: 113,
    • “question”: “Shallow copy vs. Deep copy”,
      • “answer”: “

        If you have an object, for example Employee e;

        Shallow Copy: Employee f = e; //you are just copying the reference e to f. Now both e and f pointing to same one object.

        Deep copy: Employee f = new Emplyee(), f.setName(e.getName()); //you create a new employee f, and then you copy every field in employee e to f. so f and e having same contents. But they are TWO objects in memeory.

        “,
      • “keyword”: “Java”,
      • “frequency”: 1,
  • “id”: 115,
    • “question”: “How does ConcurrentHashMap works?”,
      • “answer”: “

        ConcurrentHashMap is thread safe and it has better performance then SynchornizedMap

        ConcurrentHashMap divides its internal buckets into 16 segments. When 1 thread visits the map, it will lock that segement, and the other threads can still visit other segments.

        The SyncrhonziedMap will lock the entire map, so its performance is not as good as ConcurrentHashMap

        “,
      • “keyword”: “Java”,
      • “frequency”: 2,
  • “id”: 117,
    • “question”: “What is ConcurrentModificationException and how to handle it?”,
      • “answer”: “

        ConcurrentModificationException is thrown when you have multiple threads try to modify the NON-thread-safe java collections, like ArrayList, HashSet, HashMap etc.

        To handle:

        1. When modify collection, like remove element, using Iterator instead of for loop.
        2. Use thread safe collection, like CopyOnWriteArrayList, ConcurrentHashMap, CopyOnWriteHashSet etc.
        “,
      • “keyword”: “Java”,
      • “frequency”: 4,
  • “id”: 118,
    • “question”: “Relationship between equals() and hashcode()”,
      • “answer”: “

        In HashMap, when you do a get(key) call, first key is passed to hashcode() to locate a bucket, and then inside bucket, call equals() to find the entry.

        HashCode() and Equals() should use exactly the same object fields.

        1. If two objects are equal according to the equals() method, they must have the same hash code (equal objects must produce equal hash codes).
        2. However, the reverse is not necessarily true: two objects with the same hash code may or may not be equal.


        “,
      • “keyword”: “Java”,
      • “frequency”: 3,
  • “id”: 119,
    • “question”: “How to make class immutable?”,
      • “answer”: “

        Immutable means it cannot be changed. So we should prevent all ways to change a class and its object

        • make class final, public final class ..so we cannot extend and modify it
        • make fields private, so we cannot modify it directly from outside
        • Do NOT provide setter method.
        • in the get method, don’t return fields directly, return copy of the fields.
        “,
      • “keyword”: “Java”,
      • “frequency”: 5,
  • “id”: 121,
    • “question”: “What is the deadlock? How to FIND it? How to avoid it?”,
      • “answer”: “

        Deadlock is when you have 2 threads, Thread1 is waiting Thread2 to release lock on an object while Thread2 is waiting for Thread1 to release lock on an object. They are waiting on each other.

        To find:

        use Thread dump, thread dump is like to take a snapshot/photos of all current threads, so it will show if there are deadlocks.

        JProfiler/FastThread/JStack are all tools can show thread dump.

        To prevent:

        1) For all shared objects/resources by both threads should be combined as a whole entity and should be locked together.

        2) Set global orders for the shared objects, so that threads will only lock them in same order.

        “,
      • “keyword”: “Java”,
      • “frequency”: 3,
  • “id”: 127,
    • “question”: “Difference between HashSet and TreeSet, HashMap and TreeMap”,
      • “answer”: “

        TreeSet the key is sorted in binary tree order. (left smaller than root, root smaller than right)

        Same for HashMap vs TreeMap. TreeMap the key is also sorted in tree structure. So hashMap time complexity is O(1) because of hashing, but TreeMap is O(logn) for binary search.

        Benefit of tree structure is that the keys are ordered, so you can quickly know if a key exists in that structure.

        “,
      • “keyword”: “Java”,
      • “frequency”: 2,
  • “id”: 131,
    • “question”: “When implements Serializable, what if you don’t define the serialVersionUID? What if you remove it?”,
      • “answer”: “

        System will use a default SerialVersionUID

        “,
      • “keyword”: “Java”,
      • “frequency”: 1,
  • “id”: 132,
    • “question”: “What is fail-fast and fail-safe?”,
      • “answer”: “

        Fail-Fast: detects the possible failures before it happens. Like when you loop element of HashMap and try to remove it. It will fail fast with ConcurrentModificationException

        Fail-safe: Use the data structure that can handle ConcurrentModificationException by itself, so it will not throw exception, like when loop and remove elements from ConcurrentHashMap.

        “,
      • “keyword”: “Java”,
      • “frequency”: 3,
  • “id”: 135,
    • “question”: “Map vs. FlatMap”,
      • “answer”: “

        In Java 8 stream api.

        Map is to convert data, it takes a function as input.

        FlatMap is Map + Flat. It can handle 2 dimensional matrix, and apply Map on each row and then Flat each row result into a final 1 dimensional array.

        “,
      • “keyword”: “Java”,
      • “frequency”: 4,
  • “id”: 138,
    • “question”: “HashMap vs LinkedHashMap and HashSet vs LinkedHashSet”,
      • “answer”: “

        HashMap vs LinkedHashMap; HashSet vs LinkedHashset

        HashMap/HashSet: key is not ordered, random order.

        LinkedHashMap/LinkedHashSet: key is in insertion order - keep the order when they are inserted.

        “,
      • “keyword”: “Java”,
      • “frequency”: 4,
  • “id”: 139,
    • “question”: “why using static and why not?”,
      • “answer”: “

        What: static is a keyword to make sure there is only 1 copy of the resource. like static field, static method or static inner class

        For What: static resources can be shared across whole applications, like use static block so initalize some global data. Static method can be used as helper or util methods, we can just call Class.StaticMethod so we dont need to create instances.

        Why Not: Static object will not be garbage collected. They will stay in memory forever. Too many static objects can cause memory leak.

        “,
      • “keyword”: “Java”,
      • “frequency”: 3,
  • “id”: 163,
    • “question”: “what is SOLID principle?”,
      • “answer”: “

        SOLID represents 5 principles

        S: Single responsibility - a class does its own thing, like Employee class only does things, will not handle Department things.

        O: open for extension and close for modification. A child class can extend a parent class but cannot modify the parent class.

        L: Liskov Principle, The Liskov Substitution Principle (LSP) applies to inheritance hierarchies such that derived classes must be completely substitutable for their base classes.

        I: The Interface Segregation Principle (ISP) states that clients should not be forced to depend upon interface members they do not use. In other words, do not force any client to implement an interface that is irrelevant to them.

        D: The Dependency Inversion Principle (DIP) states that we should depend on abstractions (interfaces and abstract classes) instead of concrete implementations (classes). The abstractions should not depend on details; instead, the details should depend on abstractions.

        “,
      • “keyword”: “Java”,
      • “frequency”: 4,
  • “id”: 295,
    • “question”: “How to make a global count in multithreading environment”,
      • “answer”: “

        A: Use AtomicInteger. \”Atomic\” is to keep object/field thread safe in multi-threading environment. There are AtomicInteger, AtomicBoolean, AtomicReference etc

        “,
      • “keyword”: “Java”,
      • “frequency”: 2,
  • “id”: 296,
    • “question”: “Difference: Synchronized, ThreadLocal, Volatile, AtomicInteger”,
      • “answer”: “

        Synchronized: it is to make resource thread safe in multi-threading environments, can be used on block of code OR method. If we have Employee object and it contains another address object and updateEmployee() method. If we put synchronized on the method, it will lock the whole employee object. If we use synchronized(address) in the code, it will only lock the address field, will not lock whole employee object, So the synchronized block has better performance.

        ThreadLocal: If a variable is defined as ThreadLocal, then when a thread gets this variable, it will gets its own copy, so when this thread update this variable, it only updates its own copy, the other copies used by other threads will not be affected.

        Volatile: If a variable is volatile, it is kept at a core main memory. All threads will only read and update this main copy. They will not have their own copy. All threas share exactly the same main copy. It guarantees that if one thread updates the value, the other threads will get that updated value because there is only 1 copy.

        AtomicInteger: AtomicInteger/AtomicBoolean/AtomicReference etc: the ‘atomic’ is to make sure the operations on the variable is a single operation and cannot be splitted further. It is typically used as a Global Counting and prevent thread race conditions.

        “,
      • “keyword”: “Java”,
      • “frequency”: 5,
  • “id”: 303,
    • “question”: “How does string works? Why is String immutable in Java?”,
      • “answer”: “

        String is immutable in java, means once you create a string object, you cannot change it anymore. If you want to use mutable string, use StringBuilder instead.


        How string memory works:

        String s1 = \”abc\”;\nString s2 = new String(\”abc\”);\nString s3 = \”abc\”;\nString s4 = new String(\”abc\”);\nString s5 = \”abc\”.intern();\n

        In memory, there is a \”constant pool\” which only stores the quoted string, like \”abc\”, it will not have duplicates in this constant pool. So when we create s1, it goes to constant pool. S2 is created by new String() constructor, whenever we call this constructore, we create a separate copy in the heap memory, not in the constant pool. For intern() method, it will check if the constant pool has a copy, it will use it, if not, it will create one copy in the constant pool,.

        So s1 == s3 == s5 != s2 != s4


        Why is string immutable:

        1. So we can use it in many places, like as Map key.
        2. We can use it for security reasons, like store passwords or keys
        3. It will be thread safe, multi-thread cannot change the value.
        4. We can use for caching and hashing.. like as the Cache key or used in other APIs.
        “,
      • “keyword”: “Java”,
      • “frequency”: 5,
  • “id”: 310,
    • “question”: “What’s Garbage collection types and Whats new in java 8? “,
      • “answer”: “

        Types of GC:

        1. Serial Garbage Collector: Uses only single thread to perform garbage collection. Good for small sized heaps.
        2. Parallel Garbage Collector: Use multiple threads to in parallel. Good for multi-core systems, like systems with high throughput.
        3. CMS (Concurrent) Garbage Collector: perform GC concurrently with application execution. Used for system requires very low-latency.
        4. G1(Garbage-First) Garbage Collector: It is to balance between low-latency and high throughput. It divides heap into regions and perform GC with each region.

        What’s new in Java:

        1. MetaSpace: Preivouly java use fixed size for Permanent Generation (store metadata and internal code), java 8 introduces metaspace which is flexible based on system memeory.
        2. G1 is made as default GC for large heaps.


        Java allows you to choose different GC algorithms based on your JVM version. Common GC options include -XX:+UseSerialGC, -XX:+UseParallelGC, -XX:+UseConcMarkSweepGC, and -XX:+UseG1GC.

        “,
      • “keyword”: “Java”,
      • “frequency”: 4,
  • “id”: 321,
  • “id”: 330,
    • “question”: “New features in java 11 and 17”,
      • “answer”: “

        Java 11

        1. Local variable in lambda expression. Not you can use var to define local variables in java 11.
        2. New Garbage Collector: like Epsilon (for testing) and ZGC for low-latency and large heap system.


        Java 17:

        1. Sealed Class: Use \”sealed\” keyword to control which class can be subclass of this class. Use \”permits\” keyword to allow subclass.
        sealed class Shape permits Circle, Rectangle, Triangle {\n    // Common methods and properties for all subclasses\n    abstract double calculateArea();\n}\n
        1. Hidden Class: which can not be seen by java reflection.
        2. Text Blocks: allow you to use text like long strings.


        “,
      • “keyword”: “Java”,
      • “frequency”: 3,
  • “id”: 332,
    • “question”: “Difference: Sleep and Wait”,
      • “answer”: “

        Sleep(time): when a thread sleeps, it will hold the lock and just pause running for given time, after the time, it will resume running again by itself.

        Wait: when a thread waits, it will give the lock to other threads, this thread will only resume when other thread notify() it or notifyAll()

        “,
      • “keyword”: “Java”,
      • “frequency”: 5,
  • “id”: 343,
    • “question”: “Suppose when you have Employee class to store data, when do you use list or map”,
      • “answer”: “

        1) List can have duplicates and it is just to store all information. Map is key value pair, key must be unique

        2) In application, if you just want to show all employees in json format, you can use list; but if you want to show list of employee Ids and if you click the Ids it will display the whole employee json, so it is like you need a id –> employee association, then you can use map.

        “,
      • “keyword”: “Java”,
      • “frequency”: 2,
  • “id”: 344,
    • “question”: “Difference: Arraylist vs LinkedList, when to use which”,
      • “answer”: “

        READ:

        • ArrayList: is usually faster because it has index. It can be O(1), or worst O(n) if you dont know index
        • LinkedList: is slower because you have to traverse from header, so it is always O(n)

        ADD/REMOVE

        • ArrayList: is usually slower because when you add element, you have to shift all elements after it. So it is O(n)
        • LinkedList: is faster because you just change the pointer, O(1)

        INTERNAL IMPLEMENTATION:

        • ArrayList: implemented by dynamic Array, Need less space because it only need to store value and index
        • Linkedlist: double linkedlist, with value and pointers. Need more space to store, value, left and right pointer

        WHICH ONE:

        • If your app need more READ, less ADD/REMOVE, then linkedlist is good

        USE CASE:

        • ArrayList: for example to store a list of objects
        • Linkedlist: to store object where you just need previous or next value, like browser history or stack.
        “,
      • “keyword”: “Java”,
      • “frequency”: 5,
  • “id”: 363,
    • “question”: “Difference runnable vs callable”,
      • “answer”: “

        Both are used to run tasks/threads

        Runnable 1) return type is void. 2) cannot handle exception

        Callable 1) can have return type 2) can handle exception

        “,
      • “keyword”: “Java”,
      • “frequency”: 4,
  • “id”: 364,
    • “question”: “Difference future vs completableFuture”,
      • “answer”: “

        When you submit a task to executor service, it returns a future.

        CompletableFuture is advanced version of future.

        1) It has method like \”thenApply\”, \”thenCombine\” etc. so you can build thread chain.

        2) it has \”handle\” and \”whenComplete\” method, which you can handle exception with it.

        “,
      • “keyword”: “Java”,
      • “frequency”: 4,
  • “id”: 371,
    • “question”: “JDK vs JRE vs JVM”,
      • “answer”: “

        JDK is for developer to write java code, it can compile the java code to binary class code and also it has debug mode.

        JRE is a java running environment, if you want to run java application, you have to have JRE installed.

        JVM: java virtual machine, is to mange java memory, like heap, stack, metaspace etc.

        “,
      • “keyword”: “Java”,
      • “frequency”: 2,
  • “id”: 372,
    • “question”: “What is externalization and its difference with serialization”,
      • “answer”: “

        Both serialization and externalization are used to serialize objects. Externalization gives you more control of the process.

        Serializable is a marker interface which does not contain any methods for you to implement

        Externalizable is not marker interface, it has readExternal() and writeExternal() method that you can override

        “,
      • “keyword”: “Java”,
      • “frequency”: 1,
  • “id”: 373,
    • “question”: “How do you implement a deadlock”,
      • “answer”: “
        public class ThreadLock\n{\n    final static String R1 = \”Hello Welcome to Pilot!\”;\n    final static String R2 = \”Visit Pilot!\”;\n\n\n    public static void main(String[] args)\n    {\n    \t    // creating thread T1\n \t    Thread T1 = new Thread(){\n                // implementing run method\n \t\tpublic void run(){\n\n\n \t            // thread T1 locking the R1 resource\n \t\t    synchronized (R1){\n \t\t        System.out.println(\”Thread T1 locked ->   Resource R1\”);\n\n\n \t\t        // thread T1 locking the R2 resource\n \t\t\tsynchronized (R2){\n \t\t\t    System.out.println(\”Thread T1 locked -> Resource R2\”);\n \t\t        }\n \t\t    }\n \t\t}\n \t    };\n\n\n \t    // creating thread T2\n \t    Thread T2 = new Thread(){\n \t\t// implementing run method\n \t\tpublic void run(){\n\n\n \t\t    // thread T2 locking the R2 resource\n \t\t    synchronized (R2){\n \t\t        System.out.println(\”Thread T2 locked -> Resource R2\”);\n\n\n \t\t\t// thread T2 locking the R1 resource\n \t\t\tsynchronized (R1){\n \t\t\t        System.out.println(\”Thread T1 locked -> Resource R1\”);\n \t\t\t}\n \t\t    }\n \t\t}\n \t};\n\n\n \t// starting both the threads\n \tT1.start();\n \tT2.start();\n    }\n}\n\n\n
        “,
      • “keyword”: “Java”,
      • “frequency”: 4,
  • “id”: 374,
    • “question”: “Synchronized method vs Synchronized block”,
      • “answer”: “
        public class UserService{\n    private Address address;\n    private String username;\n\n    public static synchronized void lockUserServiceClass(){\n       //synchronized method is to lock whole object, but since this method is static, it only stays in the class\n       //so \”static synchronized\” will lock the class, not the created objects/instances\n    }\n\n    public synchronized void lockUserServiceInstance(){\n       //this method will lock the entier userService Instance\n    }\n\n    public void lockBlock(){\n       synchronized(address){\n         //here only lock the \”address\” object, not the whole instance, performance is best\n       }\n    }\n}\n
        “,
      • “keyword”: “Java”,
      • “frequency”: 3,
  • “id”: 375,
    • “question”: “Difference between Iterator and Enumeration”,
      • “answer”: “

        Both use to loop java collections.

        Iterator: can remove elements when iterator.

        Enumeration: cannot remove elements.

        “,
      • “keyword”: “Java”,
      • “frequency”: 2,
  • “id”: 448,
    • “question”: “What is proxy design pattern”,
      • “answer”: null,
      • “keyword”: “Java”,
      • “frequency”: 4,

JDBC

  • “id”: 141,
    • “question”: “PreparedStatement vs Statement vs Callable Statement”,
      • “answer”: “

        Statement is to run a SQL as string directly.

        PreparedStatement is to compile the SQL and use ? to take the passed-in paramter

        Callable statement is to call Stored Procedure.

        “,
      • “keyword”: “JDBC”,
      • “frequency”: 1,

Kafka

  • “id”: 143,
    • “question”: “Did you use Kafka in your project? How does it work?”,
      • “answer”: “

        Kafka has 3 parts, Producer, Cluster/Broker, Consumer (!DO NOT READ AS CUSTOMER!)

        Producer send message (has topic) to broker

        Broker has topics, each topic has several partitions, the messages are send to these partitions.

        Consumer belongs to one consumer group, they will read the message from partition.

        “,
      • “keyword”: “Kafka”,
      • “frequency”: 5,
  • “id”: 149,
    • “question”: “Talk about Kafka and Zookeeper”,
      • “answer”: “

        In Early version of Kafka, Zookeeper is like manager, it managers the metadata, like which broker is the leader and the offset tracking.

        In new Kafka version, it uses Raft consensus algorithm for leader election. So it does not need Zookeeper.

        “,
      • “keyword”: “Kafka”,
      • “frequency”: 3,
  • “id”: 331,
    • “question”: “How to start and stop kafka server?”,
      • “answer”: “

        Kafka has 2 scripts to start and stop the server.

        bin/kafka-server-start.sh\nbin/kafka-server-stop.sh\n
        “,
      • “keyword”: “Kafka”,
      • “frequency”: 1,
  • “id”: 334,
    • “question”: “How to prevent data loss in kafka”,
      • “answer”: “

        There are 3 parts of Kafka, all 3 parts need to prevent data loss.

        Producer: when producer sends message to broker, the broker will send a status back to producer if the message is received, if not received, producer will keep sending the same message again and again.

        Broker: Each partition has K replications/backups, there is a parameter ACKS (acknowledgement), ACKS = 0 means broker will not tell if the message is received, so if there broker is down, then it is lost. ACKS = 1 means if the message is received by leader partition, but not yet received by replications, it will tell producer the message is received, so when ACKS = 1 and the leader broker is down, the message will be lost. ACKS = ALL means only when all replications of partitions receive the message and then the producer will be notified. ACKS = 0/1 could cause message loss, but ACKS = ALL will slow down performance.

        Consumer: enable.auto.commit is a configuration that let consumer auto commit the offset, once auto commit, the message is considered read by consumer successfully. But if the consumer has some error, it may cause the read failure. so we can set enable.auto.commit = false and manually commit the offset.

        “,
      • “keyword”: “Kafka”,
      • “frequency”: 5,
  • “id”: 335,
    • “question”: “How to keep message order in Kafka”,
      • “answer”: “

        Key: message in one partition is consumed in order. So to make message in order, we just need to send them to same partition. In kafka, each message has an id, if you don’t give id, kafka will assign auto generated id, Kafka use hashing to convert this id to hashcode which is corresponding the partition. (just like hashmap hashcode and bucket). So to make message in order, we need to assign same message ID to them, like if it is order message, we can use order id, if it is like transaction messages, we can use transaction id.

        “,
      • “keyword”: “Kafka”,
      • “frequency”: 5,
  • “id”: 336,
    • “question”: “How to prevent duplicate message in kafka”,
      • “answer”: “

        Kafka has consumer and producer. To prevent duplicate, we should try on both side [reference]

        Producer:

        • Kakfa has many producers and each producer can send many messages, to make each message unique, we need to assign producer an ID and each message an ID, so the producer ID + message ID combination will be unique.

        Consumer:

        • enable.auto.commit should be set to false. enable.auto.commit = true means kafka will auto commit the offset even if consumer failed to process the message, this could cause message loss.
        • Consumer has 2 ways to prevent duplicate messages, 1) it can check the message unique id, if found that id is already processed, it will ignore it. 2) it can make its opreation idempotent, just like put, update once and twice will yield same results.

        One more thing, if each message is sent only once, but the consumer is down, then we could have message lost, so we need to configure auto.offset.reset, this is a parameter to decide when consumer is down, whether we should restart reading from last failed position (latest - default) or beginning of the partition (earliest).

        “,
      • “keyword”: “Kafka”,
      • “frequency”: 5,
  • “id”: 345,
    • “question”: “Kafka how to let two consumers read the same message”,
      • “answer”: “

        Put them in different consumer group.

        In kafka, consumers in same group can only read different partitions - that is why the number of consumers cannot be more than number of partitions in each group. But consumer in different group can read the same partition.

        “,
      • “keyword”: “Kafka”,
      • “frequency”: 2,
  • “id”: 346,
    • “question”: “Kafka how to determine the consumption rate”,
      • “answer”: “

        What is kafka consumption rate:

        It is defined by the offset of last produced message divide by time. For example, if producer sent message1 out and the offset of message1 in partition is 1000 (there are 999 messages ahead of it to be processed). Now, if to process this 1000 messages, it will take 100 seconds, so the consumption rate will be 1000msgs/100s = 10 messages/second.

        To improve the consumption rate:

        1. increase the network bandwidth. The bandwidth can be a bottleneck for the consumption uplimit. Kafka has monitor to see bandwidth.
        2. increase hardware. like CPU and memeory.
        3. reduce the average time for every consumers or add more consumers.
        “,
      • “keyword”: “Kafka”,
      • “frequency”: 1,
  • “id”: 359,
    • “question”: “How to implement security to kafka. Kafka Security”,
      • “answer”: “
        1. Broker authentication: Add authentication for kafka broker, only authenticated applications can connect to kafka brokers.
        • We can use SASL (Simple authentication and security layer) to implement it, SASL supports secure authenticaiton like PLAIN, SCRAM. SASL is a tool to add security to many network protocols, like LDAP, SMTP, IMAP etc.
        1. Data Encryption: Add encryption to broker so that data sent in and out of kafka brokers are encrypted.
        • We can use SSL/TLS to encrypt data. To add SSL certificate to kafka. We can first use openSSL to create a certificate and then use keytool to create a truststore and add the certificate to it. We also need to configure kafka to use the SSL certificate like security.portocol=SSL
        1. Maintain a Access Control List (ACL) to specify which user or group can access which topic or partition.
        “,
      • “keyword”: “Kafka”,
      • “frequency”: 4,
  • “id”: 450,
    • “question”: “What is kafka dead letter queue and how do you handle it?”,
      • “answer”: null,
      • “keyword”: “Kafka”,
      • “frequency”: 4,

Microservice

  • “id”: 145,
    • “question”: “What application details are stored in service registry?”,
      • “answer”: “Service Registry and Service Discovery — Erueka


        1. Service Name: The name or identifier of the service. (This helps other services in the system locate and communicate with the desired service)
        2. Service EndPoints: The IP addresses and port number where the service currently hosing on.
        3. Health Status: Information about the health and availability of the service. (whether the services is up and running)



        “,
      • “keyword”: “Microservice”,
      • “frequency”: 0,
  • “id”: 146,
    • “question”: “How can you make services communicate with each other? -> Tools like Spring Cloud to setup microservice or use message queue like Kafka”,
      • “answer”: “

        There are two ways to communicate between services, sync and async

        Sync: RestTemplate/RestClient – when service 1 call rest api of service 2, service 1 will have wait for the return from service 2, so this is sync communication.

        Async: message queue like Kafka – service 1 as producer sends message to kafka cluster, service 2 as consumer subscribes from kakfa cluster.

        “,
      • “keyword”: “Microservice”,
      • “frequency”: 5,
  • “id”: 152,
    • “question”: “How to use the Zuul Gateway API? / How does the Zuul Gateway API work?”,
      • “answer”: “

        Zuul API Gateway is to distribute the traffic do a particular service.

        For example, Amazon has 3 services, order service is at localhost:8070, payment service is at localhost:8080, delivery service is at localhost: 8090. You don’t want to expose all 3 different addresses to customers. So you add one API Gateway like at localhost:9000. Customers only access to API Gateway. API will redirect to different services based on the URL. For example, localhost:9000/order will be redirected to order service, localhost:9000/payment will be redirected to payment service, localhost:9000/delivery will be redirected to delivery service.

        To set API Gateway, we need Zuul gateway server, all the other services should register the zuul gateway server in their application.properties.

        “,
      • “keyword”: “Microservice”,
      • “frequency”: 4,
  • “id”: 153,
    • “question”: “How to manage the entire transaction across different microservices? How to rollback?”,
      • “answer”: “

        Saga Pattern

        Saga Orchestration Pattern is a design pattern to manage global transaction across multiple microservices based on message queue.

        For example, if you make one order which involves Order Service, Payment Service and Delivery Service as one transaction. In saga orchestration pattern, you will need one command center service, like Command Service which works as a communication center for all the services.

        When order service is completed, it sends a completion message to command center, the command center received and send a message to payment service, the payment service will process payment and send complete message to command service, the command service received payment completion message and send message to delivery service and once delivery is done, it tells command service and command service will mark the entire transaction as completed.

        When there is error, the transaction will be rolled back in reverse order. For example, if delivery service failed, it sends failure message to command service, the command service will tell payment service to rollback payments, once payment service completes the rollback and tells the command service, the command service will ask the order service to rollback. It goes this way until the entire transaction is rolled back.

        “,
      • “keyword”: “Microservice”,
      • “frequency”: 5,
  • “id”: 191,
    • “question”: “How to communicate between microservices”,
      • “answer”: “

        Sync: use RestTemplate or FeignClient

        Async: use message queue, like Kafka, ActiveMQ, RabbitMQ etc

        “,
      • “keyword”: “Microservice”,
      • “frequency”: 5,
  • “id”: 147,
    • “question”: “Explain microservice”,
      • “answer”: null,
      • “keyword”: “Microservice”,
      • “frequency”: 0,
  • “id”: 148,
    • “question”: “What microservice did your team use?”,
      • “answer”: null,
      • “keyword”: “Microservice”,
      • “frequency”: 0,
  • “id”: 150,
    • “question”: “Disadvantage of microservice”,
      • “answer”: null,
      • “keyword”: “Microservice”,
      • “frequency”: 0,
  • “id”: 151,
    • “question”: “Synchronous communication and A-Synchrounous commuication in microservice-> RestTemplate or feign and message queue like Kafka”,
      • “answer”: null,
      • “keyword”: “Microservice”,
      • “frequency”: 0,
  • “id”: 154,
    • “question”: “vertically and horizontally”,
      • “answer”: null,
      • “keyword”: “Microservice”,
      • “frequency”: 0,
  • “id”: 155,
    • “question”: “How to deploy microservices to AWS EC2?”,
      • “answer”: null,
      • “keyword”: “Microservice”,
      • “frequency”: 0,
  • “id”: 156,
    • “question”: “What type of application is suitable for microservice architecture? What type is not?”,
      • “answer”: null,
      • “keyword”: “Microservice”,
      • “frequency”: 0,
  • “id”: 157,
    • “question”: “Suppose you have two Eureka servers, how does each application know which Eureka server it is registered to?”,
      • “answer”: null,
      • “keyword”: “Microservice”,
      • “frequency”: 0,
  • “id”: 158,
    • “question”: “What is the circuit breaker?”,
      • “answer”: null,
      • “keyword”: “Microservice”,
      • “frequency”: 0,
  • “id”: 159,
    • “question”: “How does microservices communicate with each other?”,
      • “answer”: null,
      • “keyword”: “Microservice”,
      • “frequency”: 0,
  • “id”: 160,
    • “question”: “How do you use RestTemplate?”,
      • “answer”: null,
      • “keyword”: “Microservice”,
      • “frequency”: 0,
  • “id”: 161,
    • “question”: “How do you get noticed when a service is down?”,
      • “answer”: null,
      • “keyword”: “Microservice”,
      • “frequency”: 0,
  • “id”: 233,
    • “question”: “How to setup service discovery?”,
      • “answer”: null,
      • “keyword”: “Microservice”,
      • “frequency”: 0,
  • “id”: 301,
    • “question”: “What is Granuarity Line in microserivce”,
      • “answer”: null,
      • “keyword”: “Microservice”,
      • “frequency”: 0,
  • “id”: 325,
    • “question”: “How check services and their status, what is they are hosted in docker”,
      • “answer”: null,
      • “keyword”: “Microservice”,
      • “frequency”: 5,

NoSQL

  • “id”: 352,
    • “question”: “How do you decide which database to choose, SQL or NoSQL”,
      • “answer”: “

        Several Main difference

        • 1. SQL: only have pre-defined structure schema/data, it is table based.
        • 1. NOSQL: unstructure data, like MongoDB can store PDF/audio/video/text/json data easily. Cassandra is column based, you can easily expand the columns
        • 2. SQL: based on ACID rules, designed to handle transactions.
        • 2. NOSQL: based on CAP theorem, not good for transactions.
        • 3. SQL: traditional database with SQL, not designed for big data
        • 3. NOSQL: designed for big data, have partitions.
        “,
      • “keyword”: “NoSQL”,
      • “frequency”: 0,
  • “id”: 290,
    • “question”: “Explain CAP theorem and which database use them”,
      • “answer”: null,
      • “keyword”: “NoSQL”,
      • “frequency”: 0,
  • “id”: 337,
    • “question”: “How to find all available keyspaces in Cassandra”,
      • “answer”: “
        2 Ways:\n\n1.select * from system_schema.keyspaces;\n\n2.describe keyspaces\n
        “,
      • “keyword”: “NoSQL Cassandra”,
      • “frequency”: 2,
  • “id”: 452,
    • “question”: “What is consistent hashing in cassandra”,
      • “answer”: null,
      • “keyword”: “NoSQL Cassandra”,
      • “frequency”: 3,
  • “id”: 453,
    • “question”: “what is cassandra replicatoin strategy”,
      • “answer”: null,
      • “keyword”: “NoSQL Cassandra”,
      • “frequency”: 2,
  • “id”: 376,
    • “question”: “What is sharding in MongoDB?”,
      • “answer”: “

        Sharding is to split the dataset into multiple partitions. For example, if you have data from 1 to 10 million, you can store the id from 1 to 1 million as first shard, 1 million to 2 million as 2nd shard etc.

        “,
      • “keyword”: “NoSQL MongoDB”,
      • “frequency”: 4,
  • “id”: 377,
    • “question”: “How replication works in MongoDB”,
      • “answer”: “

        To prevent the data loss, MongoDB set replication of the nodes.

        like if you have 20 shards, the 1st shard is in Virginia, MongoDB can make 2 replications (copies) of this node and put them in Ohio and California so if Virginia server is down, the other 2 replications will back up.

        “,
      • “keyword”: “NoSQL MongoDB”,
      • “frequency”: 1,
  • “id”: 162,
    • “question”: “Design a Employee Voting system according to the requirements”,
      • “answer”: null,
      • “keyword”: “OOD”,
      • “frequency”: 0,

OOP

  • “id”: 166,
    • “question”: “Basic principles of the OOP”,
      • “answer”: null,
      • “keyword”: “OOP”,
      • “frequency”: 0,
  • “id”: 167,
    • “question”: “Why Inheritance? / Benefit of using Inheritance”,
      • “answer”: null,
      • “keyword”: “OOP”,
      • “frequency”: 0,
  • “id”: 169,
    • “question”: “Design a parking lot according to the requirements”,
      • “answer”: null,
      • “keyword”: “OOP”,
      • “frequency”: 0,
  • “id”: 170,
    • “question”: “Inheritance vs. Composition/Aggregation -> IS-A and HAS-A”,
      • “answer”: null,
      • “keyword”: “OOP”,
      • “frequency”: 0,
  • “id”: 171,
    • “question”: “Can a class inherits multiple parent classes? / Is multiple inheritance allowed? Why?”,
      • “answer”: null,
      • “keyword”: “OOP”,
      • “frequency”: 0,
  • “id”: 353,
    • “question”: “When you API request or Frontend page loading slowly, how do you handle it?”,
      • “answer”: “

        Key things:

        1. For large dataset request, you can use Pagination. Just like google search, you can split your data into batches, each request only fetch fixed amount of rows.
        2. Use cache instead of database visit, Frontend: cache the visited page data. Backend: in-memory java cache for monolithic application, distributed cache, redis, for microservices.
        3. Other tools can help improve read performance, like elasticsearch can boost the search.
        4. Database side: Optimize the SQL, use Sql tuning tools, like the Oracle explain plan. Add proper index (non-cluster index) on some frequently visited columns.
        “,
      • “keyword”: “Performance”,
      • “frequency”: 0,
  • “id”: 298,
    • “question”: “Key Difference: Soap vs Rest”,
      • “answer”: null,
      • “keyword”: “Rest”,
      • “frequency”: 0,
  • “id”: 354,
    • “question”: “How do you implement security for your application or microservices”,
      • “answer”: “

        Principles:

        For Authentication

        • Basic Authentication: use username and password authentication. the password should be encrypted. common encryption algorithm: BCrypt, SHA256, RSA.
        • JWT Token: When the first time user login with username and password, backend will create a JWT token which contains the user info, the token will be stored in the frontend cookie. Every single request will carry this token, backend will validate this token to decide if user is authenticated. A token usually has a expiration time.
        • Asymmetric key pairs: this is used for something like AWS command portal validation. It create a private key on server side and give public key to the client side. client with public key should be able to match with the private key on the server side.
        • OAuth2: this is like 3rd party SSO (single sign on). Like for some applications, you can login with google or facebook. The application is pre-registered with the 3rd party, when a user login, it sends a request to 3rd party authentication server and gets a token, and once got the token, it will use that token to call the 3rd party authorization server to get the user role. [Learn more]

        For Authentication:

        • OAuth2 is a authorization method.
        • For other authentication, we can have AntMatcher to match the routes/paths and use hasRole to allow particular role to access it.


        Implementations:

        \t\tIn spring, we can override the WebSecurityConfigureAdaptor class, it is part of the security filter chain and it contains configure method, we will need to override the configure method and override the UserDetails object and UserDetailService class.



        “,
      • “keyword”: “Security”,
      • “frequency”: 0,

Spring Boot

  • “id”: 12,
    • “question”: “How do you config for multiple environments?”,
      • “answer”: “
        1. In spring boot, we can define different profiles for different environments, like DEV, QA/Staging, PROD etc.
        2. We can have application-dev.propeties, application-staging.properties, application-prod.applications, when we run the application, we just need to set the active profile to corresponding env.
        3. In microservice, we can also use Config Server, which we can config the different profiles and put them in server hardware or in code repository and use active profile to refer to it. The benefit is we can track the version of the files.
        “,
      • “keyword”: “Spring Boot”,
      • “frequency”: 5,
  • “id”: 196,
    • “question”: “Why do you use Spring Boot? / Benefits of Spring Boot”,
      • “answer”: “

        Top 1 question in spring boot.

        Spring boot has many benefits, the top 4 are like:

        1. Embedded Server: spring boot has \”Web\” starter which contains the tomcat or Jetty server, you dont need to deploy the application, it is auto-deployed by one click or one command line. You just run your whole application with server together as a JAR file
        2. Auto Configuration: Spring boot has auto configuration, as long as you put the properties there, spring boot will auto setup everything. Example, if you have Data Source entries in the application.properties file, Spring boot will try to auto connect the database for you.
        3. Dependency Management: Spring boot wraps up related dependencies into \”starters\”, like the Web Starter contains json, rest api, mvc model, server etc. You don’t need to add them to POM.XML separately, also you dont need to worry about the version conflicts in the dependencies.
        4. Actuator: Spring boot provides actuator which has many endpoints to tell the status of the spring boot application. Like: /info is to tell the status, /health summarizes the health status of our application. /metrics details metrics of our application. This might include generic metrics as well as custom ones.


        Disadvantage:

        Spring boot wrap too many things in the box, so many things are in under the cover.

        “,
      • “keyword”: “Spring Boot”,
      • “frequency”: 5,
  • “id”: 220,
    • “question”: “How to start a Spring Boot project?”,
      • “answer”: “

        Several Steps in order:

        1. Go to spring initializer, fill information like Java Version, Build Tool Maven, enter project name description, Package type as Jar or War
        2. Choose Starters, like Web Stater, Spring Data Starter, Security Starter etc
        3. generate the project and download the zipfile
        4. Unzip and import into IDE as new project.
        “,
      • “keyword”: “Spring Boot”,
      • “frequency”: 5,
  • “id”: 221,
    • “question”: “Command to run a spring boot application”,
      • “answer”: “

        Maven Command: mvn spring-boot:run

        Java command: java -jar application-name.jar

        “,
      • “keyword”: “Spring Boot”,
      • “frequency”: 1,
  • “id”: 228,
    • “question”: “What does @SpringBootApplication mean?”,
      • “answer”: “

        3 Key Things included in this application

        @ComponentScan: will scan all beans at current level or lower level, this is why the @SpringBootApplication is on top of a main class that is higher than all other classes, so that it can scan all beans

        @AutoConfiguration: will let spring boot auto configure. For example, if you have put datasource in the application.properties, spring boot will auto connect for you. If you dont want auto configuration, use Excludes=XXX.Class to exclude that particular configuration

        @Configuration: means this is a configuration class.


        “,
      • “keyword”: “Spring Boot”,
      • “frequency”: 5,
  • “id”: 234,
    • “question”: “For Spring Boot, how do I use another server such as WebLogic instead of the embedded Tomcat server?”,
      • “answer”: “

        Some configurations needed:

        1. add Exclusions in POM.XML to exclude the embedded tomcat and jetty server
        2. need to add JNDI in the application.properteis for the new server (such as weblogic)
        3. the main class needs to extend the SpringBootServletInitializer
        4. Change package in POM.XML from JAR to WAR.
        “,
      • “keyword”: “Spring Boot”,
      • “frequency”: 4,
  • “id”: 307,
    • “question”: “Regarding @Async 1) what is it for 2) how to define it 3) how to call async method 4) can async method be private and why”,
      • “answer”: “

        What is @Async?

        • @Async is used to make a method asynchronous, meaning it will be executed in a separate thread without blocking the main thread.

        How to use @Async?

        • First, the spring boot must enable async support, we can do it by adding @EnableAsync on top of the main class
        • add @Async on the target method
        @Service\npublic class MyService {\n\n    @Async\n    public void asyncMethod() {  //has no return\n        // Method logic\n    }\n\n    @Async\n    public Future<String> asynMethod2(){  //return a future\n       //logic\n    }\n}\n

        How to call the async method?

        • Just call it as regular method, but since it is in another thread, so result may not be ready when you call it, so have to use while loop to handle the future and wait for it.
        public void callAsyncMethod(){\n     Future<String> future = myService.asynMethod2(); //just call and host result in future\n     while(true){\n         if(future.isDone()){\n               String result = future.get();\n               break; // stop while loop when result is returned\n           }\n       }\n  }\n

        Can async method be private and why?

        • The async method can only be PUBLIC.
        • The @Async is internally implemented by spring AOP, if the method is private, AOP cannot find it, so @Async will not work.
        “,
      • “keyword”: “Spring Boot”,
      • “frequency”: 2,
  • “id”: 312,
    • “question”: “What is Conditional bean in Spring boot?”,
      • “answer”: “

        the Conditional bean is only created when the condition is met, it can be applied on top of a class or a method bean

        @Configuration\n@Conditional(isDevCondition.class)  //only create bean if it is dev environment (common used)\n@ConditionalOnProperty(value=\”isDev\”, havingValue=\”true\”) //create bean only if properties have entry isDev=true\n@ConditionalOnExpression(${isDev:true}) //use Expression\n@ConditionalOnBean(MyBean.class) //create bean if MyBean.class is created  (common used)\n@ConditinoalOnClass(MyConfig.class) //create bean only if this configuration class exists in the classpath\n@ConditionalOnJava(JavaVersion.EIGHT) //create bean only if java version >= 8\n@ConditionalOnWarDeployment   //create this bean only if deployed as war\npublic class DevLoggingService{\n    @Bean\n    @Conditional(isDevCondition.class) //only create bean if it is dev environment  (common used)\n    public AnotherDevLoggingService anotherDevLoggingService(){\n         return new AnotherDevLoggingService();\n    }\n}\n

        Spring comes with many default @Conditional annotations as showing above. Some can be used on method, and most can be used on class.

        They are all having one purpose: to only create a bean based on the given condition

        “,
      • “keyword”: “Spring Boot”,
      • “frequency”: 2,
  • “id”: 350,
    • “question”: “Difference between Spring boot and Spring”,
      • “answer”: “
        1. Spring boot use starter to manager dependencies, like Web Starter has MVC, REST, JSON, TOMCAT, IOC etc all included in one web starter. You dont need to worry about dependency conflicts.
        2. Spring boot has tomcat in web starter by default, so you dont need to package and deploy to tomcat. You can just run it directly or package it as JAR file and run it everywhere.
        3. Spring boot put everything in annotation by default, you dont need to write a lot code as in Spring.
        4. Spring boot add auto configuration, like if you put datasource in application.properties file, it will auto connect for you. You dont need to write the java connection code.
        5. Spring boot provide actuator which you can use to measure the metrics of the applications, like /info, /heath etc to tell the metrics, it is very useful in microservice environments.
        “,
      • “keyword”: “Spring Boot”,
      • “frequency”: 0,
  • “id”: 447,
    • “question”: “How to do cache in spring boot and how to refresh the cache”,
      • “answer”: “

        We can use @Cachable on a method to make the returned object

        “,
      • “keyword”: “Spring Boot”,
      • “frequency”: 4,

Spring Core

  • “id”: 174,
    • “question”: “Spring Annotation you used in your project?”,
      • “answer”: “

        @Controller, @RestController, @RequsetMapping @GetMapping @PutMapping @PostMapping @DeleteMapping

        @PathVariable @RequestParam

        @Autowired, @Qualifier

        @Service @Repository @Componenet


        “,
      • “keyword”: “Spring Core”,
      • “frequency”: 5,
  • “id”: 176,
    • “question”: “What is IoC/Dependency Injection?”,
      • “answer”: “

        That is the most basic module of spring. Without spring, if you want to use another bean in one class, you have to create instance by yourself by calling the constructor. But with spring, you dont need to do that, you just use @component or @bean and other spring annotations to let spring manage the beans for you, so spring has a bucket called bean factory, it manages all the beans there for you, if you need to inject a bean, you just use @autowired, spring will find the instance and wire it for you. So you are giving the control of creating instance to spring, that is why it is also called inversion of control.


        “,
      • “keyword”: “Spring Core”,
      • “frequency”: 5,
  • “id”: 177,
    • “question”: “What is AOP and how do you implement AOP in the project?”,
      • “answer”: “

        AOP - Aspect oriented programming, is to interfere with main application execution.

        Aspect: @Aspect is to mark a class as AOP class which contains AOP annotations and methods

        Pointcut: an expression to find all the main application package or methods to apply AOP. like \”execution( com.example.CalculatorService.(..))\” means find all methods in CalculatorService package.

        Advise: when to apply the AOP logic, @before, @after @around @afterThrowing etc.


        Purpose of AOP: 1)exception handling 2) logging

        “,
      • “keyword”: “Spring Core”,
      • “frequency”: 3,
  • “id”: 180,
    • “question”: “Spring bean annotation, bean life cycle and bean scope”,
      • “answer”: “

        Annotations:

        • @Component @Bean @Controlelr @Service @Configuration etc

        Bean lifecycle

        • Bean instantiated –> dependency injected –> init() –> custom operation –> destory()

        Bean Scope:

        • Singleton (DEFAULT): only one instance per whole applcation/container
        • Prototype: create a new instance whenever you need to INJECT this bean
        • session: one instance per user session
        • request: one instance per user request-response cycle.


        EXTRA: Does spring has thread scope? – NO: if you need, create by yourself.

        “,
      • “keyword”: “Spring Core”,
      • “frequency”: 5,
  • “id”: 184,
    • “question”: “Spring Bean scope and explain the request scope”,
      • “answer”: “

        Singleton: DEFAULT scope, only one instance per application.

        Prototype: create new instance whenever you use @Autowired to inject

        Request: create new instance per user request response cycle

        Session: create one new instance per one user session

        “,
      • “keyword”: “Spring Core”,
      • “frequency”: 5,
  • “id”: 186,
    • “question”: “Different ways of DI”,
      • “answer”: “

        Constructor based, Setter based, Field based

        Assume you have Bean A and Bean B. A depends on B and B also depends on A.

        Constructor based: when you start spring application, spring will create bean and inject the dependencies. So in this case, when create Bean A, it will need Bean B to inject, so it will create Bean B, and then it finds Bean B will need Bean A. So Bean A and Bean B are waiting for each other. It will throw BeanCurrentlyInCreation exception.

        Setter based: the dependency is only injected when it is used. Spring will first create Bean A and Bean B, but will not inject to each other until B is used in methods inside A. so there will be no exceptions

        Field Based: it is based on java reflection, so it will not throw exception either.

        “,
      • “keyword”: “Spring Core”,
      • “frequency”: 4,
  • “id”: 190,
    • “question”: “Difference between @Component and @Bean”,
      • “answer”: “

        @Component is used on top of a class. @Bean is used on top of a method.

        “,
      • “keyword”: “Spring Core”,
      • “frequency”: 3,
  • “id”: 193,
    • “question”: “When there is circular dependency, use which type of Injection? / Setter based Injection vs. Constructor based”,
      • “answer”: “

        Circular Dependency: when 2 beans are dependent for each other. Bean A and B, A is injected into B and B is also injected into A.

        Constructor based: the beans are injected when initialized. So when you create bean A, it will try to create bean B so it can be injected, but while it tries to create bean B, it needs bean A. So using constructor based, it will throw BeanCurrentlyInCreationException.

        Setter Based: Dependencies are only injected when they are used, they are not injected when spring initialize the ApplicationContext. So this will not throw the exception.


        “,
      • “keyword”: “Spring Core”,
      • “frequency”: 4,
  • “id”: 194,
    • “question”: “Explain DispatcherServlet in detail”,
      • “answer”: “

        Dispatch Servlet is the CORE of spring MVC module.

        1. When a \”request\” comes, it goes to dispatcher servlet
        2. The request is sent to \”Mapping Handler\” which will decide which \”controller\” it will be redirected to
        3. The request is sent to that \”controller\” and then \”service\” and \”repository\” and then \”database\” with returned data
        4. The response from controller is sent to \”View Resolver\” which will determine which view page to be displayed
        5. The view page and the data together will be combined as a \”response\” and rendered to user.


        \

        “,
      • “keyword”: “Spring Core”,
      • “frequency”: 4,
  • “id”: 199,
    • “question”: “ApplicationContext vs. BeanFactory”,
      • “answer”: “

        Both are the IOC container of spring beans. ApplicationContext extends BeanFactory. So it has more features than BeanFactory, like the ApplicationContext contains the I18n language support etc.

        “,
      • “keyword”: “Spring Core”,
      • “frequency”: 2,
  • “id”: 218,
    • “question”: “How to inject bean when there are two beans with same type?”,
      • “answer”: “

        Use @Qualifier. Like if you have an interface and 2 children, you can use @Qualifier to decide which one to inject

        “,
      • “keyword”: “Spring Core”,
      • “frequency”: 5,
  • “id”: 227,
    • “question”: “Spring validation?”,
      • “answer”: “

        It is used to add validation on the data object. Example:

        public class User {\n\n    @NotBlank(message = \”Username is mandatory\”)\n    private String username;\n\n    @NotEmpty(message = \”Password cannot be empty\”)\n    @Size(min = 8, message = \”Password must have at least 8 characters\”)\n    private String password;\n\n    // Getters and setters\n}\n

        @NotBlank, @NotEmpty @Size are all validations added on top of a field. There are many more annotations.

        “,
      • “keyword”: “Spring Core”,
      • “frequency”: 2,
  • “id”: 349,
    • “question”: “How to make a java class managed by Spring”,
      • “answer”: “
        • Use annotation like @Component, @Bean @Configuration, @Service @Controller etc
        • Use XML. <bean id = \”bean1\”, reference=\”com.test.MyClass\”>
        “,
      • “keyword”: “Spring Core”,
      • “frequency”: 4,
  • “id”: 362,
    • “question”: “What is Spring Retryable”,
      • “answer”: “

        Spring Retry is to let a method auto retry for given max attempts. Its is implemented by @Retryable and @Recover

        @Service\npublic interface MyService { \n\n    @Retryable(retryFor = SQLException.class, maxAttempts = 3)\n    void retryMethod(String sql) throws SQLException; \n\n    @Recover\n    void recover(SQLException e, String sql); \n}\n

        For example, if the \”retryMethod\” throws SQLException, it will rerun for at most 3 times. If it throw SQLException for all the 3 retries, it will stop and call the \”recover\” method instead.

        “,
      • “keyword”: “Spring Core”,
      • “frequency”: 2,
  • “id”: 365,
    • “question”: “How does spring inject singleton bean into prototype bean?”,
      • “answer”: “

        If spring inject the real prototype into singleton bean, then singleton bean will not be singleton anymore.

        To solve it, spring create a proxy for the protype bean, so it actually just inject the proxy once. When proxy is called during runtime, spring will decide if create a new instance based on the real bean scope.

        “,
      • “keyword”: “Spring Core”,
      • “frequency”: 4,
  • “id”: 366,
    • “question”: “How to let spring create a bean only when that bean is needed instead of create at beginning”,
      • “answer”: “

        Use annotation @Lazy. It will skip the bean when spring starts, only create the bean when that bean is used/injected

        “,
      • “keyword”: “Spring Core”,
      • “frequency”: 2,
  • “id”: 449,
    • “question”: “What to lazy loading a spring bean”,
      • “answer”: null,
      • “keyword”: “Spring Core”,
      • “frequency”: 4,

Spring JPA

  • “id”: 204,
    • “question”: “How do you implement transaction?”,
      • “answer”: “

        The transactions have been managed so that the operations inside one transaction is purely Atomic

        Use @Transactional to mark a method (usually in server layer) as a transaction. The annotation has some parameters

        • ROLLBACKFOR, NOROLLBACKFOR: parameters to control what kinda of exceptions will cause the transaction to rollback.
        • PROPAGATION: defines when a new transaction is needed. Propagation=Required (default) means always a transaction is needed. Propagation=NEW means need to create a new transaction. etc
        • ISOLATION: set the isolation level, like READ COMMITTED means you can only read the committed data, READ UNCOMMITTED means you can read uncommitted data which could cause phantom reading.


        Extra:

        if you dont use spring, hiberneate has transaction management which can handle the transactions as well. You can use session.beginTransaction to start a new transaction and you use try catch to handle the errors

        “,
      • “keyword”: “Spring JPA”,
      • “frequency”: 5,
  • “id”: 315,
    • “question”: “How does hibernate internally check if entity version has changed”,
      • “answer”: “
        1. locking
        2. call the update SQL, that sql return integer, use that method to decide
        “,
      • “keyword”: “Spring JPA”,
      • “frequency”: 1,
  • “id”: 319,
    • “question”: “How to configure multiple database using JPA”,
      • “answer”: “

        Each database is connected by its own datasource(driver, url, username, password). We need to list them in application.properties and use them to create different dataSource beans, so JPA can use these beans.

        — in Application.properties:\nspring.datasource.jdbcUrl = [url]\nspring.datasource.username = [username]\nspring.datasource.password = [password]\n\nspring.second-datasource.jdbcUrl = [url]\nspring.second-datasource.username = [username]\nspring.second-datasource.password = [password]\n\n    @Bean\n    @ConfigurationProperties(prefix=\”spring.datasource\”)\n    public DataSource firstDataSource() {\n        return DataSourceBuilder.create().build();\n    }\n\n    @Bean\n    @ConfigurationProperties(prefix=\”spring.second-datasource\”)\n    public DataSource secondDataSource() {\n        return DataSourceBuilder.create().build();\n    }\n\n\n
        “,
      • “keyword”: “Spring JPA”,
      • “frequency”: 4,

Spring Rest

  • “id”: 172,
    • “question”: “How does the RestTemplate work?”,
      • “answer”: “

        RestTemplate is the tool to call other REST APIs inside java code. It is Async call.

        ResponseEntity<String> response = restTemplate.getForEntity(url, String.class);\nString responseBody = response.getBody();\n
        “,
      • “keyword”: “Spring Rest”,
      • “frequency”: 2,
  • “id”: 178,
    • “question”: “Http status code you ever met”,
      • “answer”: “

        2XX: success

        • 200: Success
        • 201: Resource created successfully
        • 202: Accepted: the request is accepted, but not processed yet.
        • 204: No Content: request is success, nothing to return

        3XX: the requested resources have been moved, client needs to do a redirect.

        • 301: resource is permanently moved.
        • 302: resource is not found - temporary moved to another location
        • 308: permanently redirected to a new location

        4XX: client side error

        • 400: Bad Request
        • 401: Unauthorized
        • 403: Forbidden
        • 404: Not found
        • 405: Method not Allowed

        5XX: server side error

        • 500: Internal server error
        • 502: Bad Gateway
        • 503: Service Unavailable
        • 504: Gateway timeout


        “,
      • “keyword”: “Spring Rest”,
      • “frequency”: 5,
  • “id”: 187,
    • “question”: “Explain MVC and the order of each components”,
      • “answer”: “

        Request –> security –> controller –> service –> repository –> response

        Security: handles request authentication and authorization

        controller: handles request, contains the mapping, endpoint, methods, return type etc.

        service: for business logic

        repository: crud operation with database tables

        “,
      • “keyword”: “Spring Rest”,
      • “frequency”: 5,
  • “id”: 197,
    • “question”: “Different types of request mapping/rest api/http methods”,
      • “answer”: “

        CRUD METHODS: C - POST, R - GET, U - PUT, D - DELETE

        PUT vs POST:

        1. PUT is to update, it is idempotent (means, if you do PUT 2 times with same data, you get the same results)
        2. POST is to create new object, if you do POST 2 times, you create 2 objects, so it is not idempotent.

        Can you write create object or update object in GET request?

        \tYES. the methods are contracts in REST api, it is just to limit how you call the rest api, the detailed logic has to be implemented by yourself, so you can write any logic you want, but it is not good idea to write post or put logic inside get method.


        “,
      • “keyword”: “Spring Rest”,
      • “frequency”: 5,
  • “id”: 198,
    • “question”: “Comparison between Soap and Rest”,
      • “answer”: “
        1. Soap is a Protocol based on XML, it works over HTTP, SMTP, TCP etc. But REST is a architecture type of webservice that is based on HTTP only
        2. Soap use XML for format of data, REST uses json format by default. But they do support other types
        3. Soap is Stateful and Rest is Stateless. (If 2nd request knows the data of 1st request, that is stateful, if each request is independent, it is stateless)
        4. Soap has built-in security features like WS-Security, but Rest is based on HTTP, you have to use http security, like SSL, Oauth etc.
        “,
      • “keyword”: “Spring Rest”,
      • “frequency”: 3,
  • “id”: 206,
    • “question”: “When designing a public API, what needs to be considered?”,
      • “answer”: “
        1. Restful Principles: follow the principles, like the HTTP methods, JSON format etc
        2. Good naming conventions: endpoints should have good naming conventions so caller can easily know which endpoint to call.
        3. Version: add version to the rest and make it back compatible.
        4. Security: add authentication and authorization to the endpoints
        5. Rate Limiting: Enforce rate limiting to prevent attack and abuse.
        6. Performance: Pagination can split resources and cache can reduce network travel to improve performance
        7. Scalability: Make the API easy to scale so it can handle large requests
        “,
      • “keyword”: “Spring Rest”,
      • “frequency”: 4,
  • “id”: 219,
    • “question”: “If define a object in the controller, and then other request update the value of the object, then which value will be fetched by a new request?”,
      • “answer”: “

        Spring beans by default are all Singleton. So Controller, Service, Repository are all singleton. If you define an field or object in them, it will be shared by all threads, if a request comes to update the value, another request will get the updated value.

        “,
      • “keyword”: “Spring Rest”,
      • “frequency”: 3,
  • “id”: 226,
    • “question”: “How to handle controller exceptions? How spring handles exception?”,
      • “answer”: “

        @ExceptionHandler can handle exceptions at controller level. @ControllerAdvice + @ExceptionHandler together can handle exceptions in all exceptions.

        “,
      • “keyword”: “Spring Rest”,
      • “frequency”: 5,
  • “id”: 229,
    • “question”: “How do you create a controller?”,
      • “answer”: “

        @RestController

        @RequestMapping(\”/user\”)

        public class UserController{

        @Autowired

        private UserRepository userRepository


        @GetMapping(\”\”)

        public ResponseEntity<List<User>> getAllUsers(){

        try{

        List<User> users = userRepository.findAll();

        return ResponseEntity.status(HttpStatus.OK).body(users);

        }catch(Exception e){

        return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();

        }

        }


        @GetMapping(\”/{id}\”)

        public ResponseEntity<User> getUser(@PathVariable int id){

        try{

        User user = userRepository.findById(id);

        return ResponseEntity.status(HttpStatus.OK).body(user);

        }catch(Exception e){

        return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();

        }

        }

        }

        “,
      • “keyword”: “Spring Rest”,
      • “frequency”: 5,
  • “id”: 232,
    • “question”: “What is difference between path variable and query param?”,
      • “answer”: “

        PathVariable is a MUST-HAVE parameter in URL. Query Param is more like for optional parameters.

        “,
      • “keyword”: “Spring Rest”,
      • “frequency”: 4,
  • “id”: 236,
    • “question”: “What will happen after clicking the URL?”,
      • “answer”: “

        How is application deployed?

        \tFor example, when you deploy amazon application to amazon.com, the application is deployed on a server with a static URL, that static URL is mapped to the domain name \”amazon.com\”, the mapping is managed by DNS(Domain Name System), so when someone click domain amazon.com, the DNS will find mapping and redirect to the original static URL.


        What happens after clicking a URL?

        1. browser will parse the URL, find protocol (http or https), domain name, path, query parameter etc.
        2. browser will call to check DNS to find the IP address for the application for the URL domain.
        3. browser will attempt to visit the original URL and build the connection
        4. The request will goes through security layer, and then to controller, service, repository and then to database
        5. the data comes back as a response will go back to the browser
        6. the browser will render the view
        “,
      • “keyword”: “Spring Rest”,
      • “frequency”: 4,

Spring Security

  • “id”: 201,
    • “question”: “How does JWT work?”,
      • “answer”: “

        JWT is to a tool that you don’t need to keep login with your username and password.


        JWT token has 3 parts, the header, payload body and signature. The header contains the type of the token and the algorithms such as SHA256. The payload body contains the user data like username and userrole etc. The signature is to a string used to verify the payload data.


        Flow:

        1. User login with username and password, the backend will validate and create a JWT token.
        2. The token is sent back to frontend and stored in the Cookie.
        3. Subsequent requests come with the cookie and the JWT token is passed in the request header.
        4. The token will be validated to check if user is authenticated.
        5. The token expiration time can be extended.


        You dont have to store the token in database, but if you want to persist it or set the expiration time, you can store it in the database.

        \

        “,
      • “keyword”: “Spring Security”,
      • “frequency”: 5,
  • “id”: 211,
    • “question”: “Have you used security? how do you protect your rest api? how do you protect your application?”,
      • “answer”: “

        What: We use spring security.

        How: We override the spring framework WebSecurityConfigureAdaptor and its many configure method. We can use JdbcAuthentication, InMemoryAuthentication etc and Store the user credentials in the UserDetails object. We can also use BCrypt to encode the password and JWT token to do validations. We can use use \”antMatcher\” to let certain URLs only be accessed by certain User Roles.

        Ways for authentication and Authorization:

        • UserNamePassword authentication: When user fill username password in frontend, we can encode their password and validate with database or check if credentials match in UserDetails object.
        • JWT token, if the user is validated, we can use JWT token to validate the subsequent requests so user won’t need to to enter credentials anymore for a validate token period. The JWT token is stored in cookie and will be passed along every request. Each token can have an expiration time and can be extended. The token does not have to be saved to database.
        • Oauth2: we can also use Oauth2 to do authorization, it is 3rd part authorization, just like \”login with google\”, :login with facebook\” etc. You first request 3rd party to get authentication token and then use that authentication token to get authorization access.
        • Asymmetric Key pair, also called public key and private key. Many online portal uses it, just like AWS SDK.
        • Remember-Me feature, it is just to let user choose to let application remember the credentials and store the settings in the user cookie
        • Authorization: can use AntMatcher to do authorization for certain roles.
        “,
      • “keyword”: “Spring Security”,
      • “frequency”: 5,

SQL

  • “id”: 31,
    • “question”: “Different type of Joins”,
      • “answer”: “

        Supposed you have table A 100 records, table B 50 records, they match by 20 records

        1. Inner/Equi Join: the match part (like: where a.id = b.ta_id), should be 20 records
        2. Left Join : match plus remaining of left side table, if A left join B, then return 100, if B left join A, then return 50
        3. Right Join, match plus remaining of right side table. A left join B = B right join A
        4. Full Outer Join: match plus remaining of A and B, 20 + 80 + 30 = 130
        5. Cross Join: Each row of A join Each row of B: 100 * 50 = 5000
        6. Self Join: A self Join A, treat as 2 tables, A1, A2, so A self join is like A1 join A2
        “,
      • “keyword”: “SQL”,
      • “frequency”: 5,
  • “id”: 33,
    • “question”: “Write a query: find the most popular product of one month”,
      • “answer”: “

        Analysis:

        most popular –> appear most times –> max count –> find count and order, GROUP BY always needed for aggregate function

        SELECT p.name, count()\nFROM product p\nWHERE p.month = ‘GivenMonth’\nGROUP BY p.name.  //group by name –count by name, field must appear in select caluse\nORDER BY count() DESC //order in desc of count\nLIMIT 1 // just find top1\n
        “,
      • “keyword”: “SQL”,
      • “frequency”: 0,
  • “id”: 34,
    • “question”: “What is normalization and denormalization? Give a example”,
      • “answer”: “

        Normalization is to make every data a single cell so there will be no mess up in data, like Address is consisted of street, city, state, zip. You should have 4 columns instead of just one address column in database, this is called normalization. Data normalization should be done to all data to make sure you can write SQL easily (like if you want to join on zipcode, you just read zipcode column)

        Denormalization is opposite, if you have street, city, state, zip 4 columns, you add 1 more column called address which is combination of all 4 columns. So if you want to find address, you can just call \”address\” column instead of concatenation of 4 columns. Denormalization is for convenience.


        “,
      • “keyword”: “SQL”,
      • “frequency”: 1,
  • “id”: 35,
    • “question”: “Is the primary key unique? Difference between the primary key and unique key”,
      • “answer”: “

        Primary Key must be Unique. Unique key may not be primary key

        For example, User table, UserID is primary key, it must be unique. UserEmail and SSN are also unique, but it is not primary key

        “,
      • “keyword”: “SQL”,
      • “frequency”: 2,
  • “id”: 38,
    • “question”: “Explain the ACID concepts”,
      • “answer”: “

        ACID is the design principle for SQL relational database.

        A: atomicity: means every transaction to database should be atomic, should be as a whole operation. If there is any failure inside, the whole transaction should rollback.

        C: Consistency. Data should be consistent. It should not violate any rules of the database constraints.

        I: Isolation, it refers to the isolation level, like READ_COMMITTED, READ_UNCOMMITED. The READ_COMMITTED level means you can only read the data that is already committed.

        D: durability: when there is system crash or node failure, the data should still be available.

        “,
      • “keyword”: “SQL”,
      • “frequency”: 5,
  • “id”: 39,
    • “question”: “What kind of database did you use and how do you communicate with the DB”,
      • “answer”: “

        Ways to communicate with database: JDBC, JPA, HIBERNATE, MYBATIS etc

        “,
      • “keyword”: “SQL”,
      • “frequency”: 5,
  • “id”: 355,
    • “question”: “Find the 2nd largest salary in employee table”,
      • “answer”: “

        SOLUTION 1 (best for highest, 2nd highest, not good for 3rd, 4th etc, need to understand subquery)

        SELECT MAX(salary) FROM employee WHERE salary < (SELECT MAX(salary) FROM employee);\n

        SOLUTION 2: (best for Kth highest. need to understand OFFSET, LIMIT)

        SELECT DISTINCT salary FROM employee ORDER BY salary DESC OFFSET 1 LIMIT 1\n
        “,
      • “keyword”: “SQL”,
      • “frequency”: 0,
  • “id”: 356,
    • “question”: “Find employee whose salary is higher than its own manager (only given employee table which contains employee id and its manager id)”,
      • “answer”: “

        Employee (id, name, salary, managerId)

        KEY: we need to get employee salary and manager salary from same table, it is SELF JOIN, when do SELF join, we can always treat Employee as 2 tables, employee and manager

        SELECT emp.name\nFROM employee emp\nJOIN employee mgr\nON emp.managerId = mgr.id\nWHERE emp.salary > mgr.salary;\n
        “,
      • “keyword”: “SQL”,
      • “frequency”: 0,
  • “id”: 378,
    • “question”: “Given employee table contain employee id, name, salary and manager id, find the employee whose salary is higher than their manager.”,
      • “answer”: “

        When you are asked to compare data inside same table, that is SELF join, the key to do self join is to treat the table as 2 tables.

        SELECT emp.name, mgr.name AS manager, emp.salary, mgr.salary AS manager_salary\nFROM employee emp\nJOIN employee mgr\nON emp.managerId = mgr.id\nWHERE emp.salary > mgr.salary;\n

        Here, i treat emplyee table as 2 tables, one is employee and another is manager, the SQL becomes very clear.

        “,
      • “keyword”: “SQL”,
      • “frequency”: 4,
  • “id”: 316,
    • “question”: “SQL how to delete duplicate rows, only keep unique rows”,
      • “answer”: null,
      • “keyword”: “SQL”,
      • “frequency”: 0,
  • “id”: 328,
    • “question”: “SQL: Given 2 tables, find the data in both of table that not matching each other”,
      • “answer”: null,
      • “keyword”: “SQL”,
      • “frequency”: 0,
  • “id”: 341,
    • “question”: “String literal and new and intern() objects”,
      • “answer”: “

        String str = \”abc\”. //constant pool create \”abc\” and str is referring pointing to \”abc\”

        String str1 = \”abc\” // since \”abc\” already in constant pool, so str1 just point to it, so there is only \”abc\” and str and str1 both point to the same one

        String str2 = \”abc\”.intern() //inter() will create a copy and put in constant pool, but since \”abc\” is already in constant pool, it will not create the copy, so str, str1, str2 point to same \”abc\”

        String str3 = new String(\”abc\”) // new String() always create a new Object in heap memory, not in constant pool.

        In the end, str, str1, str2 all point to same \”abc\” in constant pool. str3 point to new heap memory string

        “,
      • “keyword”: “String”,
      • “frequency”: 5,
  • “id”: 342,
    • “question”: “Why is String immutable in Java?”,
      • “answer”: “
        1. String use \”constant pool\”, once you put one string object in the constant pool, that object cannot be changed, if you try to change it, you will end up create new string instead of modifying it.
        2. String is made immutable because it can be used to hold security information like database credentials, user credentials, tokens etc, these information should not be changed.
        3. String is made immutable because it can be used as cache. Like when use String as map key, the hashcode will be cached as string, so when you call map.get(key) you dont need to calculate hashcode everytime.
        4. String is made immutable so that it is thread safe.
        “,
      • “keyword”: “String”,
      • “frequency”: 4,

System

  • “id”: 28,
    • “question”: “How much load can your API handle at the same time? What is your RPS”,
      • “answer”: “

        RPS: Requests per second is a metrics measuring how many requests per second.

        If your project is internal, it will be very minimal, you can have 1-10 requests at the same time and about 1-10 RPS

        if your project is not ecommerce, like insurance or bank, and if it is nation-wide, it could be 100 RPS.

        If your project is ecommerce or bank transactions, it could be very high, like 1000 or more RPS.

        For example, if you work on amazon or walmart or ebay or mastercard, chase bank, it is very busy, it could have 10,000 RPS.

        If you work in cvs, Geico etc, it could be up to 100 RPS


        “,
      • “keyword”: “System”,
      • “frequency”: 4,
  • “id”: 205,
    • “question”: “When your frontend or rest api loads slowly, how do you solve it?”,
      • “answer”: “

        Performance issue always can be answered from below points, you can address it from frontend to backend and then database

        Frontend:

        • If the request contains large amount of data, you can always split it into pages, just like Google display results in many pages, each page only has 50 records.
        • Use cache. If a page is visited or some data is previously loaded, cache it out, when load the page or data again, just use Cache.

        Backend:

        • Use pagination - same as frontend, Spring has PagingAndSortingRepository which can do pagination of the large dataset.
        • Use cache, if the data is not changing on every request, we can always cache it out to reduce calls to database
        • Use fast data retrieval tools, like Elastic Search, it will index the data and data reading very fast.
        • Use inspection tools, like JProfiler, DataDog etc to reduce unnecessary calls to database.
        • Improve the time complexity of the code.

        Database:

        • Improve SQL, use tools like \”Oracle Explain Plan\” to analyze the SQL performance, optimize the query and change joining order to improve SQL.
        • Add index to database tables, if a column is frequently used in SQL, we can add non-cluster index on the column
        • Combine multiple SQL calls into a stored procedure, so backend only call stored procedure once instead of calling multiple SQLs.



        “,
      • “keyword”: “System”,
      • “frequency”: 5,
  • “id”: 207,
    • “question”: “How to monitor the status of the application? / What dependency is used when monitoring the application?”,
      • “answer”: “

        Many tools to monitor

        Splunk: Use as application log file, can also use splunk SQL to search log, good for production

        CloudWatch: AWS tool, can track system memory usage, CPU usages, traffic, alerts etc

        DataDog: Performance and Analytics tools, can be used to record metrics, like Active Users, Requests, CPU, Memory usages. Also can be used for logs. Also used to traces, like availability and latency etc.

        JProfiler: Tool to for Java applications, can be used to check performance bottleneck, CPU usages, memory leaks and thread issues etc.

        Spring Actuator: Spring boot provided actuator tool with many endpoints to show the health of one service, like /metrics and /health and /info


        For Microservice

        Eureka: Service discovery, can be used to register services and check their running status.


        “,
      • “keyword”: “System”,
      • “frequency”: 5,
  • “id”: 209,
    • “question”: “How do you use cache in your whole project?”,
      • “answer”: “

        Also refer to the problem of \”how do you improve performance\”

        Cache can be used directly based on different applications.

        Frontend, you can cache the page out, you can also cache the data out, so the whole page will be cached.

        Backend

        • Inside Java, you can use java native cache, just like static hashmap can cache data as key-value entries
        • For application level or microservices, you can use distributed cache, like Redis or MemCached.
        “,
      • “keyword”: “System”,
      • “frequency”: 3,
  • “id”: 237,
    • “question”: “Ways to connect to database”,
      • “answer”: “
        1. JDBC - the basic way to connect to database, use statement/preparedStatement/callableStatement to run SQL direclty, use RestSet to host data. JDBC is the core for all other connections
        2. Hibernate - ORM framework. Use ORM so you dont need to write statement, SQL and ResultSet. Use Session and SessionFactory to do CRUD. Has 3 types of cache.
        3. Spring Data JPA - build on top of Java JPA. Use ORM framework as internal mapping tools and Use Naming Convention to do CRUD.
        “,
      • “keyword”: “System”,
      • “frequency”: 4,
  • “id”: 40,
    • “question”: “If you have error, but it is not showing in log, how do you debug and find it.”,
      • “answer”: null,
      • “keyword”: “System”,
      • “frequency”: 4,

Test

  • “id”: 240,
    • “question”: “What kind of test experience do you have?”,
      • “answer”: “

        Unit test: Junit, mockito, powermock – test each method, this is method level. The way to write unit test is to define a hard code input and call the target method and then verify if the result is correct using assert.

        Automation test: Selenium, Cucumber, TestNG

        Regression test: is to make sure the new part of code does not break the existing functions

        Integration test: is to make sure the new parts interacts/works well with the other parts.

        End to End test: is to make sure the entire workflow works from beginning to end.


        Regression/Integration/End2End tests are just different type of tests, they are mostly implemented by Selenium and Cucumber or TestNG.

        “,
      • “keyword”: “Test”,
      • “frequency”: 5,
  • “id”: 245,
    • “question”: “Cucumber and its annotations / How cucumber works, give an example”,
      • “answer”: “

        When they ask what test framework have you done, always mention \”Junit/Mockito\” and \”Selenium/Cucumber\”

        Cucumber aims to create tests cases that both business team and developers can understand. Business team knows the requirements but does not know how to write test cases, developer team knows how to write test cases but not very familiar with the requirements. Cucumber uses Gherkins language with feature file and step definitions script to connect them.

        Feature file defines test scenarios like below, it uses keyword like \”scenario\”, \”given\”, \”when\”, \”and\”, \”then\”:

        Feature: Login Functionality\n  Scenario: Successful login with valid credentials\n    Given the user is on the login page\n    When the user enters a valid username and password\n    And clicks the login button\n    Then the user should be redirected to the dashboard page\n

        The step definitions file uses annotations like @Given @When @Then to write test cases. @Given is for given conditions, @When is for input @Then is for result.

        For example for login, @Given is user is at the login page, @When is a method when user enters the credentials and click login, @Then will be a method to verify the user enters homepage.

        these annotations use brackets to include the feature file steps

        \n    @Given(\”the user is on the login page\”)\n    public void the_user_is_on_the_login_page() {\n        System.setProperty(\”webdriver.chrome.driver\”, \”/path/to/chromedriver\”);\n        driver = new ChromeDriver();\n        driver.get(\”https://example.com/login\");\n&nbsp;   }\n\n\n    @When(\”the user enters a valid username and password\”)\n    public void the_user_enters_a_valid_username_and_password() {\n        driver.findElement(By.id(\”username\”)).sendKeys(\”validUsername\”);\n        driver.findElement(By.id(\”password\”)).sendKeys(\”validPassword\”);\n    }\n\n\n    @When(\”clicks the login button\”)\n    public void clicks_the_login_button() {\n        driver.findElement(By.id(\”loginButton\”)).click();\n    }\n\n\n    @Then(\”the user should be redirected to the dashboard page\”)\n    public void the_user_should_be_redirected_to_the_dashboard_page() {\n        String expectedUrl = \”https://example.com/dashboard\";\n&nbsp;       String actualUrl = driver.getCurrentUrl();\n        Assert.assertEquals(actualUrl, expectedUrl);\n        driver.quit();\n    }\n}\n\n\n
        “,
      • “keyword”: “Test”,
      • “frequency”: 5,
  • “id”: 239,
    • “question”: “Functional test & Integrtion test & Unit test”,
      • “answer”: null,
      • “keyword”: “Test”,
      • “frequency”: 0,
  • “id”: 241,
    • “question”: “What’s the test framework in your team?”,
      • “answer”: null,
      • “keyword”: “Test”,
      • “frequency”: 0,
  • “id”: 242,
    • “question”: “Talk about Mockito and give an example”,
      • “answer”: null,
      • “keyword”: “Test”,
      • “frequency”: 0,
  • “id”: 243,
    • “question”: “Talk about different test you did before”,
      • “answer”: null,
      • “keyword”: “Test”,
      • “frequency”: 0,
  • “id”: 244,
    • “question”: “JUnit vs. Automation”,
      • “answer”: null,
      • “keyword”: “Test”,
      • “frequency”: 0,
  • “id”: 246,
    • “question”: “What is the limitation of the Mockito?”,
      • “answer”: null,
      • “keyword”: “Test”,
      • “frequency”: 0,
  • “id”: 247,
    • “question”: “Can you mock a static field using Mockito?”,
      • “answer”: null,
      • “keyword”: “Test”,
      • “frequency”: 0,
  • “id”: 248,
    • “question”: “How to test a private method without other framework?”,
      • “answer”: null,
      • “keyword”: “Test”,
      • “frequency”: 0,
  • “id”: 304,
    • “question”: “Difference: InjectMock vs InjectMockBean”,
      • “answer”: null,
      • “keyword”: “Test”,
      • “frequency”: 0,
  • “id”: 326,
    • “question”: “Unix/Linux: list java process, kill a process, search a file”,
      • “answer”: null,