高级java实验指导书(1)

(1)输出下面程序的运行结果。 public class TestTreeSet { public static void main(String []args){ Set set = new HashSet(); set.add(\); set.add(\); set.add(\); set.add(\); set.add(\); set.add(\); TreeSet set2 = new TreeSet(set); System.out.println(\+set2); System.out.println(\+set2.first()); System.out.println(\+set2.last()); \+set2.headSet(\ System.out.println(\york\)); \+set2.tailSet(\ System.out.println(\york\)); System.out.println(\+set2.lower(\)); System.out.println(\+set2.higher(\)); System.out.println(\+set2.floor(\)); System.out.println(\+set2.ceiling(\)); System.out.println(\+set2.pollFirst()); System.out.println(\+set2.pollLast()); System.out.println(\+set2); } }

(1)————————

(2)输出下面程序的运行结果。

5

Public class Test{ Public static void main(String [] args){ Map map = new LinkedHashMap(); map.put(\ Smith\map.put(\ Smith\map.put(\map.put(\System.out.println(\System.out.println(\} } (2)__________________ 三、根据下面要求编写程序

1、编写一个程序,读取一个java源代码文件,然后报告该文件中关键字的个数。从命令行传递这个java源文件。

2、编写一个程序,从文本文件读取单词,并按字母的升序显示所有的单词(可以重复),文本文件被作为命令行参数传递。

四、实验结果

写实验报告。内容包括:

1、习题的运行结果,源程序。 2、程序调试中出现的错误提示。(英文、中文对照) 3、若有没通过的程序,分析原因。

五、选做题目

1、写出Comparable和Comparator 两个接口的不同之处,以及各自的方法。 2、编写一条语句,找出由可以比较的对象构成的数组中的最大元素。 3、用UML图描述HashMap、LinkedHashMap、TreeMap。

实验2 类型信息与反射

6

一、实验目的

1、了解类型信息的基本概念、类型信息的存储、类型信息的加载以及类型信息的表示。

2、了解什么是反射、为什么需要反射以及深入反射机制。 3、深入了解Class类,通过Class对象实现反射机制。 4、了解代理模式以及如何实现动态代理。

二、实验内容

1、验证实验 (1)输入如下程序,编译看在bin目录下有无一个与此类同名的.class文件。

Public class Person{

} (2)输入如下程序,编译后看在bin目录下会产生多少个.class文件,这些文件名的命名方式是怎样的?

Public class Person{ class Tool{ } interface Communication{ } } (3)输入如下程序,编译并运行写出输出结果。 public class Bootstrap {

static{

System.out.println(\

}

public static void main(String[] args) {

ClassLoader loader = Bootstrap.class.getClassLoader();

System.out.println(loader);

System.out.println(loader.getParent());

System.out.println(loader.getParent().getParent());

7

2、程序填空题

(1)如下程序,利用反射机制在Bootstrap中获得Person类的构造方法。请填写缺失代码。 public class Person {

} public Person(){} public Person(String name){} public Person(String name,int age){} protected Person(boolean sex){}; private Person(Date birthday){}; public class Bootstrap { public static void main(String[] NoSuchMethodException { Class clazz = Person.class; ———————————— ———————————— ———————————— ———————————— } } args) throws SecurityException, (2)如下代码,利用反射机制在Bootstrap中获得Person类的方法。请把缺失的代码补全。

public abstract class Person { public void speak(){}; protected void useTool(){}; private void useTool(String toolName){}; public void eat(String food){}; public static void listen(){}; protected abstract void listen(String destination); } public class Bootstrap { public static void main(String[] NoSuchMethodException { Class clazz = Person.class; —————————— —————————— —————————— } } 3、根据下面的要求编写程序。 8 args) throws SecurityException,

联系客服:779662525#qq.com(#替换为@)