1
实验项目列表
序号
实验项目名称
成绩
1
J2SDK 的安装和设置
2
简单的 Application 和 Applet
3
JAVA 语言基础
4
JAVA 的类和对象
5
面向对象高级编程
6
JAVA 的核心 API
7
异常处理
8
多线程
9
Applet
10
GUI 与事件处理
11
输入输出处理
12
综合实验
2
实验一:J2SDK 的安装和设置
安装成功后运行 javac 的结果:
实验二:简单的 Java Application 和 Applet
2.1 简单的 Java Application
源程序:
/**
*The HelloWorldApp class implements an application that
*displays "Hello World!"to the standard output.
*/
public class HelloWorldApp{
public static void main(String[] args){
//Display "Hello World!"
System.out.println("Hello World!");
}
}
运行结果:
修 改 后 : 显 示 一 个 错 误 。 原 因 : 类 的 名 字 与 文 件 名 不 同 。
3
2.2 简单的 Java Applet
源程序:
import java.awt.Graphics;
import java.applet.Applet;
public class HelloWorldApplet extends Applet{
public void paint(Graphics g){
g.drawString("Hello World",25,25);
}
}
运行结果:
修改后:结果没有显示“Hello World”。
实验三:Java 语言基础
3.1:变量定义与基本数据类型
(1)源程序:
public class JLab0301{
public static void main(String[] args){
boolean b=true;
short si=128;
int i=-99;
long l=123456789l;
char ch='J';
float f=3.1415926f;
double d=-1.04e-5;
System.out.println();
System.out.println("布尔型变量 b="+b);
System.out.println("短整型变量 si="+si);
System.out.println("整型变量 i="+i);
System.out.println("长整型变量 l="+l);
System.out.println("字符型变量 ch="+ch);
System.out.println("浮点型变量 f="+f);
System.out.println("双精度型变量 d="+d);
}
}
4
运行结果:
(2)运行结果:
(3)运行结果: error 溢出
3.2:基本算术运算符
(1)预测输出:
10
4
21
2
1
10
12
27
21
(2)源程序:
class JLab0302{
public static void main(String[] args){
int a=7;
int b=3;
5
System.out.println(a+b);
System.out.println(a-b);
System.out.println(a*b);
System.out.println(a/b);
System.out.println(a%b);
System.out.println(a++ +b);
System.out.println(++a+b);
System.out.println(a--*b);
System.out.println(--a*b);
}
}
运行结果:与预测一致
(3)结果和(2)不同
3.3 循环语句
(1)源程序:
class JLab0303_1{
public static void main(String[] args){
int numChips=1;
System.out.println("Open the bag and ...");
do{
System.out.println("can't stop ...");
numChips=numChips+1;
}while(numChips<6);
System.out.println("CAN'T STOP!");