document7

46
© 2007, Cognizant Technology Solutions. All Rights Reserved. The information contained herein is subject to change without notice. C3: Protected Core Java Targeted at: Entry Level Trainees Session 108: Updates in JDK 1.6

Upload: akilaananth

Post on 25-Nov-2014

645 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Document7

© 2007, Cognizant Technology Solutions. All Rights Reserved.The information contained herein is subject to change without notice. C3: Protected

Core Java

Targeted at: Entry Level Trainees

Session 108: Updates in JDK 1.6

Page 2: Document7

22

About the Author

Created By: Raju Chandrasekaran (117834)

Credential Information:

5+ years of experience in Java programming

Version and Date:

COREJAVA/PPT/0408/1.0

Page 3: Document7

33

Icons Used

Questions

Contacts

Reference

Try it Out

Hands on Exercise

Coding Standards

Test Your Understanding

Tools

A Welcome Break

Page 4: Document7

44

Core Java Session 108: Overview

Introduction:

This session will discuss about the new features of

Java SDK 1.6

Page 5: Document7

55

Core Java Session 108: Objective

Objective:

After completing this session, you will be able to:

» Describe the key features of Java SE (Standard

Edition) 6 (JDK 1.6)

Page 6: Document7

66

The Java SE 6 (JDK 1.6) Top 10 Features

The top 10 features of JDK 1.6 are:» Scripting

» Web Services

» Database (JDBC 4.0, Java DB)

» More Desktop APIs

» Monitoring and Management

» Compiler Access

» Pluggable Annotations

» Desktop Deployment

» Security

» Quality, Compatibility, and Stability

Page 7: Document7

7

Motivation for Scripting Support

Scripting support provides developers an opportunity to leverage the advantages of different languages in the same application.It extends scripting languages applying the powerful Java technology libraries.It provides reuse of code modules in other programming languages.It produces an environment in which developers and end users can collaborate to create more useful and dynamic applications.You can now mix in JavaScript technology with your Java technology source code, useful for prototyping. Also useful when you have teams with a variety of skill sets.

Page 8: Document7

8

Scripting

Scripting for the Java Platform (JSR 223):» Mechanism for configuring script engines into Java

SE

» APIs for mixing script fragments into Java applications

A JavaScript engine is included in the implementation of Java SE 6 of Sun:» Mozilla Rhino engine

Conformant scripting engines: scripting.java.net

Page 9: Document7

9

Scripting: Developer Example

// create a ScriptEngineManagerScriptEngineManager m = new ScriptEngineManager();

// get an instance of JavaScript script engineScriptEngine engine = m.getEngineByName("js");

// evaluate a scriptengine.eval("alert(\"Hello World!\")");

Page 10: Document7

10

Web Services Support on Java SE 6 Platform

JAX-WS

Data binding using JAXB 2.0

Updates to the JAXP, which includes StaX

Standards supported are:» SOAP 1.2

» WS-I Basic Profile 1.1

» XML-binary Optimized Packaging (XOP) and SOAP Message Transmission Optimization Mechanism (MTOM)

» Representational State Transfer (REST)

» Totally on XML schema

Page 11: Document7

11

API Support

Java SE 6 provides support for the JAX- WS

Web services stack:

» For the client side: Service class for creating proxy

» For the server side: Endpoint class for publication

Page 12: Document7

12

Database: JDBC 4.0 Support

Developers will get the updated JDBC 4.0, which focuses on ease of use.

It contains many feature additions like support for XML as an SQL datatype and better integration of Binary Large OBjects (BLOBs) and Character Large OBjects (CLOBs) into the APIs.

Additional features that improve ease of use include removal of some JDBC boilerplate and some of the new annotations that make SQL strings embed better into your JDBC application – like decorating your getAllUsers() method with an @Query(sql=”select * from user”) annotation, and that being all you need.

Page 13: Document7

13

Java DB

Java DB is based on Apache Derby:

» JDBC conformant all-Java relational database

» Bundled and pre-configured in JDK

Page 14: Document7

14

Desktop APIs

AWT (Abstract Window Toolkit) improvements are:» Tray icon

» Splash screen

» Desktop class

» Dialog Modality enhancements and API

» Text printing

Swing improvement:» GroupLayout: Basis for NetBeans GUI Builder

(Matisse)

» JTable sorting and filtering

» SwingWorker

Page 15: Document7

15

Tray Icon

Tray icon lets you to access the system tray in your Java application:» SystemTray

» TrayIcon

Tray icon gives you the ability to add graphics, popup menus, and floating tip functionality to the system tray.

Page 16: Document7

16

Tray Icon: Usage

// Construct a TrayIcon

TrayIcon trayIcon = new TrayIcon(image, "Tray Demo", popupMenu);

// Add event listener

trayIcon.addActionListener(actionListener);

// Add the tray icon to the System tray

SystemTray.getSystemTray().add(trayIcon);

Page 17: Document7

17

Splash Screen: Overview

