Sunday 4 July 2021

Java Coding Interview Question for Automation Testing / QA / SDET?




Java Interview question Set-1:
SET-01 1-10

Java Interview question Set-2:

SET-02 10-20

Java Interview question Set-3:

SET-03 21-30


1. Find the second largest in an ARRAY?

public class firstsecodlargest {

public static void main(String[] args) {

int[] arr = {1,2,3,4,5,6};

int firstlargest=0;

int secondlargest=0;

int i=0;

int n= arr.length;

for (i=0;i<n;i++) 

{

if (arr[i]>firstlargest){

secondlargest=firstlargest;

firstlargest=arr[i];

}

}

System.out.println(firstlargest + "  " + secondlargest);


}}


2. How to do sorting in HashMap?

Click Here For Answer


3. How to find maximum and minimum in an ARRAY?


class maxminarray {

static int findmax[] = {10, 324, 45, 90, 9808};

static int max()

{

int i;

int max = findmax[0];

for (i=1;i<findmax.length;i++)

if (findmax[i] > max)

max = findmax[i];

return max;

}

static int min()

{

int i;

int min = findmax[0];

for (i=1;i<findmax.length;i++)

if (findmax[i] < min)

min = findmax[i];

return min;

}

public static void main(String[] args) {

System.out.println("largest element is:" + max() + "\n" + "smallest element is:" + min());

}

}


4. How to Add/Join/Combine two list?

Click Here For Answers


5. Give an example of Overriding?


package LearnJavaCoding;


 class overriding {

public void test(String name) {

System.out.println("testone");

}}

class child extends overriding{

protected void test() {

//super.test();

System.out.println("testtwo");

}

}

class testthree{

public static void main(String args[]) {

child chg = new child();

chg.test();

}}


6. How to find duplicate element in Array?


Click Here For Answer


7. How to check if two strings are Anagrams?


public class Anagrams {

 

    /* function to check whether two strings are  

    anagram of each other */

    static boolean areAnagram(char[] str1, char[] str2) 

    { 

        // Get lenghts of both strings 

        int n1 = str1.length; 

        int n2 = str2.length; 

 

        // If length of both strings is not same, 

        // then they cannot be anagram 

        if (n1 != n2) 

            return false; 

 

        // Sort both strings 

        Arrays.sort(str1); 

        Arrays.sort(str2); 

 

        // Compare sorted strings

        for (int i = 0; i < n1; i++) 

            if (str1[i] != str2[i]) 

                return false;

        return true; 

    } 

 

    /* Driver program to test to print printDups*/

    public static void main(String args[]) 

    { 

        char str1[] = { 't', 'e', 'w', 't' }; 

        char str2[] = { 't', 't', 'e', 'w' }; 

        if (areAnagram(str1, str2)) 

            System.out.println("The two strings are"

                              + " anagram of each other"); 

        else

            System.out.println("The two strings are not"

                              + " anagram of each other"); 

    } 

} 


8. How to reverse a string without using function?


Click Here For Answer


**********************

Check Selenium Interviewquestions from 1 to 10 below:


Check Selenium-SDET-UIAutomation Questions set 11 to 20:
Qus Set - 11 to 20

Check Selenium-SDET-UIAutomation Questions set 21 to 30:
 
Check Selenium-SDET-UIAutomation Questions set 31 to 40: 

 Question Set 31-40  

Check Selenium-SDET-UIAutomation Questions set 41-50:

Q&A Set 41-50 

**********************


9. How to find a number is Palindrome or not?


public static void main(String args[]){  

  int r,sum=0,temp;    

  int n=454;//It is the number variable to be checked for palindrome  

  

  temp=n;    

  while(n>0){    

   r=n%10;  //getting remainder  

   n=n/10;

   sum=(sum*10)+r;     

  }    

  if(temp==sum)    

   System.out.println("palindrome number ");    

  else    

   System.out.println("not palindrome");    

}  

}  


10. How to check a number is prime or not?


Click Here For Answer


Java Interview question Set-1:
SET-01 1-10

Java Interview question Set-2:

SET-02 10-20

Java Interview question Set-3:

SET-03 21-30

**********

Coding Interview Question Set:
https://automationreinvented.blogspot.com/search/label/Coding%20Questions

**********


*************************************************

API Testing Interview Question Set:
https://automationreinvented.blogspot.com/search/label/Rest-API

 
Kubernetes Interview Question Set
https://automationreinvented.blogspot.com/search/label/Kubernetes

 
Docker Interview Question Set
https://automationreinvented.blogspot.com/2020/02/top-18-docker-commands-for-aytomation.html

 
Linux Interview question Set
https://automationreinvented.blogspot.com/search/label/Linux

 
Automation Testing/SDET Framework Design
https://automationreinvented.blogspot.com/search/label/FrameworkDesign


Java Related Interview Question Set

https://automationreinvented.blogspot.com/search/label/Java


GIT Interview Question Set:
https://automationreinvented.blogspot.com/search/label/GIT


Coding Interview Question Set:
https://automationreinvented.blogspot.com/search/label/Coding%20Questions







1 comment:

  1. hey siddarth , can you post some more coding questions?

    ReplyDelete

All Time Popular Posts

Most Featured Post

API Status Codes with examples for QA-Testers

  🔺 LinkedIn: https://www.linkedin.com/in/sidharth-shukla-77b53145/ 🔺 Telegram Group:  https://t.me/+FTf_NPb--GQ2ODhl 🏮In API testing, it...