Vikyath Ram has Published 169 Articles

Are Multiple Constructors possible in Java?

Vikyath Ram

Vikyath Ram

Updated on 30-Jun-2020 08:45:40

There can be multiple constructors in a class. However, the parameter list of the constructors should not be same. This is known as constructor overloading.A program that demonstrates this is given as follows −Example Live Democlass NumberValue {    private int num;    public NumberValue() {       num = ... Read More

Using Method Overloading in Java

Vikyath Ram

Vikyath Ram

Updated on 30-Jun-2020 08:42:54

A class can have multiple methods with the same name but the parameter list of the methods should not be the same. This is known as method overloading. Method overloading is somewhat similar to constructor overloading.A program that demonstrates this is given as follows −Example Live Democlass PrintValues {    public ... Read More

Class declaration with one method in Java

Vikyath Ram

Vikyath Ram

Updated on 30-Jun-2020 08:34:50

A class declaration can contain a single method. A program that demonstrates this is given as follows:Example Live Democlass Message {    public void messagePrint() {       System.out.println("This is a class with a single method");    } } public class Demo {    public static void main(String args[]) { ... Read More

Use Pattern class to match in Java

Vikyath Ram

Vikyath Ram

Updated on 30-Jun-2020 08:33:56

The representation of the regular expressions are available in the java.util.regex.Pattern class. This class basically defines a pattern that is used by the regex engine.A program that demonstrates using the Pattern class to match in Java is given as follows −Example Live Demoimport java.util.regex.Matcher; import java.util.regex.Pattern; public class Demo {   ... Read More

Working with simple groups in Java Regular Expressions

Vikyath Ram

Vikyath Ram

Updated on 30-Jun-2020 08:29:44

Multiple characters can be treated as a single unit using groups in Java regular expressions. The method java.time.Matcher.group() is used to find the subsequence in the input sequence string that is a match to the required pattern.A program that demonstrates groups in Java regular expressions is given as follows −Example Live ... Read More

Convert a Vector to an array in Java

Vikyath Ram

Vikyath Ram

Updated on 30-Jun-2020 08:18:22

A Vector can be converted into an Array using the java.util.Vector.toArray() method. This method requires no parameters and it returns an Array that contains all the elements of the Vector in the correct order.A program that demonstrates this is given as follows −Example Live Demoimport java.util.Vector; public class Demo {   ... Read More

Get reverse order using Comparator in Java

Vikyath Ram

Vikyath Ram

Updated on 30-Jun-2020 08:16:08

The objects of a user defined class can be ordered using the Comparator interface in Java. The java.util.Collections.reverseOrder() method reverses the order of an element collection using a Comparator.A program that demonstrates this is given as follows −Exampleimport java.util.Arrays; import java.util.Collections; import java.util.Comparator; public class Demo {    public static ... Read More

Add elements to a Vector in Java

Vikyath Ram

Vikyath Ram

Updated on 30-Jun-2020 08:11:22

A dynamic array is implemented by a Vector. This means an array that can grow or reduce in size as required.Elements can be added at the end of the Vector using the java.util.Vector.add() method. This method has a single parameter i.e. the element to be added. It returns true if ... Read More

Matcher.pattern() method in Java Regular Expressions

Vikyath Ram

Vikyath Ram

Updated on 30-Jun-2020 08:05:47

The method java.time.Matcher.pattern() returns the pattern that is matched upon by the Matcher. This method accepts no parameters.A program that demonstrates the method Matcher.pattern() in Java regular expressions is given as follows −Example Live Demoimport java.util.regex.Matcher; import java.util.regex.Pattern; public class Demo {    public static void main(String args[]) {     ... Read More

Private and final methods in Java Programming

Vikyath Ram

Vikyath Ram

Updated on 27-Jun-2020 08:12:16

In Java private methods are the methods having private access modifier and are restricted to be access in the defining class only and are not visible in their child class due to which are not eligible for overridden. However, we can define a method with the same name in the ... Read More

1 2 3 4 5 ... 17 Next
Advertisements