Before Java SE 6, Java run time needs to be fully loaded and initialized before a visual image can be displayed.Splash screen allows displaying a splash screen for the application instantly before the Java runtime software starts:» GIF (Graphic Interchange Format), PNG (Portable

Network Graphics), and JPEG (Joint Photographic Experts Group) images supported

» Transparency, translucency, and animation supported

» Closed automatically when first top-level window displays

Page 18: Document7

18

Splash Screen: Usage

Display from command line:java -splash:image.gif TheApp

Display from MANIFEST.MF (in a jar file):Splashscreen-Image: image.gif

Painting: You can change the image shown after the splash screen is loaded, but before the application starts:

SplashScreen splash = SplashScreen.getSplashScreen();Graphics2D g = splash.createGraphics();//your painting code heresplash.update();

Page 19: Document7

19

Desktop APIs

GUI developers get a large number of new tricks to play like the ever popular yet newly incorporated SwingWorker utility to help you with threading in GUI apps, JTable sorting and filtering, and a new facility for quick splash screens to quiet impatient users.

Desktop class has an enumeration of actions that may be supported for a file or URI like BROWSE, EDIT, MAIL, OPEN, and PRINT.

File processing: Opening, editing, and printing files with applications registered in native system

Browsing: Opening a URL with the default browser

Email: Sending a message with the default mail client

Page 20: Document7

20

Dialog Modality Enhancement

New modality model is introduced:

» This new model allows the developer to scope, or

limit the modality blocking of a dialog box, based on

the modality type that the developer chooses.

» This new model allows windows and dialog boxes to

be truly parentless.

» This new model solves the problem of interacting

with JavaHelp in J2SE 1.5 when modal dialog box is

on the front.

Page 21: Document7

21

Modality Types

The modality types are:

» modeless: Does not block any other window

» document-modal: Blocks input to all top-level

windows from the same document

» application-modal: Blocks all windows from the

same application

» toolkit-modal: Blocks all windows that run in the

same toolkit

Page 22: Document7

22

New Dialog Modality API

The new dialog modality API is shown in the following screenshot:

Sample dialog boxes

Page 23: Document7

23

Text Printing

Text printing easily print a Swing text component:» Prints the entire contents of the text component

» Does not have to be visible

» javax.swing.text.JTextComponent.print();

Text printing reformats for printed page.

It optionally displays print dialog and progress box.

It supports optional header or footer.

It will not split lines in half!

Page 24: Document7

24

SwingWorker

SwingWorker makes it easy to offload work to separate

threads.

It makes use of concurrency package.

It makes it more generic.

It supports partial results.

It supports PropertyChangeListener.

More information:

http://java.sun.com/docs/books/tutorial/uiswing/concur

rency/

Page 25: Document7

25

javax.swing.GroupLayout Class

This class is a new layout manager to support

new Matisse GUI builder:

» NetBeans™ IDE ships with Matisse

» Can also apply GroupLayout in J2SE 1.5 software

implementing stand-alone library

This have more capabilities for relative

positioning of components.

This works with horizontal and vertical layout

separately.

Page 26: Document7

26

JTable Sorting and Filtering

JTable sorting and filtering add sorting to your JTable with one method call: setAutoCreateRowSorter(true)

This specify your own comparators

This supports secondary and tertiary sort columns

Page 27: Document7

27

Monitoring and Management

The potential problems that can be detected

are:

» Memory leaks

» Thread deadlocks

» Dirty references

» Infinite loops

Page 28: Document7

28

Monitoring and Management (Contd.)

jps: Lists JVMs

jconsole: Can connect to applications that did not start

up with the JMX (Java Management Extensions) agent

jmap: Takes a detailed 'photograph' of what is going on

in memory at any one point in time

jhat: Forensic expert that will help you to interpret the

result of jmap

jstack: Takes a 'photograph' of all the threads and

what they are up to in their own stack frames

Page 29: Document7

29

Compiler Access

Compiler access opens up programmatic access to javacfor in process compilation of dynamically generated Java code.

This is really aimed at people who create tools for Java development and for frameworks:» JavaServer Pages (JSP) or PHP construction kit engines

that need to generate a bunch of classes on demand

» Average developers will benefit indirectly from faster performing tool

» The compiler API is not directly intended for the everyday developer, but for those of you deafened by your screaming inner geek, roll up your sleeves and give it a try.

Page 30: Document7

30

Pluggable Annotations

JSR 175 of JDK 5 standardized how annotations are

declared in Java code but annotation processing details

were relegated as an implementation detail.

Java tool and framework vendors (and you) can define

annotations and have core API support for plugging in

and executing the processors that do the heavy lifting.

It seamlessly integrates your custom annotations.

Processing API standardizes annotation processing as

well. The annotation processors act as plug-ins to the

compiler, hence "pluggable annotation processing”.

Page 31: Document7

31

Desktop Deployment

Desktop deployment improved actual performance: Graphics hardware acceleration on Windows

It perceived performance: True double buffering

It improved the native look and feels:

