Java Overview and Java SE 6 What's New Max Li Campus Ambassador in - - PowerPoint PPT Presentation

java overview and java se 6 what s new
SMART_READER_LITE
LIVE PREVIEW

Java Overview and Java SE 6 What's New Max Li Campus Ambassador in - - PowerPoint PPT Presentation

Java Overview and Java SE 6 What's New Max Li Campus Ambassador in HKUST Gigi Li Campus Ambassador in CUHK Sun Microsystems, Inc. All About What's the meaning of ? ? Andy Bechtolsheim Vinod Khosla Scott McNealy Bill Joy


slide-1
SLIDE 1

Java Overview and Java SE 6 What's New

Max Li Campus Ambassador in HKUST Gigi Li Campus Ambassador in CUHK Sun Microsystems, Inc.

slide-2
SLIDE 2

All About

slide-3
SLIDE 3

What's the meaning of

? ?

■ Andy Bechtolsheim ■ Vinod Khosla ■ Scott McNealy ■ Bill Joy

slide-4
SLIDE 4

What is doing ?

?

slide-5
SLIDE 5

Product of Sun

  • Computer servers and workstations

(based on Sun's SPARC, AMD's Opteron, Intel's Xeon)

  • Storage systems

(Sun StorageTek 5800 System, Sun Fire X4500 storage server, SAM-QFS filesystem)

  • Operating System

(Solaris OS)

  • Developer tools

(Netbeans, Sun Studio)

  • Platform& Standards

(Java, Java SE, Java EE, Java ME)

  • Database Management Systems

(JavaDB, PostgreSQL for Solaris, MySQL)

  • Others

(Sunspot, Systems Management, Mozilla Suite, Identity Manager etc.)

slide-6
SLIDE 6
slide-7
SLIDE 7

Campus Ambassador

Program

Towards

Education

slide-8
SLIDE 8
slide-9
SLIDE 9

Sun Academic Initiative Program

Take the online course of Sun technologies for FREE!

based on 2 websites: http://learningconnection.sun.com http://sunsite.scut.edu.cn

Nearly 60% discount for the Sun Certificate !!!

SCJP: Sun Certified Java Programmer

SCSA: Sun Certified System Administration for the Solaris Operating System Sun Certified Developer for Sun Application Server Sun Certified Engineer for Sun Directory Server

slide-10
SLIDE 10

share the most to the world !

slide-11
SLIDE 11

BUILDING A COMMUNITY Opening Day: June 14, 2005

slide-12
SLIDE 12

November 13rd. 2006

slide-13
SLIDE 13

http://mustang.dev.java.net

slide-14
SLIDE 14

Community

Sun Developer Community of China

http://developers.sun.com.cn

Open Technology Community

http://www.opentech.org.cn

NetBeans Community

http://www.netbeans.org

OpenSolaris Community

http://www.opensolaris.org

Java Community

http://www.java.net

OpenJDK Community

http://community.java.net/OpenJDK

slide-15
SLIDE 15

Java and Netbeans Java and Netbeans Overview Overview

slide-16
SLIDE 16

What is Java?

slide-17
SLIDE 17

Java is a Brand! Compatibility is Guaranteed!

slide-18
SLIDE 18

Java is a Programming Language!

slide-19
SLIDE 19

Java is a Platform!

slide-20
SLIDE 20

Where is Java?

slide-21
SLIDE 21

Java is Everywhere

NASA’s Mars Exploration Rovers NASA's Mars Exploration Rovers

slide-22
SLIDE 22

Java is FREE Software

slide-23
SLIDE 23

Java is being used by everyone!

Printers

TVs

Webcams

STBs

Cash Registers

PDAs

Telescopes

Medical Equipment

Lottery Terminals Consumer Electronics Game Consoles

Robots

slide-24
SLIDE 24
slide-25
SLIDE 25

Java Dominates in Financial Services

Source: Forresters’ Architect Survey on European Financial Industry in Jan 2008 http://www.sun.com/aboutsun/media/analyst/european_fsa.pdf

slide-26
SLIDE 26

Java Community

slide-27
SLIDE 27

Java.net: The Source for Java Technology

Collaboration

  • What it is:

> Web-based community for Java

developers

> Open, collaborative Java

development

> Communities with common

interests (java gaming)

  • Active and vibrant

> 175,000+ members > 2,200+ projects > 19 Java communities > 74 hosted JUGs > 100 RSS feeds > Blogs, Wikis, Javapedia

slide-28
SLIDE 28
slide-29
SLIDE 29

Mark Your Calendar! San Francisco: May 6-9, 2008

slide-30
SLIDE 30

NetBeans

slide-31
SLIDE 31

What Is NetBeans?

There are two answers... #1: It is an award-winning IDE

  • For Java developers (but we're adding more

languages...)

  • Free, open-source - http://www.netbeans.org
  • Large (and growing) community of users that can

help.

slide-32
SLIDE 32

What Is NetBeans?

#2: It is a Platform

  • For building rich client applications that will

run on any operating system that supports a standard JVM.

  • Provides a rich framework of windows,

menus, tool bars, actions, etc.

  • Used for building a wide variety of

applications

slide-33
SLIDE 33

What Is NetBeans?

Seeing is believing

  • Quick Examples

> Minex

slide-34
SLIDE 34

What makes NetBeans the best?

  • 1. Ant Based Project System
  • 2. Friendly Editor
  • 3. Powerful J2EE Support
  • 4. Visual J2ME Development
  • 5. An integrated Profiler
  • 6. Collaboration tools
slide-35
SLIDE 35

What makes NetBeans the best? (cont.)

  • 7. Spectacular GUI Builder (Project

Matisse)

  • 8. Refactoring support
  • 9. CVS support
  • 10. Java BluePrints Solution Catalog
  • 11. Module Development Support
  • 12. Update Center
slide-36
SLIDE 36

What's New In NetBeans 6.0?

  • Code editor enhancements
  • Ruby, JRuby, & Ruby on Rails support
  • Easier installation and upgrading
  • Swing GUI data binding
  • Integrated profiling, profiling “points”
  • Integrated visual web features
  • Mobility graphical game builder
  • SOA & UML enhancements
  • Netbeans platform enhancements
slide-37
SLIDE 37

Netbeans 6.0 Resources

  • Netbeans Product Site: http://www.netbeans.org

> Download: previews, current & past releases of IDE, plugins > Learning: tutorials, technical articles, flash demos > Community: latest news, forums, events, mailing lists

  • Netbeans Wiki: http://wiki.netbeans.org/wiki/

> Open-source documentation site for Netbeans

  • Planet Netbeans: http://www.planetnetbeans.org/

> Aggregate for all Netbeans-related blogs

  • Source Code: cvs.netbeans.org:/cvs

> CVS source code access for Netbeans platform + IDE

slide-38
SLIDE 38

=Opportunity Go Get It !

slide-39
SLIDE 39

Hello World

The Scene Behind Programming with Java

slide-40
SLIDE 40

Hello World

public class HelloWorld { public static void main( String[] arg ) { System.out.println( "Hello World" ); } }

slide-41
SLIDE 41

Compile “Hello World”

Compile

slide-42
SLIDE 42

Compile ...

HelloWorld.java HelloWorld.class Compiler

slide-43
SLIDE 43

javac and g++ ??

  • compile to binary

bytecode

  • resolve all reference

as symbolic “handles”

  • memory layout is

defined upon execution

  • compile to binary

machine code

  • resolve all “pointers”

into memory address

  • memory layout is

defined by compiler

javac g++

slide-44
SLIDE 44

class System

public final class System { public final static InputStream in = nullInputStream(); public final static PrintStream out = nullPrintStream(); } System.out.println( "Hello World" ); Handle to PrintStream

  • bject
slide-45
SLIDE 45

Problem with Pointers

  • Fragile Super-class Problem
  • Security Problem
slide-46
SLIDE 46

Fragile Super-class Problem

Before After Although there is no change in the impl. of B, B is still needed to re-compile

slide-47
SLIDE 47

Security Problem

invoke the Hack_Class routine

slide-48
SLIDE 48

The Hack Class Output

Memory layout of class A re-construct private variable Modify the private constant

slide-49
SLIDE 49

Run "Hello World"

Run

slide-50
SLIDE 50

Run...

HelloWorld.class

Verifier Interpreter

JVM

Class Loader

slide-51
SLIDE 51

Class Loader

Local File System Class Namespace Network-loaded Class Namespace JVM

HelloWorld.class WorldWideWeb.class

slide-52
SLIDE 52

Verifier

  • Verify the executing Bytecode comes

from different compiler

  • No forging pointers
  • No violating access restrictions
  • No object is accessed with invalid type
slide-53
SLIDE 53

The Entire Process

slide-54
SLIDE 54

♫ How to manage memory without pointer in Java? ♫ Why need manage memory?

How & Why?

slide-55
SLIDE 55

Execute ...

public class HelloWorld { public static void main( String[] arg ) { System.out.println( "Hello World" ); } }

String instance PrintStream Method

slide-56
SLIDE 56

class String

public final class String { private final char value[]; private final int offset; private final int count; private int hash; }

Read-only immutable obj

slide-57
SLIDE 57

Hello World Modified

public class HelloWorld { public static void main( String[] arg ) { System.out.println( "Hello World" + "~" ); } }

What's happening?

slide-58
SLIDE 58

class String

public final class String { public String concat( String str ) { int otherLen = str.length(); if ( otherLen == 0 ) { return this; } char buf[] = new char[ count + otherLen ]; getChars( 0, count, buf, 0 ); str.getChars( 0, otherLen, buf, count ); return new String( 0, count + otherLen, buf ); } } return new String, where is the old

  • ne?
slide-59
SLIDE 59

Where is the old String?

  • Un-referenced ... becomes memory leak?
  • Deallocated immediately?
  • Threw into the Trash?

Trash

slide-60
SLIDE 60

The Garbage Collector

  • Problem of Explicit malloc() and free()
  • 1. Dangling reference
  • 2. Memory leak
  • GC automatically allocate memory and deallocate

memory

  • Responsibility:
  • 1. Allocating memory
  • 2. Ensuring referenced object in memory
  • 3. Recovering memory no longer in use
slide-61
SLIDE 61

Simple GC

class ReferenceCounter { public: static void NewReference( Object *obj ) { ++obj->reference_count; } static void ThrowAway( Object *obj ) {

  • -obj->reference_count;

if ( obj->reference_count == 0 ) { free( obj ); } } };

slide-62
SLIDE 62

GC Design Choice

  • Serial vs Parallel
  • Concurrent vs Stop-the-World
  • Compact vs Non-compact vs Copying

Tradeoff Time Heap Space GC Frequency

slide-63
SLIDE 63

GC Design in JVM

JVM

Conventional Garbage Collection

Pre-HotSpot: Post-HotSpot: Exact JVM (JVM 1.2.2)

Exact Garbage Collection

JVM 1.3

Generational Garbage Collection

slide-64
SLIDE 64

Generation Collection

Heap Young Generation Old Generation

slide-65
SLIDE 65

The Philosophy

  • Most object dies young
  • Objects survived in several rounds of GC

are important

  • Large objects are mostly important
  • Few references from older to younger
  • bjects exist
slide-66
SLIDE 66

Object dies Young??

public int Search( Vector<String> vector, String value ) { Iterator<String> iter = vector.iterator(); for( int i = 0; iter.hasNext(); ++i ) { if ( iter.next() == value ) { return i; } } return -1; }

slide-67
SLIDE 67

Generation Characteristic

  • High garbage

density

  • Occupy small heap

space

  • Carry frequent GC
  • Low garbage

density

  • Occupy big heap

space

  • Carry few GC

Young Generation (Minor Collection) Old Generation (Major Collection)

slide-68
SLIDE 68

How it works?? (young -> old)

slide-69
SLIDE 69

Java Hotspot Generations

  • Young generation
  • Old generation
  • Permanent generation

(e.g. Class, Method objects)

Eden From To Survivor Big Heap

slide-70
SLIDE 70

Hotspot Collectors

  • Serial Collector
  • Parallel Collector
  • Parallel Compacting Collector
  • Concurrent Mark-sweep Collector
slide-71
SLIDE 71

Serial Collector – young generation

slide-72
SLIDE 72

mark-sweep-compact

slide

Serial Collector – old generation

slide-73
SLIDE 73

Parallel Collector – young generation

slide-74
SLIDE 74

Parallel Compacting Collector – old generation

Mark phase

  • live objects are marked in parallel

Summary phase

  • calculate density and find the region worth to compact

dense prefix dense prefix

Compaction phase

  • compaction is not carried in the dense prefix
slide-75
SLIDE 75

Concurrent Mark-Sweep Collector – old generation

slide-76
SLIDE 76

Concurrent Mark-Sweep Collector

slide-77
SLIDE 77

Hotspot Collectors

  • Serial Collector
  • XX:+UseSerialGC
  • Parallel Collector
  • XX:+UseParallelGC
  • Parallel Compacting Collector
  • XX:+UseParallelOldGC
  • Concurrent Mark-sweep Collector
  • XX:+UseConcMarkSweepGC
slide-78
SLIDE 78

Java Past, Now, and Future

The Evolution Process

slide-79
SLIDE 79

Java SE Timeline

slide-80
SLIDE 80

History

  • 1995 (1.0) – The First Public Release
  • 1997 (1.1) – Nested Class Added

Support for Function Objects

  • 2001 (1.4) – Assertions Added

Support for Verifying Codes

slide-81
SLIDE 81

Java SE 5 Language Features

  • Autoboxing and unboxing
  • Enhanced for loop
  • Static import
  • Typesafe enumerations
  • Variable argument list
  • Generics
  • Annotations (metadata)

http://java.sun.com/j2se/1.5.0/docs/relnotes/features.html#lang

slide-82
SLIDE 82

Sample Code

int sum = 0; List<Integer> list = Arrays.asList(1, 2, 3); for (int i: list) sum += i; System.out.println(“sum = “ + sum); Generics

Auto-boxing

For-loop

slide-83
SLIDE 83

Generics

  • New code

> Example 1 > Example 2

List<String> list = new LinkedList<String>(); list.add("hello world"); String msg = list.iterator().next();

public void print(Hashtable<String, Integer> list) { for (String key: list.keySet()) System.out.println(key + “ = “ + list.get(key)); }

slide-84
SLIDE 84

Autoboxing of Primitive Types

  • Old code
  • New Code

ArrayList list = new ArrayList(); list.add(0, new Integer(42)); int total = ((Integer)list.get(0)).intValue(); ArrayList<Integer> list = new ArrayList<Integer>(); list.add(0, 42); int total = list.get(0);

slide-85
SLIDE 85

Enhanced for Loop

  • Old code
  • New code

Iterator iter = hashSet.iterator(); while (iter.hasNext()) { Object obj = iter.next(); ... } for (Object obj: hashSet) { ... }

slide-86
SLIDE 86

Variable Argument List

  • Old code
  • New code

public void printArgs(String[] args) { ... public void printArgs(String... args) { for (String a: args) System.out.println(a);

printArgs(x, y); printArgs(x, y, z);

slide-87
SLIDE 87

Java SE 6 Top 10 Feature

  • Web Services
  • Scripting
  • Database
  • More Desktop APIs
  • Monitoring Management
  • Compiler Access
  • Pluggable Annotations
  • Desktop Deployment
  • Security
  • The -lities: Quality, Compatibility, Stability

http://java.sun.com/developer/technicalArticles/J2SE/Desktop/javase6/beta2.html#top10

slide-88
SLIDE 88

Synchronization Optimization

  • All modern JVMs incorporate light-weight

locking > Avoid associating an OS mutex / condition variable (heavy-weight lock) with each object

  • Effective because most locking is

uncontended – not competed by threads

slide-89
SLIDE 89

Java Object Header

Mark Word (32/64bits) Class Metadata Address (32/64bits) Array Length (32//64bits) 2 words for Object, 3 words for Arrays

slide-90
SLIDE 90

Mark Word

slide-91
SLIDE 91

Light Weight Locking

  • unlocked

Thread stack

Execution Stack Method Activation Lock Record

hash + age | 01 Object Header

slide-92
SLIDE 92

Light Weight Locking

  • locked

Thread stack

Execution Stack Method Activation

hash + age | 01 Stack Pointer Object Header Displaced Mark Word CAS

slide-93
SLIDE 93

Light Weight Locking

  • contented

Memory Mutex OR Condition Variable Mutex Pointer Object Header

slide-94
SLIDE 94

Light Weight Locking

  • recursed

Thread stack

Execution Stack Method Activation

hash + age | 01 Stack Pointer Object Header CAS recursion count

slide-95
SLIDE 95

Observation

  • Most lockings are not only uncontended,

but performed repeatedly by the same thread >> Make it cheap for a single thread to reacquire a lock can be an optimization

slide-96
SLIDE 96

Biased Locking

Object Header CAS Light Weight Locking

slide-97
SLIDE 97

What happens when Revoke?

  • Fallback to light weight locking
  • Need to wait for Global Safepoint

( No bytecode is executing )

  • Thread stack is walked and lock record is

enumerated

  • Update Object Header when object is

locked

slide-98
SLIDE 98

Revoking ...

Thread stack

Execution Stack Method Activation

Displaced Mark Stack Pointer Object Header walk Update

slide-99
SLIDE 99

Comparing the Lockings

Light Weight Locking lock (CAS) : unlock (CAS) lock (CAS) : unlock (CAS) Biased Locking lock (CAS) : unlock (TAB) lock (TAB) : unlock (TAB) Execution

slide-100
SLIDE 100

JavaSE 7

slide-101
SLIDE 101
slide-102
SLIDE 102

Where Are We?

JDK 5 2004/9/30 JDK 6 2006/12/11 JDK 7 2008/H2

slide-103
SLIDE 103

Future?

Source : Forrestor's Architect Survey on European Financial Industry in Jan 2008 http://www.sun.com/aboutsun/media/analyst/european_fsa.pdf

slide-104
SLIDE 104

Further Readings

http://openjdk.java.net/ http://java.sun.com/docs/white/langenv/ http://java.sun.com/j2se/reference/whitepapers/memorymanagement_whitepaper.pdf http://java.sun.com/j2se/1.5.0/docs/relnotes/features.html#lang http://java.sun.com/developer/technicalArticles/J2SE/Desktop/javase6/beta2.html#top10 http://java.sun.com/performance/reference/whitepapers/6_performance.html

slide-105
SLIDE 105

Q & A