Thursday, 7 March 2019

String Manipulation Interview questions? String concat,replace, substring, trim, lowercase, uppercase? Selenium, Automation core java interview questions?

Interview question for SDET 2023?

SDET Interview Question and Answers.  

Jenkins Interview Questions and Answers

Appium Interview Questions and Answers

Selenium Interview Questions and answers

GIT Interview Questions and Answer

 Pre-requisite: How to install JDK and set Java Home path in Windows and MacOs ?

Ans: Click here for Steps


In Java, a string is a sequence of characters. It is a data type used to store text-based information, such as names, addresses, and messages. Strings are represented by the class "String" in Java.


Why String is Immutable?

In Java, a string is immutable, meaning its value cannot be changed once it is created. Once a string object is created, its value cannot be altered.

The reason for this is to ensure that string objects are thread-safe and to improve performance. Since strings are widely used in Java, immutable strings help to prevent errors that can occur due to changes made to the string value by different threads simultaneously. This ensures that the value of the string remains constant throughout the program execution.

Also, immutable strings can be optimized by the Java Virtual Machine (JVM) for memory usage. Since immutable strings cannot be changed, the JVM can reuse existing string objects, rather than creating new ones each time a modification is made. This can result in better performance and reduced memory usage.

In summary, immutability of strings in Java is a design decision made for the purposes of thread-safety, performance, and memory optimization.


String Manipulation

public class StringManipulation {

    public static void main(String[] args) {
        // Strings are immutable
        String str3 = "java";
        str3.concat("oops");
        System.out.println(str3); // java

        // The result should be assigned to a new reference variable (or same
        // variable) can be reused.
        String concat = str3.concat("value2");
        System.out.println(concat); // value1value2

        // -----------------------String methods-------------------------------------
        String str = "abcdefghijk";

        // char charAt(int paramInt)
        System.out.println(str.charAt(2)); // prints a char - c

        // String concat(String paramString)
        System.out.println(str.concat("lmn"));// abcdefghijklmn

        System.out.println("ABC".equalsIgnoreCase("abc"));// true
        System.out.println("ABCDEFGH".length());// 8

        // String replace(char paramChar1, char paramChar2)
        System.out.println("012301230123".replace('0', '4'));// 412341234123

        // String replace(CharSequence paramCharSequence1, CharSequence
        // paramCharSequence2)
        System.out.println("012301230123".replace("01", "45"));// 452345234523

        // All characters from index paramInt
        // String substring(int paramInt)
        System.out.println("abcdefghij".substring(3)); // defghij
        // 0123456789

        // All characters from index 3 to 6
        System.out.println("abcdefghij".substring(3, 7)); // defg
        // 0123456789

        System.out.println("ABCDEFGHIJ".toLowerCase()); // abcdefghij

        System.out.println("abcdefghij".toUpperCase()); // ABCDEFGHIJ

        System.out.println("abcdefghij".toString()); // abcdefghij

        // trim removes leading and trailings spaces
        System.out.println(" abcd  ".trim()); // abcd
    }
}

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


What are the two ways to create String?

There are two ways to create a string in Java:

  1. Using String literals - This is the most common and simple way of creating a string in Java. A string literal is a sequence of characters enclosed in double quotes. For example:

String str1 = "Hello World"; String str2 = "Java is awesome";

In this method, a new string object is created each time a string literal is assigned to a variable.

  1. Using String constructor - Another way of creating a string in Java is by using the constructor of the String class. This constructor takes a character array as its argument and creates a new string object with the same character sequence. For example:

char[] charArray = {'H', 'e', 'l', 'l', 'o'}; String str3 = new String(charArray);

In this method, we create a character array and pass it as an argument to the String constructor. This creates a new string object with the same character sequence as the character array.

It is important to note that the second method of creating a string using a constructor is less common than the first method, as it is more verbose and requires more steps.

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

For any doubts or career guidance, reach out to me 

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

TOP 15 BDD - CUCUMBER Interview Q&A


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

