安徽工业大学2012-2013期末考试Java题考前整理_第1页
安徽工业大学2012-2013期末考试Java题考前整理_第2页
安徽工业大学2012-2013期末考试Java题考前整理_第3页
安徽工业大学2012-2013期末考试Java题考前整理_第4页
安徽工业大学2012-2013期末考试Java题考前整理_第5页
已阅读5页,还剩16页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1 Java 中对数据库查询结果集进行操作的对象是 中对数据库查询结果集进行操作的对象是 D A Connection 对象对象 B Statement 对象对象 C DriverManager 对象对象 D ResultSet 对象对象 2按运算符操作数的数目划分 运算符 的类型是 A A 三目 B 双目 C 四目 D 单目 3 有关在有关在 Java 中定义实例方法和类方法的叙述正确的是 中定义实例方法和类方法的叙述正确的是 D A 前者有 前者有 public 修饰 后者没有修饰 后者没有 public 修饰修饰 B 前者没有 前者没有 public 修饰 后者有修饰 后者有 public 修饰修饰 C 前者有 前者有 static 修饰 后者没有修饰 后者没有 static 修饰修饰 D 前者没有 前者没有 static 修饰 后者有修饰 后者有 static 修饰修饰 4 Java 代码 g drawLine 100 100 100 100 的功能是 B A 画一个圆 B 画一条线段 C 画一个点 D 代码是错误的 5有有 Java 语句如下 则说法正确的是 语句如下 则说法正确的是 C int a b new int 3 1分分 A 此语句是错误的 此语句是错误的 B a length 的值为的值为3 C b length 的值为的值为3 D a length 和和 b length 的值都为的值都为3 6 以下程序代码的输出结果是 以下程序代码的输出结果是 B System out println 100 8 1分分 A 12 5 B 12 C 4 D 0 7 在 Java 语言中 一般不作为容器使用的是 C A JDialog B JFrame C JTextArea D JPanel 8 在 Java 语言中 把按钮 button 的标题文字设置为 第一个按钮 的方法是 A A button SetText 第一个按钮 B button GetText 第一个按钮 C button SetLabel 第一个按钮 D button GetLabel 第一个按钮 9 在 在 Java 程序中声明一个数组 错误的是 程序中声明一个数组 错误的是 C A int a B int a C float a 10 D float a 10 在 在 Java 程序中有定义 程序中有定义 int x new int 4 5 则则 x length 和和 x 3 length 的值分别是 的值分别是 A A 4和和5 B 5和和4 C 4和和3 D 5和和3 11 定义一个使用接口 Java lang Runnable 的类 必须要实现的方法是 1分 B A start B run C init D paint 12 如果发生多个线程形成一个等待环 这样 所有线程都陷入相互等待的状态 这种循环等 待现象称为 1分 C A 互斥 B 同步 C 死锁 D 临界 13 下列关于线程的说法正确的是 下列关于线程的说法正确的是 D A 一个线程被创建 它就立即开始运行 一个线程被创建 它就立即开始运行 B 使用 使用 start 方法可以使一个线程立即开始运行方法可以使一个线程立即开始运行 C 当一个线程因为抢先机制而停止运行时 它被放在可运行队列的前面 当一个线程因为抢先机制而停止运行时 它被放在可运行队列的前面 D 一个正在运行的线程可能因为某些情况而进入阻塞状态 一个正在运行的线程可能因为某些情况而进入阻塞状态 14 在 Java 程序中有代码如下 System out println new StringTokenizer I am a student a countTokens 则输出结果为 1分 c A I am a student B 2 C 3 D 4 15 定义一个使用接口 定义一个使用接口 Java lang Runnable 的类 必须要实现的方法是 的类 必须要实现的方法是 B A start B run C init D paint 16 在编写 Java 程序访问数据库的过程中 用来处理驱动程序的加载和建立新数据库连接的类 是 1分 A A DriverManager 类 B Statement 类 C Connection 类 D ResultSet 类 17 以下是创建 以下是创建 File 对象的代码 错误的是 对象的代码 错误的是 D A File f1 new File mydir myfile txt B File f2 new File mydir myfile txt C File f3 new File mydir myfile txt D File f4 new File mydir myfile txt 18 在 Java 语言中执行如下语句后 i 和 j 的值分别为 int i 10 int j i 1分 A A 11和11 B 10和10 C 10和11 D 11和10 19 JAVA 中为字符型输入 输出流提供的读字符的方法所使用的类是 C A InputStream B OutputStream C FIleReader D FileWriter 20 以下程序代码的输出结果是 以下程序代码的输出结果是 D int x 100 System out println 5 5 x 8 1分分 A 5 512 B 5 512 5 C 18 D 5 54 21 下列哪些字符串匹配模式 boy w 3 题目错了 A boy111 B boy C boyweo D boyboyboyboy 22下列哪个关键可用来定义 Java 常量 C A public B static C final D void 23 在 在 Java 程序中有代码如下 程序中有代码如下 System out println new StringTokenizer I am a student a countTokens 则输出结果为 则输出结果为 1分分 C A I am a student B 2 C 3 D 4 24 为 为8位字节流数据提供读操作支持的类是 位字节流数据提供读操作支持的类是 1分分 A A FileInputStream B FileOutputStrem C FileReader D FileWriter 25 下列有关抽象类及抽象方法的叙述错误的是 下列有关抽象类及抽象方法的叙述错误的是 1分分 A A 使用 使用 final 修饰的类是抽象类修饰的类是抽象类 B 使用 使用 abstract 修饰的方法是抽象方法修饰的方法是抽象方法 C 抽象类必须被继承才能使用 抽象类不可能有实例 抽象类必须被继承才能使用 抽象类不可能有实例 D 抽象类可以没有抽象方法 但有抽象方法的类一定是抽象类 抽象类可以没有抽象方法 但有抽象方法的类一定是抽象类 26 设 x 40 则执行 y x x 1 后 x y 的结果分别为 D A 42 80 B 41 81 C 43 82 D 42 83 27 在编写 Java Application 程序时 若需要使用到标准输入输出语句 必须 在程序的开头写上 语句 C A import java awt B import java applet Applet C import java io D import java awt Graphics 28 有关 Java 语言的特点 哪种是错误的 D A 多态 B 可移植 C 多线程 D 手动垃圾回收 29 J2SE 是 B A Java 企业平台 B Java 标准平台 C Java 小型平台 D Java 小型平台第二版 31 下列哪种操作不会跑出异常 下列哪种操作不会跑出异常 A A 浮点数除以浮点数除以0得到得到 InfinityB i 0 0 C 打开不存在的文件打开不存在的文件 D a 1 100 32 于 于 length 表述正确的是 表述正确的是 C A 数组有数组有 length 方法 方法 String 也有也有 length 方法 方法 A 数组有数组有 length 方法 方法 String 没有没有 length 方法 方法 A 数组没有数组没有 length 方法 方法 String 有有 length 方法 方法 A 数组没有数组没有 length 方法 方法 String 也没有也没有 length 方法 方法 33 下列正确的句子是 下列正确的句子是 1分分 D A float 3 14 B byte i 225 C int k 33L D int p 34 在在 Java 语言中执行如下语句后 语言中执行如下语句后 i 和和 j 的值分别为 的值分别为 A int i 10 int j i 1分分 A A 11和和11 B 10和和10 C 10和和11 D 11和和10 35 当使用 当使用 FileInputStream 类中的类中的 read 方法时 如果没有读入一个字节数据时 方法时 如果没有读入一个字节数据时 返回值为 返回值为 B A 0 B 1 C true D false 36 下列程序的输入结果是 B StringBuffer buf1 new StringBuffer 20 buf1 append student System out println buf1 length buf1 capacity A 20 20 B 7 20 C 0 20 D 0 0 39 一个实现 一个实现 Runnabel 接口的类必须要实现的方法是 接口的类必须要实现的方法是 B A start B run C sleep D init 40 下列有关 下列有关 Java 的叙述错误的是 的叙述错误的是 1分分 D A 强类型语言 强类型语言 B 与平台无关 与平台无关 C 可以使用汉字变量名 可以使用汉字变量名 D 不检查数组下标越界 不检查数组下标越界 41下列有关数组的叙述错误的是 下列有关数组的叙述错误的是 1分分 D A 数组是将一组相同类型的数据顺序存储 组成一种复合数据类型 数组是将一组相同类型的数据顺序存储 组成一种复合数据类型 B 在 在 Java 语言中 数组是一种引用类型 数组名如同对象名一样 是一种引用语言中 数组是一种引用类型 数组名如同对象名一样 是一种引用 C 对于多维数组 从最高维开始 可以对每一维分配不等长的空间 对于多维数组 从最高维开始 可以对每一维分配不等长的空间 D 在 在 Java 语言中 数组元素可以互相赋值 而数组名不能直接赋值语言中 数组元素可以互相赋值 而数组名不能直接赋值 42 当线程当线程 A 使用某个对象 而此对象又需要线程使用某个对象 而此对象又需要线程 B 修改后才能符合修改后才能符合 A 线程的需要 线程的需要 这时线程这时线程 A 就要等待线程就要等待线程 B 完成修改工作 这种现象称为 完成修改工作 这种现象称为 1分分 A A 线程的同步 线程的同步 B 线程的互斥 线程的互斥 C 线程的调度 线程的调度 43 StringBuffer 类的字符对象的长度是 类的字符对象的长度是 B A 固定长度固定长度 B 可变长度可变长度 C 长度必须小于长度必须小于16个字符个字符 D 长度必须大于长度必须大于 16个字符个字符 44 对于 对于 catch 子句的排列 下列正确的是 子句的排列 下列正确的是 B A 父类在前 子类在后父类在前 子类在后 B 父类在后 子类在前父类在后 子类在前 C 有继承关系的异常类不有继承关系的异常类不 能在同一个能在同一个 try 内内 D 必须有必须有 Exception 类的类的 Catch 捕捉捕捉 二 阅读下列程序 写出程序运行结果 二 阅读下列程序 写出程序运行结果 1 class A int x y A int xx int yy x xx y yy interface A3202 int f3202 A a interface B3202 int g3202 public class C3202 extends A implements A3202 B3202 A a new A x y C3202 int x int y super x y this x x x this y y y public int f3202 A a return x a x x a y public int g3202 return x a x x a y public static void main String args int x 10 y 20 A a new C3202 x y C3202 c new C3202 x y System out println a x a y System out println c f3202 a System out println c g3202 100 400 50000 3000 2 class A B obj A obj new B obj print System out println AAA class B public void print System out println BBB public class Class3202 public static void main String arg A obj new A BBB AAA 3 写出下面程序的运行结果 写出下面程序的运行结果 public class Class34ThreadTest public static void main String args Hello h new Hello Thread t new Thread h t start class Hello implements Runnable int i public void run while true System out println Hello i if i 5 break Hello0 Hello1 Hello2 Hello3 Hello4 4 publicpublic classclass AAAAaAAAAa publicpublic staticstatic voidvoid main Stringmain String arg arg StringString str con index php str con index php StringString regex regex StringString s str split regex s str split regex for intfor int i 0 i s length i i 0 i s length i System out println s i System out println s i www sina com con index php 5 publicpublic classclass BBBBB BBBBB publicpublic staticstatic voidvoid main String main String args args bytebyte d d 我是一个学生工大的我是一个学生工大的sdfsd getBytes sdfsd getBytes System out println System out println 数组数组d d的长度 的长度 d length d length StringString s news new String d 10 2 String d 10 2 System out println s System out println s 数组d的长度 23 生 6 importimport java io java io publicpublic classclass CCCCCCCCCC publicpublic staticstatic voidvoid main Stringmain String args args FileFile file newfile new File hello txt File hello txt charchar b b 北京欢迎你北京欢迎你 toCharArray toCharArray try try FileWriterFileWriter out newout new FileWriter file writingFileWriter file writing out write b out write b out write out write 你好中国你好中国 out close out close FileReaderFileReader in newin new FileReader file readingFileReader file reading intint n 0 n 0 while n in read b 0 2 1 while n in read b 0 2 1 StringString str newstr new String b 0 2 String b 0 2 System out println str System out println str in close in close catch IOExceptioncatch IOException e e System out println e System out println e System out println b newSystem out println b new String b String b 北京 欢迎 你你 好中 国中 b 国中欢迎你 7 写出下面程序的运行结果写出下面程序的运行结果 class Employee private int id private byte sex private String name private String duty private float salary private int holidays public Employee int id byte sex String name String duty float salary int holidays this id id this sex sex this name name this duty duty this salary salary this holidays holidays public String getDuty return duty public void setDuty String duty this duty duty public int getHolidays return holidays public void setHolidays int holidays this holidays holidays public int getId return id public void setId int id this id id public String getName return name public void setName String name this name name public float getSalary return salary public void setSalary float salary this salary salary public byte getSex return sex public void setSex byte sex this sex sex display 无返回值 该方法能打印员工的姓名 性别以及职务 param employee public void display Employee employee System out println 员工姓名为 employee getName if employee getSex 1 System out println 员工性别为 男 else if employee getSex 2 System out println 员工性别为 女 System out println 员工职务为 employee getDuty getDecMoney int day 返回值是 int 型 如果请假天数 3 则扣款为 30 请假天数 如果请假天数超过 3 天 则扣款为 50 请假天数 param day return public int getDecMoney int day int deduction 0 扣除的工资 if day 4 deduction 44 day return deduction public static void main String args 创建一个员工类的对象 Employee employee new Employee 123456789 byte 1 的 生产帽子的 color float 300 8 3 employee display employee 调用 display int deduction employee getDecMoney employee getHolidays 调用 getDecMoney System out println 该员工因请假扣除工资 deduction 元 员工姓名为 的 员工性别为 男 员工职务为 生产帽子的 color 该员工因请假扣除工资 90 元 8 classclass ancestorClassancestorClass privateprivate intint a 8 a 8 protectedprotected intint b 15 b 15 voidvoid f f System out print a b System out print a b voidvoid g g System out print ancestorClass System out print ancestorClass FunctionFunction g g hashas beenbeen called called publicpublic classclass TestTest extendsextends ancestorClassancestorClass intint c 5 c 5 publicpublic voidvoid f f System out println b c System out println b c publicpublic voidvoid testfun testfun System out println son System out println son functionfunction testfuntestfun hashas beenbeen called called publicpublic staticstatic voidvoid main Stringmain String args args ancestorClassancestorClass sc newsc new ancestorClass ancestorClass sc f sc f sc g sc g sc newsc new Test Test Test sc testfun Test sc testfun 120ancestorClass Function g has been called son function testfun has been called 9 class Test float F public double getF float F F return this F public static void main String args System out println new Test getF 10 0 0 10 classclass putOutDataputOutData extendsextends ThreadThread public public voidvoid run run for intfor int i 2 i 10 i i 2 i 10 i System out printSystem out print i i classclass TestTest publicpublic staticstatic voidvoid main Stringmain String args args throwsthrows InterruptedExceptionInterruptedException Thread Thread th newth new putOutData putOutData th start th start System out print System out print 程序结束啦 程序结束啦 程序结束啦 2 3 4 5 6 7 8 9 10 四 简答四 简答 1 什么是上转型对象 什么是上转型对象 2 什么叫接口回调 什么叫接口回调 3 什么是正则表达式 写出与模式 什么是正则表达式 写出与模式 A 13568 3 匹配的几个字符串 匹配的几个字符串 4 程序 线程和进程的关系 程序 线程和进程的关系 5 线程有 线程有 4 种状态 种状态 6 FileInputStream 流的流的 read 方法和 方法和 FileReader 流的流的 read 方法有何不同 它们的文 方法有何不同 它们的文 件输出流分别对应哪个类 件输出流分别对应哪个类 7 java 的方法重写继承的方法的规则是什么 的方法重写继承的方法的规则是什么 8 String 和 StringBuffer 的区别 9 子类继承方法时 可以降低方法的访问权限吗 五 程序设计题五 程序设计题 1 编写一个方法 编写一个方法 string3703 要求在一个字符串数组中找出长度最长的一个元素 其中 要求在一个字符串数组中找出长度最长的一个元素 其中 字符串数组是方法的参数 最长的一个元素是方法的返回值 字符串数组是方法的参数 最长的一个元素是方法的返回值 6分分 public static String string3703 String ary String max ary 0 for int i 1 i ary length i if max length ary i length max ary i return max 2 应用程序 求整数文件应用程序 求整数文件 intfile1 txt 中各行整数的和 并把和存入到另一个文件中各行整数的和 并把和存入到另一个文件 intfile2 txt 中 设整数文件中全是整数 整数序列被分成行 各行整数个数不等且用中 设整数文件中全是整数 整数序列被分成行 各行整数个数不等且用 空格分隔 要求程序将文件中各行整数的和及乘积输出在另一个文件中 空格分隔 要求程序将文件中各行整数的和及乘积输出在另一个文件中 6分分 infile1 Txt Infile2 txt 1 2 3 4 10 24 1 2 3 6 6 5 6 11 30 import java io import java util public class IntFile public static void main String args try BufferedReader in new BufferedReader new InputStreamReader new FileInputStream intfile1 txt gbk PrintWriter out new PrintWriter new OutputStreamWriter new FileOutputStream intfile2 txt gbk String s while s in readLine null int sum 0 int product 1 int acc 0 String ary1 s split for int i 0 i1 char ary2 ary1 i toCharArray int a 0 for int k ary1 i length 1 k 0 k int m int ary2 k 0 double m2 m Math pow 10 a acc int acc m2 sum int sum m2 product product acc acc 0 else char ary3 new char ary1 i length for int j 0 j ary1 i length j ary3 j ary1 i charAt j if ary3 j int n int ary3 j 0 sum sum n product product n out println sum product in close out close catch FileNotFoundException e System out println 文件找不到 e catch IOException e System out println 文件读写错 e 有集合有集合 A 1 2 3 4 和和 B 1 3 7 9 11 编写一个应用程序输出 编写一个应用程序输出 A 和和 B 交集 并集和差交集 并集和差 集 集 import java util public class Example public static void main String args Integer one new Integer 1 Integer two new Integer 2 Integer three new Integer 3 Integer four new Integer 4 Integer seven new Integer 7 Integer nine new Integer 9 Integer eleven new Integer 11 HashSet A new HashSet HashSet B new HashSet HashSet tempSet new HashSet A add one A add two A add three A add four B add one B add two B add seven B add nine B add eleven tempSet HashSet A clone A removeAll B A B 差集 A B removeAll tempSet B A 的差集 B addAll A A B U B A B int number B size System out println A和B的对称差集合有 number 个元素 Iterator iter B iterator while iter hasNext Integer te iter next System out printf d te intValue 4 球两个日子之间的天数球两个日子之间的天数 Calendar calendar new GregorianCalendar calendar set 2004 9 1 long time1949 calendar getTimeInMillis calendar set 2005 9 1 long time2005 calendar getTimeInMillis long 相隔天数 time2005 time1949 1000 60 60 24 System out print

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论