Krantik Chavan has Published 278 Articles

Display the amount of free memory in the Java Virtual Machine

Krantik Chavan

Krantik Chavan

Updated on 25-Jun-2020 14:55:03

377 Views

In order to display the amount of free memory in the Java Virtual Machine, we use the freeMemory() method. It is a method of the java.lang.Runtime Class. It returns the amount of free memory in the Java Virtual Machine. If we call the gc method, there is a possibility of ... Read More

Get number of available processors in Java

Krantik Chavan

Krantik Chavan

Updated on 25-Jun-2020 14:53:39

6K+ Views

In order to get the number of available processors in Java, we use the availableProcessors() method. The java.lang.Runtime.availableProcessors() method returns the number of processors which are available to the Java virtual machine. This number may vary during a particular call of the virtual machine.Declaration − The java.lang.Runtime.availableProcessors() method is declared ... Read More

Roll a six-sided die 6000 times in Java

Krantik Chavan

Krantik Chavan

Updated on 25-Jun-2020 14:51:04

626 Views

In order to roll a six sided die 6000 times in Java, we need to the nextInt() statement with decision making statements.The nextInt() method returns the next random integer value from this random number generator sequence.Declaration − The java.util.Random.nextInt() method is declared as follows −public int nextInt()Let us see a ... Read More

Get array upperbound in Java Multidimensional Arrays

Krantik Chavan

Krantik Chavan

Updated on 25-Jun-2020 13:18:03

578 Views

In order to get the array upperbound of a multidimensional array, we use the length() method. For a 2D array, the length() method returns the number of rows. We can access the number of columns using the array_name[0].length method.Let us see a program to get the array upperbound in Java ... Read More

Create array with Array.newInstance with Java Reflection

Krantik Chavan

Krantik Chavan

Updated on 25-Jun-2020 13:14:40

149 Views

The java.lang.reflect.Array.newInstance(Class componentType, int length) method forms a new array with the component type and length as specified in the argumentsDeclaration − The java.lang.reflect.Array.newInstance(Class componentType, int length) method is declared as follows −public static Object newInstance(Class componentType, int length) throws IllegalArgumentException, NegativeArraySizeExceptionLet us see a program to create array with ... Read More

Get class from an object in Java

Krantik Chavan

Krantik Chavan

Updated on 25-Jun-2020 12:30:16

277 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 ... Read More

List the Interfaces that an Interface Extends in Java

Krantik Chavan

Krantik Chavan

Updated on 25-Jun-2020 12:27:52

427 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 ... Read More

List the Interfaces That a Class Implements in Java

Krantik Chavan

Krantik Chavan

Updated on 25-Jun-2020 12:26:04

658 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 ... Read More

Get all declared fields from a class in Java

Krantik Chavan

Krantik Chavan

Updated on 25-Jun-2020 12:22:18

4K+ Views

An array of field objects is returned by the method java.lang.Class.getDeclaredFields(). These field objects include the objects with the public, private, protected and default access but not the inherited fields.Also, the getDeclaredFields() method returns a zero length array if the class or interface has no declared fields or if a ... Read More

List methods of a class using Java Reflection

Krantik Chavan

Krantik Chavan

Updated on 25-Jun-2020 12:08:15

2K+ Views

The methods of a class can be listed 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 ... Read More

Advertisements