Home >Java >javaTutorial >What does class mean in java

What does class mean in java

藏色散人
藏色散人Original
2019-05-14 09:36:1941754browse

Class in java represents a class, and the class class exists in the java.lang package. In Java, each class has a corresponding Class object. When we write a class and compile it, a Class object will be generated in the generated [.class] file, which is used to represent the type information of this class.

What does class mean in java

Class class (in the java.lang package, Instances of the class Classrepresent classes and interfaces in a running Javaapplication).

(Video tutorial recommendation: java course)

In Java, each class has a corresponding Class object. That is to say, when we write a class and the compilation is completed, a Class object will be generated in the generated .class file to represent the type information of this class.

Method 1

Use the object to call the getClass() method to obtain the Class instance of the object;

Method 2

Use Class The static method of the classforName(), uses the name of the class to obtain a Class instance (staticClass forName(String className) Returns the Classobject associated with the class or interface with the given stringname.);

Method 3

Use .class to obtain Class instances. For encapsulation classes of basic data types, you can also use .TYPE to obtain Class instances of the corresponding basic data types

Call the default constructor ObjectnewInstance() in the class in newInstance() (you can create an instance of this class when you don’t know the name of the class) Creates a new instance of the class represented by this Classobject.

During runtime, if we want to generate an object of a certain class, the Java Virtual Machine (JVM) will check whether the Class object of that type has been loaded. If it is not loaded, the JVM will find the .class file based on the name of the class and load it. Once a Class object of a certain type has been loaded into memory, it can be used to generate all objects of that type.

Related tutorials: java introductory tutorial

The above is the detailed content of What does class mean in java. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn