Posts Tagged ‘Java’

Core Java学习笔记

星期三, 4月 23rd, 2008

最近在看core java ,记录了一些以前没仔细留意过的东西:

1.数组的定义

int[] a = new int[] { 1, 2, 3 };//普通定义
a = new int[] { 1, 2, 3, };// 多个逗号,数组长度还是3

int[] b = { 1 };// 定义变量,声明数组的时候可以不用new
String[][] strs = { { “a” }, { “b” } };
//// strs = { { “a” }, { “b” } };//声明好的变量再赋值的时候,这样就会出错
strs = new String[][]{ { “a” }, { “b” } };//声明好的变量再赋值的时候,必须写上 new

2.static 代码块,

在类中可以定义多个static的代码块,

可以放在类的任何位置(不在方法里),类被加载的时候,从上到下依次执行.

例如

package com.lizongbo;

public class CoreJavaTest {
static {
System.out.println(”bbb”);
}
static {
System.out.println(”cccc”);
}
public static void main(String[] args) throws Exception {
////
}

static {
System.out.println(”dddd”);
}
}

同样,初始化的代码块也可以这样定义。

package com.lizongbo;

public class CoreJavaTest {
static {
System.out.println(”bbb”);
}
static {
System.out.println(”cccc”);
}
{
System.out.println(”eeee”);
}
public CoreJavaTest(){
System.out.println(”init”);
}
public static void main(String[] args) throws Exception {
CoreJavaTest cc=new CoreJavaTest();cc=new CoreJavaTest();
//
}

static {
System.out.println(”dddd”);
}
{
System.out.println(”ffff”);
}
}

执行结果为:

bbb
cccc
dddd
eeee
ffff
init
eeee
ffff
init

Tags: Java

Related posts

用HPjmeter分析jvm的gc日志和heap dump

星期日, 4月 13th, 2008

HPjmeter下载:
ftp://ftp.hp.com/pub/gsy/HPjmeter_3.0.01.jar

或者:
ftp://ftp.hp.com/pub/gsy/hpjmeter_console_3.0.01.00_windows_setup.exe
ftp://ftp.hp.com/pub/gsy/hpjmeter_console_3.0.01.00_linux_setup.sh

(ftp://ftp.hp.com/pub/gsy 支持目录方式浏览。)

jvm参数设置:
1. -Xloggc:gclog.vgc -XX:+PrintGCTimeStamps -XX:-PrintGCDetails -XX:+UseConcMarkSweepGC

3. -agentlib:hprof
(按Ctrl+C生成 java.hprof.txt)

(我在 Openfire的 openfired.vmoptions里添加了如下的的参数:

-Xloggc:gc.log
-XX:+PrintGCTimeStamps
-XX:-PrintGCDetails
-XX:+UseConcMarkSweepGC
-agentlib:hprof

)

运行HPjmeterjava -Xmx384m -jar HPjmeter_3.0.01.jar

File–>Open file –>

选择gclog.vgc参看gc日志。

或者 java.hprof.txt.

其它相关下载:

HPjtune下载:
ftp://ftp.hp.com/pub/gsy/--escaped_anchor:bc25305bc272f3a903e3221e6c44716e---1.3.zip

SAP Memory Analyzer 1.1.1 的Eclipse插件下载:
http://dl2.csdn.net/down1/20071218/18144755624.zip

官方下载地址: MemoryAnalyzer-1.1.1-plugins-only.zip
https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/e025ff62-1148-2a10-9994-f9436c40fcb9

gcviewer下载:
http://www.tagtraum.com/download/--escaped_anchor:15dec456521bdaff7482b857700c2124---1.28-bin.zip

来源:http://www.tagtraum.com/--escaped_anchor:15dec456521bdaff7482b857700c2124---download.html

http://www.tagtraum.com/--escaped_anchor:15dec456521bdaff7482b857700c2124--.html

参考: http://www.javaperformancetuning.com/tools/--escaped_anchor:73cda882f4e877ca12ddb00f5e1c8cfa--/index.shtml

http://www.javaperformancetuning.com/

scimark2 benchmark下载:

http://math.nist.gov/scimark2/scimark2lib.jar

来源: http://math.nist.gov/scimark2/download_java.html

jvm可设置的选项参数: http://blogs.sun.com/watt/resource/jvm-options-list.html

http://java.sun.com/docs/performance/index.html

http://java.sun.com/performance/reference/whitepapers/5.0_performance.html
http://java.sun.com/docs/hotspot/gc5.0/gc_tuning_5.html

http://java.sun.com/javase/technologies/hotspot/gc/gc_tuning_6.html

运行hpjmeter_console_3.0.01.00_windows_setup.exe安装的话,
可以得到两个demo.Java2Demo.eprof和Java2Demo.vgc。
HPjmeter自己生成的hpjmeter.bat 内容如下:
[code]
@echo off

rem Product: HPjmeter Console
rem
rem (c) Copyright 2005-2006 Hewlett-Packard Development Company, L.P.
rem
rem Confidential computer software. Valid license from HP required for
rem possession, use or copying. Consistent with FAR 12.211 and 12.212,
rem Commercial Computer Software, Computer Software Documentation, and
rem Technical Data for Commercial Items are licensed to the U.S. Government
rem under vendor’s standard commercial license.

rem Parameters (can be processed in any order):
rem 1) hpjmeter.bat -log LEVEL [optional, defaults to OFF. Choices are: FINE, FINER, FINEST, ]
rem 2) hpjmeter.bat -X<switch> [optional]
rem 3) hpjmeter.bat tooloption [optional, currently not used]
rem 4) hpjmeter.bat -help [optional, prints usage message]
rem

