Java Class getFields() Method21 Mar 2025 | 2 min read The getFields() method of java Class returns an array containing field objects representing all the accessible public fields of the class or interface represented by this Class object otherwise if no field is present then it returns an array of length 0. SyntaxParameterNA ReturnsAn array of field object. ThrowsSecurityException. Example 1Output: All Fields = public static final int java.awt.Label.LEFT public static final int java.awt.Label.CENTER public static final int java.awt.Label.RIGHT public static final float java.awt.Component.TOP_ALIGNMENT public static final float java.awt.Component.CENTER_ALIGNMENT public static final float java.awt.Component.BOTTOM_ALIGNMENT public static final float java.awt.Component.LEFT_ALIGNMENT public static final float java.awt.Component.RIGHT_ALIGNMENT public static final int java.awt.image.ImageObserver.WIDTH public static final int java.awt.image.ImageObserver.HEIGHT public static final int java.awt.image.ImageObserver.PROPERTIES public static final int java.awt.image.ImageObserver.SOMEBITS public static final int java.awt.image.ImageObserver.FRAMEBITS public static final int java.awt.image.ImageObserver.ALLBITS public static final int java.awt.image.ImageObserver.ERROR public static final int java.awt.image.ImageObserver.ABORT Example 2Output: public static final java.math.BigDecimal ClassgetFieldsExample2$Interface1.dnum public static final java.math.BigInteger ClassgetFieldsExample2$Interface1.Inum public static final java.math.BigDecimal ClassgetFieldsExample2$Interface1.dnum2 public java.lang.String ClassgetFieldsExample2$SuperClass.str public java.math.BigInteger ClassgetFieldsExample2$SuperClass.iinum public java.math.BigInteger ClassgetFieldsExample2$SuperClass.inum3 public double ClassgetFieldsExample2$SuperSuperClass.dbl Next TopicJava Class |
Java Class Method The method of java Class class gets the superclass of this class. If no superclass exists then null is returned. Syntax public Class<? super T> getSuperclass() Parameter NA Returns Immediate superclass of the class Throws NA Example 1 import java.lang.*; public class ClassgetSuperClassExample1 extends Object { public static void main(String...
1 min read
Java Class Method The getField() method of java Class class returns the Types as an array of the type Type representing the interfaces directly implemented by the class or interface. Syntax public Type[] Parameter NA Returns An array. Throws GenericSignatureFormatError, TypeNotPresentException MalformedParameterizedTypeException Example 1 //import statements import java.lang.reflect.*; public class ClassgetGenericInterfacesExample1 { ...
3 min read
Java Class Method The method of java Class class returns an array of the objects of the type AnnotatedType that represents the use of types to specify superinterfaces of the entity represented by this(Current class object) Class object. Syntax public AnnotatedType[] Parameter No parameter is passed. Returns An array...
2 min read
Java Class Method The method of java Class class gets the annotation by type that is associated with this element. If no annotation is related to this element, it returns an array of length 0. Syntax public <A extends Annotation> A[] getAnnotationsByType(Class<A> annotationClass) Parameter annotationClass - the Class...
2 min read
Java Class Method The method of java Class class returns a field object which represents the public member field of the class or interface represented by this Class object. A string specifying the simple name of the desired field is passed as the parameter. Syntax public...
2 min read
Java Class Method The method of java Class class returns this element's annotation for the specified type if any annotation is directly present otherwise null. Syntax public <A extends Annotation> A getDeclaredAnnotation(Class<A> annotationClass) Parameter annotationClass - the Class object corresponding to the annotation type Returns annotation for the specified annotation...
2 min read
Java Class Method The method of java Class class returns a field object representing the specified field declared inside the class or interface of this class. Syntax public Field getDeclaredField(String name) throws NoSuchFieldException, SecurityException Parameter name - the name of the field Returns Field object. Throws NoSuchMethodException , SecurityException Example 1 import java.lang.reflect.*; public class ClassgetDeclaredFieldExample1...
2 min read
Java Class Method The method of java Class class returns this element's annotation for the specified type if such an annotation is present, otherwise returns the null. Syntax public <A extends Annotation> A getAnnotation(Class<A> annotationClass) Parameter A - the type of the annotation to query for and return...
1 min read
Java Class Method The method of java Class class returns an array containing the Class objects which represents all the public classes and interfaces that are members of the class represented by the Class object. Syntax public Class<?>[] Parameter NA Returns Returns an array of class object. Throws SecurityException Example 1 import java.lang.*; public...
2 min read
Java Class Method The method of java Class class returns the package name of the class. Syntax public Package Parameter NA Returns The int representing the modifiers for this class. Throws The package of this class. Example 1 import java.lang.*; public class ClassgetPackageExample1 { public static void main(String[] args) { ...
1 min read
We request you to subscribe our newsletter for upcoming updates.
We provides tutorials and interview questions of all technology like java tutorial, android, java frameworks
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India