1. Always keep data private.
6. Break up classes with too many responsibilities.
The javac compiler always looks for files in the current directory, but the java interpreter only looks into the current directory if the "." directory is on the class path. If you have no class path set, this is not a problem—the default class path consists of the "." directory. But if you have set the class path and forgot to include the "." directory, then your programs will compile without error, but they won't run.
Features tagged as public can be used by any class. Private features can be used only by the class that defines them. If you don't specify either public or private, then the feature (that is, the class, method, or variable) can be accessed by all methods in the same package.
Here, docDirectory is the name of the directory where you want the HTML files to go. Follow these steps:
1.
|
Change to the directory that contains the source files you want to document. If you have nested packages to document, such as com.horstmann.corejava, you must be working in the directory that contains the subdirectory com. (This is the directory that contains the overview.html file if you supplied one.)
|
2.
|
Run the command
|
Java中有8種基本數(shù)據(jù)類型:int, short, long, byte, float, double, char, boolean
在Java中,整型的范圍與運(yùn)行java代碼的機(jī)器無關(guān)。在C/C++程序中,int類型占用的字節(jié)可能會因不同機(jī)器不同操作系統(tǒng)而不同;而在java中,各種整型的存儲需求已經(jīng)被明確定義(int: 4 bytes; short: 2 bytes; long: 8 bytes; byte: 1 byte),從而實現(xiàn)了平臺無關(guān)性。
常用整型、浮點型常量:
l Integer.MAX_VALUE
l Ingeger.MIN_VALUE
l Double.POSITIVE_INFINITY (正無窮大)
l Double.NEGATIVE_INFINITY (負(fù)無窮大)
l Double.NaN (Not a number)
PS: 判斷一個特定值是否等于Double.NaN:
if (x == Double.NaN) //is never true
Should use:
if (Double.isNaN(x)) // check whether x is “Not a number”
char 類型用于表示Unicode編碼的字符單元。Unicode可表示為16進(jìn)制值,從"u0000到"uffff。
關(guān)于Unicode: 在Unicode出現(xiàn)前,已經(jīng)有了很多的字符編碼標(biāo)準(zhǔn)(如美國的ASCII, 西歐的ISO 8859-1, 俄羅斯的KOI-8, 中國的GB118030和BIG-5,etc),這樣造成了兩個問題:a). 對于給定的代碼值,不同的編碼方案下可能對應(yīng)不同的字母; b). 采用大字符集的語言其編碼長度可能不同,e.g., 有些常用的字符采用單字節(jié)編碼,而另一些字符則需要兩個或更多字節(jié)。設(shè)計Unicode就是為了解決這些問題。但遺憾的是,經(jīng)過一段時間,Unicode字符超過了65536個,現(xiàn)在,連16位的char類型也已經(jīng)不能滿足所有Unicode字符的需求了。強(qiáng)烈建議不要在程序中用char類型。
當(dāng)將一個字符串和一個非字符串的值進(jìn)行拼接時,后者被轉(zhuǎn)換成字符串。E.g:
int age = 24;
String s = “abce” + age; //age被轉(zhuǎn)換成字符串,結(jié)果為“abcd24”。
Command: jar xvf file.zip 用于解壓文件。Java庫源文件在JDK中保存為src.zip,可用該命令解壓。
Javac將.java文件編譯成.class文件,發(fā)送到j(luò)vm, jvm執(zhí)行編譯器存放在.class文件中的字節(jié)碼。
運(yùn)行applet:1). 直接用瀏覽器打開html,該html里包含applet。2). appletviewer ***.html。applet嵌入到html的寫法如下:
<html>
<head></head>
<body>
......
<applet code = "WelcomeApplet.class" width="400" height="200">
<param name = "greeting" value="Welcome to core java!" />
</applet>
</body>
<html>