Arushi has Published 157 Articles

Demonstrating variable-length arguments in Java

Arushi

Arushi

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

4K+ Views

A method with variable length arguments(Varargs) in Java can have zero or multiple arguments. Variable length arguments are most useful when the number of arguments to be passed to the method is not known beforehand. They also reduce the code as overloaded methods are not required.A program that demonstrates this ... Read More

How to extend Interfaces in Java

Arushi

Arushi

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

23K+ Views

An interface contains variables and methods like a class but the methods in an interface are abstract by default unlike a class. An interface extends another interface like a class implements an interface in interface inheritance.A program that demonstrates extending interfaces in Java is given as follows:Example Live Demointerface A { ... Read More

A static initialization block in Java

Arushi

Arushi

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

8K+ Views

Instance variables are initialized using initialization blocks. However, the static initialization blocks can only initialize the static instance variables. These blocks are only executed once when the class is loaded. There can be multiple static initialization blocks in a class that is called in the order they appear in the ... Read More

Add elements at the end of a Vector in Java

Arushi

Arushi

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

300 Views

Elements can be added at the end of a 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 the element is added to the Vector as required and false otherwise.A program that demonstrates this is given as follows:Example Live ... Read More

Create class Objects in Java using new operator

Arushi

Arushi

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

449 Views

Class objects can be created in Java by using the new operator. A class is instantiated by the new operator by allocating memory for the object dynamically and then returning a reference for that memory. A variable is used to store the memory reference.A program that demonstrates this is given ... Read More

Demonstrate constructors in a Multilevel Hierarchy in Java

Arushi

Arushi

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

1K+ Views

Multilevel inheritance is when a class inherits a class which inherits another class. An example of this is class C inherits class B and class B in turn inherits class A.A program that demonstrates constructors in a Multilevel Hierarchy in Java is given as follows:Example Live Democlass A {    A() ... Read More

Class that contains a String instance variable and methods to set and get its value in Java

Arushi

Arushi

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

455 Views

A class declaration can contain a String instance and methods to set and get its value in Java.A program that demonstrates this is given as follows:Example Live Democlass Name {    private String name;    public void setName(String n) {       name = n;    }    public String ... Read More

Zip Code validation using Java Regular Expressions

Arushi

Arushi

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

1K+ Views

The zip code can be validated using the java.util.regex.Pattern.matches() method. This method matches the regular expression for the zip code and the given input zip code and returns true if they match and false otherwise.A program that demonstrates this is given as follows:Example Live Demopublic class Demo {    public static ... Read More

Demonstrate Private access modifier in Java

Arushi

Arushi

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

119 Views

The data members and methods of a class can be accessed only from within their declared class if they are specified with the private access modifier. The keyword private is used to specify this modifier.A program that demonstrates the private access modifier in Java is given as follows:Example Live Democlass A ... Read More

Set the size of a Vector in Java

Arushi

Arushi

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

323 Views

The java.util.Vector.setSize() method can be used to set the size of a Vector in Java. If the new size that is set is greater than the old size of the Vector, then null values are added to the positions created. If the new size that is set is lesser than ... Read More

Advertisements