Maruthi Krishna has Published 870 Articles

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

373 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

822 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

771 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

2K+ 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

How to convert an array to Set and vice versa in Java?

Maruthi Krishna

Maruthi Krishna

Updated on 03-Jul-2020 08:18:11

2K+ Views

Array is a container which can hold a fix number of entities, which are of the same type. Each entity of an array is known as element and, the position of each element is indicated by an integer (starting from 0) value known as index.Exampleimport java.util.Arrays; public class ArrayExample { ... Read More

Can We handle the RuntimeException in java?

Maruthi Krishna

Maruthi Krishna

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

145 Views

A Run time exception or an unchecked exception is the one which occurs at the time of execution. These include programming bugs, such as logic errors or improper use of an API. Runtime exceptions are ignored at the time of compilation.IndexOutOfBoundsException, ArithmeticException, ArrayStoreException and, ClassCastException are the examples of run ... Read More

Is there any way to skip finally block even if some exception occurs in exception block using java?

Maruthi Krishna

Maruthi Krishna

Updated on 03-Jul-2020 08:07:01

4K+ Views

An exception is an issue (run time error) occurred during the execution of a program. When an exception occurred the program gets terminated abruptly and, the code past the line that generated the exception never gets executed.Try, catch, finally blocksTo handle exceptions Java provides a try-catch block mechanism.A try/catch block ... Read More

Is it possible to resume java execution after exception occurs?

Maruthi Krishna

Maruthi Krishna

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

6K+ Views

An exception is an issue (run time error) occurred during the execution of a program. When an exception occurred the program gets terminated abruptly and, the code past the line that generated the exception never gets executed.There are two types of exceptions in Java.Unchecked Exception − An unchecked exception is ... Read More

How can we decide that custom exception should be checked or unchecked in java?

Maruthi Krishna

Maruthi Krishna

Updated on 03-Jul-2020 08:02:42

6K+ Views

An exception is an issue (run time error) occurred during the execution of a program. When an exception occurred the program gets terminated abruptly and, the code past the line that generated the exception never gets executed.User defined exceptionsYou can create your own exceptions in Java and they are known ... Read More

Advertisements