setlocal

rem
rem Process commandline arguments if any
rem

set VMOPT=
set OPT=
set LOG_LEVEL=OFF
set HEAPSIZE=-Xmx256m

set ARG=%1
:getarg
if “%ARG%”==”" goto getarg_done
if “%ARG%”==”-log” goto set_log_level
if not “%ARG:-Xmx=”"%”==”%ARG%” goto set_heapsize
if not “%ARG:-X=”"%”==”%ARG%” goto set_vmopt
if not “%ARG:-D=”"%”==”%ARG%” goto set_vmopt
if “%ARG%”==”-help” goto display_help
if not %ARG:-”"%==”" goto set_opt
shift
set ARG=%1
goto getarg

:set_log_level
shift
set LOG_LEVEL=%1
shift
set ARG=%1
goto getarg

:set_heapsize
set HEAPSIZE=%ARG%
shift
set ARG=%1
goto getarg

:set_vmopt
set VMOPT=%VMOPT% %ARG%
shift
set ARG=%1
goto getarg

:set_opt
set OPT=%OPT% %ARG%
shift
set ARG=%1
goto getarg

:display_help
echo “Usage: hpjmeter [<options>]”
echo “where each option starting with -X is a Java option,”
echo “otherwise it is an HPjmeter option, or has the ‘-log <level>’ form”
echo “<level> is SEVERE, WARNING, INFO, CONFIG, FINE, FINER, or FINEST”
echo “For example: hpjmeter -Xmx64m -log INFO -Xeprof”
goto end

:getarg_done

rem
rem Set JM_JAVA_HOME
rem

if defined JM_JAVA_HOME goto skipset
set JM_JAVA_HOME=D:\Program Files\Java\jre1.5.0_11
:skipset

rem
rem Absolute path to installed jar files set by InstallShield
rem

set JARBASE=D:\Program Files\HPjmeter\lib

rem
rem Set main class and classpath arguments
rem

set TOOL_NAME=com.hp.jmeter.Console
set JARS=%JARBASE%\HPjmeter.jar
set VMOPT=%VMOPT% -ea -Dcom.hp.jmeter.all.LogLevel=%LOG_LEVEL%

rem
rem Start HP Java Manager Console
rem

start “HPjmeter” /MIN “%JM_JAVA_HOME%\bin\java” %HEAPSIZE% %VMOPT% -cp “%JARS%” “%TOOL_NAME%” %OPT%

:end
endlocal

[/code]

Tags: gcviewer, HPjmeter, HPjtune, Java

