- 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 9317 Articles for Object Oriented Programming
![Naveen Singh](https://www.tutorialspoint.com/assets/profiles/13511/profile/60_58410-1512537824.png)
550 Views
The immediate superclass of any entity such as an object, class, primitive type, interface etc. can be obtained using the method java.lang.Class.getSuperclass(). This method contains no parameters.A program that demonstrates this is given as follows −Example Live Demopublic class Main { public static void main(String[] args) { Object obj1 = new String("Hello"); Object obj2 = new Integer(15); Class c1 = obj1.getClass().getSuperclass(); System.out.println("Super Class = " + c1); Class c2 = obj2.getClass().getSuperclass(); System.out.println("Super Class = " + c2); } }OutputSuper Class = ... Read More
![Naveen Singh](https://www.tutorialspoint.com/assets/profiles/22328/profile/60_142162-1519038074.jpg)
527 Views
The availability can be checked using the method java.lang.Class.forName(). The class object associated with the class with the given string name can be returned using the method java.lang.Class.forName(String name, boolean initialize, ClassLoader loader), using the class loader that is used to load the class.A program that demonstrates this is given as follows −Example Live Demopublic class Main { public static void main(String args[]) { System.out.println(Availability("java.lang.String")); } public static boolean Availability(String name) { boolean flag = false; try { Class.forName(name, false, null); ... Read More
![Naveen Singh](https://www.tutorialspoint.com/assets/profiles/13574/profile/60_74441-1560315595.jpg)
760 Views
The package for an object of a class can be obtained using the getPackage() method with the help of the class loader of the class. If there is no package object created by the class loader of the class, then null is returned.A program that demonstrates this is given as follows −Example Live Demoimport java.util.ArrayList; import java.util.LinkedList; import java.util.HashSet; public class Main { public static void main(String[] args) { System.out.println("The package is: " + new ArrayList().getClass().getPackage().getName()); System.out.println("The package is: " + new LinkedList().getClass().getPackage().getName()); System.out.println("The package is: " + new HashSet().getClass().getPackage().getName()); ... Read More
![Naveen Singh](https://www.tutorialspoint.com/assets/profiles/22330/profile/60_142811-1519038104.jpg)
95 Views
The package for a class can be obtained using the java.lang.Class.getPackage() method with the help of the class loader of the class.The getPackage() method returns null for a primitive or array in unnamed package. A program that demonstrates this is given as follows −Example Live Demopublic class Main { public static void main(String[] argv) throws Exception { Package pack1 = int.class.getPackage(); System.out.println(pack1); Package pack2 = int[].class.getPackage(); System.out.println(pack2); } }Outputnull nullNow let us understand the above program.The getPackage() method is used to obtain the package for the class. ... Read More
![Naveen Singh](https://www.tutorialspoint.com/assets/profiles/13511/profile/60_58410-1512537824.png)
211 Views
The package for a class can be obtained using the java.lang.Class.getPackage() method with the help of the class loader of the class.The getPackage() method returns null for a class in unnamed package. A program that demonstrates this is given as follows −Example Live Democlass Class1 { public class Main { public static void main(String[] argv) throws Exception { Class c = Class1.class; System.out.println(c.getPackage()); } }OutputnullNow let us understand the above program.The getPackage() method is used to obtain the package for the class. However, the getPackage() method returns null for the ... Read More
![Naveen Singh](https://www.tutorialspoint.com/assets/profiles/22328/profile/60_142162-1519038074.jpg)
201 Views
Binary search on a float array can be implemented by using the method java.util.Arrays.binarySearch(). This method returns the index of the required float 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) { float f_arr[] = { 5.2f, 9.5f, 6.5f, 2.8f, 3.6f }; Arrays.sort(f_arr); System.out.print("The sorted array ... Read More
![Naveen Singh](https://www.tutorialspoint.com/assets/profiles/13574/profile/60_74441-1560315595.jpg)
4K+ Views
In order to generate Random long type numbers in Java, we use the nextLong() method of the java.util.Random class. This returns the next random long value from the random generator sequence.Declaration − The java.util.Random.nextLong() method is declared as follows −public long nextLong()Let us see a program to generate random long type numbers in Java −Example Live Demoimport java.util.Random; public class Example { public static void main(String[] args) { Random rd = new Random(); // creating Random object System.out.println(rd.nextLong()); // displaying a random long value } }Output-4787108556148621714Note - The output may vary on Online compilers.Read More
![Naveen Singh](https://www.tutorialspoint.com/assets/profiles/22330/profile/60_142811-1519038104.jpg)
5K+ Views
The package for a class can be obtained using the java.lang.Class.getPackage() method with the help of the class loader of the class. If there is no package object created by the class loader of the class, then null is returned.A program that demonstrates this is given as follows −Example Live Demoimport java.util.Date; public class Main { public static void main(String[] args) { Date d = new Date(); Package p = d.getClass().getPackage(); String pName = p.getName(); System.out.println("The package name is: " + pName); } }OutputThe package name is: ... Read More
![Naveen Singh](https://www.tutorialspoint.com/assets/profiles/13511/profile/60_58410-1512537824.png)
5K+ Views
A list of all the public methods of a class or interface that is represented by an object are provided using the method java.lang.Class.getMethods(). The public methods include that are declared by the class or interface and also those that are inherited by the class or interface.Also, the getMethods() method returns a zero length array if the class or interface has no public methods or if a primitive type, array class or void is represented in the Class object.A program that demonstrates this is given as follows −Example Live Demoimport java.lang.reflect.Method; public class Main { public static void main(String[] argv) ... Read More
![Naveen Singh](https://www.tutorialspoint.com/assets/profiles/22328/profile/60_142162-1519038074.jpg)
854 Views
The list of all the declared methods can be obtained using the java.lang.Class.getDeclaredMethods() method. This method returns an array that contains all the Method objects with public, private, protected and default access. However, the inherited methods are not included.Also, the getDeclaredMethods() method returns a zero-length array if the class or interface has no methods or if a primitive type, array class or void is represented in the Class object.A program that demonstrates this is given as follows −Example Live Demoimport java.lang.reflect.Method; public class Main { public static void main(String[] argv) throws Exception { Class c = java.lang.String.class; ... Read More