This repository will contain all the java, spring, hibernate, mysql, elastic search, thread, related questions.
-
- Blocking queue
- Producer and consumer approach
- final syncronization variable or method can be possible?
- Why is synchronized block better than synchronized method?
- Why Wait(), Notify() and NotifyAll() Defined in Object Class?
- Guide To CompletableFuture
- Difference Between ConcurrentHashMap and SynchronizedHashMap
-
- Wha is metaspace in java 8?
- Supplier Interface in java
- Predicate Interface in java
- Parallel Stream with findFirst?
- Stateless and stateful operations of stream
- How parallel stream works?
- What is major diff. between forEach and stream?
- Optional class in java 8 uses and methods available
- Functional Interface
- Why java is known as functional programing?
- Stream map and flatmap example
- What is ThreadLocal and when to use this?
-
Why is it need for hashCode and equal method to override in a class?
- @Bean can be used at class level?--No
- What is difference between spring and spring boot?
- Types of autowiring in spring
- How to include one package to another package?
- Use of @ComponentScan annotation?
- Can we use @component instead of @service in spring?
- Why spingboot?
- How spring transaction management work?
- What is a transitive Maven dependency?
- Maven Dependency Scopes
- Types of IOC containers in Spring Framework
- What is servlet controller?
- What is sping boot acuator
- What is dev tools in spring? For what purpose it is used?
- What is spring MVC?
- Write spring annotation with cron expression for a job which execute at every 5 min. Is at main class we to annotate any annotaion?If yes then with which?
- When to use Qualifier and Primary in Spring?
- How to add intercept in Spring Application or which annotation is used to implement interceptor
- Twelve-Factor Methodology in a Spring Boot Microservice
- How to write centralized exception handler in SpringBoot?
- What is @ControllerAdvice in Spring?
- What is PostConstruct in Spring?
- What is springboot actuators?
- what is difference between component and bean in spring?
- How to configure multiple datasource in springboot?
http://hibernate.org/orm/documentation/5.4/
- What Is a Second-Level Cache?
- [Is cache persist for session means for session object or application or db system?]
- Different annotations in hibernate?
- @OneToMany mapping?
- What is the use of @inheritance?
- How to use super class and subclass as individual entity?
- Where we can use @manyToMany mapping, explain we example?
- What is disadvantage of hibernate?
- What is the "N+1 selects problem" in ORM (Object-Relational Mapping)?
- Different between clear(), evict() and close() methods in Hibernate?
- Self join of same table for username and manager name.
- What is the use of Composite key? - MySql Tuning?
- How to delete only duplicate/copy from employ table?
- How to fetch first and last record from the table?
- Write MySql query to print second highest salary from employee table?
- What is difference between OLAP and OLTP
- What is left outer join? Explain
- What are the types of normalization? Explain all?
- Best practice for writing naming convention of api URI.
- Difference between PATCH, PUT and POST Method?
- REST API using POST instead of GET
https://www.elastic.co/guide/en/elasticsearch/reference/current/docs.html
- different types of queries
- less than and greater than
- How to fetch total record no. of a query?
- What is token filter(stopwords, tokenizer, etc)?
- What is analyser? How we can use this in ES?
- How to create mapping?
- What are different Http methods use in ES query?
- [Instead of POST when we PUT some record/doc then what will happen?]
- Why double checking in Singleton?
- Singleton real world example.
- What is proxy class?
- How to create proxy design pattern?
- What is abstract design pattern?
- What is Command design pattern? Where we can use this?
- What are the different design pattern use in Spring framework?
- How to prevent Singleton Pattern from Reflection, Serialization and Cloning?
- What is microservice design pattern?
- What is factory design pattern and how is it correlated to Singleton design pattern?
- What is a transitive Maven dependency?
- Dependency scope of maven
- What is main purpose of maven?
- How maven search dependency in your system? Explain.
- How to prevent a network or service failure from cascading to other services?
- How to manage Latency and Fault Tolerance for Distributed Systems?
- What are the Components are Microservices Architecture?
- How to call Rest Service in Python?
- What are the ways to fetch second element from list in Python?
- What are different Access Modifier?
- What is Inheritence?
- What is the use of @staticmethod and @property?
- Types of Arguments
- What are differnt places where single(_) and double Underscore (__) is being used?
- What is pass keyword?
- What are tuples, and give an example where you prefer to use tuple instead of list?
- What are different types of React Component?
- How router is done in react?
- How to consume rest api from react?
- What are the design principle you follow while creating react app?
- What is hooks in react?
- What is promise and Observable?
- What is the life cycle of react?
- Different HTTP types? What is PATCH http method?
- What will be differrent reason when below 2 mb file uploaded and above doesn't through a api?
- What is difference between process and program?
- What is CSRF(Cross-Site Request Forgery)?
- What is CROS Policy?
- What is Oauth2?
- How to improve website proformance(frontend, backend, database,etc)
- Find 2nd lagest number in an array? Input: {23,10,34,23,20} -> output: 23
set arr = [23,10,34,23,20] int lengthOfArray = arr.length(); int max = 0; int secondMax = 0; for(int i=0;i<lengthOfArray;i++){ if(arr[i]>max){ secondMax = max; max= arr[i]; } s.o.p(secondMax); }
- Occurance count string = "AAABBCCCDDAACCEE" then ouput : 3A2B3C2D2A2C2E
public class Main { public static void main(String[] args) { String str = "AAABBCCCDDAACCEE"; int strLength = str.length(); char ch = str.charAt(0); int counter = 0; for(int i=0;i<strLength;i++){ if(ch == str.charAt(i)){ counter=counter+1; continue; } else { System.out.print(counter); System.out.print(ch); counter = 1; ch = str.charAt(i); } } System.out.print(counter); System.out.print(ch); } }
- all permutation of a string = "ABC" then ouput : ABC, ACB, BAC, BCA, CAB, CBA
- https://www.onlinegdb.com/Ptod_C-qS
- https://www.onlinegdb.com/2_k3E2v6H
- Print the second highest from the given list of integer in java
- Java Program to Get the middle element of LinkedList in a single iteration.
- Recursive find fibonacci number?
public class Test { //0,1,1,2,3,5,8,13 public static int fib(int n) { if(n==1) { return 0; }else if(n==2){ return 1; }else { return fib(n-1)+fib(n-2); } } public static void main(String []args) { System.out.println(fib(8)); } }
- [Using Steam API genelrate list of string from a comma seperated string]
String commanSeperated = "ashish,karn,sunil,kumar,anil,verma"; List<String> listOfStr = Arrays.stream(commanSeperated.split(",")).collect(Collectors.toList());
- Transform from [0,1,0,1,0,1,1,1,0,0] to [0,0,0,0,0,1,1,1,1,1]
int[] arr = {0, 1, 0, 1, 0, 1, 1, 0, 1, 1 };
boolean flagFindOne = true;
int indexOfOne = -1;
for (int i = 0; i < arr.length; i++) {
if (flagFindOne && arr[i] == 1) {
indexOfOne = i;
flagFindOne = false;
} else if (!flagFindOne && arr[i] == 0) {
int temp = arr[i];
arr[i] = arr[indexOfOne];
arr[indexOfOne] = temp;
i = indexOfOne;
flagFindOne = true;
}
}
System.out.println(Arrays.toString(arr));
- Write a java program to get maxing profit by buying and selling a share from a given set of values. If consider buying only once and selling once.
- You are given an array prices where prices[i] is the price of a given stock on the ith day.
Return the maximum profit you can achieve from this transaction. If you cannot achieve any profit, return 0.
Example 1:
Input: prices = [7,1,5,3,6,4]
Output: 5
Explanation: Buy on day 2 (price = 1) and sell on day 5 (price = 6), profit = 6-1 = 5.
Note that buying on day 2 and selling on day 1 is not allowed because you must buy before you sell.
Example 2:
Input: prices = [7,6,4,3,1]
Output: 0
Explanation: In this case, no transactions are done and the max profit = 0.
int stockPrices[] = {7,6,4,3,1};
int len = stockPrices.length;
Map<Integer,Integer> pairs = new HashMap<>();
for(int i=0;i<len;i++) {
for(int j=i+1;j<len;j++) {
if(stockPrices[i] < stockPrices[j] ) {
if(pairs.get(stockPrices[i]) == null || pairs.get(stockPrices[i]) < stockPrices[j]) {
pairs.put(stockPrices[i], stockPrices[j]);
}
}
}
}
System.out.println(pairs);
int max = 0;
for(Entry<Integer, Integer> value:pairs.entrySet()) {
if(max < (value.getValue() - value.getKey())) {
max = value.getValue() - value.getKey();
}
}
System.out.println(max);
-
Find forth largest number using stream api.
int fourthLargest = Arrays.stream(arr).boxed().sorted(Comparator.reverseOrder()).skip(3).findFirst().get(); System.out.print(fourthLargest);
-
Find employe list which have lowest salary from the dept.
name:
salary:
dept:
emp_id
Map<Integer, Employe> mapOfEmployes
- Find count of string and all char existence
main(){
String str = "ashish Karnqweeeqwewqes123645dfsdfa123";
int arr[] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}; //26 length
for(int i=0;i<str.lenght;i++){
if(ascii(str[i]) > 96 && ascii(str[i]) < 122){
arr[ascii(str[i])-97] = arr[ascii(str[i])-97] + 1;
}
}
print(isAllCharExists(arr))
}
boolean isAllCharExists(int []arr){
for(int i=0;i<arr.length;i++){
if(arr[i]==0){
return false;
}
}
return true;
}
boolean displayCharCount(int []arr){
for(int i=0;i<arr.length;i++){
print(charValueOf(97+i), " ")
print(arr[i])
}
return true;
}
- Reverse word of the sentence. Like "my name is khan" to "ym eman si nahk"
String str = "my name is khan";
String[] strArr = str.split(" ");
for(int i=0;i<strArr.length;i++) {
for(int j=strArr[i].length()-1;j>=0;j--) {
System.out.print(strArr[i].charAt(j));
}
System.out.print(" ");
}
- Three best rating from Employee list
Employee employee = new Employee();
employee.rating = 5;
employees.add(employee);
employee = new Employee();
employee.rating = 6;
employees.add(employee);
List<Employee> collect = employees.stream().sorted((f1, f2) -> Integer.compare(f2.rating, f1.rating)).limit(3).collect(Collectors.toList());
or
List<Employee> collect = employees.stream().sorted(Comparator.comparingLong(Employee::getRating).reversed()).limit(3).collect(Collectors.toList());
System.out.println(collect);
return items.stream()
.filter(Objects::nonNull)
.collect(Collectors.groupingBy(Function.identity(), Collectors.counting()));