Related posts

Xref-Java2Html — 很好用的java2html工具

星期五, 12月 28th, 2007

Xref-Java2Html — 很好用的java2html工具

Xref-Java2Html生成的超链接最多,方便在浏览器中阅读代码,跳转也非常方便。
其它的一些java2hhtml的工具,只能算是语法高亮的html,
缺少class之间关联跳转的链接,使得阅读代码并不方便。

Xref-Java2Html的安装步骤为:

1.运行 java -jar xref-java2html-i86pc-windows.jar,选择安装目录:
比如我选的 d:\java\xref-java2html,安装完成。

2.再到D:\Java\xref-java2html下面运行 java -jar java2html.jar

D:\Java\xref-java2html>java -jar java2html.jar

3.在界面中,添加需要生成html的java源代码的目录,
点“Options” 设置参数:

把Generate  .html files instead of .java.html的钩去掉.

实际最终生成html是xrefw.exe这个程序执行的结果

D:\Java\xref-java2html>xrefw.exe -java2html -stderr -html -nostdop -nocxfile -javafilesonly -mf20 -htmlgxlist -htmllxlist -htmldirectx -refalphahash -htmllinenums -htmlcutsuffix -htmlgenjavadoclinks -htmllinenumlabel=line. -jdkclasspath D:\Java\jdk1.6.0_03\jre\lib\rt.jar -classpath C:\ -javadocpath C:\ -sourcepath D:\  -d “E:\mywork\minasmpp\java2html” “E:\mywork\minasmpp\src” -htmljavadocpath=http://download.--escaped_anchor:330b518f285a7a54651177f07dbabf01--.net/jdk/jdk-api-localizations/jdk-api-zh-cn/publish/1.6.0/html/zh_CN/api

官方网站只提供了1.4版本的可执行文件。

因此需要自己编译1.6.10的代码。
(我用cygwin编译成功,但是只能在cygwin下运行)

编译步骤如下:
1.安装cygwin. 我安装的是: cygwinenv-2.00.exe
安装到D:\cygwin
2.解压代码到D:\cygwin\xrefactory-1.6.10-src

3.启动cygwin,转到对应目录,执行make

—————-

Copying skeleton files.
These files are for the user to personalize
their cygwin experience.

These will never be overwritten.

`./.bashrc’ -> `/home/Administrator//.bashrc’
`./.bash_profile’ -> `/home/Administrator//.bash_profile’
`./.inputrc’ -> `/home/Administrator//.inputrc’

Administrator@lizongbo ~
$ ls

Administrator@lizongbo ~
$ cd /

Administrator@lizongbo /
$ ls
bin         cygwin.ico  home  tmp  var
cygwin.bat  etc         lib   usr  xrefactory-1.6.10-src

Administrator@lizongbo /
$ cd xrefactory-1.6.10-src/

Administrator@lizongbo /xrefactory-1.6.10-src
$ ls
byacc-1.9  xref-any

Administrator@lizongbo /xrefactory-1.6.10-src
$ cd xref-any/

