KB Java Microservics Int
KB Java Microservics Int
another micro service using Eureka. Each micro service is Eureka client and there
will be one Eureka server)
@EnableEurekaClient
@EnableEurekaServer
Circuit Breaker Pattern : Hystrix (When micro service is down, you call
"getFallbackMethod" method is executed)
@EnableCircuitBreaker
@HystrixCommand(fallbackMethod= "getFallbackMethod")
@HystrixProperty
spring boot actuator : This will expose all the endpoints when some prop enables in
application.properties
spring profile : It will pick default profile by default and it will pick specific
profile with "application-<profile>.extension"
spring.profiles.active: <profile>
@profile("dev")
@profile("production")
@RefereshScope --> Refreshes the spring cloud server config file from git repo
Kubernetes :
1.High Avaialbility or no downtime
2.Scalability or High performance
3.Disaster Recovery : Backup and restore
NodePort :
Dynamic Programming :
Solid principles
Thread Local
when to use static and when to use immutable class
what is ?
what is polymorphism?
Polymorphism in Java has two types: Compile time polymorphism (static binding) and
Runtime polymorphism (dynamic binding). Method overloading is an example of static
polymorphism, while method overriding is an example of dynamic polymorphism
what is shallow copy and deep copy in clone method?
shallow copy : Copies the reference and if original value changes, the copied value
also changes for obhjects
and it copies the exact value of the primitives and not objects
deep copy : creates objects with new operator so the values will never change after
orginal value changes or it copies all the fields
Try with resource --> Which all objects eligible : Closable interface
Bifunctional interface? :
@FunctionalInterface
public interface BiFunction<T, U, R> {
R apply(T t, U u);
Solid principles:
Example :
// Can be implemented
public void drive() {...}
public void stop() {...}
public void refuel() {...}
ThreadLocal :
It is used for individual thread and it acts as a local thread for each thread and
the values of one thread cannot be read and modified by other thread
2 threads cannot see the value of each other. They can set and get different
values.
Design Pattern :
1. Singleton
2. Micro Service
3. Circuit Breaker
4. Service Discovery
5. Iterator Pattern
6. Dependency Injection Pattern
7. Factory Design Pattern
8. Observer Design Pattern
9. MVC Pattern
10. Builder Pattern
What is bean?
https://app.coderpad.io/PRPC4TWA
Map<id, Employee>
Employee
id, name, slaary
https://www.youtube.com/watch?v=SzbeDqBSRkc&t=540s
Searching Algorithm :
2. Binary Search : Search element based on left and right index. Check if the
element is present in the first half or second half.
T(n) = T(n/2) + c
3. Jump Search : The basic idea is to check fewer elements (than linear search) by
jumping ahead by fixed steps or skipping some elements in place of searching all
elements.
Let’s consider the following array: (0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144,
233, 377, 610). Length of the array is 16. Jump search will find the value of 55
with the following steps assuming that the block size to be jumped is 4.
STEP 1: Jump from index 0 to index 4;
STEP 2: Jump from index 4 to index 8;
STEP 3: Jump from index 8 to index 12;
STEP 4: Since the element at index 12 is greater than 55 we will jump back a step
to come to index 8.
STEP 5: Perform linear search from index 8 to get the element 55.
Linear Search finds the element in O(n) time, Jump Search takes O(√ n) time and
Binary Search take O(Log n) time.
4. Interpolation Search :
The Interpolation Search is an improvement over Binary Search for instances, where
the values in a sorted array are uniformly distributed. Binary Search always goes
to the middle element to check. On the other hand, interpolation search may go to
different locations according to the value of the key being searched. For example,
if the value of the key is closer to the last element, interpolation search is
likely to start search toward the end side.
------------------------------------------------Sorting
Algorithm-------------------------------
1. Selection Sort
The selection sort algorithm sorts an array by repeatedly finding the minimum
element (considering ascending order) from unsorted part and putting it at the
beginning. The algorithm maintains two subarrays in a given array.
arr[] = 64 25 12 22 11
2. Bubble Sort
Bubble Sort is the simplest sorting algorithm that works by repeatedly swapping the
adjacent elements if they are in wrong order.
Example:
First Pass:
( 5 1 4 2 8 ) –> ( 1 5 4 2 8 ), Here, algorithm compares the first two elements,
and swaps since 5 > 1.
( 1 5 4 2 8 ) –> ( 1 4 5 2 8 ), Swap since 5 > 4
( 1 4 5 2 8 ) –> ( 1 4 2 5 8 ), Swap since 5 > 2
( 1 4 2 5 8 ) –> ( 1 4 2 5 8 ), Now, since these elements are already in order (8 >
5), algorithm does not swap them.
Second Pass:
( 1 4 2 5 8 ) –> ( 1 4 2 5 8 )
( 1 4 2 5 8 ) –> ( 1 2 4 5 8 ), Swap since 4 > 2
( 1 2 4 5 8 ) –> ( 1 2 4 5 8 )
( 1 2 4 5 8 ) –> ( 1 2 4 5 8 )
Now, the array is already sorted, but our algorithm does not know if it is
completed. The algorithm needs one whole pass without any swap to know it is
sorted.
Third Pass:
( 1 2 4 5 8 ) –> ( 1 2 4 5 8 )
( 1 2 4 5 8 ) –> ( 1 2 4 5 8 )
( 1 2 4 5 8 ) –> ( 1 2 4 5 8 )
( 1 2 4 5 8 ) –> ( 1 2 4 5 8 )
3. Insertion Sort :
Insertion sort is a simple sorting algorithm that works similar to the way you sort
playing cards in your hands. The array is virtually split into a sorted and an
unsorted part. Values from the unsorted part are picked and placed at the correct
position in the sorted part.
Algorithm
To sort an array of size n in ascending order:
1: Iterate from arr[1] to arr[n] over the array.
2: Compare the current element (key) to its predecessor.
3: If the key element is smaller than its predecessor, compare it to the elements
before. Move the greater elements one position up to make space for the swapped
element.
4. Merge Sort
Like QuickSort, Merge Sort is a Divide and Conquer algorithm. It divides the input
array into two halves, calls itself for the two halves, and then merges the two
sorted halves. The merge() function is used for merging two halves. The merge(arr,
l, m, r) is a key process that assumes that arr[l..m] and arr[m+1..r] are sorted
and merges the two sorted sub-arrays into one