This document discusses how Ajax can benefit content management systems (CMS) in two ways: 1) By improving the CMS interface experience for authors and site managers with a more desktop-like feel. 2) By providing tools for CMS users to build Ajax-enabled websites. It outlines several opportunities Ajax brings, such as single-page interfaces, drag-and-drop, and better performance. It also notes some potential drawbacks, such as breaking the back button functionality, unexpected page refreshes, and challenges for visual accessibility. In general, the document examines both the promises and limitations of incorporating Ajax into CMS products and websites.
This document discusses how Ajax can benefit content management systems (CMS) in two ways: 1) By improving the CMS interface experience for authors and site managers with a more desktop-like feel. 2) By providing tools for CMS users to build Ajax-enabled websites. It outlines several opportunities Ajax brings, such as single-page interfaces, drag-and-drop, and better performance. It also notes some potential drawbacks, such as breaking the back button functionality, unexpected page refreshes, and challenges for visual accessibility. In general, the document examines both the promises and limitations of incorporating Ajax into CMS products and websites.
This document discusses using the MXML compiler (mxmlc) to compile Flex projects from the command line rather than within Flex Builder. It provides an example command to compile a FlexMXML file located in the user's Documents folder. Additional command line arguments are also demonstrated, such as specifying the output SWF file location and adding library paths. The document recommends adding the Flex SDK bin directory to the system PATH environment variable so mxmlc can be called directly from the command line without specifying the full SDK path.
30. 第一个Java程序
• javac HelloJava.java
• error: cannot read: HelloJava.java
– javac工具程序找不到您指定的.java档案
• HelloJava.java:1: class HelloJava is public,
should be declared in a file named
HellJava.java
– 类别名称与主档名不符
43. 输出格式控制
控制字符 作用
反斜杠
' 单引号'
" 双引号"
uxxxx 以16进位数指定Unicode字符输出
xxx 以8进位数指定Unicode字符输出
b 倒退一个字符
f 换页
n 换行
r 游标移至行首
t 跳格(一个Tab键)
System.out.println("u0048u0065u006Cu006Cu006F");
60. 逻辑、位运算
• 「且」(&&)、「或」(||)、「反相」(!)
int number = 75;
System.out.println((number > 70 && number < 80));
System.out.println((number > 80 || number < 75));
System.out.println(!(number > 80 || number < 75));
• &(AND)、|(OR)、^(XOR)与~(补
码)
System.out.println("0 AND 0tt" + (0 & 0));
System.out.println("0 AND 1tt" + (0 & 1));
System.out.println("1 AND 0tt" + (1 & 0));
System.out.println("1 AND 1tt" + (1 & 1));
byte number = 0;
System.out.println((int)(~number));
61. 逻辑、位运算
• 左移(<<)、右移(>>)、>>>运算符
int number = 1;
System.out.println( "2的0次: " + number);
number =number << 1;
System.out.println("2的1次: " + number);
number = number << 1;
System.out.println("2的2次: " + number);
number = number << 1;
System.out.println("2的3次:" + number);
00000001 1
00000010 2
00000100 4
00001000 8
62. 递增、递减运算
• 递增、递减运算符
int i = 0;
System.out.println(++i);
System.out.println(--i);
• 将递增或递减运算符撰写在变量之前或变
量之后
int i = 0;
int number = 0;
number = ++i; //相当於i = i + 1; number = i;
System.out.println(number);
number = --i; //相当於i = i - 1; number = i;
System.out.println(number);
63. 递增、递减运算
• 将递增或递减运算符撰写在变量之前或变
量之后
int i = 0;
int number = 0;
number = i++; //相当於number = i; i = i + 1;
System.out.println(number);
number = i--; //相当于number = i; i = i - 1;
System.out.println(number);
64. 递增、递减运算
指定运算符 范 例 结 果
+= a += b a=a+b
-= a -= b a=a-b
*= a *= b a=a*b
/= a /= b a=a/b
%= a %= b a=a%b
&= a &= b a=a&b
|= a |= b a=a|b
^= a ^= b a=a^b
<<= a <<= b a = a << b
>>= a >>= b a = a >> b
70. Scanner scanner = new Scanner(System.in);
System.out.print("请输入分數: ");
int score = scanner.nextInt();
int level = (int) score/10;
switch(level) {
case 10:
case 9:
System.out.println("得A");
break;
case 8:
System.out.println("得B");
break;
case 7:
System.out.println("得C");
break;
case 6:
System.out.println("得D");
break;
default:
System.out.println("得E(不及格)");
79. 使用对象
• 想写一个程序取得现在的系统时间,您只
要产生一个java.util.Date工具就可以了
• Date实际上如何向系统取得时间,则无需
您来操心
Date date = new Date();
System.out.println(date.toString());
Tue May 03 16:06:46 GMT+08:00 2005
89. 小心使用boxing
• 自动装箱与拆箱的功能是编译程序来帮忙
Integer i = 100; Integer i = new Integer(100);
• 自动装箱与拆箱的功能是所谓的「编译程
序蜜糖」(Compilersugar)
Integer i = null; Integer i = null;
int j = i; int j = i.intValue();
NullPointerException
137. 使用正则表示式
• 几个常用的字符比对符号
方 法 说 明
. 符合任一字符
d 符合0到9任一个数字字符
D 符合0-9以外的字符
s 符合't'、'n'、'x0B'、'f'、'r'等空格符
w 符合a到z、A到Z、0到9等字符,也就是数字或是字母都符合
W 符合a到z、A到Z、0到9等之外的字符,也就是除数字与字母外
都符合
154. 类别成员(Classmember)
class MethodDemo {
private int data = 10;
public void scopeDemo() { // void表示没有传回值
int data = 100;
}
public int getData() {
return data;
}
public void setData(int data) { // void表示没有传回值
data = data; //这样写是没用的
//写下面这个才有用
// this.data = data;
}
}
164. 关于static
• 可以宣告方法成员为"static"方法,又称
「静态方法」
public class Ball {
...
public static double toRadian(double angle) {
return 3.14159 / 180 * angle;
}
}
System.out.println("角度90等于径度" + Ball.toRadian (90));
165. 关于static
• 静态方法中不会有this参考名称
• 静态方法中不允许使用非静态成员
non-static variable test cannot be referenced from a static context
• 在静态方法中不能呼叫非静态方法
non-static method showHello() cannot be referenced from a static context
166. 关于static
• 可以使用“static”定义一个静态区块,并在
当中撰写类别载入时的初始化动作
public class Ball {
static {
//一些初始化程序代码
}
....
}
• 在类别被加载时,默认会先执行静态区块
中的程序代码,且只会执行一次
172. 不定长度自变量
• J2SE5.0之后开始支持「不定长度自变量」
(Variable-lengthArgument)
public static int sum(int... nums) { //使用...宣告参数
int sum = 0;
for(int num : nums) {
sum += num;
}
return sum;
}
• 实际上nums是一个数组
173. 不定长度自变量
• 宣告的参数必须设定在参数列的最后一
个,下面的方式是合法的
public void someMethod(int arg1, int arg2, int... varargs) {
// ....
}
• 下面的方式是不合法的
public void someMethod(int... varargs, int arg1, int arg2) {
// ....
}
175. 递归方法
• 在方法中呼叫自身同名方法,而呼叫者本
身会先被置入内存「堆栈」(Stack)中
• 堆栈是一种「先进后出」(First in,
lastout)的数据结构
private static int gcd(int m, int n) {
if(n == 0)
return m;
else
return gcd(n, m % n);
}
185. 被保护的(protected)成员
public class Rectangle {
//受保护的member
protected int x;
protected int y;
protected int width;
protected int height;
…
}
public class CubicextendsRectangle {
…
public int getVolumn() {
//可以直接使用父类别中的width、height成员
return length*width*height;
}
}
187. 重新定义(Override)方法
public class SimpleArray {
protected int[] array;
public SimpleArray(int i) {
array = new int[i];
}
public void setElement(int i, int data) {
array[i] = data;
}
....
}
public class SafeArrayextends SimpleArray {
…
//重新定义setElement()
public void setElement(int i, int data) {
if(i < array.length)
super.setElement(i, data);
}
....
}
190. 重新定义(Override)方法
• 您可以增大父类别中的方法权限,但不可
以缩小父类别的方法权限
– 若原来成员是"public"的话,您不可以在父类别
中重新定义它为"private"或"protected"
public class SafeArray extends SimpleArray {
//不可以缩小父类别中同名方法的权限
private void setElement(int i, int data) {
....
}
}
setElement(int,int) in SafeArray cannot override
setElement(int,in t) in SimpleArray; attempting to assign
weaker accessprivileges; was publicprivate void
setElement(int i, int data) {^1 error
191.
192. 重新定义(Override)方法
• 从J2SE5.0开始在重新定义方法时,您可以
重新定义返回值的型态
public class Bird {
protected String name;
public Bird(String name) {
this.name = name;
}
public Bird getCopied {
return new Bird(name);
}
}
193. 重新定义(Override)方法
• 重新定义的返回值型态必须是父类别中同一方法
返回型态的子类别
public class Chicken extends Bird {
protected String crest;
public Chicken(String name, String crest) {
super(name);
this.crest = crest;
} //重新定义返回值型态为Chicken
publicChicken getCopied() {
return new Chicken(name, crest);
}
}
• 无法重新定义static方法
197. toString()、equals()、hashCode()
public boolean equals(Object other) {
if (this == other)
return true;
if (!(other instanceof Cat))
return false;
final Cat cat = (Cat) other;
if (!getName().equals(cat.getName()))
return false;
if (!getBirthday().equals(cat.getBirthday()))
return false;
return true;
}
public int hashCode() {
int result = getName().hashCode();
result = 29 * result + getBirthday().hashCode();
return result;
}
198. clone()方法
• 如何复制对象本身
• 最基本的作法:实作java.lang.Cloneable界
面(Interface)
public class PointimplementsCloneable { //要实作Cloneable
…
public Object clone() throws CloneNotSupportedException {
//呼叫父类别的clone()来进行复制
return super.clone();
}
}
199. clone()方法
public class TableimplementsCloneable { //要实作Cloneable
private Point center;
// …
public Object clone ()
throws CloneNotSupportedException {
//呼叫父类的clone()来复制
Table table = (Table) super.clone();
if(this.center != null) {
//复制Point类型的数据成员
table.center = (Point) center.clone();
}
return table;
}
}
223. 成员内部类别、区域内部类别
• 被宣告为static的内部类别,事实上也可以
看作是另一种名称空间的管理方式
public class Outer {
public static class Inner {
....
}
....
}
Outer.Inner inner = new Outer.Inner();
229. 设定套件(package)
• 「完全描述」(Fullyqualified)名称
– 完整的指出「套件加类别」名称
onlyfun.caterpillar.Point2D p1 = new
onlyfun.caterpillar.Point2D(10, 20);
• 最后编译完成的.class档案必须放在onlyfun
目录的caterpillar目录下
bad class file: .Point2D.classclass file contains
wrong class: onlyfun.caterpillar.Point2DPlease remove
or make sure it appears in the correct subdirectory of
the classpath.
Point2D p1 = new Point2D(10, 20);
^1 error
230. import的意义
• 您可以使用"import"关键词,告知编译程序
您所要使用的类别是位于哪一个套件
import onlyfun.caterpillar.Point2D;
public class Point2DDemo2 {
public static void main(String[] args) {
Point2D p1 = new Point2D(10, 20);
System.out.printf("p1: (x, y) = (%d, %d)%n",
p1.getX(), p1.getY());
}
}
231. import的意义
• 使用"import"指定时,可于套件指定加上'*'
import onlyfun.caterpillar.*;
public class Point2DDemo3 {
public static void main(String[] args) {
Point2D p1 = new Point2D(10, 20);
System.out.printf("p1: (x, y) = (%d, %d)%n",
p1.getX(), p1.getY());
}
}
232. import的意义
• 可能出现以下的错误讯息
bad class file: .Point2D.java
file does not contain class Point2D
Please remove or make sure it appears in the correct
subdirectory of the classpath.
• 将原始码与编译完成的档案放在一起并不
是一个好的管理方式
javac -d ./classes ./src/*.java
• 指定Classpath的方式如下执行程序
java -cp ./classes Point2DDemo3
233. import的意义
• 同名冲突
import java.util.Arrays;
import onlyfun.caterpillar.Arrays;
public class SomeClass {
....
}
java.util.Arrays is already defined in a single-type import
import onlyfun.caterpillar.Arrays;
^1 error
234. public与套件
• 没有被宣告为“public”的类别只能被同一个套件中
的类别之实例呼叫使用
Point2DDemo.java:3: onlyfun.caterpillar.Point2D is not
public in onlyfun.caterpillar; cannot be accessed from
outside package
onlyfun.caterpillar.Point2D p1 = new
• 类别成员也可以宣告为"public",宣告为"public"
的类别成员可以被其它对象呼叫使用
• 如果宣告类别时不使用"public"、"protected"或
"private"设定权限,则预设为「套件存取范围」
237. public与套件
• 定义一个类别,但没有定义建构方法时,
编译程序会自动帮您产生一个预设建构方
法
package onlyfun.caterpillar;
public class Test {
....
}
package onlyfun.caterpillar;
public class Test {
public Test() {
}
....
}
238. public与套件
• 如果您自行定义建构方法,则编译程序就
不会帮您加上预设建构方法
package onlyfun.caterpillar;
public class Test {
public Test(int i) {
...
}
....
}
• 在建构时,就必须指明使用哪个建构方法
239. public与套件
• 建议即使没有用到,在定义自己的建构方法的同
时,也加上个没有参数的建构方法
package onlyfun.caterpillar;
public class Test {
public Test() { //即使没用到,也先建立一个空的建构方法
}
public Test(int i) {
...
}
....
}
• 没有使用super()指定要使用父类别的哪个建构方
法,则预设会寻找父类别中无参数的建构方法
240. public与套件
• 预设建构方法的访问权限是跟随着类别的
访问权限而设定
package onlyfun.caterpillar;
public class Test {}
• 由于类别宣告为public,所以预设建构方法
访问权限為public
241. public与套件
• 如果是以下的话
package onlyfun.caterpillar;
class Test {}
• 则预设建构方法访问权限为套件访问权
限,也就是编译程序会自动为您扩展为
package onlyfun.caterpillar;
class Test {
Test() { }
}
242. public与套件
存取修饰 同一类别 同一套件 子类别 全局
private OK
(default) OK OK
protected OK OK OK
public OK OK OK OK
243. import静态成员
import static java.lang.System.out;
public class HelloWorld {
public static void main(String[] args) {
out.println("Hello! World!");
}
}
import static java.lang.System.out;
import static java.util.Arrays.sort;
public class ImportStaticDemo {
public static void main(String[] args) {
int[] array = {2, 5, 3, 1, 7, 6, 8};
sort(array);
for(int i : array) {
out.print(i + " ");
}
}
}
251. 受检例外、执行时期例外
• 如果您不在程序中处理的话,例如将
IOException的"catch"区块拿掉
CheckedExceptionDemo.java:9: unreported exception
java.io.IOException; must be caught or declared to be
thrown
263. 常数设置
• 可使用接口来定义操作时所需的共享常数
public interface ActionConstants {
public static final int TURN_LEFT = 1;
public static final int TURN_RIGHT = 2;
public static final int SHOT = 3;
}
264. 常数设置
public void someMethod() {
....
doAction(ActionConstants.TURN_RIGHT);
....
}
public void doAction(int action) {
switch(action) {
case ActionConstants.TURN_LEFT:
System.out.println("向左转");
break;
case ActionConstants.TURN_RIGHT:
System.out.println("向右转");
break;
case ActionConstants.SHOOT:
System.out.println("射击");
break;
}
}
265. 常数设置
• 使用类别来宣告的话
public class CommandTool {
public static final String ADMIN = "onlyfun.caterpillar.admin";
public static final String DEVELOPER =
"onlyfun.caterpillar.developer";
public void someMethod() {
// ....
}
}
• 如果常数只是在类别内部使用的话,就宣
告其为“private”或是“protected”就可以了
– 宣告为类别外可取用的常数,通常是与类别功
能相依的常数