✍️AUTHORLinkedIn Profile

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

Learn (API-Microservice)Testing+ Selenium UI Automation-SDET with Self Paced Videos prepared by FAANG employees and LIVE Doubt Session 

SDET TRANING VIDEOS AVAILABLE with Live Doubt Session(course-1 below,API TRaining Videos With Class Notes and Coding Set) and (API+UI, both course-1 & 2 below) Check Training Page for Course Content or reach out @whatsapp +91-9619094122. 
This includes classnotes, 300+ interview questions, 3 projects, Java Coding question set for product companies along with career guidance from FAANG employees for Automation and SDET.

For more details whatsapp : https://lnkd.in/dnBWDM33

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

SeleniumWebdriver Automation Testing Interview Questions:

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

API Testing Interview Question Set:

https://automationreinvented.blogspot.com/2022/03/top-80-api-testing-interview-questions.html

DevOps Interview Q&A:

https://automationreinvented.blogspot.com/2021/11/top-11-devops-interview-questions-and.html 

Kubernetes Interview Question Set

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

Docker Interview Question Set

https://automationreinvented.blogspot.com/Docker

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/2021/09/top-40-git-interview-questions-and.html

Coding Interview Question Set:

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

Mobile Testing Interview Question Set:

https://automationreinvented.blogspot.com/search/label/Mobile%20Testing

Python Interview Question Set for QAE - SDET - SDE:

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


 


 


Wednesday, 6 March 2019

How to sort hashmap? sorting with collections? Hashmap sorting with key?

This is a common interview question asked in most of the companies for people with 3+ years of experience in Automation:

public class hashmapsort {

    public static void main(String[] args) {

         HashMap<Integer, String> hmap = new HashMap<Integer, String>();
         hmap.put(1, "Java");
         hmap.put(13, "C");
         hmap.put(2, "Python");
         Map<Integer, String> map = new TreeMap<Integer, String>(hmap);
         System.out.println(" Sorting:");
         Set set2 = map.entrySet();
         Iterator iterator2 = set2.iterator();
         while(iterator2.hasNext()) {
              Map.Entry m2 = (Map.Entry)iterator2.next();
              System.out.print(m2.getKey() + ": ");
              System.out.println(m2.getValue());
         }
    }
}


Note: To sort with values need to do using comparator, will do that in my next post.

Tuesday, 5 March 2019

What are the most used API status codes? RestAPI Interview question? API status Codes?

200:  OK

201:  Created

204:  No Content

400:  Bad Request

401: Unauthorized

403: Forbidden

404: Not Found

302: Redirect

405: Method Not Allowed

422: Unprocessable Entity

417: Expectation failed

500: Internal Server Error


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

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

Monday, 4 March 2019

How to get the count of elements in an array? Duplicate Elements in array? Count of duplicate elements in array?Collection Interview Questions

This is one of the mostly asked interview question.

package CountElements;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;

public class findduplicate {
    public static void main (String args[]) {
        String str2 = "findduplicateelementsinarray";
        String[] ary = str2.split("");
     ArrayList<String> list = new ArrayList<String>(Arrays.asList(ary));
 //Set does not allow duplicate elements
     Set<String> str1 = new HashSet<String>();{
     for ( String str21 : list) {
         if (str1.add(str21) == false) {
             System.out.println(str21 + " occurs: " + Collections.frequency(list, str21) +": is the Duplicate Element");
         }else if (Collections.frequency(list, str21) < 2) {
             System.out.println(str21 + " occurs: " + Collections.frequency(list, str21));
         }
     }
   
}}
}

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

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





Note: Ask me questions in the comment section, or any doubts on the above post.

Click To Learn most asked Interview question
Java questions:
Most asked Java Interview Questions

All Time Popular Posts

Most Featured Post

Introduction to Web Testing with Playwright

  Introduction to Web Testing with Playwright 📌  Telegram Group:  https://t.me/+FTf_NPb--GQ2ODhl 📌  YouTube channel:  https://lnkd.in/gGUG...