Vikyath Ram has Published 151 Articles

Demonstrate the usage of the Pattern.split() method in Java

Vikyath Ram

Vikyath Ram

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

58 Views

The specified input sequence can be split around a particular match for a pattern using the java.util.regex.Pattern.split() method. This method has a single parameter i.e. the input sequence to split and it returns the string array obtained by splitting the input sequence around a particular match for a pattern.A program ... Read More

Using Varargs with standard arguments in Java

Vikyath Ram

Vikyath Ram

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

92 Views

A method with variable length arguments(Varargs) in Java can have zero or multiple arguments. Variable length arguments(Varargs) can also be used with standard arguments However they must be the last argument in the argument list. Moreover, there can only be one variable length argument in the method.A program that demonstrates ... Read More

Recursive fibonacci method in Java

Vikyath Ram

Vikyath Ram

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

9K+ Views

The fibonacci series is a series in which each number is the sum of the previous two numbers. The number at a particular position in the fibonacci series can be obtained using a recursive method.A program that demonstrates this is given as follows:Example Live Demopublic class Demo {    public static ... Read More

A non-static initialization block in Java

Vikyath Ram

Vikyath Ram

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

1K+ Views

Instance variables are initialized using initialization blocks. These blocks are executed when the class object is created and before the invocation of the class constructor. Also, it is not necessary to have initialization blocks in the class.A program that demonstrates a non-static initialization block in Java is given as follows:Example Live ... Read More

Deriving a Class in Java

Vikyath Ram

Vikyath Ram

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

3K+ Views

A class can be derived from the base class in Java by using the extends keyword. This keyword is basically used to indicate that a new class is derived from the base class using inheritance. It can also be said that it is used to extend the functionality of the ... Read More

Variable in subclass hides the variable in the super class in Java

Vikyath Ram

Vikyath Ram

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

341 Views

Sometimes the variable in the subclass may hide the variable in the super class. In that case, the parent class variable can be referred to using the super keyword in Java.A program that demonstrates this is given as follows:Example Live Democlass A {    char ch; } class B extends A ... Read More

Raise x to the power n using Recursion in Java

Vikyath Ram

Vikyath Ram

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

580 Views

The power of a number can be calculated using recursion. Here the number is x and it is raised to power n.A program that demonstrates this is given as follows:Example Live Demopublic class Demo {    static double pow(double x, int n) {       if (n != 0)   ... Read More

Replace an element at a specified index of the Vector in Java

Vikyath Ram

Vikyath Ram

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

489 Views

An element in a Vector can be replaced at a specified index using the java.util.Vector.set() method. This method has two parameters i.e the index at which the Vector element is to be replaced and the element that it should be replaced with. Vector.set() method returns the element that was at ... Read More

Why Final Class used in Java?

Vikyath Ram

Vikyath Ram

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

720 Views

The final keyword is used with a class to create a final class. The final class cannot be inherited and so the final keyword is commonly used with a class to prevent inheritance.A program that demonstrates a final class in Java is given as follows:Example Live Demofinal class A {   ... Read More

Get first and last elements from Vector in Java

Vikyath Ram

Vikyath Ram

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

469 Views

The first element in the Vector can be obtained using the java.util.Vector.firstElement() method. The last element in the Vector can be obtained using the java.util.Vector.lastElement() method. Neither of these methods requires any parameters.A program that demonstrates this is given as follows:Example Live Demoimport java.util.Vector; public class Demo { ... Read More

Advertisements