» Updated Swing Look and Feel Windows/Unix

» LCD text rendering

It revamped Java Web Start and JRE installations:No more scary security dialog

Page 32: Document7

32

Windows Look and Feel Improvements SwingSet on Vista with 5.0Windows look and feel improvements SwingSet on Vista with 5.0 is shown in the following screenshot:

Sample screen shot on Vista with Java 2, v5.0

Page 33: Document7

33

Windows Look and Feel ImprovementsSwingSet on Vista with 6Windows look and feel improvements SwingSet on Vista with 6 is shown in the following screenshot:

Sample screen shot on Vista with Java 2, v6

Page 34: Document7

34

Security

Security added important new APIs:

» XML Digital Signature (XMLDSig) API (JSR 105)

» Smart Card I/O API (JSR 268)

Security improved authentication schemes:

» JAAS-based authentication using LDAP

» Native Platform Java GSSAPI (Generic Security

Page 35: Document7

35

Security (Contd.)

Java SE 6 has simplified the job of its security

administrators by providing various new ways

to access platform-native security services,

such as native Public Key Infrastructure (PKI)

and cryptographic services on Microsoft

Windows for secure authentication and

communication, Java Generic Security

Services (Java GSS) and Kerberos services for

authentication, and access to LDAP servers for

authenticating users.

Page 36: Document7

36

Quality, Stability, and Compatibility

Sun has around 80,000 test cases and several

million lines of code testing conformance.

People have been downloading (and testing)

snapshots of Java SE 6 (Mustang) for the last 15

months and filing bugs.

So even before beta release, several quality and

regression issues were fixed.

Performance is claimed to be better than J2SE 5.

Page 37: Document7

37

Performance Improvement

Client Benchmark: SwingMark

Page 38: Document7

38

Performance Improvement (Contd.)Server Benchmark: SPECjbb2000

Page 39: Document7

39

Running Applications on Java SE 6

Applications run faster on the desktop and

servers.

New 'Dynamic Attach' diagnostics simplify

troubleshooting.

Expanded Solaris DTrace support provides

additional value on Solaris.

The Swing Look and Feel of the applications

deployed in Windows or Unix is greatly

enhanced.

Page 40: Document7

40

Building Applications on Java SE 6

This JSR 223 specification introduces the basic technical background to bridge the scripting and the Java community.

The JSR 223 specification is concerned with how to write and package Java classes that will be accessible from different scripting engines.

The Java classes may be part of a Servlet application or may be in a standard Java VM.

Scripting languages framework extends support for Ruby, Python, and other languages.

With Java SE 6, applications can use JAX-WS to build web applications and web services, incorporating the newer XML-based web services functionality.

JDK 6 uses the font smoothing settings of the host desktop to ensure consistent text rendering, the new desktop integration features, and the new dialog modality options.

Page 41: Document7

41

Building Applications on Java SE 6 (Contd.)

The JDBC 4.0 API specification seeks to improve Java application

access to SQL data stores by the provision of ease-of-

development focused features and improvements at both the

utility and API level.

Java DB is ideal for:

» Departmental Java client-server applications that need up to 24 x 7

support and the sophistication of a standards-based, transactional

SQL database that protects against data corruption or systems

crashes without also requiring a database administrator.

» Multi-platform use due to Java portability. And, because Java DB is

fully standards-compliant and 100% Java, it is easy to migrate an

application using Java DB to other open standard databases.

The NetBeans IDE fully supports Java SE v5.5, v5.5.1 and v6.0

Page 42: Document7

4242

Q & A

Allow time for questions from participants

Page 43: Document7

43

Test Your Understanding

1. State true or false for the following:

a) JDBC 4.0 is available with Java SE v5 (Tiger).

b) With Java SE 6, applications can use JAX-WS to

build web applications and web services,

incorporating the newer XML-based web services

functionality.

c) A JavaScript engine named as Mozilla Rhino engine

is included in the Sun’s implementation of Java SE

6.

Page 44: Document7

4444

Core Java Session 108: Summary

The key features of Java SE 6 (JDk 1.6) are:» Scripting

» Web Services

» Database (JDBC 4.0, Java DB)

» More Desktop APIs

» Monitoring and Management

» Compiler Access

» Pluggable Annotations

» Desktop Deployment

» Security

» Quality, Compatibility, and Stability

Page 45: Document7

4545

Core Java Session 108: Source

Head First Java – 2nd edition – Kathy Sierra & Bert Bates – O’REILLY

http://java.sun.com

http://www.javapassion.com

Disclaimer: Parts of the content of this course is based on the materials available from the Web sites and books listed above. The materials that can be accessed from linked sites are not maintained by Cognizant Academy and we are not responsible for the contents thereof. All trademarks, service marks, and trade names in this course are the marks of the respective owner(s).

Page 46: Document7

© 2007, Cognizant Technology Solutions. All Rights Reserved.The information contained herein is subject to change without notice.

You have completed the Session 108 of

Core Java.