×

Java class class

Java Class class instances are an executing Java application's implementation of the classes and interfaces. As well as, every Array is indeed an object that is common for all Arrays that correspond to the Class. 

asSubclass(Class<U> clazz)It converts the supplied class object into this Class object to describe a subclass of that Class.
cast(Object obj)It converts an entity to the Class or interfaces that this Class object represents.
desiredAssertionStatus()Whenever the method is invoked, it returns the argument status, which would be given to this Class if it had been instantiated at that moment.
forName(String className)The Class object connected to the Class or method with the given string name is returned.
forName(String name, boolean initialize,ClassLoader loader)To use the chosen class loader, the method produces the Class object related to the Class or protocol with the provided string name.
getAnnotatedInterfaces()It gives back a list of Named Type objects, showing how the item that this Class object describes uses types to describe super interfaces.
getAnnotatedSuperclass()It gives back an Annotated Type object which illustrates how a type may be used to describe the default constructor of the object described through this Class object. Even if an annotation is available, this function returns it; otherwise, it provides null.
getAnnotation(Class annotationClass)It returns this entity's annotations for the specified type.
getAnnotations()   This function retrieves any annotations which are currently associated with this element.
getAnnotationsByType(ClassannotationClass)This function gives back any annotations connected to the element.
getCanonicalName()According to the Java Language Standard, it yields the conventional identity of the underneath class.
getClasses()It then produces an arrays comprising Class objects for each of the public protocols and classes that belong to the Class and therefore are referenced through this Class object.
getClassLoader()This function returns the Class's class loader.
getComponentType()This function returns the Class describing the component category of an array.
getConstructor(Class... parameterTypes)It gives back a Constructor object corresponding to the designated public function Object()  of both the Class that even this Class object represents.
getConstructors()It contains an array containing objects from the many public constructors of the Class that this Class object represents.
getDeclaredAnnotation(ClassannotationClass)Even when an annotation of the requested type is immediately present, it provides it; otherwise, it returns nil.
getDeclaredAnnotations()Annotations that are present on just this component are returned.
getDeclaredAnnotationsByType(Class annotationClass)If any such annotations were in any way available for the provided type, it provides the annotation(s) for this component.
getDeclaredClasses()It gives back an array of Class objects representing all the interfaces and classes listed as components of the Class that the object represents.
getDeclaredConstructor(Class... parameterTypes)The function Object()  of the Class or interfaces that Class object represents is reflected inside the Constructor object that this function would return.
getDeclaredConstructors()It returns a list of function Object()  objects that include each function Object() defined by the Class that this Class object represents.
getDeclaredField(String name)It gives back a Field object representing the stated field of the Class or protocol that now the Class object is meant to represent.
getDeclaredMethod(String name, Class... parameterTypes)It gives back a Method object which corresponds to the defined method of the Class or interfaces that even this Class object represents.
getDeclaringClass()It yields both the Class object indicating the Class for which it was defined and the Class or interfaces provided by this Class object, which really is a membership of some other class.
getEnclosingClass()It yields the upper Class's immediately surrounding Class.
getEnclosingConstructor()The returned Constructor object reflects the immediately preceding function Object()  of the fundamental Class if the requested Class's object indicates a local or anonymous class within a function Object().
getEnclosingMethod()A Method object that describes the leading up to the incident method of such fundamental Class is returned if the called Class object contains a local or anonymous Class within such a method.
getEnumConstants()If this Class object doesn't really match an enum type, zero is returned instead of the components of this enum class.
getField(String name)It gives back a Field object that corresponds to the provided public member field of the interfaces or Class that all this Class object is a representation of.
getFields()It produces an array of Field objects that represent each of the open, public properties of the interfaces or Class that this Class object represents.
getGenericInterfaces()    Returns the types that correspond to the interfaces that this object's corresponding Class or interface directly implements.
getGenericSuperclass()gets the Type corresponding to the entity (Class, interfaces, primitive type, or null) specified by this Class' indirect superclass.
getInterfaces()It identifies the interfaces that the interfaces or Class that this object represents implements.
getMethod(String name, Class... parameterTypes)It provides the requested public membership method of the interfaces or Class that this Class object represents in the form of a method object.
getMethods()It returns a list of Method objects that correspond to all of the public methods of the Class or interface that this Class object represents. The methods that are defined by the Class or interfaces as well as those that are derived from super classes or super interfaces are included as well.
getModifiers()It gives back the integer-encoded Java programming language modifiers specific to this Class or interface.
getName()It provides a String representation of the name of both the entity this Class object represents.
getPackage(It only obtains the Class's packages.
getProtectionDomain()    It gives back this Class's Protected Category.
getResource(String name)This approach looks for a source using the specified name.
getResourceAsStream(String name)   This approach looks for a component using a specific name.
getSigners()The current members of this Class are returned.
getSimpleName()  The name of the fundamental Class as specified in the source code is returned by this function.
getSuperclass()The Class referenced by the superclass of the thing this Class describes is returned by this method.
getTypeName()For the element's name, this function produces an informational string.
getTypeParameters()When t is called, it produces an array of Type Constant objects that, in publication order, reflect the type variables defined by the generic proclamation represented through this Generic Declaration objects.
isAnnotation()If this Class object matches an annotations type, this function will return a Boolean value of "true."
isAnnotationPresent(Class annotationClass)If an annotation is provided on this element, this function produces a Boolean value of "true,"; otherwise, it returns "false."
isAnonymousClass()If the underneath class is an anonymous class, then and only when it is, this function returns the Boolean value "true."
isArray()     This function ascertains whether this Class object would be an array class representative.
isAssignableFrom(Class cls)This function determines if the Class or interfaces indicated by the supplied Class argument is identical to, or a superclass or superinterface of, the Class or protocol indicated by that of the Class object.
isEnum()If the same Class was specified as an enum inside the source code, but if only it were, it outputs the Boolean value "true."
isInstance(Object obj) determines if the given Object is assignable to the object this Class represents.
isInterface()If the provided Class object contains a connection type, it is verified.
isLocalClass()If the fundamental Class is indeed a local class, this method yields the Boolean value "true."
isMemberClass()If the base class is a member class, this function will return a Boolean value of "true."
isPrimitive()This method determines if a specific primitive type is represented by the Class object given.
isSynthetic()In the event that the given Class is a synthetic class, this function returns the Boolean expression "true," otherwise, it returns "false."
newInstance()The Class that this Class object represents is created anew using this function.
toGenericString()This function provides a string containing data about the type parameters and modifiers and a description of this Class.
toString()The object is turned into a string using this technique.

Example: JavaClassExamples1.java

public class JavaClassExamples1 {  
    public static void main(String[] args) throws ClassNotFoundException, IllegalAccessException, InstantiationException {  
        // the Class will return the class name 
        Class clas1 = Class.forName("java.lang.String");  
        Class clas2 = int.class;  
        System.out.print("The class indicated by Clas1 is: ");  
        // method was used for the clas1
        System.out.println(clas1.toString());  
        System.out.print("Class represented by class2: ");  
        // the toString() method is used for the clas1 
        System.out.println(clas2.toString());  
        String str = "Programming";  
        int index = 145;  
  
        // verifying the objects of the Class
        boolean bool1 = clas1.isInstance(str);  
        boolean bool2 = clas1.isInstance(index);  
        System.out.println("Whether p instance of the String : " + bool1);  
        System.out.println("Whether j instance of the String : " + bool2);  
    }  
}  

Output

The Class indicated by Clas1 is: class java.lang.String
Class represented by class2: int
Whether p instance of the String : true
Whether j instance of the String : false

Related Topics

Reverse a String in Java

Reversing a string means that if we have a string called “what is your name”, the reversed format is “eman ruoy si tahw”. Reversing a string involves totally flipping the...

3 minutes read.

What is advance Java?

The definition of advance inside the dictionary refers to a forward motion, development, or progress, and the definition of enhancing is something that improves things. To become experts in that...

3 minutes read.

How to reverse a linked list in java

The process of reversing a linked list in Java will be covered in this section. One of the most common questions in interviews is about reversing a linked list. If...

11 minutes read.

How to check if date is valid in Java?

In this article, you will acknowledge about how to verify if a date is valid or not. For this you will learn the approach, you will be able to write...

3 minutes read.

Producer Consumer Problem in Java Using Synchronized Block

The producer-consumer dilemma is a well-known instance of a multi-process synchronization issue in computing. Two processes—the producer and the consumer—are described in the issue, and they share a single, fixed-size...

4 minutes read.

How to take Array Input in Java

In this tutorial, we will learn about how to take array input in Java. So, before taking inputs let us know what an array is first. Array: An array is a collection...

10 minutes read.

Java Integer decode() method

The decode() method of Integer class decodes a String into an Integer. It can accept decimal, hexadecimal and octal numbers. Syntax public static Integer decode(String nm) throws NumberFormatException Parameters The parameter ‘nm’ represents the...

2 minutes read.

Java If Keyword

Definition: The if statement specifies a section of Java code that will run if an if statement's condition is false. The following conditional statements can be used in Java: To provide a block...

3 minutes read.

Awesome explanation of Strings in Java

What do you mean by String? Strings are a collection of characters that are commonly used in Java programming. Strings are regarded as objects in the Java programming language. “String” is a...

4 minutes read.

Types of Assignment Operators in Java

In this tutorial, we are going to study assignment operators and their types in Java language. Before proceeding to the types, let us know the term ‘assignment operator’.  The assignment...

5 minutes read.

Java Math acos() Method

The acos() method of Math class computes the trigonometric Arc Cosine (inverse of cosine ) of an angle. The value returned is between 0.0 to pi. Syntax: public static double acos(double a) Parameters: The...

1 minute read.

Perfect Number in Java

The concept of a perfect number in Java will be defined in this chapter, along with creating Program code that determine whether a specific number is perfect or not. Additionally,...

4 minutes read.

Time Class Operation in Java

The Java SQL package includes the time class. This class is merely a lightweight wrapper for java. util. THANKS TO THE recognize BC API can recognize this as a SQL...

3 minutes read.

Java Read File to String

There are different ways to deal with forming and examining a text record. This is normal while dealing with various applications. There are different ways to deal with looking at a...

6 minutes read.

Java Integer toBinaryString() method

The toBinaryString() method of Java Integer class returns a string representing the specified int argument as an unsigned integer in base 2. Syntax public static String toBinaryString (int  i)  Parameters The parameter ‘i’ represents...

1 minute read.

How to check Date Null in Java?

In this section, we will be acknowledged about Date Null in Java. The date null in Java is an entity that is used when there is no specified value for...

3 minutes read.

Powerful Number in Java

We will define a powerful number in this article and write Java programs to determine whether a given number is a powerful number or not. Java coding interviews and academic...

6 minutes read.

Java Delete File

There are two techniques to erase a record in Java: Utilizing File.delete() technique.Utilizing File.deleteOnExit() technique. Using File.delete() technique: In Java, we can erase a document by utilizing the File.delete() technique for File class....

2 minutes read.

JDK | Java Development Kit

Java Development Kit (JDK) The Java Development Kit is a software development environment used to create Java applications. The JDK includes JRE (Java Runtime Environment), an interpreter (java), a compiler (javac),...

3 minutes read.

Convert JSON to Map in Java

JACKSON and GSON libraries are two extremely capable JSON-related libraries offered by Java. To efficiently work with the returned JSON data, we frequently need to convert JSON responses into a...

6 minutes read.