The HashCode for an Integer can be obtained using the hashCode() method in Java. This method does not accept any parameters and it returns a hash code value of the Integer object. A program that demonstrates the hashCode() method in Java is given as follows: Live Demo , , Now let us understand the above program. The Integer i is defined. Then the Integer value is printed and its HashC.....
Static import means that the fields and methods in a class can be used in the code without specifying their class if they are defined as public static. The Math class method sqrt() in the package java.lang is static imported. A program that demonstrates this is given as follows: Live Demo , , Now let us understand the above program. The Math class is not required along with the method.....
An interface contains variables and methods like a class but the methods in an interface are abstract by default unlike a class. Multiple inheritance by interface occurs if a class implements multiple interfaces or also if an interface itself extends multiple interfaces. A program that demonstrates multiple inheritance by interface in Java is given as follows: Live Demo , , Now let us.....
One of the quantifiers is the plus(+). This matches one or more of the subsequence specified with the sequence. A program that demonstrates using the quantifier plus(+) to find a match in Java is given as follows: Live Demo , , Now let us understand the above program. The subsequence “o+” is searched in the string sequence "o oo ooo". Then the find() method is used to find.....
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: Live Demo , , Now let us understand the above program. The class A has a private data member a tha.....
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: Live Demo , , Now let us understand the above program. The zip code is printed. The Pattern.matches() method m.....
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: Live Demo , , Now let us understand the above program. The Name class is created with a data member name and member functions setName() and getName() that set and get its value respectively. A code snippet which demonstrates this is as f.....
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: Live Demo , , Now let us understand the above program. The class A contains the constructor A(). The class B uses the ex.....
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 as follows: Live Demo , , Now let us understand the above program. The Student class is cre.....
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: Live Demo , , Now let us understand the above program. The Vector is created. Then Vector.add().....
Sign up now to get your own personalized profile!
We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy. Accept Learn more