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

How to work with this keyword in Java?

Answered on 15th Feb, 2019, 0 Views

The this keyword in Java is mainly used to refer to the current instance variable of the class. It can also be used to implicitly invoke the method or to invoke the constructor of the current class. A program that demonstrates the this keyword in Java is given as follows:  Live Demo , , Now let us understand the above program. The Student class is created with data members rno, name. T.....

Methods Accepting a Variable Number of objects in Java

Answered on 15th Feb, 2019, 0 Views

A method that accepts a variable number of Object arguments in Java is a form of variable length arguments(Varargs). These can have zero or multiple Object type arguments. A program that demonstrates this is given as follows:  Live Demo , , Now let us understand the above program. The method Varargs() in class Demo has variable-length arguments of type Object. This method prints the nu.....

Pass long parameter to an overloaded method in Java

Answered on 12th Feb, 2019, 0 Views

Method overloading in a class contains multiple methods with the same name but the parameter list of the methods should not be the same. One of these methods can have a long parameter in their parameter list. A program that demonstrates this is given as follows:  Live Demo , , Now let us understand the above program. The PrintValues class is created with two methods print() in the impl.....

Duplicating Objects using a Constructor in Java

Answered on 12th Feb, 2019, 0 Views

A copy constructor can be used to duplicate an object in Java. The copy constructor takes a single parameter i.e. the object of the same class that is to be copied. However, the copy constructor can only be explicitly created by the programmer as there is no default copy constructor provided by Java. A program that demonstrates this is given as follows:  Live Demo , , Now let us unders.....

Why variables are declared final in Java

Answered on 12th Feb, 2019, 0 Views

A variable cannot be modified after it is declared as final. In other words, a final variable is constant. So, a final variable must be initialized and an error occurs if there is any attempt to change the value. A program that demonstrates a final variable in Java is given as follows:  Live Demo , , Now let us understand the above program. In the main() method in class Demo, the final.....

Role of Matcher.find(int) method in Java Regular Expressions

Answered on 7th Feb, 2019, 0 Views

The Matcher.find(int) method finds the subsequence in an input sequence after the subsequence number that is specified as a parameter. This method is available in the Matcher class that is available in the java.util.regex package. The Matcher.find(int) method has one parameter i.e. the subsequence number after which the subsequence is obtained and it returns true is the required subsequence.....

Get current thread in Java

Answered on 7th Feb, 2019, 0 Views

A thread can be created by implementing the Runnable interface and overriding the run() method. The current thread is the currently executing thread object in Java. The method currentThread() of the Thread class can be used to obtain the current thread. This method requires no parameters. A program that demonstrates this is given as follows:  Live Demo , The output of the above program.....

Sort a List in reverse order in Java

Answered on 7th Feb, 2019, 0 Views

A list can be sorted in reverse order i.e. descending order using the java.util.Collections.sort() method. This method requires two parameters i.e. the list to be sorted and the Collections.reverseOrder() that reverses the order of an element collection using a Comparator. The ClassCastException is thrown by the Collections.sort() method if there are mutually incomparable elements in the li.....

How a Vector can be cloned in Java

Answered on 7th Feb, 2019, 0 Views

A Vector can be cloned using the java.util.Vector.clone() method. This method does not take any parameters but returns a clone of the specified Vector instance as an object. 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 program. The Vector vec1 is created. Then Vector.add() is used to .....

Enumerate through the Vector elements in Java

Answered on 7th Feb, 2019, 0 Views

The Vector elements can be traversed using the Enumeration interface. The method hasMoreElements( ) returns true if there are more elements to be enumerated and false if there are no more elements to be enumerated. The method nextElement( ) returns the next object in the enumeration. A program that demonstrates this is given as follows:  Live Demo , The output of the above program is a.....

loader
Advertisements
Contribution

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