Explore topic-wise InterviewSolutions in .

This section includes InterviewSolutions, each offering curated multiple-choice questions to sharpen your knowledge and support exam preparation. Choose a topic below to get started.

1.

What does public int end(int group) return?(a) offset from last character of the subsequent group(b) offset from first character of the subsequent group(c) offset from last character matched(d) offset from first character matchedI had been asked this question by my school principal while I was bunking the class.This is a very interesting question from Regular Expression in portion Regular Expressions of Java

Answer»

Correct OPTION is (a) offset from LAST CHARACTER of the subsequent group

To elaborate: public int END(int group) returns offset from the last character of the subsequent group.

2.

Which of the following matches nonword character using regular expression in java?(a) \w(b) \W(c) \s(d) \SThe question was asked during an interview.Question is from Regular Expression in portion Regular Expressions of Java

Answer» RIGHT ANSWER is (b) \W

The explanation is: \W matches nonword characters. [0-9], [A-Z] and _ (UNDERSCORE) are word characters. All other than these characters are nonword characters.
3.

what does public String replaceAll(string replace) do?(a) Replace all characters that matches pattern with a replacement string(b) Replace first subsequence that matches pattern with a replacement string(c) Replace all other than first subsequence of that matches pattern with a replacement string(d) Replace every subsequence of the input sequence that matches pattern with a replacement stringThis question was posed to me in class test.This interesting question is from Regular Expression topic in section Regular Expressions of Java

Answer» RIGHT choice is (d) REPLACE EVERY subsequence of the input sequence that matches PATTERN with a replacement string

To ELABORATE: replaceAll method replaces every subsequence of the sequence that matches pattern with a replacement string.
4.

Which of the following matches end of the string using regular expression in java?(a) \z(b) \\(c) \*(d) \ZThe question was asked in final exam.This interesting question is from Regular Expression topic in chapter Regular Expressions of Java

Answer» CORRECT answer is (a) \z

Explanation: \z is used to match END of the ENTIRE string in regular expression in java.
5.

groupCount reports a total number of Capturing groups.(a) True(b) FalseI had been asked this question in unit test.The origin of the question is Regular Expression topic in portion Regular Expressions of Java

Answer»

The correct OPTION is (a) True

The BEST I can explain: groupCount reports TOTAL number of Capturing groups. this does not INCLUDE special group, group 0.

6.

Which capturing group can represent the entire expression?(a) group *(b) group 0(c) group * or group 0(d) None of the mentionedThis question was addressed to me in unit test.My enquiry is from Regular Expression in portion Regular Expressions of Java

Answer»

Correct option is (B) group 0

The best EXPLANATION: Group 0 is a special group which REPRESENTS the ENTIRE expression.

7.

Object of which class is used to compile regular expression?(a) Pattern class(b) Matcher class(c) PatternSyntaxException(d) None of the mentionedThis question was posed to me in a national level competition.My question is based upon Regular Expression topic in division Regular Expressions of Java

Answer»

The correct answer is (a) Pattern class

Easiest EXPLANATION: object of Pattern class can represent COMPILED regular EXPRESSION.

8.

Which of these formatting strings of SimpleDateFormat class is used to print AM or PM in time?(a) a(b) b(c) c(d) dI got this question in class test.The doubt is from Text Formatting in section Regular Expressions of Java

Answer»

Right ANSWER is (a) a

Easiest explanation: By USING FORMAT STRING “a” we can print AM/PM in TIME.

9.

What is the significance of Matcher class for regular expression in java?(a) interpretes pattern in the string(b) Performs match in the string(c) interpreted both pattern and performs match operations in the string(d) None of the mentioned.The question was asked in my homework.The doubt is from Regular Expression topic in portion Regular Expressions of Java

Answer»

The correct answer is (C) INTERPRETED both pattern and performs match operations in the string

Easiest EXPLANATION: macther() METHOD is invoked USING matcher object which interpretes pattern and performs match operations in the input string.

10.

Which of the following is not a class of java.util.regex?(a) Pattern class(b) matcher class(c) PatternSyntaxException(d) Regex classThis question was posed to me by my school principal while I was bunking the class.This interesting question is from Regular Expression in section Regular Expressions of Java

Answer»

Correct ANSWER is (d) Regex class

Explanation: java.util.regex CONSISTS 3 CLASSES. PatternSyntaxException indicates SYNTAX ERROR in regex.

11.

Which of these class allows us to define our own formatting pattern for dates and time?(a) DefinedDateFormat(b) SimpleDateFormat(c) ComplexDateFormat(d) UsersDateFormatI had been asked this question by my school principal while I was bunking the class.The doubt is from Text Formatting topic in division Regular Expressions of Java

Answer» CORRECT choice is (b) SimpleDateFormat

Best explanation: The DateFormat is a CONCRETE subclass of DateFormat. It allows you to define your own formatting PATTERNS that are USED to display date and time INFORMATION.
12.

Which of these method returns an instance of DateFormat that can format time information?(a) getTime()(b) getTimeInstance()(c) getTimeDateinstance()(d) getDateFormatinstance()The question was posed to me in unit test.This interesting question is from Text Formatting topic in division Regular Expressions of Java

Answer»

The CORRECT answer is (B) getTimeInstance()

Easiest explanation: getTimeInstance() method RETURNS an instance of DateFormat that can format TIME information.

13.

Which of this class can be used to format dates and times?(a) Date(b) SimpleDate(c) DateFormat(d) textFormatI have been asked this question by my college professor while I was bunking the class.Question is taken from Text Formatting topic in section Regular Expressions of Java

Answer»

The correct choice is (c) DateFormat

Explanation: DateFormat is an ABSTRACT class that provides the ability to FORMAT and PARSE DATES and times.

14.

Which of these package is used for text formatting in Java programming language?(a) java.text(b) java.awt(c) java.awt.text(d) java.ioThis question was posed to me in a job interview.This key question is from Text Formatting in division Regular Expressions of Java

Answer»

Correct answer is (a) java.text

For explanation I WOULD say: java.text allows formatting, SEARCHING and MANIPULATING text.