Rishi Raj has Published 127 Articles

Reset the Matcher in Java Regular Expressions

Rishi Raj

Rishi Raj

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

68 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

471 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

225 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

176 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

219 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

453 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

303 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

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

Removing Single Elements in a Vector in Java

Rishi Raj

Rishi Raj

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

86 Views

A single element in the Vector can be removed using the java.util.Vector.remove() method. This method removes the element at the specified index in the Vector. It returns the element that was removed. Also after the element is removed from the specified index, the rest of the Vector elements are shifted ... Read More

Recursive factorial method in Java

Rishi Raj

Rishi Raj

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

4K+ Views

The factorial of any non-negative integer is basically the product of all the integers that are smaller than or equal to it. The factorial can be obtained using a recursive method.A program that demonstrates this is given as follows:Example Live Demopublic class Demo {    public static long fact(long n) { ... Read More

Advertisements