Java SE 6 Platform

+2

No comments posted yet

Comments

Slide 1

New Features - JavaTM SE 6 Platform 報告人:高明權 DATE :2009/08/23 Released V1.0 BLOG:http://tommykao.blogspot.com EMAIL : MCK6214@gmail.com

Slide 2

Source From: http://java.sun.com/j2se/1.5.0/docs/

Slide 3

Source From: http://java.sun.com/javase/6/docs/

Slide 4

JConsole A JMX-compliant graphical tool for monitoring a Java virtual machine. It can monitor both local and remote JVMs. The Java virtual machine (Java VM ) has built-in instrumentation that enables you to monitor and manage it using the Java Management Extensions (JMX) technology.

Slide 5

JConsole hostName is the name of the system running the application and portNum is the port number you specified when you enabled the JMX agent when you started the Java VM. Ex: java -Dcom.sun.management.jmxremote

Slide 6

Java VisualVM Java VisualVM is a tool that provides a visual interface for viewing detailed information about Java technology-based applications (Java applications) while they are running on a Java Virtual Machine (JVM).

Slide 7

Java VisualVM

Slide 8

Java VisualVM Working with Local Applications Enable Heap Dump on OOME. Select this if you want Java VisualVM to automatically take a heap dump when the application encounters an OutOfMemoryException.

Slide 9

Scripting JSR 223: Scripting for the Java™ Platform API. This is a framework by which Java Applications can "host" script engines. This is a scripting language independent framework for using script engines from Java code.

Slide 10

Scripting Programmer's Guide 1/4 Hello, World import javax.script.*; public class EvalScript { public static void main(String[] args) throws Exception { // create a script engine manager ScriptEngineManager factory = new ScriptEngineManager(); // create a JavaScript engine ScriptEngine engine = factory.getEngineByName("JavaScript"); // evaluate JavaScript code from String engine.eval("print('Hello, World')"); } } Script Variables public class ScriptVars { public static void main(String[] args) throws Exception { ScriptEngineManager manager = new ScriptEngineManager(); ScriptEngine engine = manager.getEngineByName("JavaScript"); File f = new File("test.txt"); // expose File object as variable to script engine.put("file", f); // evaluate a script string. The script accesses // "file“ variable and calls method on it engine.eval("print(file.getAbsolutePath())"); } }

Slide 11

Scripting Programmer's Guide 2/4 Invoking Script Functions and Methods import javax.script.*; public class InvokeScriptFunction { public static void main(String[] args) throws Exception { ScriptEngineManager manager = new ScriptEngineManager(); ScriptEngine engine = manager.getEngineByName("JavaScript"); // JavaScript code in a String String script = "function hello(name) { print('Hello, ' + name); }"; // evaluate script engine.eval(script); // javax.script.Invocable is an optional interface. // Check whether your script engine implements // Or not! Note that the JavaScript engine // implements Invocable interface. Invocable inv = (Invocable) engine; // invoke the global function named "hello" inv.invokeFunction("hello", "Scripting!!" ); } }

Slide 12

Scripting Programmer's Guide 3/4 Implementing Java Interfaces by Scripts import javax.script.*; public class RunnableImpl { public static void main(String[] args) throws Exception { ScriptEngineManager manager = new ScriptEngineManager(); ScriptEngine engine = manager.getEngineByName("JavaScript"); // JavaScript code in a String String script = "function run() { println('run called'); }"; // evaluate script engine.eval(script); Invocable inv = (Invocable) engine; // get Runnable interface object from engine. // This interface methods are implemented by // script functions with the matching name. Runnable r = inv.getInterface(Runnable.class); // start a new thread that runs the script // implemented runnable interface Thread th = new Thread(r); th.start(); } }

Slide 13

Scripting Programmer's Guide 4/4 Multiple Scopes for Scripts import javax.script.*; public class MultiScopes { public static void main(String[] args) throws Exception { ScriptEngineManager manager = new ScriptEngineManager(); ScriptEngine engine = manager.getEngineByName("JavaScript"); engine.put("x", "hello"); // print global variable "x" engine.eval("println(x);"); // the above line prints "hello" // Now, pass a different script context ScriptContext newContext = new SimpleScriptContext(); Bindings engineScope = newContext.getBindings(ScriptContext.ENGINE_SCOPE); // add new variable "x" to the new engineScope engineScope.put("x", "world"); // execute the same script – // but this time pass a different script context engine.eval("println(x);", newContext); // the above line prints "world" } }

Slide 14

Java™ java.lang.instrument Package Instrumentation is the addition of byte-codes to methods for the purpose of gathering data to be utilized by tools. Provides services that allow Java programming language agents to instrument programs running on the JVM. monitoring agents profilers coverage analyzers event loggers

Slide 15

JavaTM SE 6.0 Platform Know-How, ExAct, Knowledge 15

Slide 16

參考資料 1/2 JavaTM SE 6 JDKTM 6 Documentation JConsole Using JConsole Monitoring and Management Using JMX Technology Java VisualVM Introduction to Java VisualVM Working with Local Applications

Slide 17

參考資料 2/2 Scripting JSR-223 Scripting for the Java Platform Java Scripting Programmer's Guide Mozilla Rhino:Java Script for Java (Rhino is an open-source implementation of JavaScript written entirely in Java.) Instrument Package Java™ java.lang.instrument Package The JVMTM tool interface (JVM TI) To replaces the Java Virtual Machine Profiler Interface (JVMPI) and the Java Virtual Machine Debug Interface (JVMDI)

Summary: new features of Java SE 6 Platform

URL: