Maruthi Krishna has Published 952 Articles

What is the use of parametrized constructor in Java?

Maruthi Krishna

Maruthi Krishna

Updated on 05-Feb-2021 10:31:10

352 Views

A constructor is similar to method and it is invoked at the time creating an object of the class, it is generally used to initialize the instance variables of a class. The constructors have same name as their class and, have no return type.There are two types of constructors parameterized ... Read More

How to use regular expression in Java to pattern match?

Maruthi Krishna

Maruthi Krishna

Updated on 05-Feb-2021 10:27:49

182 Views

A regular expression is a string of characters that defines/forms a pattern to search an input text. A regular expression may contain one or more characters, using a regular expression you can search or replace a string.Java provides the java.util.regex package for pattern matching with regular expressions. The pattern class ... Read More

Is Java matcher thread safe in Java?

Maruthi Krishna

Maruthi Krishna

Updated on 05-Feb-2021 10:27:28

670 Views

A regular expression is a special sequence of characters that helps you match or find other strings or sets of strings, using a specialized syntax held in a pattern. They can be used to search, edit, or manipulate text and data. Java provides the java.util.regex package for pattern matching with ... Read More

What is a sub string in Java?

Maruthi Krishna

Maruthi Krishna

Updated on 05-Feb-2021 10:25:09

99 Views

The String class of the java.lang package represents set of characters. All string literals in Java programs, such as "abc", are implemented as instances of this class. A string index is an integer representing the position of each character in the string starting from zero.A substring is a part/segment of ... Read More

Do static variables get initialized in a default constructor in java?

Maruthi Krishna

Maruthi Krishna

Updated on 19-Nov-2020 15:41:03

6K+ Views

A static filed/variable belongs to the class and it will be loaded into the memory along with the class. You can invoke them without creating an object. (using the class name as reference). There is only one copy of the static field available throughout the class i.e. the value of ... Read More

Regular expression for a hexadecimal number greater than 10 and should be even in length in java.

Maruthi Krishna

Maruthi Krishna

Updated on 13-Jul-2020 13:15:09

271 Views

Following is the regular expression to match hexadecimal number greater than 10 with even length −^(?=.{10, 255}$)(?:0x)?\p{XDigit}{2}(?:\p{XDigit}{2})*$Where, ^ − Matches the starting of the sentence.(?=.{10, 255}$) − String ending with characters with 10 to 255.\p{XDigit}{2} − Two hexa-decimal characters.(?:\p{XDigit}{2})* − 0 or more sequences of double hexa-decimal characters.$ − Matches ... Read More

Types of quantifiers in Java regex

Maruthi Krishna

Maruthi Krishna

Updated on 13-Jul-2020 12:14:40

546 Views

If you want to specify the number of occurrences while constructing a regular expression you can use quantifiers. Java supports three types of quantifiers namely: greedy quantifiers, reluctant quantifiers and possessive quantifiers.Greedy quantifiers − Greedy quantifiers are the default quantifiers. A greedy quantifier matches as much as possible from the ... Read More

While chaining, can we throw unchecked exception from a checked exception in java?

Maruthi Krishna

Maruthi Krishna

Updated on 03-Jul-2020 08:32:08

601 Views

When an exception is cached in a catch block, you can re-throw it using the throw keyword (which is used to throw the exception objects).While re-throwing exceptions you can throw the same exception as it is with out adjusting it as −try {    int result = (arr[a])/(arr[b]);    System.out.println("Result ... Read More

Is there any method to convert a Set to immutable in Java

Maruthi Krishna

Maruthi Krishna

Updated on 03-Jul-2020 08:20:05

1K+ Views

Whenever you need to create an object which cannot be changed after initialization you can define an immutable object. There are no specific rules to create immutable objects, the idea is to restrict the access of the fields of a class after initialization.A Set is an interface in collection framework, ... Read More

Why TreeSet Does not allow null values in Java?

Maruthi Krishna

Maruthi Krishna

Updated on 03-Jul-2020 08:19:19

2K+ Views

TreeSet provides an implementation of the Set interface that uses a tree for storage. Objects are stored in a sorted and ascending order.Access and retrieval times are quite fast, which makes TreeSet an excellent choice when storing large amounts of sorted information that must be found quickly.The reason is, if ... Read More

Previous 1 ... 7 8 9 10 11 ... 96 Next
Advertisements