SlideShare a Scribd company logo
Visit me @  www.Pavel-Kaminsky.com Java 6 :  Mustang Unleashed!
Visit me @ www.Pavel-Kaminsky.com Source Code SVN All Sources can be checked out (SVN)  from here: http://code.google.com/p/java6-features/
What’s New? Web Services Scripting Database More Desktop APIs Monitoring and Management Compiler Access Pluggable Annotations Desktop Deployment Security Performance and Quality Visit me @ www.Pavel-Kaminsky.com
Language Enhancements in Java SE 6 No language changes were introduced in Java SE 6 !!!!!!!!! where is my “syntactic sugar”?! Visit me @ www.Pavel-Kaminsky.com
What’s New? Web Services Scripting Database More Desktop APIs Monitoring and Management Compiler Access Pluggable Annotations Desktop Deployment Security Performance and Quality Visit me @ www.Pavel-Kaminsky.com
Visit me @ www.Pavel-Kaminsky.com JAX-WS 2.0 (JSR 224) includes “ Java Architecture for XML Binding” (JAXB) 2.0. “ SOAP with Attachments API for Java” (SAAJ) 1.3.
Visit me @ www.Pavel-Kaminsky.com @WebService package webServices; import javax.jws.WebService; import javax.xml.ws.Endpoint; /** * @Author: webmaster@pavel-kaminsky.com * @Date: 11/09/11 */ @WebService public class CalculatorWS { public int add(int a , int b) { return a+b; } public static void main(String[] args) { Endpoint.publish("http://localhost:8080/calculator",new CalculatorWS()); } }
What’s New? Web Services Scripting Database More Desktop APIs Monitoring and Management Compiler Access Pluggable Annotations Desktop Deployment Security Performance and Quality Visit me @ www.Pavel-Kaminsky.com
Scripting (JSR 223) Scripting language independent framework for using script engines from Java code Write customizable/extendable applications in the Java language and leave the customization scripting language choice to the end user The Java application developer need not choose the extension language during development Sun's implementation of JDK 6 is co-bundled with the  Mozilla Rhino  based JavaScript script engine. Visit me @ www.Pavel-Kaminsky.com
Scripting – example package scripting.example2; /** * @Author: pavel.kaminsky@hp.com * @Date: 31/08/11 */ import javax.script.*; import java.io.File; public class InvokeScriptMethod { public static void main(String[] args) throws Exception { ScriptEngineManager manager = new ScriptEngineManager(); ScriptEngine engine = manager.getEngineByName("JavaScript");   engine.eval(new java.io.FileReader(new  File("src/scripting/example2/script.js").getAbsoluteFile()));   Invocable inv = (Invocable) engine; // get script object on which we want to call the method Object obj = engine.get("obj"); // invoke the method named "hello" on the script object "obj" inv.invokeMethod(obj, "rock", "Pavel-Kaminsky.com" ); } } Visit me @ www.Pavel-Kaminsky.com
Scripting – example Scripts.js var obj = new Object(); obj.rock = function(name) {   result = name + ',Are you ready to rock?!!';   print(result);   return result; } Output :   Pavel Kaminsky , Are you ready to rock?!! Answer:   HAIL YEAH!!! Visit me @ www.Pavel-Kaminsky.com
Importing Java Packages package scripting.example3; /** * @Author: pavel.kaminsky@hp.com * @Date: 31/08/11 */ import javax.script.Invocable; import javax.script.ScriptEngine; import javax.script.ScriptEngineManager; import java.io.File; import java.util.ArrayList; public class ScriptMethodImportPackages { public static void main(String[] args) throws Exception { ScriptEngineManager manager = new ScriptEngineManager(); ScriptEngine engine = manager.getEngineByName("JavaScript"); engine.eval(new java.io.FileReader(new File("src/scripting/example3/script.js").getAbsoluteFile())); Invocable inv = (Invocable) engine; String myArray[] = (String[]) engine.get("myArray"); ArrayList yourArray = (ArrayList)engine.get("yourArray"); System.out.println(myArray[myArray.length-1]); System.out.println(yourArray.get(yourArray.size()-1)); } } Visit me @ www.Pavel-Kaminsky.com
Scripting – example 1 Scripts.js var myArray = java.lang.reflect.Array.newInstance(java.lang.String, 1); var yourArray = new java.util.ArrayList(); myArray[0] = "this is MY Array!"; yourArray.add("this is YOUR Array!"); Output :   this is MY Array! this is YOUR Array! Visit me @ www.Pavel-Kaminsky.com
What’s New? Web Services Scripting Database More Desktop APIs Monitoring and Management Compiler Access Pluggable Annotations Desktop Deployment Security Performance and Quality Visit me @ www.Pavel-Kaminsky.com
Database Shipped with a  Java DB   ( = DB Apache Derby) A transactional, relational database. storage of a database archived in a JAR file,  which allows you to simply distribute the JAR file. Start/Stop locally : java �jar derbyrun.jar server start 192.168.0.1 1555 Accessed via JDBC  The $ JAVA_HOME/db  subdirectory contains class libraries for Java DB,  Sun Microsystems's distribution of the Apache Derby  database technology. Visit me @ www.Pavel-Kaminsky.com
Database Example package database; /** * @Author: pavel.kaminsky@hp.com * @Date: 31/08/11 */ import java.sql.*; public class JavaDBExample { static Connection conn; public static void main(String[] args) throws Exception { if (args.length != 2) { System.out.println(&quot;Usage: <Name> <Address>&quot;); System.exit(1); } String dbName = &quot;UsersDB&quot;; String connectionURL = &quot;jdbc:derby:&quot; + dbName + &quot;;create=true&quot;; Class.forName(&quot;org.apache.derby.jdbc.EmbeddedDriver&quot;); conn = DriverManager.getConnection(connectionURL); // create table Statement stmt = conn.createStatement(); stmt.executeUpdate(&quot;CREATE TABLE USERS (ID NUMBER NOT NULL, UserName VARCHAR(250) NOT NULL)&quot;); Visit me @ www.Pavel-Kaminsky.com
// insert user PreparedStatement psInsert = conn.prepareStatement(&quot;insert into USERS values (?,?)&quot;); psInsert.setInt(1, 1); psInsert.setString(2, &quot;Lenny Kravitz&quot;); psInsert.executeUpdate(); // load user Statement usetStmt = conn.createStatement(); ResultSet rs = usetStmt.executeQuery(&quot;select * from USERS&quot;); while (rs.next()) { System.out.println(&quot;Id: &quot; + rs.getInt(1) + &quot; Name&quot; + rs.getString(2)); } rs.close(); } } Output  :   Id:1 Name:Lenny Kravitz Visit me @ www.Pavel-Kaminsky.com
What’s New? Web Services Scripting Database More Desktop APIs Monitoring and Management Compiler Access Pluggable Annotations Desktop Deployment Security Performance and Quality Visit me @ www.Pavel-Kaminsky.com
java.awt.Desktop class Minimize the difference between the  performance  and  integration  of native applications and Java applications.   Adopted  JDesktop Integration Components (JDIC)  API   (http://jdic.dev.java.net/) Visit me @ www.Pavel-Kaminsky.com
Java.awt.Desktop public static  enum   Action  { /** * Represents an &quot;open&quot; action.  * @see Desktop#open(java.io.File) */ OPEN , /** * Represents an &quot;edit&quot; action. * @see Desktop#edit(java.io.File) */ EDIT , /** * Represents a &quot;print&quot; action. * @see Desktop#print(java.io.File) */ PRINT , /** * Represents a &quot;mail&quot; action.  * @see Desktop#mail() * @see Desktop#mail(java.net.URI)  */ MAIL , /** * Represents a &quot;browse&quot; action. * @see Desktop#browse(java.net.URI) */ BROWSE }; Visit me @ www.Pavel-Kaminsky.com
Desktop.isDesktopSupported() – checks whether Desktop functionality is available. Desktop desktop = Desktop.getDesktop();  desktop.isSupported(Desktop.Action) – check whether the functionality is available. 5 New functionalities : public void mail() throws IOException public void open(File file) throws IOException public void edit(File file) throws IOException  public void print(File file) throws IOException public void browse(URI uri) throws IOException Let’s See a DEMO! Visit me @ www.Pavel-Kaminsky.com
System Tray Functionality Now it’s possible to hook the “System Tray” SystemTray tray = SystemTray.getSystemTray(); public TrayIcon(Image image, String tooltip, PopupMenu popup)  public static boolean isSupported() public void add(TrayIcon trayIcon) throws AWTException  public void remove(TrayIcon trayIcon)  Let’s See a DEMO! Question  : why there is no AWTException thrown on “remove” method? Visit me @ www.Pavel-Kaminsky.com
What’s New? Web Services Scripting Database More Desktop APIs Monitoring and Management Compiler Access Pluggable Annotations Desktop Deployment Security Performance and Quality Visit me @ www.Pavel-Kaminsky.com
Monitoring and Management Improvements in  jconsle “ jps ” tool - Roll call of all the names and numbers of all the Java processes on your machine. Good for other command lines as they required id’s. >C:\Users\kaminskp>jps.exe >5484 >5324 >7816 Jps “ jhat ” - Java Heap Analysis Tool Visit me @ www.Pavel-Kaminsky.com
Usage Find java application id with  jps. Create a dump with  jmap  into a file. C:\Users\kaminskp>jmap -dump:file=output.txt <id> Jhat  the dump file. C:\Users\kaminskp>jhat  output.txt  Reading from  output.txt ... Dump file created Thu Sep 01 13:18:09 IDT 2011 Snapshot read, resolving... Resolving 45981 objects... Chasing references, expect 9 dots......... Eliminating duplicate references......... Snapshot resolved. Started HTTP server on port 7000 Server is ready. Browse to http://localhost:7000 Visit me @ www.Pavel-Kaminsky.com Let’s see an Example!
Personal Recommendation  Don’t use JHat. Use IBM’s MAT (Memory Analyzing Tool) instead , download  here . Visit me @ www.Pavel-Kaminsky.com
What’s New? Web Services Scripting Database More Desktop APIs Monitoring and Management Compiler Access Pluggable Annotations Desktop Deployment Security Performance and Quality Visit me @ www.Pavel-Kaminsky.com
Compiler Access ( JSR 199) Compile java source files from within java files No need to fork into new javac.exe process  JavaCompiler compiler = ToolProvider.getSystemJavaCompiler(); int run(InputStream in, OutputStream out, OutputStream err, String... arguments); Good for IDE’s (compiling on the fly) Visit me @ www.Pavel-Kaminsky.com compiler.run(null, null, null, “One.java”, “Two.java”);  Let’s see an Example!
What’s New? Web Services Scripting Database More Desktop APIs Monitoring and Management Compiler Access Pluggable Annotations Desktop Deployment Security Performance and Quality Visit me @ www.Pavel-Kaminsky.com
Pluggable Annotations (JSR 269) @Annotation – remember that  ?!? Common annotations : @SuppressWarnings @Override  @Deprecated Integrate  custom annotation with compiler! Visit me @ www.Pavel-Kaminsky.com
Example  (included in the example’s code) Let’s create a new annotation  package pluggableAnnotations; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; @Retention( RetentionPolicy.SOURCE ) @Target( ElementType.METHOD ) public  @interface Borat  { } Visit me @ www.Pavel-Kaminsky.com
BoratBuilderProcessor package pluggableAnnotations; import javax.annotation.processing.AbstractProcessor; import javax.annotation.processing.RoundEnvironment; import javax.annotation.processing.SupportedAnnotationTypes; import javax.annotation.processing.SupportedSourceVersion; import javax.lang.model.SourceVersion; import javax.lang.model.element.Element; import javax.lang.model.element.TypeElement; import javax.tools.Diagnostic; import java.util.Set; @SupportedAnnotationTypes(&quot;pluggableAnnotations.Borat&quot;) @SupportedSourceVersion(SourceVersion.RELEASE_6) public class BoratBuilderProcessor extends AbstractProcessor { @Override public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) { for (TypeElement typeElement : annotations) { for (Element element : roundEnv.getElementsAnnotatedWith(typeElement)) { this.processingEnv.getMessager().printMessage(Diagnostic.Kind.ERROR,  &quot;I Like! but we don't use this method in Kazakhstan&quot;, element); } } return true; } } Visit me @ www.Pavel-Kaminsky.com
Packaging Create an “META-INF/Services” Folder Add a text file named javax.annotation.processing.Processor Insert the path to BoratBuilderProcessor  into the file Package into Jar! Visit me @ www.Pavel-Kaminsky.com
Visual .. Visit me @ www.Pavel-Kaminsky.com
Create a TestApp Link the jar into your project (I use IntelliJ) Visit me @ www.Pavel-Kaminsky.com
Tester.java import pluggableAnnotations.Borat; import javax.annotation.processing.Processor; import java.util.ServiceLoader; public class Tester { @Borat public static String annotateMe() { return &quot;Welcome to America&quot;; } public static void main(String[] args) { ServiceLoader<Processor> processors = ServiceLoader.load(Processor.class); for (Processor processor : processors) { System.out.println(processor.getClass().getSimpleName() + &quot; : &quot; + processor.getClass().getCanonicalName()); } System.out.println(Tester.annotateMe()); } } Visit me @ www.Pavel-Kaminsky.com
javac What do you think would happen? Visit me @ www.Pavel-Kaminsky.com
What’s New? Web Services Scripting Database More Desktop APIs Monitoring and Management Compiler Access Pluggable Annotations Desktop Deployment Security Performance and Quality Visit me @ www.Pavel-Kaminsky.com
Visit me @ www.Pavel-Kaminsky.com Desktop Deployment Swing Improvements for Windows  and GTK look and Feel Can you tell the difference?! 29
Visit me @ www.Pavel-Kaminsky.com More “Perks” JTable Sorting and Filtering no more customs implemantations. JTable table = new JTable(model); final TableRowSorter<TableModel> sorter = new TableRowSorter<TableModel>(model); table.setRowSorter(sorter); sorter.setRowFilter(RowFilter.regexFilter(text )); New Modality   Modeless –  no modality Document-modal -  blocks all windows from the same document , except those from its child hierarchy Application-modal -  blocks all windows from the same application , except those from its child hierarchy Toolkit-modal -  blocks all windows that run in the same toolkit , except those from its child hierarchy
Visit me @ www.Pavel-Kaminsky.com More “Perks” Splash Screen – revamped Security Dialogs
What’s New? Web Services Scripting Database More Desktop APIs Monitoring and Management Compiler Access Pluggable Annotations Desktop Deployment Security Performance and Quality Visit me @ www.Pavel-Kaminsky.com
Security Kerberos Integration Support for Smart Card I/O API JAAS-based authentication using LDAP Visit me @ www.Pavel-Kaminsky.com
What’s New? Web Services Scripting Database More Desktop APIs Monitoring and Management Compiler Access Pluggable Annotations Desktop Deployment Security Performance and Quality Visit me @ www.Pavel-Kaminsky.com
Performance Visit me @ www.Pavel-Kaminsky.com
Visit me @ www.Pavel-Kaminsky.com SPECjbb2005 Test SPECjbb2005 is an industry-standard benchmark designed to measure the server-side performance of Java runtime environments SPECjbb2005 bops (business operations per second), obtained by averaging the total transaction rate in a SPECjbb2005 run from the expected peak number of warehouses, to twice the peak number of warehouses Bops   metric  measures the overall throughput achieved by all the JVMs in a benchmark run.  SPECjbb2005 bops/JVM reflects the contribution of a single JVM to the overall metric  ,  and is thus a measure of the performance and scaling of a single JVM http://www.spec.org/jbb2005/results/
Visit me @ www.Pavel-Kaminsky.com Server Side Performance
Visit me @ www.Pavel-Kaminsky.com Server Side Performance
Visit me @ www.Pavel-Kaminsky.com Thank You! Visit and Subscribe

More Related Content

PPTX
Gruntwork Executive Summary
PDF
Play Framework: The Basics
PPTX
Spring Boot
PDF
#NoXML: Eliminating XML in Spring Projects - SpringOne 2GX 2015
ODP
CodeIgniter PHP MVC Framework
PPTX
Spring boot Introduction
PDF
Developing Modern Java Web Applications with Java EE 7 and AngularJS
PDF
Play Framework 2.5
Gruntwork Executive Summary
Play Framework: The Basics
Spring Boot
#NoXML: Eliminating XML in Spring Projects - SpringOne 2GX 2015
CodeIgniter PHP MVC Framework
Spring boot Introduction
Developing Modern Java Web Applications with Java EE 7 and AngularJS
Play Framework 2.5

What's hot (20)

PDF
Java REST API Framework Comparison - UberConf 2021
PPTX
Spring Boot and REST API
PPT
Spring Boot in Action
PDF
Spring boot introduction
PDF
Using Play Framework 2 in production
PDF
REST APIs with Spring
PDF
Apache DeltaSpike the CDI toolbox
PDF
Java EE 6 CDI Integrates with Spring & JSF
PDF
Introduction to Spring Boot
PDF
Building a Spring Boot Application - Ask the Audience!
PDF
The Many Ways to Test Your React App
PDF
Play vs Grails Smackdown - Devoxx France 2013
PPTX
Agility Requires Safety
PDF
Apache Lucene for Java EE Developers
PPTX
Spring Boot Tutorial
PDF
Spring boot入門ハンズオン第二回
PDF
Cross-browser testing in the real world
PDF
GitBucket: The perfect Github clone by Scala
PPTX
Play framework : A Walkthrough
PPTX
How to customize Spring Boot?
Java REST API Framework Comparison - UberConf 2021
Spring Boot and REST API
Spring Boot in Action
Spring boot introduction
Using Play Framework 2 in production
REST APIs with Spring
Apache DeltaSpike the CDI toolbox
Java EE 6 CDI Integrates with Spring & JSF
Introduction to Spring Boot
Building a Spring Boot Application - Ask the Audience!
The Many Ways to Test Your React App
Play vs Grails Smackdown - Devoxx France 2013
Agility Requires Safety
Apache Lucene for Java EE Developers
Spring Boot Tutorial
Spring boot入門ハンズオン第二回
Cross-browser testing in the real world
GitBucket: The perfect Github clone by Scala
Play framework : A Walkthrough
How to customize Spring Boot?
Ad

Similar to Java 6 [Mustang] - Features and Enchantments (20)

PDF
Java 5 and 6 New Features
PDF
Introduction java programming
PPTX
Core java over view basics introduction by quontra solutions
PDF
02 basic java programming and operators
PPTX
GOTO Night with Charles Nutter Slides
PPTX
What is Java? Presentation On Introduction To Core Java By PSK Technologies
PPTX
Introduction to java
PPT
Java SpringMVC SpringBOOT (Divergent).ppt
PPTX
JAVA AND OOPS CONCEPTS.pptx helpful for engineering
PPT
basic_java.ppt
PPTX
Java Programming and J2ME: The Basics
PPTX
UNIT 1.pptx
PPT
INTRODUCTION TO JAVA
PPT
Java ppts unit1
PPT
PPT
PPT
PPT
RIBBUN SOFTWARE
PPT
Introduction what is java
PPT
Java01
Java 5 and 6 New Features
Introduction java programming
Core java over view basics introduction by quontra solutions
02 basic java programming and operators
GOTO Night with Charles Nutter Slides
What is Java? Presentation On Introduction To Core Java By PSK Technologies
Introduction to java
Java SpringMVC SpringBOOT (Divergent).ppt
JAVA AND OOPS CONCEPTS.pptx helpful for engineering
basic_java.ppt
Java Programming and J2ME: The Basics
UNIT 1.pptx
INTRODUCTION TO JAVA
Java ppts unit1
RIBBUN SOFTWARE
Introduction what is java
Java01
Ad

Recently uploaded (20)

PDF
High Ground Student Revision Booklet Preview
PPTX
Week 4 Term 3 Study Techniques revisited.pptx
PPTX
Introduction and Scope of Bichemistry.pptx
PDF
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
PDF
Sunset Boulevard Student Revision Booklet
PDF
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
PDF
Module 3: Health Systems Tutorial Slides S2 2025
PDF
From loneliness to social connection charting
PDF
Landforms and landscapes data surprise preview
PDF
LDMMIA Reiki Yoga Workshop 15 MidTerm Review
PDF
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
PDF
Piense y hagase Rico - Napoleon Hill Ccesa007.pdf
PDF
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
PDF
Mga Unang Hakbang Tungo Sa Tao by Joe Vibar Nero.pdf
PPTX
Introduction to Child Health Nursing – Unit I | Child Health Nursing I | B.Sc...
PPTX
How to Manage Bill Control Policy in Odoo 18
PDF
102 student loan defaulters named and shamed – Is someone you know on the list?
PPTX
Open Quiz Monsoon Mind Game Prelims.pptx
PDF
Open folder Downloads.pdf yes yes ges yes
PPTX
The Healthy Child – Unit II | Child Health Nursing I | B.Sc Nursing 5th Semester
High Ground Student Revision Booklet Preview
Week 4 Term 3 Study Techniques revisited.pptx
Introduction and Scope of Bichemistry.pptx
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
Sunset Boulevard Student Revision Booklet
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
Module 3: Health Systems Tutorial Slides S2 2025
From loneliness to social connection charting
Landforms and landscapes data surprise preview
LDMMIA Reiki Yoga Workshop 15 MidTerm Review
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
Piense y hagase Rico - Napoleon Hill Ccesa007.pdf
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
Mga Unang Hakbang Tungo Sa Tao by Joe Vibar Nero.pdf
Introduction to Child Health Nursing – Unit I | Child Health Nursing I | B.Sc...
How to Manage Bill Control Policy in Odoo 18
102 student loan defaulters named and shamed – Is someone you know on the list?
Open Quiz Monsoon Mind Game Prelims.pptx
Open folder Downloads.pdf yes yes ges yes
The Healthy Child – Unit II | Child Health Nursing I | B.Sc Nursing 5th Semester

Java 6 [Mustang] - Features and Enchantments

  • 1. Visit me @ www.Pavel-Kaminsky.com Java 6 : Mustang Unleashed!
  • 2. Visit me @ www.Pavel-Kaminsky.com Source Code SVN All Sources can be checked out (SVN) from here: http://code.google.com/p/java6-features/
  • 3. What’s New? Web Services Scripting Database More Desktop APIs Monitoring and Management Compiler Access Pluggable Annotations Desktop Deployment Security Performance and Quality Visit me @ www.Pavel-Kaminsky.com
  • 4. Language Enhancements in Java SE 6 No language changes were introduced in Java SE 6 !!!!!!!!! where is my “syntactic sugar”?! Visit me @ www.Pavel-Kaminsky.com
  • 5. What’s New? Web Services Scripting Database More Desktop APIs Monitoring and Management Compiler Access Pluggable Annotations Desktop Deployment Security Performance and Quality Visit me @ www.Pavel-Kaminsky.com
  • 6. Visit me @ www.Pavel-Kaminsky.com JAX-WS 2.0 (JSR 224) includes “ Java Architecture for XML Binding” (JAXB) 2.0. “ SOAP with Attachments API for Java” (SAAJ) 1.3.
  • 7. Visit me @ www.Pavel-Kaminsky.com @WebService package webServices; import javax.jws.WebService; import javax.xml.ws.Endpoint; /** * @Author: [email protected] * @Date: 11/09/11 */ @WebService public class CalculatorWS { public int add(int a , int b) { return a+b; } public static void main(String[] args) { Endpoint.publish(&quot;http://localhost:8080/calculator&quot;,new CalculatorWS()); } }
  • 8. What’s New? Web Services Scripting Database More Desktop APIs Monitoring and Management Compiler Access Pluggable Annotations Desktop Deployment Security Performance and Quality Visit me @ www.Pavel-Kaminsky.com
  • 9. Scripting (JSR 223) Scripting language independent framework for using script engines from Java code Write customizable/extendable applications in the Java language and leave the customization scripting language choice to the end user The Java application developer need not choose the extension language during development Sun's implementation of JDK 6 is co-bundled with the  Mozilla Rhino  based JavaScript script engine. Visit me @ www.Pavel-Kaminsky.com
  • 10. Scripting – example package scripting.example2; /** * @Author: [email protected] * @Date: 31/08/11 */ import javax.script.*; import java.io.File; public class InvokeScriptMethod { public static void main(String[] args) throws Exception { ScriptEngineManager manager = new ScriptEngineManager(); ScriptEngine engine = manager.getEngineByName(&quot;JavaScript&quot;); engine.eval(new java.io.FileReader(new File(&quot;src/scripting/example2/script.js&quot;).getAbsoluteFile())); Invocable inv = (Invocable) engine; // get script object on which we want to call the method Object obj = engine.get(&quot;obj&quot;); // invoke the method named &quot;hello&quot; on the script object &quot;obj&quot; inv.invokeMethod(obj, &quot;rock&quot;, &quot;Pavel-Kaminsky.com&quot; ); } } Visit me @ www.Pavel-Kaminsky.com
  • 11. Scripting – example Scripts.js var obj = new Object(); obj.rock = function(name) { result = name + ',Are you ready to rock?!!'; print(result); return result; } Output : Pavel Kaminsky , Are you ready to rock?!! Answer: HAIL YEAH!!! Visit me @ www.Pavel-Kaminsky.com
  • 12. Importing Java Packages package scripting.example3; /** * @Author: [email protected] * @Date: 31/08/11 */ import javax.script.Invocable; import javax.script.ScriptEngine; import javax.script.ScriptEngineManager; import java.io.File; import java.util.ArrayList; public class ScriptMethodImportPackages { public static void main(String[] args) throws Exception { ScriptEngineManager manager = new ScriptEngineManager(); ScriptEngine engine = manager.getEngineByName(&quot;JavaScript&quot;); engine.eval(new java.io.FileReader(new File(&quot;src/scripting/example3/script.js&quot;).getAbsoluteFile())); Invocable inv = (Invocable) engine; String myArray[] = (String[]) engine.get(&quot;myArray&quot;); ArrayList yourArray = (ArrayList)engine.get(&quot;yourArray&quot;); System.out.println(myArray[myArray.length-1]); System.out.println(yourArray.get(yourArray.size()-1)); } } Visit me @ www.Pavel-Kaminsky.com
  • 13. Scripting – example 1 Scripts.js var myArray = java.lang.reflect.Array.newInstance(java.lang.String, 1); var yourArray = new java.util.ArrayList(); myArray[0] = &quot;this is MY Array!&quot;; yourArray.add(&quot;this is YOUR Array!&quot;); Output : this is MY Array! this is YOUR Array! Visit me @ www.Pavel-Kaminsky.com
  • 14. What’s New? Web Services Scripting Database More Desktop APIs Monitoring and Management Compiler Access Pluggable Annotations Desktop Deployment Security Performance and Quality Visit me @ www.Pavel-Kaminsky.com
  • 15. Database Shipped with a Java DB ( = DB Apache Derby) A transactional, relational database. storage of a database archived in a JAR file, which allows you to simply distribute the JAR file. Start/Stop locally : java �jar derbyrun.jar server start 192.168.0.1 1555 Accessed via JDBC The $ JAVA_HOME/db subdirectory contains class libraries for Java DB, Sun Microsystems's distribution of the Apache Derby database technology. Visit me @ www.Pavel-Kaminsky.com
  • 16. Database Example package database; /** * @Author: [email protected] * @Date: 31/08/11 */ import java.sql.*; public class JavaDBExample { static Connection conn; public static void main(String[] args) throws Exception { if (args.length != 2) { System.out.println(&quot;Usage: <Name> <Address>&quot;); System.exit(1); } String dbName = &quot;UsersDB&quot;; String connectionURL = &quot;jdbc:derby:&quot; + dbName + &quot;;create=true&quot;; Class.forName(&quot;org.apache.derby.jdbc.EmbeddedDriver&quot;); conn = DriverManager.getConnection(connectionURL); // create table Statement stmt = conn.createStatement(); stmt.executeUpdate(&quot;CREATE TABLE USERS (ID NUMBER NOT NULL, UserName VARCHAR(250) NOT NULL)&quot;); Visit me @ www.Pavel-Kaminsky.com
  • 17. // insert user PreparedStatement psInsert = conn.prepareStatement(&quot;insert into USERS values (?,?)&quot;); psInsert.setInt(1, 1); psInsert.setString(2, &quot;Lenny Kravitz&quot;); psInsert.executeUpdate(); // load user Statement usetStmt = conn.createStatement(); ResultSet rs = usetStmt.executeQuery(&quot;select * from USERS&quot;); while (rs.next()) { System.out.println(&quot;Id: &quot; + rs.getInt(1) + &quot; Name&quot; + rs.getString(2)); } rs.close(); } } Output : Id:1 Name:Lenny Kravitz Visit me @ www.Pavel-Kaminsky.com
  • 18. What’s New? Web Services Scripting Database More Desktop APIs Monitoring and Management Compiler Access Pluggable Annotations Desktop Deployment Security Performance and Quality Visit me @ www.Pavel-Kaminsky.com
  • 19. java.awt.Desktop class Minimize the difference between the performance and integration of native applications and Java applications.   Adopted JDesktop Integration Components (JDIC)  API  (http://jdic.dev.java.net/) Visit me @ www.Pavel-Kaminsky.com
  • 20. Java.awt.Desktop public static enum Action { /** * Represents an &quot;open&quot; action. * @see Desktop#open(java.io.File) */ OPEN , /** * Represents an &quot;edit&quot; action. * @see Desktop#edit(java.io.File) */ EDIT , /** * Represents a &quot;print&quot; action. * @see Desktop#print(java.io.File) */ PRINT , /** * Represents a &quot;mail&quot; action. * @see Desktop#mail() * @see Desktop#mail(java.net.URI) */ MAIL , /** * Represents a &quot;browse&quot; action. * @see Desktop#browse(java.net.URI) */ BROWSE }; Visit me @ www.Pavel-Kaminsky.com
  • 21. Desktop.isDesktopSupported() – checks whether Desktop functionality is available. Desktop desktop = Desktop.getDesktop(); desktop.isSupported(Desktop.Action) – check whether the functionality is available. 5 New functionalities : public void mail() throws IOException public void open(File file) throws IOException public void edit(File file) throws IOException public void print(File file) throws IOException public void browse(URI uri) throws IOException Let’s See a DEMO! Visit me @ www.Pavel-Kaminsky.com
  • 22. System Tray Functionality Now it’s possible to hook the “System Tray” SystemTray tray = SystemTray.getSystemTray(); public TrayIcon(Image image, String tooltip, PopupMenu popup) public static boolean isSupported() public void add(TrayIcon trayIcon) throws AWTException public void remove(TrayIcon trayIcon) Let’s See a DEMO! Question : why there is no AWTException thrown on “remove” method? Visit me @ www.Pavel-Kaminsky.com
  • 23. What’s New? Web Services Scripting Database More Desktop APIs Monitoring and Management Compiler Access Pluggable Annotations Desktop Deployment Security Performance and Quality Visit me @ www.Pavel-Kaminsky.com
  • 24. Monitoring and Management Improvements in jconsle “ jps ” tool - Roll call of all the names and numbers of all the Java processes on your machine. Good for other command lines as they required id’s. >C:\Users\kaminskp>jps.exe >5484 >5324 >7816 Jps “ jhat ” - Java Heap Analysis Tool Visit me @ www.Pavel-Kaminsky.com
  • 25. Usage Find java application id with jps. Create a dump with jmap into a file. C:\Users\kaminskp>jmap -dump:file=output.txt <id> Jhat the dump file. C:\Users\kaminskp>jhat output.txt Reading from output.txt ... Dump file created Thu Sep 01 13:18:09 IDT 2011 Snapshot read, resolving... Resolving 45981 objects... Chasing references, expect 9 dots......... Eliminating duplicate references......... Snapshot resolved. Started HTTP server on port 7000 Server is ready. Browse to http://localhost:7000 Visit me @ www.Pavel-Kaminsky.com Let’s see an Example!
  • 26. Personal Recommendation Don’t use JHat. Use IBM’s MAT (Memory Analyzing Tool) instead , download here . Visit me @ www.Pavel-Kaminsky.com
  • 27. What’s New? Web Services Scripting Database More Desktop APIs Monitoring and Management Compiler Access Pluggable Annotations Desktop Deployment Security Performance and Quality Visit me @ www.Pavel-Kaminsky.com
  • 28. Compiler Access ( JSR 199) Compile java source files from within java files No need to fork into new javac.exe process JavaCompiler compiler = ToolProvider.getSystemJavaCompiler(); int run(InputStream in, OutputStream out, OutputStream err, String... arguments); Good for IDE’s (compiling on the fly) Visit me @ www.Pavel-Kaminsky.com compiler.run(null, null, null, “One.java”, “Two.java”); Let’s see an Example!
  • 29. What’s New? Web Services Scripting Database More Desktop APIs Monitoring and Management Compiler Access Pluggable Annotations Desktop Deployment Security Performance and Quality Visit me @ www.Pavel-Kaminsky.com
  • 30. Pluggable Annotations (JSR 269) @Annotation – remember that ?!? Common annotations : @SuppressWarnings @Override @Deprecated Integrate custom annotation with compiler! Visit me @ www.Pavel-Kaminsky.com
  • 31. Example (included in the example’s code) Let’s create a new annotation package pluggableAnnotations; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; @Retention( RetentionPolicy.SOURCE ) @Target( ElementType.METHOD ) public @interface Borat { } Visit me @ www.Pavel-Kaminsky.com
  • 32. BoratBuilderProcessor package pluggableAnnotations; import javax.annotation.processing.AbstractProcessor; import javax.annotation.processing.RoundEnvironment; import javax.annotation.processing.SupportedAnnotationTypes; import javax.annotation.processing.SupportedSourceVersion; import javax.lang.model.SourceVersion; import javax.lang.model.element.Element; import javax.lang.model.element.TypeElement; import javax.tools.Diagnostic; import java.util.Set; @SupportedAnnotationTypes(&quot;pluggableAnnotations.Borat&quot;) @SupportedSourceVersion(SourceVersion.RELEASE_6) public class BoratBuilderProcessor extends AbstractProcessor { @Override public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) { for (TypeElement typeElement : annotations) { for (Element element : roundEnv.getElementsAnnotatedWith(typeElement)) { this.processingEnv.getMessager().printMessage(Diagnostic.Kind.ERROR, &quot;I Like! but we don't use this method in Kazakhstan&quot;, element); } } return true; } } Visit me @ www.Pavel-Kaminsky.com
  • 33. Packaging Create an “META-INF/Services” Folder Add a text file named javax.annotation.processing.Processor Insert the path to BoratBuilderProcessor into the file Package into Jar! Visit me @ www.Pavel-Kaminsky.com
  • 34. Visual .. Visit me @ www.Pavel-Kaminsky.com
  • 35. Create a TestApp Link the jar into your project (I use IntelliJ) Visit me @ www.Pavel-Kaminsky.com
  • 36. Tester.java import pluggableAnnotations.Borat; import javax.annotation.processing.Processor; import java.util.ServiceLoader; public class Tester { @Borat public static String annotateMe() { return &quot;Welcome to America&quot;; } public static void main(String[] args) { ServiceLoader<Processor> processors = ServiceLoader.load(Processor.class); for (Processor processor : processors) { System.out.println(processor.getClass().getSimpleName() + &quot; : &quot; + processor.getClass().getCanonicalName()); } System.out.println(Tester.annotateMe()); } } Visit me @ www.Pavel-Kaminsky.com
  • 37. javac What do you think would happen? Visit me @ www.Pavel-Kaminsky.com
  • 38. What’s New? Web Services Scripting Database More Desktop APIs Monitoring and Management Compiler Access Pluggable Annotations Desktop Deployment Security Performance and Quality Visit me @ www.Pavel-Kaminsky.com
  • 39. Visit me @ www.Pavel-Kaminsky.com Desktop Deployment Swing Improvements for Windows and GTK look and Feel Can you tell the difference?! 29
  • 40. Visit me @ www.Pavel-Kaminsky.com More “Perks” JTable Sorting and Filtering no more customs implemantations. JTable table = new JTable(model); final TableRowSorter<TableModel> sorter = new TableRowSorter<TableModel>(model); table.setRowSorter(sorter); sorter.setRowFilter(RowFilter.regexFilter(text )); New Modality Modeless – no modality Document-modal - blocks all windows from the same document , except those from its child hierarchy Application-modal - blocks all windows from the same application , except those from its child hierarchy Toolkit-modal -  blocks all windows that run in the same toolkit , except those from its child hierarchy
  • 41. Visit me @ www.Pavel-Kaminsky.com More “Perks” Splash Screen – revamped Security Dialogs
  • 42. What’s New? Web Services Scripting Database More Desktop APIs Monitoring and Management Compiler Access Pluggable Annotations Desktop Deployment Security Performance and Quality Visit me @ www.Pavel-Kaminsky.com
  • 43. Security Kerberos Integration Support for Smart Card I/O API JAAS-based authentication using LDAP Visit me @ www.Pavel-Kaminsky.com
  • 44. What’s New? Web Services Scripting Database More Desktop APIs Monitoring and Management Compiler Access Pluggable Annotations Desktop Deployment Security Performance and Quality Visit me @ www.Pavel-Kaminsky.com
  • 45. Performance Visit me @ www.Pavel-Kaminsky.com
  • 46. Visit me @ www.Pavel-Kaminsky.com SPECjbb2005 Test SPECjbb2005 is an industry-standard benchmark designed to measure the server-side performance of Java runtime environments SPECjbb2005 bops (business operations per second), obtained by averaging the total transaction rate in a SPECjbb2005 run from the expected peak number of warehouses, to twice the peak number of warehouses Bops metric measures the overall throughput achieved by all the JVMs in a benchmark run. SPECjbb2005 bops/JVM reflects the contribution of a single JVM to the overall metric , and is thus a measure of the performance and scaling of a single JVM http://www.spec.org/jbb2005/results/
  • 47. Visit me @ www.Pavel-Kaminsky.com Server Side Performance
  • 48. Visit me @ www.Pavel-Kaminsky.com Server Side Performance
  • 49. Visit me @ www.Pavel-Kaminsky.com Thank You! Visit and Subscribe