Jai Janardhan has Published 69 Articles

Overloading Varargs Methods in Java

Jai Janardhan

Jai Janardhan

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

616 Views

A method with variable length arguments(Varargs) can have zero or multiple arguments. Also, Varargs methods can be overloaded if required.A program that demonstrates this is given as follows:Example Live Demopublic class Demo {    public static void Varargs(int... args) {       System.out.println("Number of int arguments are: " + args.length); ... Read More

Demonstrate static variables, methods and blocks in Java

Jai Janardhan

Jai Janardhan

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

7K+ Views

The static variable is a class level variable and it is common to all the class objects i.e. a single copy of the static variable is shared among all the class objects.A static method manipulates the static variables in a class. It belongs to the class instead of the class ... Read More

How to use the asList() method of the Arrays class to create a Vector object

Jai Janardhan

Jai Janardhan

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

1K+ Views

A Vector can be created from an Array using the java.util.Arrays.asList() method.A program that demonstrates this is given as follows:Example Live Demoimport java.util.Arrays; import java.util.Vector; public class Demo {    public static void main(String args[]) {       Integer[] arr = { 3, 1, 9, 6, 4, 8, 7 ... Read More

Creating a Multilevel Inheritance Hierarchy in Java

Jai Janardhan

Jai Janardhan

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

9K+ Views

Inheritance involves an object acquiring the properties and behaviour of another object. So basically, using inheritance can extend the functionality of the class by creating a new class that builds on the previous class by inheriting it.Multilevel inheritance is when a class inherits a class which inherits another class. An ... Read More

What is Default access level in Java?

Jai Janardhan

Jai Janardhan

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

532 Views

The default access level is available when no access level is specified. All the classes, data members, methods etc. which have the default access level can only be accessed inside the same package.A program that demonstrates the default access level in Java is given as follows:Example Live Democlass Employee {   ... Read More

Phone Number validation using Java Regular Expressions

Jai Janardhan

Jai Janardhan

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

3K+ Views

The phone number can be validated using the java.util.regex.Pattern.matches() method. This method matches the regular expression for the phone number and the given input phone number and returns true if they match and false otherwise.Note: We are considering a demo number for our example since we cannot use our phone ... Read More

Search an element of Vector in Java

Jai Janardhan

Jai Janardhan

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

495 Views

An element of a Vector can be searched using the method java.util.ArrayList.indexOf(). This method returns the index of the first occurrence of the element that is specified. If the element is not available in the Vector, then this method returns -1.A program that demonstrates this is given as follows:Example Live Demoimport ... Read More

Use find() to find multiple subsequences in Java

Jai Janardhan

Jai Janardhan

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

94 Views

The find() method finds the multiple subsequences in an input sequence that matches the pattern required. This method is available in the Matcher class that is available in the java.util.regex packageA program that uses the find() method to find multiple subsequence in Java is given as follows:Example Live Demoimport java.util.regex.Matcher; import ... Read More

What does Interface consist of in Java

Jai Janardhan

Jai Janardhan

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

217 Views

An interface can be defined using the interface keyword. It contains variables and methods like a class but the methods in an interface are abstract by default unlike a class. An interface is primarily used to implement abstraction and it cannot be instantiated.A program that demonstrates an interface in Java ... Read More

Find the Extreme elements in a List in Java

Jai Janardhan

Jai Janardhan

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

396 Views

The extreme elements in a list are the maximum and minimum elements. These can be obtained using the java.util.Collections.max() and java.util.Collections.min() methods respectively.The Collections.max() method contains a single parameter i.e. the list whose maximum element is to be found and it returns the maximum element from the list. The Collections.min() ... Read More

Advertisements