- 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
474 Views
The method java.lang.Class.isInterface() is used to find if String is an interface or class in Java. This method returns true if String is an interface, otherwise it returns false.A program that demonstrates this is given as follows −Example Live Demopackage Test; import java.lang.*; public class Demo { public static void main(String[] args) { Class c = String.class; boolean interfaceFlag = c.isInterface(); System.out.println("This is an Interface? " + interfaceFlag); } }OutputThis is an Interface? falseNow let us understand the above program.The isInterface() method is used to find if String is an ... Read More
298 Views
The interfaces that are implemented by an interface 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 interface.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(java.util.List.class); } public static void listInterfaces(Class c) { System.out.println("The interface is: " + c.getName()); Class[] interfaces = c.getInterfaces(); System.out.println("The Interfaces are: " + Arrays.asList(interfaces)); ... Read More
108 Views
The immediate superclass information of any entity such as an object, class, primitive type, interface etc. can be obtained using the method java.lang.Class.getSuperclass().A program that demonstrates this is given as follows −Example Live Demopackage Test; import java.lang.*; class Class1{ } class Class2 extends Class1{ } public class Demo { public static void main(String args[]) { Class1 obj1 = new Class1(); Class2 obj2 = new Class2(); Class c; c = obj2.getClass(); ... Read More
727 Views
The declared method can be obtained by name and parameter type by using the java.lang.Class.getDeclaredMethod() method. This method takes two parameters i.e. the name of the method and the parameter array of the method.The getDeclaredMethod() method returns a Method object for the method of the class that matches the name of the method and the parameter array that are the parameters.A program that gets the declared method by name and parameter type using the getDeclaredMethod() method is given as follows −Example Live Demopackage Test; import java.lang.reflect.*; public class Demo { public String str; private Integer func1() { ... Read More
145 Views
Two float arrays can be compared in Java using the java.util.Arrays.equals() method. This method returns true if the arrays are equal and false otherwise. The two arrays are equal if they contain the same number of elements in the same order.A program that compares two float arrays using the Arrays.equals() method is given as follows −Example Live Demoimport java.util.Arrays; public class Demo { public static void main(String[] argv) throws Exception { boolean flag = Arrays.equals(new float[] { 1.5F, 8.3F, 7.6F }, new float[] { 1.5F, 8.3F, 7.6F }); System.out.println("The two float arrays are equal? ... Read More
203 Views
The runtime class of an object can be obtained using the java.lang.Object.getClass(). Also, the getName() method is used to get the name of the class.A program that demonstrates getting the class of an object using the getClass() method is given as follows −Example Live Demopublic class Demo { public static void main (String [] args) { Integer integer = new Integer(10); Class c = integer.getClass(); System.out.println ("The class is: " + c.getName()); c = new Demo().getClass(); System.out.println ("The class is: " + c.getName()); } ... Read More
306 Views
Binary search can be implemented on an array by using the method java.util.Arrays.binarySearch(). This method returns the index of the required element if it is available in the array, otherwise it returns (- (insertion point) - 1) where the insertion point is the position at which the element would be inserted into the array.A program that demonstrates this is given as follows −Example Live Demoimport java.util.Arrays; public class Demo { public static void main(String[] args) { int arr[] = { 3, 9, 1, 6, 4}; Arrays.sort(arr); System.out.print("The sorted array is: "); ... Read More
415 Views
An array has a fixed number of values and its size is defined when it is created. Therefore, the size of the array cannot be changed later. To solve this problem, an ArrayList should be used as it implements a resizable array using the List interface.A program that demonstrates ArrayList in Java is given as follows −Example Live Demoimport java.util.*; public class Demo { public static void main(String args[]) { ArrayList aList = new ArrayList(); aList.add("Apple"); aList.add("Melon"); aList.add("Orange"); aList.add("Mango"); aList.add("Grapes"); ... Read More
152 Views
An element can be searched in a sorted object array in Java by using the methodjava.util.Arrays.binarySearch(). This method returns the index of the required element if it is available in the array, otherwise it returns (-(insertion point) - 1) where the insertion point is the position at which the element would be inserted into the array. A program that searches the required element in a sorted object array is given as follows −Example Live Demoimport java.util.Arrays; public class Demo { public static void main(String[] args) { String str[] = { "P", "M", "A", "T", "D"}; ... Read More
405 Views
An array of objects can be sorted using the java.util.Arrays.sort() method with a single argument required i.e. the array to be sorted. A program that demonstrates this is given as follows −Example Live Demoimport java.util.Arrays; public class Demo { public static void main(String args[]) throws Exception { String str[] = new String[]{"apple", "orange", "mango", "guava", "melon"}; int n = str.length; System.out.println("The original array of strings is: "); for (int i = 0; i < n; i++) { System.out.println(str[i]); } ... Read More