DEV Community

Jagadish Rajasekar
Jagadish Rajasekar

Posted on

Top 50 Programming Questions (with Answers) for Performance Testers

Performance testing interviews often include programming questions to validate that you can script, automate, and debug under real-world scenarios.

This guide compiles 50 common questions with answers β€” covering strings, arrays, algorithms, file handling, JSON/XML, random data, and concurrency β€” in Java, Groovy (JMeter), and C (LoadRunner).

Use this as a refresher before interviews.


πŸ“Œ Section 1: Strings (Q1–Q10)

Q1. Reverse a String

Java

String str = "performance";
String rev = new StringBuilder(str).reverse().toString();
System.out.println(rev);
Enter fullscreen mode Exit fullscreen mode


`

Groovy

groovy
def str = "performance"
println str.reverse()

C

c
char str[] = "performance";
int i, len = strlen(str);
for(i=len-1; i>=0; i--) printf("%c", str[i]);


Q2. Check Palindrome

java
String str="madam";
System.out.println(str.equals(new StringBuilder(str).reverse().toString()));

groovy
def str="madam"
println str == str.reverse()

c
char str[]="madam"; int i=0, j=strlen(str)-1, flag=1;
while(i<j) if(str[i++]!=str[j--]) flag=0;
printf(flag?"Palindrome":"Not Palindrome");


Q3. Find Substring

java
System.out.println("hello".contains("ell"));

groovy
println "hello".contains("ell")

c
printf(strstr("hello","ell")?"Found":"Not Found");


Q4. Count Vowels

java
String s="performance"; long count=s.chars().filter(c->"aeiou".indexOf(c)!=-1).count();
System.out.println(count);

groovy
println "performance".count{ it in ['a','e','i','o','u'] }

c
char s[]="performance"; int c=0;
for(int i=0;i<strlen(s);i++) if(strchr("aeiou",s[i])) c++;
printf("%d",c);


Q5. Remove Whitespace

java
System.out.println("a b c".replaceAll("\\s",""));

groovy
println "a b c".replaceAll("\\s","")

c
// copy only non-space chars


Q6. Find Duplicate Characters

java
String s="testing";
Map<Character,Integer> map=new HashMap<>();
for(char c:s.toCharArray()) map.put(c,map.getOrDefault(c,0)+1);
map.forEach((k,v)->{if(v>1)System.out.println(k);});


Q7. String Compression

Input: aaabbc β†’ Output: a3b2c1

java
String s="aaabbc"; StringBuilder sb=new StringBuilder();
for(int i=0;i<s.length();) {
int j=i; while(j<s.length() && s.charAt(i)==s.charAt(j)) j++;
sb.append(s.charAt(i)).append(j-i); i=j;
}
System.out.println(sb);


Q8. Anagram Check

java
char[] a="listen".toCharArray(), b="silent".toCharArray();
Arrays.sort(a); Arrays.sort(b);
System.out.println(Arrays.equals(a,b));


Q9. Extract Tokens from URL

java
String url="https://site.com?id=123&user=john";
String[] parts=url.split("\\?");
System.out.println(parts[1]); // id=123&user=john


Q10. Replace Words

java
System.out.println("LoadRunner vs JMeter".replace("vs","and"));


πŸ“Œ Section 2: Arrays & Collections (Q11–Q20)

Q11. Find Duplicates

java
int[] arr={1,2,3,2,1};
Set<Integer> set=new HashSet<>();
for(int n:arr) if(!set.add(n)) System.out.println("Dup:"+n);


Q12. Find Missing Number (1..N)

java
int[] arr={1,2,4,5}; int n=5, sum=n*(n+1)/2, s=0;
for(int x:arr) s+=x;
System.out.println("Missing:"+(sum-s));


Q13. Max/Min

java
int[] arr={3,5,1};
System.out.println(Arrays.stream(arr).max().getAsInt());


Q14. Reverse an Array

java
int[] arr={1,2,3};
for(int i=0,j=arr.length-1;i<j;i++,j--){
int tmp=arr[i]; arr[i]=arr[j]; arr[j]=tmp;
}


Q15. Rotate Array

java
Collections.rotate(Arrays.asList(arr),2);


Q16. Check Sorted

java
boolean sorted=IntStream.range(1,arr.length).allMatch(i->arr[i]>=arr[i-1]);


Q17. Common Elements

java
Set<Integer> s1=new HashSet<>(Arrays.asList(1,2,3));
Set<Integer> s2=new HashSet<>(Arrays.asList(2,3,4));
s1.retainAll(s2);
System.out.println(s1);


Q18. Merge Two Sorted Arrays

java
// classic merge procedure


Q19. Remove Duplicates

java
Arrays.stream(arr).distinct().toArray();


Q20. Frequency Count

java
Map<Integer,Long> freq=Arrays.stream(arr).boxed()
.collect(Collectors.groupingBy(i->i,Collectors.counting()));


πŸ“Œ Section 3: Numbers & Algorithms (Q21–Q30)

Q21. Fibonacci

java
int a=0,b=1;
for(int i=0;i<10;i++){System.out.print(a+" "); int c=a+b; a=b;b=c;}


Q22. Factorial

java
int f=1,n=5;
for(int i=1;i<=n;i++) f*=i;


Q23. Prime Check

java
int n=17; boolean prime=IntStream.range(2,n).noneMatch(i->n%i==0);


Q24. Armstrong Number

java
int n=153,sum=0,t=n;
while(t>0){int d=t%10; sum+=d*d*d; t/=10;}
System.out.println(sum==n);


Q25. Sum of Digits

java
int n=1234,sum=0;
while(n>0){sum+=n%10;n/=10;}


Q26. Swap Numbers (No Temp)

java
a=a+b; b=a-b; a=a-b;


Q27. GCD

java
int gcd(int a,int b){return b==0?a:gcd(b,a%b);}


Q28. Binary Search

java
int bs(int arr[],int x){
int l=0,h=arr.length-1;
while(l<=h){int m=(l+h)/2;
if(arr[m]==x)return m;
if(arr[m]<x) l=m+1; else h=m-1;}
return -1;
}


Q29. Bubble Sort

java
for(int i=0;i<n-1;i++)for(int j=0;j<n-i-1;j++)
if(arr[j]>arr[j+1]){int t=arr[j];arr[j]=arr[j+1];arr[j+1]=t;}


Q30. Quick Sort

java
// standard partition-based algorithm


πŸ“Œ Section 4: Data Structures (Q31–Q35)

Q31. Stack

java
Stack<Integer> st=new Stack<>();
st.push(1); st.pop();


Q32. Queue

java
Queue<Integer> q=new LinkedList<>();
q.add(1); q.remove();


Q33. Reverse Linked List

java
// iterative reversal


Q34. Word Count

java
String s="this is test this";
Map<String,Long> map=Arrays.stream(s.split(" "))
.collect(Collectors.groupingBy(w->w,Collectors.counting()));


Q35. Balanced Parentheses

java
// use stack to check if '(' matches ')'


πŸ“Œ Section 5: File Handling (Q36–Q40)

Q36. Read File

java
Files.lines(Paths.get("file.txt")).forEach(System.out::println);


Q37. Write File

java
Files.write(Paths.get("out.txt"), "hello".getBytes());


Q38. Count Lines

java
long lines=Files.lines(Paths.get("file.txt")).count();


Q39. Search Keyword

java
Files.lines(Paths.get("file.txt")).filter(l->l.contains("error")).forEach(System.out::println);


Q40. Parse CSV

java
Files.lines(Paths.get("data.csv")).map(l->l.split(",")).forEach(arr->System.out.println(arr[0]));


πŸ“Œ Section 6: JSON & XML (Q41–Q45)

Q41. Parse JSON

java
import org.json.*;
JSONObject obj=new JSONObject("{\"user\":\"john\",\"token\":\"xyz\"}");
System.out.println(obj.getString("token"));


Q42. Convert Object to JSON

java
JSONObject obj=new JSONObject();
obj.put("id",123); obj.put("name","test");


Q43. Parse XML

java
Document doc=DocumentBuilderFactory.newInstance().newDocumentBuilder().parse("file.xml");


Q44. Count XML Nodes

java
NodeList list=doc.getElementsByTagName("user");
System.out.println(list.getLength());


Q45. Validate JSON Contains Key

java
System.out.println(obj.has("token"));


πŸ“Œ Section 7: Random Data (Q46–Q48)

Q46. Random Number

java
int n=new Random().nextInt(100);


Q47. UUID

java
String id=UUID.randomUUID().toString();


Q48. Shuffle

java
List<Integer> list=Arrays.asList(1,2,3,4,5);
Collections.shuffle(list);


πŸ“Œ Section 8: Concurrency (Q49–Q50)

Q49. Threads

java
for(int i=0;i<5;i++){
new Thread(()->System.out.println("Hello "+Thread.currentThread().getId())).start();
}


Q50. Synchronization

java
class Counter{int c=0; synchronized void inc(){c++;}}
Counter ct=new Counter();


βœ… Final Takeaway

Performance testers/engineers don’t need to be full-time developers β€” but being comfortable with strings, arrays, file I/O, JSON/XML parsing, and multithreading basics makes you stand out.
These 50 questions cover the most common interview checks across JMeter, LoadRunner, and real-world scripting.


`


Top comments (0)