The static method of the dynamic execution class in Java. This article introduces how to use Java. lang. reflect. * The reflection mechanism provided by the package is used to construct class instances/execution class static methods during runtime.
/*In
This article describes the following three C code callback Java methods1. C code callback Java NULL method2. C code callback Java int type parameter method3. C code callback javastring type parameter methodMethods are similar, first look at the C code callback Java empty method
)
Ii. Generate. Class and. H files
Javac mynative. Class
Javah-JNI mynative
The generated. h file is as follows:
/* Do not edit this file-it is machine generated */
# Include
/* Header for class mynative */
# Ifndef _ included_mynative
# DEFINE _ included_mynative
# Ifdef _ cplusplus
Extern "C "{
# Endif
/*
* Class: mynative
* Method: getstrings0
* Signature: () [ljava/lang
Background requirementsWe need to call Java code in the JNI C code. Implementation principle: Use the reflective pretext provided by JNI to reflect the Java method and make the call.The key methods of JNI are explained.1. In the same class, call other methodsJniexportvoidjnicall java_cn_itcast_ndkcallback_dataprovider_
) Ret-type
Method type
For example, the Prompt.getLine method has the signature:
(ljava/lang/string;) ljava/lang/string;
Whereas the
Callbacks.mainMethod has the signature:
([ljava/lang/string;) V
Array types
option does not include third-party jar packages used by the project into the jar package generated by the java project.
Custom configuration file MANIFEST. MF:
First, create a MANIFEST. MF file under the root directory of the project.
Next, open the file in notepad and edit it:
For example:Manifest-Version: 1.0Main-Class: StudentManager_TestClass-Path: sqlserver2005.jarThe Manifest-Version indicates the program Version, and the Main-Class indicates
programming process, we often encounter this situation: there is an object A, which contains some valid values at a time point, in this case, you may need a new object B that is exactly the same as a, and any subsequent changes to B will not affect the value in A. That is to say, A and B are two independent objects, however, the initial value of B is determined by object. In Java, simple assignment statements cannot meet this requirement. Although th
, the dynamic loading process will be more complex. Take the database connection pool as an example. Generally, the constructor of the connection pool is defined as private, and the unique instance is obtained through the custom getInstance () static method. In this case, the instance cannot be correctly constructed simply by using Class. forName (). getInstance.
Fortunately, the Reflection mechanism provided by
Reflection is an advanced feature of Java.
Reflection is a key feature of Java as a dynamic (or quasi-dynamic) language. This mechanism allows the program to obtain the internal information of any class with a known name through reflection APIs at runtime, including its modifiers (such as public and static), superclass (such as object), implements interfaces (such as serializable), also includes all informa
Parse the local method to map the data types at the Java layer, and map the data types at the java layer.Preface
The Java language defines different data types, such as basic types int and double, and all classes parent class objects. These are Java-level types, the processi
As you know, the methods or attributes modified by the private modifier in Java can only be accessed within this class, and cannot be accessed by other classes. Is that true? The following example can be used to access the private method in a class. The principle is that the reflection mechanism of Java seems insecure at this point.
A class with only one pri
method and run the XML configuration of the timing code Spring AOP, configure the method to be monitored and the cut-in method (custom Interceptor) java code: copy the code package com. cplatform. tencent. task; import java. util. hashMap; import
In JavaProgramObjects can be created explicitly or implicitly.
There are four ways to create objects:
1. New. This is the most common way to create objects.
2. Run the reflection mechanism. Call the newinstace () method of the Java. Lang. Class or Java. Lang.
. I will write an article to discuss the disadvantages of Java interface. We are concerned about the implementation of connection pool. The following provides an implementation method.
Import java. SQL .*;Import java. Lang. Reflect
the class file.
In addition, we can note that our source code in SYSTEM.OUT.PRINTLN (param1 + param2), print two string parameter connections, at compile time the compiler automatically to optimize the way to use StringBuilder, like this similar compiler optimization there are many ^_ ^.
Here's a look at the format of a class file that does not use the-G parameter or compiled with the-g:none parameter, where only the byte code of the method method1
StringBuilder, like this kind of compiler optimizations there are many ^_ ^.The following is a look at the format of a class file that does not use the-G parameter or compiled with the-g:none parameter, which shows only the byte code of the method Method1, and the other omitted:Localhost:mikan mikan$ javac-g:none-d/users/mikan/documents/workspace/project/algorithm/target/classes/users/ Mikan/documents/workspace/project/algorithm/src/main/
understand the tedious details outside of Java applications.Interaction with the operating system:JVM supports the Java language itself and the Runtime Library. It is a platform for survival of Java programs. It consists of an interpreter (interpreted bytecode) and some libraries connected to local code. However, it is not a complete system. It often relies on t
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.