Administrator@lizongbo /xrefactory-1.6.10-src/xref-any
$ make
sh CreateXrefDistribution
make[1]: Entering directory `/xrefactory-1.6.10-src/xref-any/src’
make -C ../lib/zlib libz.a
make[2]: Entering directory `/xrefactory-1.6.10-src/xref-any/lib/zlib’
cc -O   -c -o adler32.o adler32.c
cc -O   -c -o compress.o compress.c
cc -O   -c -o crc32.o crc32.c
cc -O   -c -o gzio.o gzio.c
cc -O   -c -o uncompr.o uncompr.c
cc -O   -c -o deflate.o deflate.c
cc -O   -c -o trees.o trees.c
cc -O   -c -o zutil.o zutil.c
cc -O   -c -o inflate.o inflate.c
cc -O   -c -o infblock.o infblock.c
cc -O   -c -o inftrees.o inftrees.c
cc -O   -c -o infcodes.o infcodes.c
cc -O   -c -o infutil.o infutil.c
cc -O   -c -o inffast.o inffast.c
ar rc libz.a adler32.o compress.o crc32.o gzio.o uncompr.o deflate.o trees.o zut
il.o inflate.o infblock.o inftrees.o infcodes.o infutil.o inffast.o
make[2]: Leaving directory `/xrefactory-1.6.10-src/xref-any/lib/zlib’
gcc -c -O -I../src -I../lib/zlib -I. -DDEBUG -DUSE_LIBZ -DBIN_RELEASE -DPRESERVE
_C_ARGS -D__mygnulinux__   -c -o cgram.o cgram.c
gcc -c -O -I../src -I../lib/zlib -I. -DDEBUG -DUSE_LIBZ -DBIN_RELEASE -DPRESERVE
_C_ARGS -D__mygnulinux__   -c -o main.o main.c
gcc -c -O -I../src -I../lib/zlib -I. -DDEBUG -DUSE_LIBZ -DBIN_RELEASE -DPRESERVE
_C_ARGS -D__mygnulinux__   -c -o globals.o globals.c
gcc -c -O -I../src -I../lib/zlib -I. -DDEBUG -DUSE_LIBZ -DBIN_RELEASE -DPRESERVE
_C_ARGS -D__mygnulinux__   -c -o misc.o misc.c
gcc -c -O -I../src -I../lib/zlib -I. -DDEBUG -DUSE_LIBZ -DBIN_RELEASE -DPRESERVE
_C_ARGS -D__mygnulinux__   -c -o semact.o semact.c
gcc -c -O -I../src -I../lib/zlib -I. -DDEBUG -DUSE_LIBZ -DBIN_RELEASE -DPRESERVE
_C_ARGS -D__mygnulinux__   -c -o commons.o commons.c
gcc -c -O -I../src -I../lib/zlib -I. -DDEBUG -DUSE_LIBZ -DBIN_RELEASE -DPRESERVE
_C_ARGS -D__mygnulinux__   -c -o generate.o generate.c
gcc -c -O -I../src -I../lib/zlib -I. -DDEBUG -DUSE_LIBZ -DBIN_RELEASE -DPRESERVE
_C_ARGS -D__mygnulinux__   -c -o enumTxt.o enumTxt.c
gcc -c -O -I../src -I../lib/zlib -I. -DDEBUG -DUSE_LIBZ -DBIN_RELEASE -DPRESERVE
_C_ARGS -D__mygnulinux__   -c -o complet.o complet.c
gcc -c -O -I../src -I../lib/zlib -I. -DDEBUG -DUSE_LIBZ -DBIN_RELEASE -DPRESERVE
_C_ARGS -D__mygnulinux__   -c -o cxref.o cxref.c
gcc -c -O -I../src -I../lib/zlib -I. -DDEBUG -DUSE_LIBZ -DBIN_RELEASE -DPRESERVE
_C_ARGS -D__mygnulinux__   -c -o cxfile.o cxfile.c
gcc -c -O -I../src -I../lib/zlib -I. -DDEBUG -DUSE_LIBZ -DBIN_RELEASE -DPRESERVE
_C_ARGS -D__mygnulinux__   -c -o lex.o lex.c
gcc -c -O -I../src -I../lib/zlib -I. -DDEBUG -DUSE_LIBZ -DBIN_RELEASE -DPRESERVE
_C_ARGS -D__mygnulinux__   -c -o yylex.o yylex.c
gcc -c -O -I../src -I../lib/zlib -I. -DDEBUG -DUSE_LIBZ -DBIN_RELEASE -DPRESERVE
_C_ARGS -D__mygnulinux__   -c -o cexp.o cexp.c
gcc -c -O -I../src -I../lib/zlib -I. -DDEBUG -DUSE_LIBZ -DBIN_RELEASE -DPRESERVE
_C_ARGS -D__mygnulinux__   -c -o options.o options.c
gcc -c -O -I../src -I../lib/zlib -I. -DDEBUG -DUSE_LIBZ -DBIN_RELEASE -DPRESERVE
_C_ARGS -D__mygnulinux__   -c -o caching.o caching.c
gcc -c -O -I../src -I../lib/zlib -I. -DDEBUG -DUSE_LIBZ -DBIN_RELEASE -DPRESERVE
_C_ARGS -D__mygnulinux__   -c -o javagram.o javagram.c
In file included from y.tab.c:2465:
recyacc.h:20:1: warning: “yylval” redefined
../../src/javagram.y:8:1: warning: this is the location of the previous definiti
on
recyacc.h:21:1: warning: “yydebug” redefined
../../src/javagram.y:21:1: warning: this is the location of the previous definit
ion
recyacc.h:22:1: warning: “yynerrs” redefined
../../src/javagram.y:22:1: warning: this is the location of the previous definit
ion
recyacc.h:23:1: warning: “yyerrflag” redefined
../../src/javagram.y:23:1: warning: this is the location of the previous definit
ion
recyacc.h:24:1: warning: “yychar” redefined
../../src/javagram.y:24:1: warning: this is the location of the previous definit
ion
recyacc.h:25:1: warning: “lastyystate” redefined
../../src/javagram.y:25:1: warning: this is the location of the previous definit
ion
recyacc.h:26:1: warning: “yyssp” redefined
../../src/javagram.y:26:1: warning: this is the location of the previous definit
ion
recyacc.h:27:1: warning: “yyval” redefined
../../src/javagram.y:27:1: warning: this is the location of the previous definit
ion
recyacc.h:28:1: warning: “yyss” redefined
../../src/javagram.y:28:1: warning: this is the location of the previous definit
ion
recyacc.h:29:1: warning: “yyvs” redefined
../../src/javagram.y:29:1: warning: this is the location of the previous definit
ion
recyacc.h:30:1: warning: “yyvsp” redefined
../../src/javagram.y:31:1: warning: this is the location of the previous definit
ion
gcc -c -O -I../src -I../lib/zlib -I. -DDEBUG -DUSE_LIBZ -DBIN_RELEASE -DPRESERVE
_C_ARGS -D__mygnulinux__   -c -o jsemact.o jsemact.c
gcc -c -O -I../src -I../lib/zlib -I. -DDEBUG -DUSE_LIBZ -DBIN_RELEASE -DPRESERVE
_C_ARGS -D__mygnulinux__   -c -o cfread.o cfread.c
gcc -c -O -I../src -I../lib/zlib -I. -DDEBUG -DUSE_LIBZ -DBIN_RELEASE -DPRESERVE
_C_ARGS -D__mygnulinux__   -c -o cct.o cct.c
gcc -c -O -I../src -I../lib/zlib -I. -DDEBUG -DUSE_LIBZ -DBIN_RELEASE -DPRESERVE
_C_ARGS -D__mygnulinux__   -c -o init.o init.c
gcc -c -O -I../src -I../lib/zlib -I. -DDEBUG -DUSE_LIBZ -DBIN_RELEASE -DPRESERVE
_C_ARGS -D__mygnulinux__   -c -o editor.o editor.c
gcc -c -O -I../src -I../lib/zlib -I. -DDEBUG -DUSE_LIBZ -DBIN_RELEASE -DPRESERVE
_C_ARGS -D__mygnulinux__   -c -o refactory.o refactory.c
gcc -c -O -I../src -I../lib/zlib -I. -DDEBUG -DUSE_LIBZ -DBIN_RELEASE -DPRESERVE
_C_ARGS -D__mygnulinux__   -c -o yaccgram.o yaccgram.c
gcc -c -O -I../src -I../lib/zlib -I. -DDEBUG -DUSE_LIBZ -DBIN_RELEASE -DPRESERVE
_C_ARGS -D__mygnulinux__   -c -o html.o html.c
gcc -c -O -I../src -I../lib/zlib -I. -DDEBUG -DUSE_LIBZ -DBIN_RELEASE -DPRESERVE
_C_ARGS -D__mygnulinux__   -c -o extract.o extract.c
gcc -c -O -I../src -I../lib/zlib -I. -DDEBUG -DUSE_LIBZ -DBIN_RELEASE -DPRESERVE
_C_ARGS -D__mygnulinux__   -c -o classh.o classh.c
gcc -c -O -I../src -I../lib/zlib -I. -DDEBUG -DUSE_LIBZ -DBIN_RELEASE -DPRESERVE
_C_ARGS -D__mygnulinux__   -c -o jslsemact.o jslsemact.c
gcc  -o xref cgram.o main.o globals.o misc.o semact.o commons.o generate.o enumT
xt.o complet.o cxref.o cxfile.o lex.o yylex.o cexp.o options.o caching.o javagra
m.o jsemact.o cfread.o cct.o init.o editor.o refactory.o yaccgram.o html.o extra
ct.o classh.o jslsemact.o ../lib/zlib/libz.a
echo -e “\n\t\t\t\tnormal end of make\n”

normal end of make

make[1]: Leaving directory `/xrefactory-1.6.10-src/xref-any/src’
cp: `src/xref’ and `../xref/xref’ are the same file

