Rishi Raj has Published 131 Articles

Initializer for final static field in Java

Rishi Raj

Rishi Raj

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

700 Views

The final static field variable is a constant variable. There is only one copy of this variable available. It is mandatory to initialize the final static field variable explicitly as the default value for it is not provided by the JVM. Also, this variable cannot be reinitialized.A program that initializes ... Read More

Finding all words that start with an 'a' in Java

Rishi Raj

Rishi Raj

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

454 Views

All the words that start with a can be found in a string by using regular expressions in Java. The regular expressions are character sequences that can be used to match other strings using a specific pattern syntax. The regular expressions are available in the java.util.regex package which has many ... Read More

A Reluctant qualifier in Java Regular Expressions

Rishi Raj

Rishi Raj

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

102 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

79 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

60 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

428 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

212 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

162 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

203 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

418 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

Advertisements