7
-
Upload
akilaananth -
Category
Documents
-
view
645 -
download
0
Transcript of 7
© 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
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
33
Icons Used
Questions
Contacts
Reference
Try it Out
Hands on Exercise
Coding Standards
Test Your Understanding
Tools
A Welcome Break
44
Core Java Session 108: Overview
Introduction:
This session will discuss about the new features of
Java SDK 1.6
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)
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
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.
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
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!\")");
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
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
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.
13
Java DB
Java DB is based on Apache Derby:
» JDBC conformant all-Java relational database
» Bundled and pre-configured in JDK
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
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.
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);
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
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();
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
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.
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
22
New Dialog Modality API
The new dialog modality API is shown in the following screenshot:
Sample dialog boxes
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!
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/
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.
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
27
Monitoring and Management
The potential problems that can be detected
are:
» Memory leaks
» Thread deadlocks
» Dirty references
» Infinite loops
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
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.
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”.
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
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
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
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
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.
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.
37
Performance Improvement
Client Benchmark: SwingMark
38
Performance Improvement (Contd.)Server Benchmark: SPECjbb2000
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.
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.
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
4242
Q & A
Allow time for questions from participants
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.
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
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).
© 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.