Administrator@lizongbo /xrefactory-1.6.10-src/xref-any
$

—————-

4.将D:\cygwin\xrefactory-1.6.10-src\xref下的xref.exe 复制到D:\cygwin\
(不复制到这里的话,会出现目录找不到的情况,导致html生成不了)
4.将要转换出html的java代码复制到D:\cygwin\下面
(cygwin 中 /docs/sms/src对应windows下的 D:\cygwin\docs\sms\src)

5.运行xref.exe
Administrator@lizongbo /
$ cd /

Administrator@lizongbo
$ xref -java2html -stderr -html -nostdop -nocxfile -javafilesonly -mf20 -htmlgxlist -htmllxlist -htmldirectx -refalphahash -htmllinenums -htmlcutsuffix -htmlgenjavadoclinks -htmllinenumlabel=line. -jdkclasspath D:\Java\jdk1.6.0_03\jre\lib\rt.jar -d “/docs/sms/java2html” “/docs/sms/src” -htmljavadocpath=http://download.--escaped_anchor:330b518f285a7a54651177f07dbabf01--.net/jdk/jdk-api-localizations/jdk-api-zh-cn/publish/1.6.0/html/zh_CN/api

html就全部生成了。

java的源代码拿来生成在线查看。

xref -java2html -stderr -html -nostdop -nocxfile -javafilesonly -mf20 -htmlgxlist -htmllxlist -htmldirectx -refalphahash -htmllinenums -htmlcutsuffix -source 1.4 -htmlgenjavadoclinks -htmllinenumlabel=line. -jdkclasspath D:\Java\jdk1.6.0_03\jre\lib\rt.jar -d “/docs/java” “/docs/javasrc” -htmljavadocpath=http://618119.com/docs/--escaped_anchor:330b518f285a7a54651177f07dbabf01--/java2html

