Posts

Java Interview Question - New FAQs

1. Performance Testing & Setting up benchmarks Performance testing evaluate how a system performs under load & to setup benchmarks below steps to be noted down. Steps are: Define KPIs: Response time, throughput, CPU/memory usage etc. Identify Critical Scenarios: like login, search, submit form Use Tools: Gatling, Apache Bench, JMeter (Use to simulate 1000 concurrent users hitting a Rest API and measure the response time Baseline Measurement: Run tests under normal load to establish a baseline Load Testing: Gradually increase users to find system limits Stress Testing: Push beyond limits to see how the system fails Bench marking: Compare results against industry standards or previous releases 2. ACID properties in database It ensure the reliable transaction Atomicity : All operations in a transaction succeed or none do Consistency : DB remains in a valid state before and after the transaction Isolation : Concurrent transactions don't interfere Durability : Once commited...

DSA Interview Coding Questions

1] Arrays 1] Find first and second best score Example Given an array, write a function to get first, second best scores from the array and return it in new array. Array may contain duplicates. Example myArray = { 84 , 85 , 86 , 87 , 85 , 90 , 85 , 83 , 23 , 45 , 84 , 1 , 2 , 0 } firstSecond ( myArray ) // {90, 87} Solution: import java . util . Arrays ; import java . util . Collections ; public class Exercise { public static int [] findTopTwoScores ( int [] array ) { int firstHighest = Integer . MIN_VALUE ; int secondHighest = Integer . MIN_VALUE ;   for ( int score : array ) { if ( score > firstHighest ) { secondHighest = firstHighest ; firstHighest = score ; } else if ( score > secondHighest && score < firstHighest ) { secondHighest = score ; } }   return new int []{ firstHighest , secondHighest }...

Map - DS Algo related questions

The Map data structure in Java is widely used in various scenarios and is a common topic in technical interviews. Here are some examples of how Map can be used in different programs or interview questions, along with Java and Java 8 code snippets. 1. Counting Frequency of Elements Problem: Given an array of integers, count the frequency of each element. Example: import java.util.HashMap; import java.util.Map; public class FrequencyCounter { public static void main (String[] args) { int [] arr = { 1 , 2 , 2 , 3 , 3 , 3 , 4 , 4 , 4 , 4 }; Map<Integer, Integer> frequencyMap = new HashMap <>(); for ( int num : arr) { frequencyMap.put(num, frequencyMap.getOrDefault(num, 0 ) + 1 ); } System.out.println(frequencyMap); } } Output: {1=1, 2=2, 3=3, 4=4} 2. Finding First Non-Repeated Character in a String Problem: Given a string, find the first non-repeated character. Example: import java.util.LinkedHashMa...