Spec-Zone .ru
спецификации, руководства, описания, API
|
The Java language and hence the Java Virtual Machine (JVM™ software) enable the development of applications that have the following characteristics
The Java Virtual Machine also provides robust support with respect to the following areas (and more):
The Java Virtual Machine in JDK 7, allows dynamically typed non Java languages to also leverage the infrastructure and performance optimizations of the Java Virtual Machine.
The Java language is statically typed, meaning that all type information for variables, method parameters, and return values is available when a program is compiled. The Java compiler uses this type information to produce optimized bytecode, which can then be efficiently executed by the Java Virtual Machine at runtime.
The following example of a Hello World program demonstrates static typing. Types are shown in bold.
import java.util.Date; public class HelloWorld { public static void main(String [] args) { int len = args.length; String hello = "Hello "; Date currDate = new Date(); for (int i = 0; i < len; i++) { System.out.println(hello + args[i]); System.out.println("Today's date is: " + currDate); } } }
Dynamically typed languages, such as JavaScript and Ruby, typically do not have any type information available at compile time. The "type" of an object can only be determined at runtime. Hence, in the past, they could not be efficiently implemented on the JVM. The following snippet of the Hello World program written in Ruby:
#!/usr/bin/env ruby require 'date' currDate = DateTime.now.to_s hello = "Hello " ARGV.each do|a| puts hello + "#{a}" puts "Date and time: " + currDate end
invokedynamic
InstructionThe invokedynamic
instruction introduced in the JDK
7 release simplifies the implementation of dynamically typed
languages on the Java Virtual Machine. This instruction provides
user-definable or pluggable linkage behavior. In other
instructions, class-based or interface-based linkage behavior is
hardwired by the Java Virtual Machine.
The invokedynamic
instruction uses the new
bytecode-point 186. The format is similar to
invokeinterface
, but omits the target class, and
includes just the method name and descriptor. Language implementors
should use the API in the java.dyn
package to specify
the invokedynamic
instruction.
The java.dyn
package defines the Java level APIs
that are necessary to define and manage the "target method" of each
invokedynamic
call site. This API includes a new type
called MethodHandle
, which is the target of an
invokedynamic
call.
Java Technology |
Copyright © 1993, 2010, Oracle and/or its affiliates. All rights reserved. |