Rishi Raj has Published 118 Articles

A Reluctant qualifier in Java Regular Expressions

Rishi Raj

Rishi Raj

Updated on 30-Jul-2019 22:30:24

190 Views

The reluctant qualifier starts with the shortest string size as possible. If a match is found by the engine, the process continues to find more matches otherwise the engine adds a character to the searched string section and tries again. This continues until a match is obtained or the string ... Read More

Working with Matcher.end() method in Java Regular Expressions

Rishi Raj

Rishi Raj

Updated on 30-Jul-2019 22:30:24

164 Views

The offset value after the last character is matched from the sequence according to the regex is returned by the method java.util.regex.Matcher.end(). This method requires no arguments. If no match occurs or if the match operation fails then the IllegalStateException is thrown.A program that demonstrates the method Matcher.end() Java regular ... Read More

Reset the Matcher in Java Regular Expressions

Rishi Raj

Rishi Raj

Updated on 30-Jul-2019 22:30:24

138 Views

The Matcher can be reset using the java.util.regex.Matcher.reset() method. This method returns the reset Matcher.A program that demonstrates the method Matcher.reset() in Java regular expressions is given as follows:Example Live Demoimport java.util.regex.Matcher; import java.util.regex.Pattern; public class MainClass {    public static void main(String args[]) {       Pattern p = ... Read More

Methods Accepting a Variable Number of objects in Java

Rishi Raj

Rishi Raj

Updated on 30-Jul-2019 22:30:24

594 Views

A method that accepts a variable number of Object arguments in Java is a form of variable length arguments(Varargs). These can have zero or multiple Object type arguments.A program that demonstrates this is given as follows:Example Live Demopublic class Demo {    public static void Varargs(Object... args) {       ... Read More

How to work with this keyword in Java?

Rishi Raj

Rishi Raj

Updated on 30-Jul-2019 22:30:24

366 Views

The this keyword in Java is mainly used to refer to the current instance variable of the class. It can also be used to implicitly invoke the method or to invoke the constructor of the current class.A program that demonstrates the this keyword in Java is given as follows:Example Live Democlass ... Read More

Reference static field after declaration in Java

Rishi Raj

Rishi Raj

Updated on 30-Jul-2019 22:30:24

271 Views

The static field variable is a class level variable and it belongs to the class not the class object.So the static field variable is common to all the class objects i.e. a single copy of the static field variable is shared among all the class objects.A program that demonstrates referencing ... Read More

Static Nested Classes in Java

Rishi Raj

Rishi Raj

Updated on 30-Jul-2019 22:30:24

403 Views

A nested class in Java is of two types i.e. Static nested class and Inner class. A static nested class is a nested class that is declared as static. A nested nested class cannot access the data members and methods of the outer class.A program that demonstrates a static nested ... Read More

Role of super Keyword in Java Inheritance

Rishi Raj

Rishi Raj

Updated on 30-Jul-2019 22:30:24

721 Views

Parent class objects can be referred to using the super keyword in Java. It is usually used in the context of inheritance. A program that demonstrates the super keyword in Java is given as follows:Example Live Democlass A {    int a;    A(int x) {       a = ... Read More

Using run-time polymorphism in Java

Rishi Raj

Rishi Raj

Updated on 30-Jul-2019 22:30:24

452 Views

A single action can be performed in multiple ways using the concept of polymorphism. Run-time polymorphism can be performed by method overriding. The overridden method in this is resolved at compile time.A program that demonstrates run-time polymorphism in Java is given as follows:Example Live Democlass Animal {    void sound() { ... Read More

Why do we use import statement in Java? Where it should be included in the class?

Rishi Raj

Rishi Raj

Updated on 30-Jul-2019 22:30:24

4K+ Views

The import statement can be used to import an entire package or sometimes import certain classes and interfaces inside the package. The import statement is written before the class definition and after the package statement(if there is any). Also, the import statement is optional.A program that demonstrates this in Java ... Read More

Advertisements