不过根据生成的代码来看,
页面最下方显示的还是: Html form generated by Xref-Java2Html version 1.4.0
貌似被1.6.10忽悠了。

相关下载资源:

Xref-Java2Html

http://www.xref-tech.com/--escaped_anchor:2e1085c046790a8961c7ea9c1d8e222b--/main.html

http://www.xref-tech.com/xrefactory/ftp/xref---escaped_anchor:2e1085c046790a8961c7ea9c1d8e222b---i86pc-windows.jar

http://www.xref-tech.com/xrefactory/ftp/xref---escaped_anchor:2e1085c046790a8961c7ea9c1d8e222b---i86pcWindows.zip
http://www.xref.sk/xrefactory---escaped_anchor:330b518f285a7a54651177f07dbabf01--/main.html

src-highlite:

http://jaist.dl.sourceforge.net/sourceforge/gnuwin32/src-highlite-2.1.2.exe

java2html
http://java2html.de/
http://www.--escaped_anchor:2e1085c046790a8961c7ea9c1d8e222b--.de/java2html_50.zip

The Java2HTML Tool:
http://www.--escaped_anchor:2e1085c046790a8961c7ea9c1d8e222b--.com/
http://www.--escaped_anchor:2e1085c046790a8961c7ea9c1d8e222b--.com/Java2HTML.zip

Tags: Java, java ide, Java2Html

Related posts