Which of the following statements correctly describe gestational diabetes (GDM)? (Select all that apply.) Show
More than one answer is correct. Please select all correct answers
Welcome to Java String Quiz. String is one of the most important classes in Java. If you have done any programming in java, you must have used it. The string is very popular when it comes to java interview questions or quiz. So I have gathered some great and tricky java string quiz questions that you should try. Java String QuizThere are 21 questions in this quiz. If you can correctly answer 15 or more, then consider yourself really good in String concepts. You can check the answer and detailed explanation by clicking on the “Reveal Answer” button after each question. Let’s start the String Quiz and best of luck. 1. What will be the output of below statements?
A. Convert “Z” to int 90 and prints “90” **Correct
Answer: B 2. What will be output of below statements?
A. Prints “Str” **Correct Answer: B 3. Select all valid methods of String class.A. trim() Correct Answer: A, B Valid methods of String class are - trim(), intern(), toLowerCase(), and split(String regex). 4. What will be the output of below statements?
A. truefalse **Correct Answer: A However using new operator, we force String class to create a new String object in heap space. So s1 and s2 will have reference to the same String in the pool whereas s3 will be a different object outside the pool, hence the output. 5. Which of the following statements are true for string in switch case?A. String is allowed in switch case for Java 1.5 or higher
versions. Correct Answer: B, C Read more at java switch case string 6. Which of the following statements are True for StringBuffer and StringBuilder?A. StringBuilder is not thread-safe. Correct Answer: A, B StringBuffer object is thread-safe because its methods are synchronized. But that’s an overhead in most of the cases, hence StringBuilder was introduced in Java 1.5. StringBuilder is not thread-safe. StringBuffer and StringBuilder are mutable classes. Read more at String vs StringBuffer vs StringBuilder. 7. String implementation follows which of the below design pattern?A. Flyweight Design Pattern Correct Answer: A String pool implementation follows the flyweight design pattern. 8. What will be the output of below statements?
A. 0 **Correct Answer: C compareTo method compares two strings lexicographically. The comparison is based on the Unicode value of each character in the strings. The character sequence represented by this String object is compared lexicographically to the character sequence represented by the argument string. The result is a negative integer if this String object lexicographically precedes the argument string. The result is a positive integer if this String object lexicographically follows the argument string. The result is zero if the strings are equal; compareTo returns 0 exactly when the equals(Object) method would return true. This is the definition of lexicographic ordering. If two strings are different, then either they have different characters at some index that is a valid index for both strings, or their lengths are different or both. If they have different characters at one or more index positions, let k be the smallest such index; then the string whose character at position k has the smaller value, as determined by using the < operator lexicographically precedes the other string. In this case, compareTo returns the difference of the two character values at position k in the two string – that is, the value: this.charAt(k)-anotherString.charAt(k) In our example the “abc” precedes “def”, hence negative integer is returned. Then the lowest index with different char is 0 and a-d equals to -3. 9. What will be the output of below program?
A. abc Correct Answer: A The 10. What will be the output of below program?
A. false Correct Answer: A The given statements output will be “false” because in java + operator precedence is more than == operator. So the given expression will be evaluated to “s1 == s2 is:abc” == “abc” i.e false. 11. What will be the output of below statements?
A. Java3Quiz7 Correct Answer: B First of all, the expression in the bracket is executed. Then it’s all + operators, so they get executed from left to right. We get String with each concatenation, hence the output gets produced as shown below. “Java”+1+2+“Quiz”+“”+(3+4) 12. How many String objects created in below statements?
A.
1 Correct Answer: C In statement 1, “abc” is created in the String pool. In statement 2, first of all “abcd” is created in the string pool. Then it’s passed as an argument to the String new operator and another string gets created in the heap memory. So a total of 3 string objects gets created. 13. What will be the output of below statements?
A. falsetrue Correct Answer: A The s1 is in the string pool whereas s2 is created in heap memory. Hence s1==s2 will return false. When Hence s1==s2.intern() will return true. 14. Select all the interfaces implemented by String class.A. Serializable Correct Answer: A, B, C String is serializable and comparable. The Constable is a new interface from the Java 12 release. 15. Select all the reasons that make String perfect candidate for Map key?A. String is immutable **Correct Answer: A, B, C 16. What will be the output of below code snippet?
A. JAVA **Correct Answer: A 17. What will be the output of below statements?
A. false Correct Answer: A It will print false because s2 is not of type String. If you will look at the String equals() method implementation, you will find a check
using 18. What will be the output of below code snippet?
A. false Correct Answer: A It’s a tricky question and output will be false. We know that intern() method will return the String object reference from the string pool, but since we didn’t assign it back to s2, there is no change in s2. Hence both s1 and s2 are having a different reference. If we change the code in line 3 to 19. Select all the classes that extend String class.A. StringBuffer **Correct
Answer: D 20. Which of the following statements are true about String in java?A. We can extend String class like StringBuffer does it. Correct Answer: C, D, E We can’t extend String class because it’s final. StringBuffer doesn’t extend it. String class is defined in 21. What will be the output of below statements?
A.
nullnull Correct Answer: B Line 2 will print
Line 3 will throw NullPointerException because we are trying to invoke toString() function on null. ConclusionI have tried to cover most of the important points about String in this Quiz. If you think some interesting concept has been missed, please let me know through comments. If you liked the Quiz, share it with others too. Which of the following are text mode email clients widely available in Linux select all answers that apply?7 Best Command-Line Email Clients for Linux in 2020. Mutt – Mail User Agent. Mutt is a small, lightweight yet powerful text-based email client for Unix-like operating systems. ... . Alpine – Internet News and Email. ... . Sup. ... . Notmuch. ... . Mu4e. ... . Lumail. ... . Which of the following describes things Pstree can display?The pstree command displays the running processes in the form of a tree structure.
Which of the following commands can be used to view the last 15 lines of a file select all answers that apply?Which command is used to combine three files into a fourth file? ... . Which of the following commands can be used to view the last 15 linesof a file (Select all answers that apply)?Ans:tail -15 some_filetail -n15 some_file.. Which two of the following are common protocols used to access emails stored on a remote mail server select all answers that apply mutt POP mail IMAP?There are two primary protocols used by email client applications to retrieve email from mail servers: the Post Office Protocol (POP) and the Internet Message Access Protocol (IMAP).
|