- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Found 4336 Articles for Java 8
![Anvi Jain](https://www.tutorialspoint.com/assets/profiles/13591/profile/60_98631-1512716973.jpg)
4K+ Views
In order to sort ArrayList in Descending order using Comparator, we need to use the Collections.reverseOrder() method which returns a comparator which gives the reverse of the natural ordering on a collection of objects that implement the Comparable interface.Declaration − The java.util.Collections.reverseOrder() method is declared as follows -public static Comparator reverseOrder()Let us see a program to sort an ArrayList in Descending order using Comparator with Java Collections −Example Live Demoimport java.util.*; public class Example { public static void main (String[] args) { ArrayList list = new ArrayList(); list.add(10); list.add(50); ... Read More
![Krantik Chavan](https://www.tutorialspoint.com/assets/profiles/13545/profile/60_126883-1512724834.jpg)
552 Views
The interfaces that are implemented by a class that is represented by an object can be determined using the java.lang.Class.getInterfaces() method. This method returns an array of all the interfaces that are implemented by the class.A program that demonstrates this is given as follows −Example Live Demopackage Test; import java.lang.*; import java.util.*; public class Demo { public static void main(String[] args) { listInterfaces(String.class); } public static void listInterfaces(Class c) { System.out.println("The Class is: " + c.getName()); Class[] interfaces = c.getInterfaces(); System.out.println("The Interfaces are: " + Arrays.asList(interfaces)); ... Read More
![George John](https://www.tutorialspoint.com/assets/profiles/13511/profile/60_58410-1512537824.png)
5K+ Views
In order to match the first name and last name using regular expression, we use the matches method in Java. The java.lang.String.matches() method returns a boolean value which depends on the matching of the String with the regular expression.Declaration −The java.lang.String.matches() method is declared as follows −public boolean matches(String regex)Let us see a program to validate the first name and last name with regular expressions −Example Live Demopublic class Example { public static void main( String[] args ) { System.out.println(firstName("Tom")); System.out.println(lastName("hanks")); } // validate first name public static boolean firstName( String ... Read More
![Ankith Reddy](https://www.tutorialspoint.com/assets/profiles/22328/profile/60_142162-1519038074.jpg)
2K+ Views
The array type can be checked using the java.lang.Class.getComponentType() method. This method returns the class that represents the component type of the array. The array length can be obtained in int form using the method java.lang.reflect.Array.getLength().A program that demonstrates this is given as follows −Example Live Demoimport java.lang.reflect.Array; public class Demo { public static void main (String args[]) { int[] arr = {6, 1, 9, 3, 7}; Class c = arr.getClass(); if (c.isArray()) { Class arrayType = c.getComponentType(); System.out.println("The array is of type: ... Read More
![Arjun Thakur](https://www.tutorialspoint.com/assets/profiles/13574/profile/60_74441-1560315595.jpg)
975 Views
A new instance of a two dimensional array can be created using the java.lang.reflect.Array.newInstance() method. This method basically creates the two-dimensional array with the required component type as well as length.A program that demonstrates the creation of a two-dimensional array using the Array.newInstance() method is given as follows −Example Live Demoimport java.lang.reflect.Array; public class Demo { public static void main (String args[]) { int size[] = {3, 3}; int arr[][] = (int[][])Array.newInstance(int.class, size); System.out.println("The two-dimensional array is:"); for(int[] i: arr) { for(int j: i ... Read More
![Chandu yadav](https://www.tutorialspoint.com/assets/profiles/22330/profile/60_142811-1519038104.jpg)
5K+ Views
A fully-qualified class name in Java contains the package that the class originated from. Also, an inner class is a class that is another class member. So, the fully-qualified name of an inner class can be obtained using the getName() method.A program that demonstrates this is given as follows −Example Live Demopublic class Main { public static void main(String[] argv) throws Exception { Class c = java.lang.Character.Subset.class; String innerClassName = c.getName(); System.out.println("The fully qualified name of the inner class is: " + innerClassName); } }OutputThe fully qualified name of the ... Read More
![George John](https://www.tutorialspoint.com/assets/profiles/13511/profile/60_58410-1512537824.png)
9K+ Views
A fully-qualified class name in Java contains the package that the class originated from. An example of this is java.util.ArrayList. The fully-qualified class name can be obtained using the getName() method.A program that demonstrates this is given as follows −Example Live Demopublic class Demo { public static void main(String[] argv) throws Exception { Class c = java.util.ArrayList.class; String className = c.getName(); System.out.println("The fully-qualified name of the class is: " + className); } }OutputThe fully-qualified name of the class is: java.util.ArrayListNow let us understand the above program.The getName() method is used ... Read More
![Ankith Reddy](https://www.tutorialspoint.com/assets/profiles/22328/profile/60_142162-1519038074.jpg)
441 Views
A qualified class name in Java contains the package that the class originated from. In contrast to this, the unqualified class name contains only the class name without any package information. A program that gets the unqualified name of a class is given as follows:Example Live Demopublic class Demo { public static void main(String[] argv) throws Exception { Class c = java.util.ArrayList.class; String className = c.getName(); System.out.println("The qualified class name is: " + className); if (className.lastIndexOf('.') < 0) { className = className.substring(className.lastIndexOf('.') + 1); ... Read More
![Arjun Thakur](https://www.tutorialspoint.com/assets/profiles/13574/profile/60_74441-1560315595.jpg)
4K+ Views
The getName() method is used to get the names of the entities such as interface, class, array class, void etc. that are represented by the class objects. These names are returned in the form of a string.A program that gets the name of the member objects using getName() method is given as follows −Example Live Demoimport java.lang.reflect.Constructor; import java.lang.reflect.Field; import java.lang.reflect.Method; public class Main { public static void main(String[] argv) throws Exception { Class c = java.lang.Integer.class; Method m = c.getMethods()[0]; Field f = c.getFields()[0]; Constructor cons = ... Read More
![Chandu yadav](https://www.tutorialspoint.com/assets/profiles/22330/profile/60_142811-1519038104.jpg)
153 Views
The modifiers for a class or an interface are returned by the java.lang.Class.getModifiers() method. These modifiers are encoded as an integer and they consist of the JVM’s constants for public, private, protected, final, abstract, static and interface.A program that demonstrates this is given as follows −Example Live Demoimport java.lang.reflect.Modifier; public class Main { public static void main(String[] argv) throws Exception { int modifiers = String.class.getModifiers(); String modifierString = Modifier.toString(modifiers); System.out.println("The Modifier is: " + modifierString); } }OutputThe Modifier is: public finalNow let us understand the above program.The method getModifiers() is ... Read More