August 01, 2021

Core Concepts and Brief Explanation



Question : Why to Override equals(Object) and hashCode() method ?
Solution: HashMap and HashSet use the hashcode value of an object to find out how the object would be stored in the collection, and subsequently hashcode is used to help locate the object in the collection. Hashing retrieval involves:
  1. First, find out the right bucket using hashCode().
  1. Secondly, search the bucket for the right element using equals()
Reference: https://www.geeksforgeeks.org/override-equalsobject-hashcode-method/
  
Question : Strategy design pattern


Solution: The strategy pattern is a Behavioral software design pattern that enables selecting an algorithm at runtime. Instead of implementing a single algorithm directly, code receives run-time instructions as to which in a family of algorithms to use.




Question: Advantages of MongoDB are as follows:

Solution:

  • MongoDB supports field, range-based, string pattern matching type queries. for searching the data in the database 
  • MongoDB support primary and secondary index on any fields
  • MongoDB basically uses JavaScript objects in place of procedures
  • MongoDB uses a dynamic database schema
  • MongoDB is very easy to scale up or down
  • MongoDB has inbuilt support for data partitioning (Sharding).

Reference: https://www.interviewbit.com/mongodb-interview-questions/

 

Question: Write program: get the employee salary > 10000 rupees in the provided list

Solution:

packagecom.test; 

importjava.util.*;

importjava.util.stream.Collectors;

 

publicclassTestEmployee {

        publicstaticvoidmain(String... args) {

                List<Employee> empList= newArrayList<>();

                empList.add(newEmployee("test1", 1235));

                empList.add(newEmployee("test2", 12353));

                empList.add(newEmployee("test3", 12352));

                empList.add(newEmployee("test4", 12345));

                empList.add(newEmployee("test5", 1235));

                List<String> resEmpList= empList.stream().filter(e-> e.getSalary() > 10000).map(e-> e.getName())

                                .collect(Collectors.toList());

                resEmpList.stream().forEach(System.out::println);

        }

}

 

classEmployee {

        privateString name;

        privateInteger salary;

        publicString getName() {

                return name;

        }

        publicvoidsetName(String name) {

                this.name= name;

        }

        publicInteger getSalary() {

                return salary;

        }

        publicvoidsetSalary(Integer salary) {

                this.salary= salary;

        }

        publicEmployee(String name, Integer salary) {

 

                this.name= name;

                this.salary= salary;

        }

}



Question: What is docker?

Solution:

Docker is a very popular and powerful open-source containerization platform that is used for building, deploying, and running applications. Docker allows you to decouple the application/software from the underlying infrastructure.

In order to get the status of all the containers, we run the below command:  

docker ps -a


docker save command and the syntax is: 

docker save -o <exported_name>.tar <container-name>


docker load command and the syntax is 

docker load -i <export_image_name>.tar

 

There are three docker components, they are - Docker Client, Docker Host, and Docker Registry.

  • Docker Client: This component performs “build” and “run” operations for the purpose of opening communication with the docker host.
  • Docker Host: This component has the main docker daemon and hosts containers and their associated images. The daemon establishes a connection with the docker registry.
  • Docker Registry: This component stores the docker images. There can be a public registry or a private one. The most famous public registries are Docker Hub and Docker Cloud.

Reference: https://www.interviewbit.com/docker-interview-questions/


 

Question: What is Thread life Cycle?

Solution:

The java.lang.Thread class contains a static State enum – which defines its potential states. During any given point of time, the thread can only be in one of these states:

  1. NEW – a newly created thread that has not yet started the execution
  2. RUNNABLE – either running or ready for execution but it's waiting for resource allocation
  3. BLOCKED – waiting to acquire a monitor lock to enter or re-enter a synchronized block/method
  4. WAITING – waiting for some other thread to perform a particular action without any time limit
  5. TIMED_WAITING – waiting for some other thread to perform a specific action for a specified period
  6. TERMINATED – has completed its execution 

Reference: https://www.baeldung.com/java-thread-lifecycle

 

Question: What is Hibernate Lifecycle?

Solution:

There are mainly four states of the Hibernate Lifecycle :

  1. Transient State
  2. Persistent State
  3. Detached State
  4. Removed State

Reference: https://www.geeksforgeeks.org/hibernate-lifecycle/

 


No comments:

Post a Comment

I'm certainly not an expert, but I'll try my hardest to explain what I do know and research what I don't know.

My Favorite Site's List

#update below script more than 500 posts