際際滷

際際滷Share a Scribd company logo
Java Basic Training
     III. Tool Matters
Compilation and
  Packaging
javac

  -classpath/-cp

  -d

  -source/-target

  -encoding


jar

  Behaves similar as tar

  -m manifest-鍖le
Manifest-鍖le

META-INF/MANIFEST.MF

Manifest-Version: 1.0

Created-By: 1.6.0 (Sun Microsystems Inc.)

Main-Class: c.e.m.j.Main

Class-Path: lib/a.jar lib/b.jar
Exercises
Compile a bunch of .java 鍖les and output to
classes directory

Create jar 鍖le

Write main class, manifest-鍖le

Create jar 鍖le

Create another two jar 鍖les, and try Class-
Path
Execution
java

   -classpath/-cp

   -jar

   -client/-server

   -d32/-d64

   -D<name>=<value>

   -X

          -Xms<size>

          -Xmx<size>

          -Xss<size>

   -XX
JVM Heap


Young Generation                           Eden Space   C
                                                            A
                                                                B

                                                                            from            to




 Old Generation                             Tenured Space

   Permanent
   Generation
                   class
                     A
                           class
                             B
                                   class
                                     C     Permanent Space          class
                                                                      D
                                                                            class
                                                                              E
                                                                                    class
                                                                                      F
JVM Heap
                   GC1
                                                                               B
Young Generation                            Eden Space                C
                                                                          to          from




 Old Generation                              Tenured Space

   Permanent
   Generation
                    class
                      A
                            class
                              B
                                    class
                                      C     Permanent Space   class
                                                                D
                                                                      class
                                                                        E
                                                                                   class
                                                                                     F
JVM Heap
                   GC1              GC2

Young Generation                             Eden Space
                                                                       from            to




 Old Generation                               Tenured Space                      B




   Permanent
   Generation
                    class
                      A
                            class
                              B
                                     class
                                       C     Permanent Space   class
                                                                 D
                                                                       class
                                                                         E
                                                                               class
                                                                                 F
JVM Total Memory


JVM heap

Thread execution stack

JVM itself
JVM Total Memory


JVM heap

Thread execution stack

JVM itself
                         think about -Xmx<size>
-XX

-XX:DisableExplicitGC

-XX:UseParallelGC

-XX:UseParallelOldGC

-XX:MaxPermSize=<size>

http://www.oracle.com/technetwork/java/
javase/tech/vmoptions-jsp-140102.html
Exercises


Run compiled class

Run packed jar 鍖le by specifying classpath

Run packed jar 鍖le using -jar

Try different -XX options
Tuning & Troubleshooting
jps
   List all JVM instances
   Compared with ps -elf | grep java
jstack
   Print thread stack dump of a JVM instance
   Similar as pstack and gstack
jstat
   JVM statistics monitoring
   http://docs.oracle.com/javase/1.5.0/docs/
   tooldocs/share/jstat.html
jmap

       Dump all JVM objects

       jmap -dump:live,format=b,鍖le=<鍖lename>

jhat

       Analyze dump 鍖le generated by jmap

       Start an http server where to connect to show analysis result

mat

       Memory Analyzer

       Dump 鍖le analysis tool based on Eclipse

       More ef鍖cient and be able to analyze really large dump 鍖le

jvisualvm

       Originated in NetBeans

       All-in-one tuning and troubleshooting tool
Exercises



Try all the tools mentioned one by one
The IDE
What Makes a Language
   Widely Accepted

 Simple & Stupid

 Off-the-shelf libraries

 Powerful IDE
Of鍖cial One - Eclipse


Workspace   Template

Editor      Working set

Keymap      Debug

Formatter
Other Good Choices


IDEA

NetBeans

Anymore?
Exercises


Rewrite Workable, Resource, Designer, Tester

Try to set up working set

Set a breakpoint, and debug
Homework

Apply all the tools to AddressBook project

  You may skip compilation and packaging
  tools

  You must execute your compiled binary
  from CLI using java

  Tuning and troubleshooting tools are
  mandatory

More Related Content

3 tool matters

Editor's Notes