Upload
senthil-kumar
View
247
Download
0
Embed Size (px)
Citation preview
7/31/2019 Java Overview and Java Se6
1/105
Java Overview andJava SE 6 What's New
Max LiCampus Ambassador in HKUST
Gigi LiCampus Ambassador in CUHK
Sun Microsystems, Inc.
7/31/2019 Java Overview and Java Se6
2/105
All About
7/31/2019 Java Overview and Java Se6
3/105
What's the meaning of
?? Andy Bechtolsheim Vinod Khosla Scott McNealy Bill Joy
7/31/2019 Java Overview and Java Se6
4/105
What is
doing ??
7/31/2019 Java Overview and Java Se6
5/105
Product ofSun
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 Manageretc.)
7/31/2019 Java Overview and Java Se6
6/105
7/31/2019 Java Overview and Java Se6
7/105
Campus AmbassadorProgram
Towards
Education
7/31/2019 Java Overview and Java Se6
8/105
7/31/2019 Java Overview and Java Se6
9/105
Sun Academic Initiative Program
Take the online course of Sun technologies for FREE!
based on 2 websites:http://learningconnection.sun.comhttp://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 SystemSun Certified Developer for Sun Application ServerSun Certified Engineer for Sun Directory Server
7/31/2019 Java Overview and Java Se6
10/105
share the most to the world !
7/31/2019 Java Overview and Java Se6
11/105
7/31/2019 Java Overview and Java Se6
12/105
November 13rd. 2006
7/31/2019 Java Overview and Java Se6
13/105
http://mustang.dev.java.net
7/31/2019 Java Overview and Java Se6
14/105
CommunitySun 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
http://developers.sun.com.cn/http://www.opentech.org.cn/http://www.netbeans.org/http://www.opensolaris.org/http://www.java.net/http://community.java.net/OpenJDKhttp://community.java.net/OpenJDKhttp://www.java.net/http://www.opensolaris.org/http://www.netbeans.org/http://www.opentech.org.cn/http://developers.sun.com.cn/7/31/2019 Java Overview and Java Se6
15/105
Java and NetbeansJava and NetbeansOverviewOverview
7/31/2019 Java Overview and Java Se6
16/105
What is Java?
7/31/2019 Java Overview and Java Se6
17/105
Java is a Brand!Compatibility is Guaranteed!
7/31/2019 Java Overview and Java Se6
18/105
Java is a Programming Language!
7/31/2019 Java Overview and Java Se6
19/105
Java is a Platform!
7/31/2019 Java Overview and Java Se6
20/105
Where is Java?
7/31/2019 Java Overview and Java Se6
21/105
Java is Everywhere
NASAs Mars ExplorationRovers
NASA's Mars Exploration Rovers
7/31/2019 Java Overview and Java Se6
22/105
Java is FREE Software
7/31/2019 Java Overview and Java Se6
23/105
Java is being used by everyone
Printers
TVs
Webcams
STBs
Cash Registers
PDAs
Telescopes
Medical Equipment
Lottery Terminals
Consumer Electronics
Game Consoles
Robots
7/31/2019 Java Overview and Java Se6
24/105
7/31/2019 Java Overview and Java Se6
25/105
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
7/31/2019 Java Overview and Java Se6
26/105
Java Community
7/31/2019 Java Overview and Java Se6
27/105
Java.net: The Source for Java TechnologyCollaboration
What it is:> Web-based community for Java
developers
> Open, collaborative Java
development> Communities with commoninterests (java gaming)
Active and vibrant> 175,000+ members
> 2,200+ projects> 19 Java communities
> 74 hosted JUGs
> 100 RSS feeds
> Blogs, Wikis, Javapedia
7/31/2019 Java Overview and Java Se6
28/105
7/31/2019 Java Overview and Java Se6
29/105
Mark Your Calendar!
San Francisco: May 6-9, 2008
7/31/2019 Java Overview and Java Se6
30/105
NetBeans
7/31/2019 Java Overview and Java Se6
31/105
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 canhelp.
http://www.netbeans.org/http://www.netbeans.org/7/31/2019 Java Overview and Java Se6
32/105
What Is NetBeans?
#2: It is a Platform
For building rich client applications that willrun on anyoperating system that supportsa standard JVM.
Provides a rich framework of windows,
menus, tool bars, actions, etc. Used for building a wide variety of
applications
7/31/2019 Java Overview and Java Se6
33/105
What Is NetBeans?
Seeing isbelieving
Quick Examples
> Minex
7/31/2019 Java Overview and Java Se6
34/105
What makes NetBeans the best?
1. Ant Based Project System
2. Friendly Editor
3. Powerful J2EE Support4. Visual J2ME Development
5. An integrated Profiler
6. Collaboration tools
7/31/2019 Java Overview and Java Se6
35/105
What makes NetBeans the best?
(cont.)7. Spectacular GUI Builder (Project
Matisse)
8. Refactoring support9. CVS support
10. Java BluePrints Solution Catalog
11. Module Development Support
12. Update Center
7/31/2019 Java Overview and Java Se6
36/105
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
7/31/2019 Java Overview and Java Se6
37/105
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
http://www.netbeans.org/http://wiki.netbeans.org/wiki/http://www.planetnetbeans.org/http://cvs.netbeans.org/cvshttp://cvs.netbeans.org/cvshttp://www.planetnetbeans.org/http://wiki.netbeans.org/wiki/http://www.netbeans.org/7/31/2019 Java Overview and Java Se6
38/105
=Opportunity
Go Get It !
7/31/2019 Java Overview and Java Se6
39/105
Hello World
The Scene BehindProgramming with Java
7/31/2019 Java Overview and Java Se6
40/105
Hello World
public class HelloWorld {public static void main( String[] arg ) {System.out.println( "Hello World" );
}
}
7/31/2019 Java Overview and Java Se6
41/105
Compile Hello World
Compile
7/31/2019 Java Overview and Java Se6
42/105
Compile ...
HelloWorld.java HelloWorld.classCompiler
7/31/2019 Java Overview and Java Se6
43/105
javac and g++ ??
compile to binarybytecode
resolve all referenceas symbolichandles
memory layout isdefined uponexecution
compile to binarymachine code
resolve all pointersinto memory address
memory layout is
defined by compiler
javac g++
7/31/2019 Java Overview and Java Se6
44/105
class System
public final class System {
public final static InputStream in = nullInputStream();
public final static PrintStream out = nullPrintStream();}
System.out.println( "Hello World" );
Handle toPrintStream
object
7/31/2019 Java Overview and Java Se6
45/105
Problem with Pointers
Fragile Super-class Problem
Security Problem
7/31/2019 Java Overview and Java Se6
46/105
Fragile Super-class Problem
Before
After
Although there is no change
in the impl. of B,B is still needed to re-compile
7/31/2019 Java Overview and Java Se6
47/105
Security Problem
invoke theHack_Class
routine
7/31/2019 Java Overview and Java Se6
48/105
The Hack Class Output
Memory
layout ofclass A
re-constructprivate
variable
Modify theprivate
constant
7/31/2019 Java Overview and Java Se6
49/105
Run "Hello World"
Run
7/31/2019 Java Overview and Java Se6
50/105
Run...
HelloWorld.class
Verifier Interpreter
JVM
Class Loader
7/31/2019 Java Overview and Java Se6
51/105
Class Loader
Local File SystemClass Namespace
Network-loadedClass Namespace
JVM
HelloWorld.class WorldWideWeb.class
7/31/2019 Java Overview and Java Se6
52/105
Verifier
Verify the executing Bytecode comesfrom different compiler
No forging pointers No violating access restrictions
No object is accessed with invalid type
7/31/2019 Java Overview and Java Se6
53/105
The Entire Process
7/31/2019 Java Overview and Java Se6
54/105
How to manage memory without pointer in Java?
Why need manage memory?
How & Why?
7/31/2019 Java Overview and Java Se6
55/105
Execute ...
public class HelloWorld {public static void main( String[] arg ) {System.out.println( "Hello World" );
}
}String instance
PrintStreamMethod
7/31/2019 Java Overview and Java Se6
56/105
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
7/31/2019 Java Overview and Java Se6
57/105
Hello World Modified
public class HelloWorld {public static void main( String[] arg ) {System.out.println( "Hello World" + "~" );
}
}What's
happening?
7/31/2019 Java Overview and Java Se6
58/105
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 isthe oldone?
7/31/2019 Java Overview and Java Se6
59/105
Where is the old String?
Un-referenced ... becomes memory leak?
Deallocated immediately?
Threw into the Trash?
Trash
7/31/2019 Java Overview and Java Se6
60/105
The Garbage Collector
Problem of Explicit malloc() and free()1. Dangling reference2. Memory leak
GC automatically allocate memory and deallocatememory
Responsibility:
1. Allocating memory2. Ensuring referenced object in memory3. Recovering memory no longer in use
7/31/2019 Java Overview and Java Se6
61/105
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 );
}
}
};
7/31/2019 Java Overview and Java Se6
62/105
GC Design Choice
Serial vs Parallel
Concurrent vs Stop-the-World
Compact vs Non-compact vs Copying
Tradeoff
Time
Heap Space GC Frequency
7/31/2019 Java Overview and Java Se6
63/105
GC Design in JVM
JVMConventional Garbage Collection
Pre-HotSpot:
Post-HotSpot: Exact JVM (JVM 1.2.2)Exact Garbage Collection
JVM 1.3
Generational Garbage Collection
7/31/2019 Java Overview and Java Se6
64/105
Generation Collection
Heap
Young Generation
Old Generation
7/31/2019 Java Overview and Java Se6
65/105
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
objects exist
7/31/2019 Java Overview and Java Se6
66/105
Object dies Young??
public int Search( Vector vector, String value ) {
Iterator iter = vector.iterator();
for( int i = 0; iter.hasNext(); ++i ) {
if ( iter.next() == value ) {
return i;
}
}
return -1;
}
7/31/2019 Java Overview and Java Se6
67/105
Generation Characteristic
High garbagedensity
Occupy small heap
space Carry frequent GC
Low garbagedensity
Occupy big heap
space Carry few GC
Young Generation
(Minor Collection)
Old Generation
(Major Collection)
7/31/2019 Java Overview and Java Se6
68/105
How it works?? (young -> old)
7/31/2019 Java Overview and Java Se6
69/105
Java Hotspot Generations
Young generation
Old generation
Permanent generation
(e.g. Class, Method objects)
Eden
From ToSurvivor
Big Heap
7/31/2019 Java Overview and Java Se6
70/105
Hotspot Collectors
Serial Collector
Parallel Collector
Parallel Compacting Collector
Concurrent Mark-sweep Collector
7/31/2019 Java Overview and Java Se6
71/105
Serial Collector young generation
7/31/2019 Java Overview and Java Se6
72/105
mark-sweep-compact
slide
Serial Collector old generation
7/31/2019 Java Overview and Java Se6
73/105
Parallel Collector young generation
7/31/2019 Java Overview and Java Se6
74/105
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
Conc rrent Mark S eep Collector
7/31/2019 Java Overview and Java Se6
75/105
Concurrent Mark-Sweep Collector old generation
7/31/2019 Java Overview and Java Se6
76/105
Concurrent Mark-Sweep Collector
7/31/2019 Java Overview and Java Se6
77/105
Hotspot Collectors
Serial Collector-XX:+UseSerialGC
Parallel Collector
-XX:+UseParallelGC Parallel Compacting Collector
-XX:+UseParallelOldGC
Concurrent Mark-sweep Collector-XX:+UseConcMarkSweepGC
7/31/2019 Java Overview and Java Se6
78/105
Java Past, Now, and Future
The Evolution Process
7/31/2019 Java Overview and Java Se6
79/105
Java SE Timeline
7/31/2019 Java Overview and Java Se6
80/105
History
1995 (1.0) The First Public Release
1997 (1.1) Nested Class AddedSupport for Function Objects
2001 (1.4) Assertions AddedSupport for Verifying Codes
7/31/2019 Java Overview and Java Se6
81/105
Java SE 5 Language Features
Autoboxing and unboxing
Enhanced for loop
Static importTypesafe enumerations
Variable argument list
Generics Annotations (metadata)
http://java.sun.com/j2se/1.5.0/docs/relnotes/features.html#lang
http://java.sun.com/j2se/1.5.0/docs/relnotes/features.html#langhttp://java.sun.com/j2se/1.5.0/docs/relnotes/features.html#lang7/31/2019 Java Overview and Java Se6
82/105
Sample Code
int sum = 0;
List list = Arrays.asList(1, 2, 3);
for (int i: list)
sum += i;
System.out.println(sum = + sum);
Generics
Auto-boxing
For-loop
7/31/2019 Java Overview and Java Se6
83/105
Generics
New code> Example 1
> Example 2
List list = new LinkedList();
list.add("hello world");
String msg = list.iterator().next();
public void print(Hashtable list) {
for (String key: list.keySet())System.out.println(key + =
+ list.get(key));
}
7/31/2019 Java Overview and Java Se6
84/105
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 list =
new ArrayList();
list.add(0, 42);
int total = list.get(0);
7/31/2019 Java Overview and Java Se6
85/105
Enhanced for Loop
Old code
New code
Iterator iter = hashSet.iterator();
while (iter.hasNext()) {
Object obj = iter.next();
...
}
for (Object obj: hashSet) {
...
}
7/31/2019 Java Overview and Java Se6
86/105
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);
7/31/2019 Java Overview and Java Se6
87/105
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
http://java.sun.com/developer/technicalArticles/J2SE/Desktop/javase6/beta2.html#top10http://java.sun.com/developer/technicalArticles/J2SE/Desktop/javase6/beta2.html#top107/31/2019 Java Overview and Java Se6
88/105
7/31/2019 Java Overview and Java Se6
89/105
Java Object Header
Mark Word (32/64bits)
Class Metadata Address (32/64bits)
Array Length (32//64bits)
2 words for Object, 3 words for Arrays
M k W d
7/31/2019 Java Overview and Java Se6
90/105
Mark Word
Li ht W i ht L ki
7/31/2019 Java Overview and Java Se6
91/105
Light Weight Locking-unlocked
Thread stack
Execution Stack
Method Activation
Lock Record
hash + age | 01
Object Header
Light Weight Locking
7/31/2019 Java Overview and Java Se6
92/105
Light Weight Locking-locked
Thread stack
Execution Stack
Method Activation
hash + age | 01
Stack Pointer
Object Header
DisplacedMark Word
CAS
Light Weight Locking
7/31/2019 Java Overview and Java Se6
93/105
Light Weight Locking-contented
Memory
Mutex
OR
Condition Variable
Mutex Pointer
Object Header
Light Weight Locking
7/31/2019 Java Overview and Java Se6
94/105
Light Weight Locking-recursed
Thread stack
Execution Stack
Method Activation
hash + age | 01
Stack Pointer
Object Header
CAS
recursion count
Ob ti
7/31/2019 Java Overview and Java Se6
95/105
Observation
Most lockings are not only uncontended,but performed repeatedly by the samethread
>> Make it cheap for a single thread toreacquire a lock can be an optimization
Bi d L ki
7/31/2019 Java Overview and Java Se6
96/105
Biased Locking
ObjectHeader
CAS
Light
WeightLocking
Wh t h h R k ?
7/31/2019 Java Overview and Java Se6
97/105
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 islocked
Revoking ...
7/31/2019 Java Overview and Java Se6
98/105
Revoking ...
Thread stack
Execution Stack
Method Activation
Displaced Mark
Stack Pointer
Object Header
walk
Update
Comparing the Lockings
7/31/2019 Java Overview and Java Se6
99/105
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
7/31/2019 Java Overview and Java Se6
100/105
JavaSE 7
7/31/2019 Java Overview and Java Se6
101/105
Where Are We?
7/31/2019 Java Overview and Java Se6
102/105
Where Are We?
JDK 5 2004/9/30
JDK 6 2006/12/11JDK 72008/H2
Future?
7/31/2019 Java Overview and Java Se6
103/105
Future?
Source : Forrestor's Architect Survey on European Financial Industry in Jan 2008
http://www.sun.com/aboutsun/media/analyst/european_fsa.pdf
http://www.sun.com/aboutsun/media/analyst/european_fsa.pdfhttp://www.sun.com/aboutsun/media/analyst/european_fsa.pdf7/31/2019 Java Overview and Java Se6
104/105
Further Readingshttp://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
http://openjdk.java.net/http://java.sun.com/docs/white/langenv/http://java.sun.com/j2se/reference/whitepapers/memorymanagement_whitepaper.pdfhttp://java.sun.com/j2se/1.5.0/docs/relnotes/features.html#langhttp://java.sun.com/developer/technicalArticles/J2SE/Desktop/javase6/beta2.html#top10http://java.sun.com/performance/reference/whitepapers/6_performance.htmlhttp://java.sun.com/performance/reference/whitepapers/6_performance.htmlhttp://java.sun.com/developer/technicalArticles/J2SE/Desktop/javase6/beta2.html#top10http://java.sun.com/j2se/1.5.0/docs/relnotes/features.html#langhttp://java.sun.com/j2se/reference/whitepapers/memorymanagement_whitepaper.pdfhttp://java.sun.com/docs/white/langenv/http://openjdk.java.net/7/31/2019 Java Overview and Java Se6
105/105
Q & A