Friday 21 January 2022

What we know about the "STRING"? MCQ on String for concepts and interview preparation QAE - SDET - AUTOMATION QA 2022

 


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

Ans: Click here for Steps


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


Here are the top 5 things to know about Java strings:

  1. Strings are objects:
    In Java, strings are objects of the String class, which is included in the java.lang package. This means that strings have a wide range of methods available for manipulating and processing them.

  2. Strings are immutable:
    In Java, strings are immutable, which means that once a string is created, it cannot be changed. Any operation that appears to modify a string actually creates a new string object. This has implications for memory usage and performance.

  3. String literals:
    String literals are enclosed in double quotes (e.g. "hello"), and they are automatically created as String objects when the program is executed. String literals are also pooled, which means that if two string literals have the same value, they will be references to the same object.

  4. String concatenation:
    Strings can be concatenated using the "+" operator or the concat() method. When concatenating strings in a loop or other performance-sensitive code, it is more efficient to use a StringBuilder or StringBuffer object, which can avoid creating many intermediate string objects.

  5. String comparisons:
    Strings can be compared using the equals() method or the equalsIgnoreCase() method. The == operator can also be used to compare strings, but it checks for reference equality, not value equality. When comparing many strings in a performance-sensitive application, it can be more efficient to use the intern() method to intern the strings and compare their references.


1. What is the output for below?

String str1 = "test";
String str2 = "one";

String str3 = str1.concat(str2);


Ans:

a) testone

b) test

c) one

d) Let me check in IDE :)


2. What is the output for below?

String str1 = "test";
String str2 = "test";

String str3 = new String("test");


System.out.println(str1.equals(str2));

System.out.println(str1.equals(str3));


Ans:

a) true,true

b) false, true

c) false, false

d) Let me check in IDE :)


3. What is the output for below?

String str1 = "test";

String str2 = "test";

String str3 = new String("test");


System.out.println(str1==str2));

System.out.println(str1==str3);


a) true, true

b) true, false

c) false, true

d) false, false


4. What is the output for below?

String str = "test";

System.out.println(str1.charAt(2)); 


a) s

b) e

c) error

d) es


5. What is the output for below?

System.out.println("012301230123".replace(55, "45"));

 System.out.println("012301230123".replace("01", "45"));


a) compile error, 452345234523

b) 452345234523, 452345234523

c) error, error

d) Let me check in IDE :)


6. What is the output for below?

System.out.println("tes".substring(3));

System.out.println("test".substring(3));



a) error, error

b) error, t

c)  , t

d) t, t


7. How many ways we can create String Object in Java?


a) String s = "abc"; String s1 = new String("abc");

b) Literal, Keyword

c)  Both A and B

d)  Not sure


CLICK HERE FOR ANSWERS OF ALL QUESTIONS



8. Is String thread safe?


a) true

b) false

c) Not sure


9. What is the output for below?

String str8 = new StringBuilder("test").reverse().toString();

System.out.println(str8);


a) test

b) tset

c) Not sure


10. Which one is thread safe: StringBuffer or StringBuffer ?


a) Both

b) StringBuffer

c) StringBuilder

d) None of the options


Click below link for the answers of above 1-10 Question



CLICK HERE FOR ANSWERS OF ALL THE QUESTIONS


To go through all the string manipulation related interview Q&A, refer the link here: String Manipulation Interview Q&A





String Related Q&A

*******************************************************************
For any doubts or career guidance, reach out to me 


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

These commands cover a range of basic UI interactions and are a good starting point for building automated tests with Cypress.

Do remember that knowing Linux is one of the most important aspect to work as an SDET.

Basic Linux Commands for Automation QA


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

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

No comments:

Post a Comment

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...