Reflection is a feature in the Java programming language. It allows an executing Java program to examine or "introspect" upon itself, and manipulate internal properties of the program. For example, it's possible for a Java class to obtain the names of all its members and display them.

The ability to examine and manipulate a Java class from within itself
may not sound like very much, but in other programming languages this
feature simply doesn't exist. For example, there is no way in a Pascal,
C, or C++ program to obtain information about the functions defined
within that program.

One tangible use of reflection is in JavaBeans, where software components can be manipulated visually via a builder tool.
The tool uses reflection to obtain the properties of Java components (classes) as they are dynamically loaded.

That is, the method names of class java.util.Stack are listed,
along with their fully qualified parameter and return types.

This program loads the specified class using class.forName,
and then calls getDeclaredMethods to retrieve the list of
methods defined in the class. java.lang.reflect.Method is
a class representing a single class method.

Setting Up to Use Reflection

The reflection classes, such as Method, are found in
java.lang.reflect. There are three steps that must be followed to use
these classes. The first step is to obtain a java.lang.Class

object for the class that you want to manipulate. java.lang.Class
is used to represent classes and interfaces in a running Java program.

One way of obtaining a Class object is to say:

Class c = Class.forName("java.lang.String");

to get the Class object for String. Another approach is to use:

Class c = int.class;

or

Class c = Integer.TYPE;

to obtain Class information on fundamental types. The latter approach
accesses the predefined TYPE field of the wrapper (such asInteger) for the fundamental type.

The second step is to call a method such as getDeclaredMethods,
to get a list of all the methods declared by the class.

Once this information is in hand, then the third step is to use the
reflection API to manipulate the information. For example, the sequence:

The program first gets the Class description for method1, and then callsgetDeclaredMethods to retrieve a list of Method
objects, one for each method defined in the class. These include public,
protected, package, and private methods. If you use getMethods
in the program instead of getDeclaredMethods, you can also
obtain information for inherited methods.

Once a list of the Method objects has been obtained, it's
simply a matter of displaying the information on parameter types, exception
types, and the return type for each method. Each of these types,
whether they are fundamental or class types, is in turn represented by a
Class descriptor.

This example is similar to the previous ones. One new feature is the use ofModifier. This is a reflection class that represents the
modifiers found on a field member, for example "private int".
The modifiers themselves are represented by an integer, and

Modifier.toString is used to return a string representation
in the "official" declaration order (such as "static" before
"final"). The output of the program is:

Suppose that a program wants to invoke the add method, but doesn't
know this until execution time. That is, the name of the method is
specified during execution (this might be done by a JavaBeans
development environment, for example). The above program shows a way of
doing this.

getMethod is used to find a method in the class that has two
integer parameter types and that has the appropriate name. Once this method
has been found and captured into a Method object, it is invoked
upon an object instance of the appropriate type. To invoke a method, a
parameter list must be constructed, with the fundamental integer values
37 and 47 wrapped in Integer objects. The return value (84)
is also wrapped in an Integer object.

Creating New Objects

There is no equivalent to method invocation for constructors, because
invoking a constructor is equivalent to creating a new object (to be the
most precise, creating a new object involves both memory allocation and
object construction). So the nearest equivalent to the previous example
is to say:

which finds a constructor that handles the specified parameter types and
invokes it, to create a new instance of the object. The value of this
approach is that it's purely dynamic, with constructor lookup and
invocation at execution time, rather than at compilation time.

Changing Values of Fields

Another use of reflection is to change the values of data fields in
objects. The value of this is again derived from the dynamic nature of
reflection, where a field can be looked up by name in an executing
program and then have its value changed. This is illustrated by the
following example:

This example creates a 5 x 10 x 15 array of ints, and then proceeds to
set location [3][5][10] in the array to the value 37. Note here that a
multi-dimensional array is actually an array of arrays, so that, for
example, after the first Array.get, the result in arrobj is a 10 x 15
array. This is peeled back once again to obtain a 15-long array, and
the 10th slot in that array is set using Array.setInt.

Note that the type of array that is created is dynamic, and does not
have to be known at compile time.

Summary

Java reflection is useful because it supports dynamic retrieval of
information about classes and data structures by name, and allows for
their manipulation within an executing Java program. This feature is
extremely powerful and has no equivalent in other conventional languages
such as C, C++, Fortran, or Pascal.

Glen McCluskey has focused on programming languages since 1988.
He consults in the areas of Java and C++ performance, testing, and
technical documentation.

END of Article.
This code is flavored with garlic. I like it.
My question is can this be used for matrix and tensor multiplication?

Michael Wesch
Assistant Professor of Cultural Anthropology
Kansas State University

from xml.com:
"In order to appreciate XML, it is important to understand why it was created. XML was created so that richly structured documents could be used over the web. The only viable alternatives, HTML and SGML, are not practical for this purpose. HTML, as we've already discussed, comes bound with a set of semantics and does not provide arbitrary structure."

The dining philosophers should suffer no starvation,
after reading code written from this recipe.

delicately and expressive code, suitable for compilers,
programmers and mathematicians.

This code is flavored with garlic. I like it.

In my opinion there is a difference betwen concurrency
and real parallelism in Java.
How well it scales is the next question.
I miss a test unit or an environment to measure
the actual physical parallelism.

Note: the example presented here is modified from code presented in
Thinking in Java, 4th Edition,
by Bruce Eckel (ISBN 0-13-187248-6),
which is one of the best introductions to the topic of thread pools.
Coverage of the topic, which surprisingly is not listed in the index,
begins at page 1118.

my conclusion is that latency in Java cannot be decreased with parallelism,
concurrency adds latency,

Sun/Google Android “fight” overblown by ZDNet's Ed Burnette -- Ever since Google kicked off the Open Handset Alliance and released the "gPhone" Android SDK for mobile devices, the blogosphere has been buzzing about a new conflict brewing between Sun and Google over the future of Java. But I'm here to tell you, it's all bunk.