Please note, this is a STATIC archive of website www.tutorialspoint.com from 11 May 2019, cach3.com does not collect or store any user information, there is no "phishing" involved.
Tutorialspoint
Cover Image
Cover Image
Drag to reposition
Contributed Answers

A static initialization block in Java

Answered on 15th Feb, 2019, 0 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 program. A program that demonstrates a static initialization bloc.....

How to extend Interfaces in Java

Answered on 15th Feb, 2019, 0 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:  Live Demo , , Now let us understand the above program. The interface A has an .....

Demonstrating variable-length arguments in Java

Answered on 12th Feb, 2019, 0 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 is given as follows:  Live Demo , , Now let us understand the above prog.....

Use overloaded methods to print array of different types in Java

Answered on 12th Feb, 2019, 0 Views

In method overloading, the class can have multiple methods with the same name but the parameter list of the methods should not be the same. Overloaded methods can be used to print an array of different types in Java by making sure that the parameter list of the methods contains different types of arrays that can be printed by the method. A program that demonstrates this is given as follows:.....

What are Default Constructors in Java?

Answered on 12th Feb, 2019, 0 Views

The default constructor in Java initializes the data members of the class to their default values such as 0 for int, 0.0 for double etc. This constructor is implemented by default by the Java compiler if there is no explicit constructor implemented by the user for the class. A program that demonstrates this is given as follows:  Live Demo , , Now let us understand the above program. Th.....

Class declaration with a method that has a parameter in Java

Answered on 12th Feb, 2019, 0 Views

A class declaration can contain a method that has a parameter in Java. A program that demonstrates this is given as follows:  Live Demo , , Now let us understand the above program. The Message class is created with a single member function messagePrint() that has a parameter msg i.e. the message to be printed. A code snippet which demonstrates this is as follows: , In the main() method.....

Create a Read-Only Collection in Java

Answered on 7th Feb, 2019, 0 Views

An example of a read-only collection can be an unmodifiable ArrayList. The unmodifiable view of the specified ArrayList can be obtained by using the method java.util.Collections.unmodifiableList(). This method has a single parameter i.e. the ArrayList and it returns the unmodifiable view of that ArrayList. A program that demonstrates this is given as follows:  Live Demo , The output of.....

Role of Matcher.matches() method in Java Regular Expressions

Answered on 7th Feb, 2019, 0 Views

The method java.time.Matcher.matches() matches the given region against the specified pattern. It returns true if the region sequence matches the pattern of the Matcher and false otherwise. A program that demonstrates the method Matcher.matches() in Java regular expressions is given as follows:  Live Demo , The output of the above program is as follows: , Now let us understand the abov.....

Perform Binary Search in Java using Collections.binarySearch

Answered on 7th Feb, 2019, 0 Views

Binary Search can be performed in Java using the method java.util.Collections.binarySearch(). This method requires two parameters i.e. the list in which binary search is to be performed and the element that is to be searched. It returns the index of the element if it is in the list and returns -1 if it is not in the list. A program that demonstrates this is given as follows:  Live Demo.....

Find the maximum element of a Vector in Java

Answered on 7th Feb, 2019, 0 Views

The maximum element of a Vector can be obtained using the java.util.Collections.max() method. This method contains a single parameter i.e. the Vector whose maximum element is determined and it returns the maximum element from the Vector. A program that demonstrates this is given as follows:  Live Demo , The output of the above program is as follows: , Now let us understand the above pr.....

loader
Advertisements
Contribution

We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy.