JavaSe题库15
- 格式:docx
- 大小:18.09 KB
- 文档页数:6
javase练习题一、基础知识篇1. Java基本数据类型有哪些?分别写出它们的默认值。
2. 什么是封装?简述封装的优点。
3. 请写出Java中的四种访问修饰符,并说明它们的访问权限。
4. 什么是构造方法?它与普通方法的区别是什么?5. 在Java中,如何实现方法的重载和重写?二、面向对象篇2. 如何实现一个简单的Java类,包含两个属性和一个方法?3. 简述Java中的继承机制及其作用。
4. 什么是接口?与抽象类有什么区别?5. 请举例说明Java中的多态性。
三、集合框架篇1. Java集合框架中常用的集合类有哪些?2. 请简述ArrayList和LinkedList的区别。
3. 什么是HashMap?它的工作原理是什么?4. 请解释HashSet和TreeSet的区别。
5. 如何遍历一个List集合?四、异常处理篇1. 什么是异常?Java中的异常分为哪几类?2. 请举例说明trycatchfinally语句的使用方法。
3. 什么是自定义异常?如何创建和使用自定义异常?4. 请简述Java异常处理机制的作用。
int a = 10;int b = 0;int result = a / b;五、IO流篇1. 请简述Java IO流的分类。
2. 如何实现文件复制功能?3. 请解释字节流和字符流的区别。
4. 什么是序列化和反序列化?如何实现?5. 请举例说明Java中的文件操作。
六、多线程篇1. 什么是线程?线程和进程有什么区别?2. 请简述线程的生命周期。
3. 如何创建一个线程?有哪几种方式?4. 什么是线程同步?为什么需要线程同步?5. 请解释线程池的概念及其作用。
七、网络编程篇1. 请简述TCP和UDP协议的区别。
2. 如何实现一个简单的Socket通信?3. 什么是URL?如何解析一个URL?4. 请简述HTTP协议的工作原理。
5. 如何实现一个简单的HTTP服务器?八、Java新特性篇1. 请列举Java 8中的几个新特性。
2020年JAVASE综合考试试题库188题[含答案]一、选择题1.以下哪些集合接口支持重复元素存在?答案:BA.CollectionB.ListC.MapD.Set2.定义在Math类上的round(double d)方法的返回值类型是什么?答案:A.charB.intC.longD.double3.以下哪个方法用于计算平方根?答案:BA.squareRoot()B.sqrt()C.root()D.sqr()4.调用Math.random()方法最有可能输出以下哪些结果?答案:DA.-0.12和0.56E3B.0.12和1.1E1C.-23.45和0.0D.0.356和0.035."以下代码的输出结果是什么?public class Example {public static void main(String[] args) {System.out.println(Math.round(Float.MAX_V ALUE));}}"答案:BA.输出Integer.MAX_V ALUEB.输出一个最接近Float.MAX_V ALUE的整数C.编译失败D.运行时输出异常信息6."以下代码的运行结果是什么?public class Example {public static void main(String[] args) {System.out.println(Math.min(0.0, -0.0));}}"答案:CA.代码编译失败B.输出0.0C.输出-0.0D.代码编译成功,但运行时输出异常信息7."给出以下代码,为了结果输出-12.0,方法method(d)应为以下哪个方法?public class Example {public static void main(String[] args) {double d = -11.1;double d1 = method(d);System.out.println(d1);}}"答案: AA.floor()B.ceil()C.round()D.abs()8."给出以下代码,请问在程序的第6行插入那条语句,改程序可依次打印输出11、10、9?1.public class Example {2. public static void main(String[] args) {3. double x[] = { 10.2, 9.1, 8.7 };4. int i[] = new int[3];5. for (int a = 0; a < x.length; a++) {6.7. System.out.println(i[a]);8. }9. }10.}"答案:CA.i[1] = ((int)Math.min(x[a]));B.i[1] = ((int)Math.max(x[a]));C.i[1] = ((int)Math.ceil(x[a]));D.i[1] = ((int)Math.floor(x[a]));9."以下代码执行结果是?public class Example {public static void main(String[] args) {System.out.println(Math.min(Float.NaN, Float.POSITIVE_INFINITY)); }}"答案:AA.输出NaNB.打印输出InfinityC.运行时异常,因为NaN不是有效的参数D.运行时异常,因为Infinity不是有效的参数10.下列哪些项是泛型的优点?答案:AA.不用向下强制类型转换B.代码容易编写C.类型安全D.运行速度快11."以下代码的执行结果是?public class Example {public static void main(String[] args) {File f = new File(""c:\\large.txt"");}}"答案:rge.txt文件在本地硬盘上被创建B.在Unix系统上运行失败,因为路径分割符不正确rge.txt文件在本地硬盘上没有被创建D.如果large.txt文件已经存在,则一个异常被抛出12.以下哪些有关Vector类的描述是正确的?答案:CA.该类是个public类B.该类是个final类C.该类实现了List接口D.该类可以序列化13."以下代码的输出结果是什么?选择所有的正确答案。
2020年JAVASE综合考试试题库188题[含答案]一、选择题1."下列代码执行后的输出是哪项?public class Example {public static void main(String[] args) {List<String> al = new ArrayList<String>();al.add(""1"");al.add(""2"");al.add(""2"");al.add(""3"");System.out.println(al);}}"答案:A.[1,2,3]B.[1,2,3,3]C.[1,2,2,3]D.[2,1,3,2]2.调用Math.random()方法最有可能输出以下哪些结果?答案:DA.-0.12和0.56E3B.0.12和1.1E1C.-23.45和0.0D.0.356和0.033."以下代码的运行结果是什么?public class Example {public static void main(String[] args) {System.out.println(Math.min(0.0, -0.0));}}"答案:CA.代码编译失败B.输出0.0C.输出-0.0D.代码编译成功,但运行时输出异常信息4."以下代码的运行结果是什么?public class Example {public static void main(String[] args) {double d1 = -0.5;System.out.println(""Ceil d1="" + Math.ceil(d1));System.out.println(""Floor d1="" + Math.floor(d1));}}"答案:BA.输出Ceil d1=-0.0 Floor d1=-1.0B.输出Ceil d1=0.0 Floor d1=-1.0C.输出Ceil d1=-0.0 Floor d1=-0.0D.输出Ceil d1=0.0 Floor d1=0.05."给出以下代码,请问在程序的第6行插入那条语句,改程序可依次打印输出11、10、9?1.public class Example {2. public static void main(String[] args) {3. double x[] = { 10.2, 9.1, 8.7 };4. int i[] = new int[3];5. for (int a = 0; a < x.length; a++) {6.7. System.out.println(i[a]);8. }9. }10.}"答案:CA.i[1] = ((int)Math.min(x[a]));B.i[1] = ((int)Math.max(x[a]));C.i[1] = ((int)Math.ceil(x[a]));D.i[1] = ((int)Math.floor(x[a]));6."以下代码执行结果是?public class Example {public static void main(String[] args) {System.out.println(Math.min(Float.NaN, Float.POSITIVE_INFINITY));}}"答案:AA.输出NaNB.打印输出InfinityC.运行时异常,因为NaN不是有效的参数D.运行时异常,因为Infinity不是有效的参数7.下列哪些项是泛型的优点?答案:AA.不用向下强制类型转换B.代码容易编写C.类型安全D.运行速度快8.以下哪些是Collection接口的子接口?答案:BDA.DictionaryB.ListC.MapD.Set9.以下哪些有关Vector类的描述是正确的?答案:CA.该类是个public类B.该类是个final类C.该类实现了List接口D.该类可以序列化10.表示键值对概念的接口是哪项?答案:DA.SetB.ListC.CollectionD.Map11.现有int x = reader.read(),下列哪一项正确?答案:A.reader不是FileReader或者BufferedReader类型B.reader可以使FileReader或者BufferedReaderC.reader可以使FileReader类型,但不能使BufferedReader类型D.reader可以使BufferedReader类型,但不能使FileReader类型12.创建一个只能存放String的泛型ArrayList的语句是哪项?答案:BA.ArrayList<int> al = new ArrayList<int>();B.ArrayList<String> al = new ArrayList<String>();C.ArrayList al = new ArrayList<String>();D.ArrayList<String> al = new List<String>();13.以下哪个方法是Math类中定义的?答案:A.absolute()B.log()C.cosine()D.sine()14."现有:list是一个合法的集合引用getCollection()返回一个合法集合的引用,以下语句哪些是合法的?" 答案:CA.for(Object o : list)B.for(Object o : getCollection())C.for(Object o : list.iterator())D.for(Iterator I;list.iterator();i.hasNext())15."以下代码的执行结果是?public class Example {public static void main(String[] args) {TreeSet<String> t = new TreeSet<String>();if (t.add(""one""))if (t.add(""two""))if (t.add(""three""))t.add(""four"");for (String s : t) {System.out.print(s);}}}"答案:DA.oneB.onethreetwoC.onetwothreefourD.fouronethreetwo16."现有:public class Example {public static void main(String[] args) {TreeSet<String> s = new TreeSet<String>();s.add(""one"");s.add(""two"");// 插入代码处for (String s2 : sorted) {System.out.print(s2 + "" "");}}}和四个代码片段:s1:SortedSet sorted = s.tailSet(s.first());s2:SortedSet<String> sorted = s.tailSet(s.first());s3:SortedSet sorted = (SortedSet)s.tailSet(s.first());s4:SortedSet sorted = (SortSet<String>)s.tailSet(s.first());分别插入到插入代码处,哪项可以编译?"答案:A.S2B.S2和S3C.S2和S4D.S2、S3和S417.以下哪些语句用于创建一个Map实例?答案: DA.Map m = new Map();B.Map m = new Map(init capacity,increment capacity);C.Map m = new Map(new Collection());D.以上都不对18."现有如下类型:a - java.util.Hashtableb - java.util.Listc - java.util.ArrayListd - java.util.SortedSet和定义:1-使用本接口,允许用户控制集合中每个元素的插入位置2-使用本集合,确保用户可以按照递增或元素的自然顺序遍历集合3-本具体类型允许空元素及基于索引的访问4-本集合是同步的哪一组匹配是对的?"答案:A.2描述d,3描述bB.1描述b,3描述cC.3描述a,4描述bD.4描述a,2描述c19."现有:public class Example {public static void main(String[] args) {//插入代码处c.put(""X"", 123);}}下列哪些插入到插入代码处能够正常编译?"答案:A.Map c = new SortedMap();B.HashMap c = new HashMap();C.SortedMap c = new TreeMap();D.Map c = new LinkedHashMap();20.以下哪些类提供了创建一个目录的方法?答案:AA.FileB.DataOutputC.DirectoryD.FileDescriptor21."以下代码的执行结果是?public class Example {public static void main(String[] args) {File f = new File(""c:\\large.txt"");}}"答案:rge.txt文件在本地硬盘上被创建B.在Unix系统上运行失败,因为路径分割符不正确rge.txt文件在本地硬盘上没有被创建D.如果large.txt文件已经存在,则一个异常被抛出22."现有如下代码:public class Example {public static void main(String[] args) {try {int x=Integer.parseInt(""42a"");//插入代码处System.out.println(""oops"");}}}在插入代码处插入哪些语句可以在运行后输出oops?"答案:CA. } catch (IllegalArgumentException e) { (非法参数异常)B.} catch (IllegalStateException c) {C. } catch (NumbelFormatException n) {D.} catch (ClassCastException c) {23.欲构造ArrayList类继承了List接口,下列哪个方法是正确的?答案:BA.ArrayList myList=new Object()B. List myList=new ArrayList()C.ArrayList myList=new List()D.List myList=new List()24."关于以下代码,说法正确的是?class Example {public static void main(String[] args) throws IOException {System.out.println(""Before Try"");try {} catch (java.io.IOException e) {System.out.println(""Inside Catch"");}System.out.println(""At the End"");}}"答案:A.代码编译失败,因为无异常抛出B.代码编译失败,因为未导入IOException异常类C."输出Before TryAt the End"D."输出Inside CatchAt the End"25.以下哪些方法在Class类中定义?答案:A.getConstructors()B.getPrivateMethods()C.getDeclaredFields()D.getImports()26.以下哪些是catch语句能够捕获处理的异常?答案:ACA.ThrowableB.ErrorC.ExceptionD.String27."请问以下代码的直接执行结果是?class Example{public static void main(String[] args) {try {System.out.println(args[0]);System.out.println(""I'm nomal"");if (true)return;} catch (Exception ex) {System.out.println(""I'm exception"");if (true)return;} finally {System.out.println(""I'm finally."");}System.out.println(""Out of try."");}}"答案:AA."I'm exceptionI'm finally."B.代码不能编译通过,因为最后一条语句位于return后,不可到达C.代码编译通过,但运行时输出异常信息D."I'm nomalI'm finally."28."下列代码的运行结果是?class Example {public static void main(String[] args) throws IOException {try {return;} finally{System.out.println(""Finally"");}}}"答案:BA.无内容输出B.输出FinallyC.代码编译失败D.输出异常信息29.假设有自定义异常类ServiceException,那么抛出该异常的语句正确的是哪项?答案:CA.raise ServiceExceptionB.throw new ServiceException()C.throw ServiceExceptionD.throws ServiceException30.在方法声明中,说明该方法可能会抛出的异常列表时使用哪个关键字?答案:DA.throwB.catchC.finallyD.throws31."如下代码执行后的输出结果是?public class Example {public static void main(String[] args) {try {throw new Exception();} catch (Exception e) {try {throw new Exception();} catch (Exception e2) {System.out.println(""inner"");}System.out.println(""middle"");}System.out.println(""out"");}}"答案:DA.inner outerB.middle outerC.inner middle outerD.编译失败32."现有如下代码:public class Example {public static void main(String[] args) {// anew Example().topGo();}void topGo() {// bmiddleGo();}void middleGo() {// cgo();System.out.println(""late middle"");}void go() {// dthrow new Exception();}}为了使代码能够编译通过,需要在哪个地方加入声明throws Exception?" 答案:BA.dB.c和dC.b、c和dD.a、b、c和d33."下面代码的执行结果是?class Example extends Utils {public static void main(String[] args) {try {System.out.print(new Example().getlnt(""42""));} catch (Exception e) {System.out.println(""Exc"");}}int getlnt(String arg) throws Exception {return Integer.parseInt(arg);}}class Utils {int getlnt() {return 42;}}"答案:BA.NFExcB.42C.42NFExcD.编译失败34.以下哪个方法用于计算平方根?答案:BA.squareRoot()B.sqrt()C.root()D.sqr()35."关于以下代码,说法正确的是?class Example{public static void main(String[] args) throws IOException {if (args[0] == ""hello"") {throw new IOException();}}}"答案:AA.代码编译成功B.代码编译失败,因为main()方法是入口方法,不能抛出异常C.代码编译失败,因为IOException异常是系统异常,不能由应用程序抛出D.代码编译失败,因为字符串应该用equals方法判定一致性36.定义在Math类上的round(double d)方法的返回值类型是什么?答案:A.charB.intC.longD.double37."给出以下代码:class Example {public static void main(String[] args) throws IOException {try {methodA();} catch (IOException e) {System.out.println(""caught IOException"");}catch (Exception e) {System.out.println(""caught Exception"");}}}如果methodA()方法抛出一个IOException异常,则该程序的运行结果是什么?" 答案:A.无内容输出B.代码编译失败C.输出caught IOExceptionD.输出caught Exception38."给出以下代码,执行结果是?class Example {public static void main(String[] args) throws IOException {aMethod();}static void aMethod(){try {System.out.println(""Try"");return;} catch (Exception e) {System.out.println(""Catch"");}finally{System.out.println(""Finally"");}}"答案:A.代码编译成功,但运行期间抛出异常B.代码便以失败,因为return语句错误C.输出Try和FinallyD.输出Try39."以下代码中,如果test()方法抛出一个NullPointException异常时,打印输出什么内容?class Example {public static void main(String[] args) throws IOException {try {test();System.out.println(""Message1"");} catch (ArrayIndexOutOfBoundsException e) {System.out.println(""Message2"");}finally{System.out.println(""Message3"");}}}"答案:A.打印输出Message1B.打印输出Message2C.打印输出Message3D.以上都不对40."以下代码执行结果是什么?class Example {public static String output = """";public static void foo(int i) {try {if (i == 1) {throw new Exception();}output += ""1"";} catch (Exception e) {output += ""2"";return;} finally {output += ""3"";output += ""4"";}public static void main(String[] args) throws IOException {foo(0);foo(1);System.out.println(output);}}"答案:A.无内容输出B.代码编译失败C.输出13423D.输出1432341."以下代码执行结果是?public abstract class Example extends Base {public abstract void method();}class Base {public Base() throws IOException {throw new IOException();}}"答案:A.代码编译失败,因为非抽象类不能被扩展为抽象类B.代码编译失败,因为必须提供一个可以抛出或可以不抛出IOException异常的构造器C.代码编译失败,以in为必须提供一个可以抛出IOException异常或其子类的构造器D.代码编译成功42."关于以下代码正确的说法是:1.public class Example {2. int x = 0;3.4. public Example(int inVal) throws Exception {5. if (inVal != this.x) {6. throw new Exception(""Invalid input"");7. }8. }9.10. public static void main(String[] args) {11. Example t = new Example(4);12. }13.}"答案:A.代码在第1行编译错误B.代码在第4行编译错误C.代码在第6行编译错误D.代码在第11行编译错误43."现有如下代码:public class Example {public static void main(String[] args) {try {System.out.println(""before"");doRisyThing();System.out.println(""after"");} catch (Exception e) {System.out.println(""catch"");}System.out.println(""done"");}public static void doRisyThing() throws Exception{ //this code returns unless it throws an Exception }}该代码可能的执行结果有哪些?"答案:A.before catchB.before after doneC.before catch doneD.before after catch44.Java语言中异常的分类是哪项?答案:A.运行时异常和异常B.受检异常和非受检异常C.错误和异常D.错误和运行时异常45.下列关于Math类说法错误的是ng.Math类是final类,因此不能被其他类继承ng.Math类的构造器是私有的,即声明为private,不能实例化一个Math类的对象ng.Math类上定义的所有常量和方法均是public和static的,因此可以直接通过类名调用D.min()和max()方法的参数之一,如果是NaN值,则方法将返回另一个参数值46."现有:String s = ""write a line to a file"";w.print(s + ""\n"");哪一个是对的?"答案:A.w既可以是PrintWriter类型,也可以是BufferedWriter类型B.w既不可以是PrintWriter类型,也不可以是BufferedWriter类型C.w可以是PrintWriter类型,但不可以是BufferedWriter类型D.w既可以是BufferedWriter类型,也可以是PrintWriter类型47.请问以下哪些关于try…catch…finally结构中的finally语句的描述是正确的?答案:CA.只有当一个catch语句获得执行后,finally语句才获得执行B.只有当catch语句未获得执行时,finally语句才获得执行C.如果有finally语句,return语句将在finally语句执行完毕后才会返回D.只有当异常抛出时,finally语句才获得执行48.以下哪个语句用于获取数组中的元素个数?答案:AA.intArray.size();B.intArray.size();C.intArray.length;D.intArray.length();49."下列代码在JDK1.5以上版本执行的结果是?public class Example {public static void main(String[] args) {Integer i = 10;Integer j = 10;System.out.println(i == j);i = 210;j = 210;System.out.println(i == j); (超过-128~127为false)}答案:BA.抛出异常B.输出true falseC.输出true trueD.输出false false50.数组是什么类型?答案:AA.引用类型B.基本数据类型C.不能确定D.其他类型51.下面哪条语句不正确?答案:AA.int[4] a;B.int a[];C.int[] a;D.int[] a,b;52.下面哪条语句不正确?答案:CA.int[] a={1,2,3};B.int a[]=new int[4];C.int[] a=new int[];D.int[] a=new int[]{2,3,4};53.存在Employee类,如何创建一个长度为3的Employee类型数组?答案:BA.Employee[3] e;B.Employee[] e=new Employee[3];C.Employee e[3];D.Employee[3] e=new Employee[];54.以下那种初始化数组的方式是错误的?答案:CA.String[] names = {"zhang","wang","li"};B."String names[] = new String[3];names[2] = ""li"";names[0] = ""zhang"";names[1] = ""wang"";"C.String[3] names = {"zhang","wang","li"};D.以上写法都正确55.以下哪些是声明一个字符串数组的正确形式?答案:ABDA.String[] s;B.String []s;C.Sting [s]D.String s[]56.以下哪些语句正确?答案:ADA.double snow[] = new double[31];B.double snow[31] = new array[31];C.double snow[31] = new array;D.double[] snow = new double[31];57.假设存在数组a,如何获得a的长度?答案:CA.a.length()B.a.len()C.a.lengthD.a.len58."现有:f是一个File类实例的合法引用fr是一个FileReader类实例的合法引用br是一个BufferedReader类实例的合法引用如下代码:String line = null;//插入代码处System.out.println(line);}哪一行代码插入到插入代码处将循环一次输出文本文件的一行?" 答案:A.while((line = f.read())!=null){B.while((line = fr.read())!=null){C.while((line = br.read())!=null){D.while((line = br.readLine())!=null){59."以下代码运行输出的结果是什么?public class Example {public static void main(String[] args) {char[] c = new char[100];System.out.println(c[50]);}}"答案:DA.打印输出50B.打印输出49C.打印输出\u0000D.打印输出null60."public class TestReplace {public static void stringReplace(String text){text=text.replace('j', 'i');}public static void bufferReplace(StringBuffer text){ text=text.append(""C"");}public static void main(String[] args){String textString=new String(""java""); StringBuffer bufferString=new StringBuffer(""java"");stringReplace(textString);bufferReplace(bufferString);System.out.println(textString+bufferString);}}运行结果是?"答案:AA.javajavaCB.javaCjavaCC.javajavaD.javajavaCjava61."下列代码的执行结果是什么?public class Example {public static void main(String[] args) {int index = 1;int[] foo = new int[3];int bar = foo[index];int baz = bar + index;System.out.println(baz);}}"答案:BA.打印输出0B.打印输出1C.打印输出2D.运行期间有异常抛出62."给出下面代码:public class Example{static int arr[] = new int[10];public static void main(String a[]){System.out.println(arr[1]);}}那个语句是正确的?"答案:DA.编译时将产生错误B.编译时正确,运行时将产生错误C.输出0D.输出null63.从InputStream对象中如何创建一个Reader对象?答案:A.使用InputStream类中定义的createReader()方法B.吃用Reader类中的createReader()方法C.构造一个InputStreamReader实例,将InputStream对象作为InputStreamReader类构造器的参数传入D.构造一个OutputStreamReader实例,将InputStream对象作为OutputStreamReader类构造器的参数传入64."以下程序执行结果是?public class Example {public static void main(String[] args) throws IOException {String s = ""x,yy,123"";Scanner sc = new Scanner(s);while (sc.hasNext()) {System.out.println(sc.next() + "" "");}}"答案:A.x yyB.x,yy,123C.x yy 123D.x,yy65.以下哪个描述是正确的?答案:A.多线程是Java语言独有的B.多线程需要多CPUC.多线程要求一个计算机拥有单独一个CPUD.Java语言支持多线程66."下列代码的执行结果是?public class Example{public static void main(String args[]) {Thread t = new Thread() {public void run() {pong();}};t.run();System.out.print(""ping"");}static void pong() {System.out.print(""pong"");}}"答案:A.pingpongB.pongpingC.pingpong和pongping都有可能D.都不输出67.以下哪个关于Runnable的描述是正确的?答案:A.Runnable是Java语言的一个关键字,用于修饰类,来表明该类是一个独立线程B.Runnable是一个接口,实现该接口的类对象可以提供给Thread类构造器作为创建线程的C.Runnable是一个类,继承该类的子类可以作为独立的线程存在D.以上皆不对68.在服务器上提供了基于TCP的时间服务应用,该应用使用port为6666。
javaSE作业JavaSE测试题⼀、选择题(不定项)1.在JAVA中,下列哪些说法是正确的( A C )A.java源⽂件的扩展名为.javaB.写好的java源程序可以直接运⾏C.编写的源程序必须先编译后才能运⾏D.程序员可以读懂扩展名为.class的⽂件2.下列标识符哪个是合法的( BD )A.classB.$abcC.1234D._name3.下⾯哪些赋值语句是正确的?( ab d)A. long test = 012;B. float f = -412;C. int other = (int) true;D. double d = 0x12345678;E. byte b = 128; -128~1274.在Java中,下列语句不能通过编译的有(b )A. String s= “join”+ 3;B. int a= “join”+3;C. int a= ‘a’+5;D. float f=5+5.5;5.设a = 3,则表达式(--a )< < a的结果为( b )A. 16B. 8C. 24D. 126.下列代码运⾏的结果是(c )public static void main(String[] args) {int x = 4;int y = 5;if(x++>4 & ++y>5) {x++;}System.out.println("x=" + x + ",y=" + y); }A. x=4,y=5B. x=4,y=6C. x=5,y=6D. x=6,y=67.尝试运⾏下⾯的代码会发⽣什么?( b ) public class Test {public static void main(String[] args) { boolean m = true;if (m = false) {System.out.println("true");} else {System.out.println("false");}}}A.输出字符串”true”B.输出字符串”false”C.编译时错误D.运⾏时错误8.编译并运⾏以下代码将发⽣什么? ( e) public static void main(String args[]){ char digit = 'a';for (int i = 0; i < 10; i++){switch (digit){case 'x' :{int j = 0;System.out.println(j);}default :{int j = 100;System.out.println(j);}}}int i = j;System.out.println(i);}A.输出11次100B.输出10次100,然后抛出运⾏期异常C.编译错误,因为变量i不能在main()⽅法中被声明2次D.编译错误,因为变量j不能在main()⽅法中被声明2次E.以上都不对9. class Demo{public static int fun(int c){return c+=2;}public static void main(String[] args){int temp = fun(2);System.out.println(temp);}}打印结果是(b )A. 2B. 4C. 6D. 810.下⾯哪些函数是public void aMethod(){...}的重载函数?(bd )A. void aMethod( ){...}B. public int aMethod(int a, float b){...}C. public void aMethod (){...}D. public float aMethod (int m){…}11.在java中,关于数组描述正确的是( b d )A.数组中的索引下标从1开始B.存储在数组当中的数据都属于同⼀数据类型C.通过数组名.length()能获得数组的长度D.数组的最⼤索引下标是数组的长度减112.下⾯程序的输出结果是什么( d )int[] arr = new int[10];System.out.println(arr[0]);A.编译不通过B.运⾏时出错C.输出nullD.输出013.下⾯哪个语句正确地声明⼀个整型的⼆维数组( c d )A. int a[][] = new int[][];B. int b[10][10] = new int[][];C. int c[][] = new int[10][10];D. int []d[] = new int[10][10];14.以下代码输出是( d )class Demo {public static void main(String[] args) {int i = 0;int sum = 0;while (i <= 10) {i++;if (i % 2 != 0)continue;sum += i;}System.out.println(sum);}}A. 55B. 45C. 35D. 3015.和下⾯代码能完成相同的选项是( b )class Demo {public static void main(String[] args) {int i = 1;int sum = 0;while (i <= 100) {if (i % 2 == 0) {sum = sum + i;}i++;}System.out.println(sum);}}A. for (int x =1; x<=100;x++){ sum=sum+x;}B. for (int x =0; x<=100;x+=2){ sum=sum+x;}C. for (int x =1; x<=100;x+=2){ sum=sum+x;}D.上述全对16.下列有关类、对象和实例的叙述,正确的是哪⼀项?( d )A.类就是对象,对象就是类,实例是对象的另⼀个名称,三者没有差别B.对象是类的抽象,类是对象的具体化,实例是对象的另⼀个名称C.类是对象的抽象,对象是类的具体化,实例是类的另⼀个名称D.类是对象的抽象,对象是类的具体化,实例是对象的另⼀个名称17.下⾯关于java中包的说法正确的是( a,d c )A.在java中可以使⽤import语句导⼊包B.在java中可以使⽤package语句导⼊包C.位于同⼀个包中的类,不需要导包就可以直接访问D.不同的包中可以出现类名相同的类18.下列有关抽象类的叙述正确的是哪项? (c)A.抽象类中⼀定含有抽象⽅法B.抽象类既能被实例化也能被继承C.抽象类的声明必须包含abstract关键字D.抽象类中不能有构造⽅法19.下列有关接⼝的叙述错误的是哪项?( a d )A.接⼝中只能包含抽象⽅法和常量B.⼀个类可以实现多个接⼝C.类实现接⼝时必须实现其中的⽅法D.接⼝不能被继承20.运⾏以下代码⽚段,输出结果是?( d )class X {Y b = new Y();X() {System.out.print("X");}}class Y {Y() {System.out.print("Y");}}public class Z extends X {Y y = new Y();Z() {System.out.print("Z");}public static void main(String[] args) {new Z();}}//静态(初始化⼀次)动态(创建⼀次执⾏⼀次)构造A. ZB. YZC. XYZD. YXYZ21.下列关于类的继承的描述,正确的有( b d )A.⼀个类可以同时继承多个⽗类B.⼀个类可以具有多个⼦类C.⼦类会⾃动拥有⽗类所有的⽅法D.⼀个类继承另⼀个类需要使⽤extends关键字22.下列选项中关于java中this关键字的说法错误的有( ab d )A.this关键字是⼀个对象的引⽤ //本类B.this关键字可以⽤于引⽤当前类以外其他类型的对象C.this可⽤于构造函数中,调⽤类本⾝重载的构造函数,但是必须写在⾸⾏D.this可⽤于静态⽅法中//this属于对对象的调⽤,静态⽅法属于类23.下列关于构造函数的说法正确的是( a b d )A.⽅法名必须与类名相同B.使⽤new关键字创建对象时,java虚拟机会⾃动调⽤构造函数C.我们在定义⼀个类时,必须要声明⾄少⼀个构造函数D.构造函数中不能使⽤return语句24.编译并运⾏以下代码将发⽣什么?( d )class MyClass {int x;MyClass(int i) {x = i;}public static void main(String args[]) {MyClass m1 = new MyClass(100);MyClass m2 = new MyClass(100);if (m1.equals(m2)) {System.out.println("Both are equal");} else {System.out.println("Both are not equal");}}}A.代码编译时报出错误提⽰信息“equals()⽅法未定义”B.编译通过,抛出运⾏期异常.C.输出Both are equal.D.输出Both are not equal25.运⾏以下的main()⽅法,结果是?( a c )1 public static void main(String[] args)2 {3 String myString;4 int x = 100;56 if (x < 100) myString = "x is less than 100";7 if (x > 100) myString = "x is greater than 100";8 System.out.println(myString.length());9 }A.编译时报出错误提⽰信息“变量myString没有被初始化”B.编译通过C.编译未能通过。
Java 第二阶段(WEB)测试题(卷I)姓名________________注意:考试时间为150分钟,试卷总分100分,60分为合格,80分为良好,90分以上为优秀。
闭卷考试,请遵守考场纪律,考试严禁作弊,作弊者立即停止考试,成绩按0分处理。
卷I考试时间为60分钟,到时间收卷,延迟交卷按作弊处理。
答题卡:B.类选择器>ID选择器>标签选择器>行内式(inline)C.行内式(inline)>ID选择器>类选择器>标签选择器D.行内式(inline)>类选择器>ID选择器>标签选择器5)对于转发与重定向的描述错误的语句是( )A.重定向是在客户端发生作用,通过请求新的地址实现页面转向B.使用转发时由于是服务器内部控制权的转移,因而地址栏中的URL没有变化C.使用重定向时可以在地址栏中看到转向后的URLD.转发与重定向都可以实现在页面跳转,因而没有区别6)在js中1===”1”的值为()A.true B.false C.null D.undefined7)数据库多表查询语句中,以下哪些是正确的?(多选)( )A.left joinB.center joinC.right joinD.up joinE.down join8)以下scoket端口号正确的有哪些?(多选)( )A.11111B.12345C.65533D.65535E.666379)HTML中td跟th有什么不同?( )A.字体不同B.字号不同C.对齐方式不同D.颜色不同10)CSS中用来设置字体颜色的属性是哪个?( )A.font-colorB.font-familyC.font-sizeD.color11) 在2012年12月31日执行以下代码后,变量a的结果是多少?()var d=new Date();d.setYear(2000);d.setMonth(1);var a=d.getFullYear()+”-”+d.getMonth()+”-”+d.getDate();A.2000-1-31B. 2000-2-2C. 2000-2-29D.2000-3-212)编写一个Filter需要?( )A.继承Filter类B.实现Filter接口C.继承HttpFilter类D.实现HttpFilter接口13)自定义标签的作用是?()A.编写和使用方便B.规定是这样的,如果不这么写,可能显示不专业。
2020年JAVASE综合考试试题库188题[含答案]一、选择题1.以下哪些有关Vector类的描述是正确的?答案:CA.该类是个public类B.该类是个final类C.该类实现了List接口D.该类可以序列化2."下列代码的执行结果是?class Example {private void method1() throws Exception {throw new RuntimeException();}public void method2() {try {method1();} catch (RuntimeException e) {System.out.println(""Caught Runtime Exception"");} catch (Exception e) {System.out.println(""Caught Exception"");}}public static void main(String[] args) throws IOException {Example a = new Example();a.method2();}}"答案:A.代码编译失败B.输出Caught Runtime ExceptionC.输出Caught ExceptionD.输出Caught Runtime Exception和Caught Exception3."以下代码的输出结果是什么?选择所有的正确答案。
class Example {public static void main(String[] args) throws IOException {for (int i = 0; i < 10; i++) {try {try {if (i % 3 == 0)throw new Exception(""E0"");System.out.println(i);break;} catch (Exception inner) {i *= 2;if (i % 3 == 0)throw new Exception(""E1"");} finally {++i;}} catch (Exception outer) {i += 3;} finally {--i;}}}}"答案:A.4B.5C.6D.74.Java语言中异常的分类是哪项?答案:A.运行时异常和异常B.受检异常和非受检异常C.错误和异常D.错误和运行时异常5.下列关于Math类说法错误的是答案:ng.Math类是final类,因此不能被其他类继承ng.Math类的构造器是私有的,即声明为private,不能实例化一个Math类的对象ng.Math类上定义的所有常量和方法均是public和static的,因此可以直接通过类名调用D.min()和max()方法的参数之一,如果是NaN值,则方法将返回另一个参数值6.定义在Math类上的round(double d)方法的返回值类型是什么?答案:A.charB.intC.longD.double7.以下哪个方法用于计算平方根?答案:BA.squareRoot()B.sqrt()C.root()D.sqr()8."以下代码的运行结果是什么?public class Example {public static void main(String[] args) {System.out.println(Math.min(0.0, -0.0));}}"答案:CA.代码编译失败B.输出0.0C.输出-0.0D.代码编译成功,但运行时输出异常信息9."以下代码的运行结果是什么?public class Example {public static void main(String[] args) {double d1 = -0.5;System.out.println(""Ceil d1="" + Math.ceil(d1));System.out.println(""Floor d1="" + Math.floor(d1));}}"答案:BA.输出Ceil d1=-0.0 Floor d1=-1.0B.输出Ceil d1=0.0 Floor d1=-1.0C.输出Ceil d1=-0.0 Floor d1=-0.0D.输出Ceil d1=0.0 Floor d1=0.010."给出以下代码,为了结果输出-12.0,方法method(d)应为以下哪个方法?public class Example {public static void main(String[] args) {double d = -11.1;double d1 = method(d);System.out.println(d1);}}"答案: AA.floor()B.ceil()C.round()D.abs()11."现有:public class Example {public static void main(String[] args) {//插入代码处c.put(""X"", 123);}}下列哪些插入到插入代码处能够正常编译?"答案:A.Map c = new SortedMap();B.HashMap c = new HashMap();C.SortedMap c = new TreeMap();D.Map c = new LinkedHashMap();12.以下哪些是Collection接口的子接口?答案:BDA.DictionaryB.ListC.MapD.Set13."给出以下代码,执行结果是?class Example {public static void main(String[] args) throws IOException {aMethod();}static void aMethod(){try {System.out.println(""Try"");return;} catch (Exception e) {System.out.println(""Catch"");}finally{System.out.println(""Finally"");}}}"答案:A.代码编译成功,但运行期间抛出异常B.代码便以失败,因为return语句错误C.输出Try和FinallyD.输出Try14.以下哪些集合接口支持重复元素存在?答案:BA.CollectionB.ListC.MapD.Set15.List接口的特点是哪项?答案:CA.不允许重复元素,元素有顺序B.允许重复元素,元素无顺序C.允许重复元素,元素有顺序D.不允许重复元素,元素无顺序16.欲构造ArrayList类继承了List接口,下列哪个方法是正确的?答案:BA.ArrayList myList=new Object()B. List myList=new ArrayList()C.ArrayList myList=new List()D.List myList=new List()17."现有:list是一个合法的集合引用getCollection()返回一个合法集合的引用,以下语句哪些是合法的?" 答案:CA.for(Object o : list)B.for(Object o : getCollection())C.for(Object o : list.iterator())D.for(Iterator I;list.iterator();i.hasNext())18."以下代码的执行结果是?public class Example {public static void main(String[] args) {TreeSet<String> t = new TreeSet<String>();if (t.add(""one""))if (t.add(""two""))if (t.add(""three""))t.add(""four"");for (String s : t) {System.out.print(s);}}}"答案:DA.oneB.onethreetwoC.onetwothreefourD.fouronethreetwo19."现有:public class Example {public static void main(String[] args) {TreeSet<String> s = new TreeSet<String>();s.add(""one"");s.add(""two"");// 插入代码处for (String s2 : sorted) {System.out.print(s2 + "" "");}}}和四个代码片段:s1:SortedSet sorted = s.tailSet(s.first());s2:SortedSet<String> sorted = s.tailSet(s.first());s3:SortedSet sorted = (SortedSet)s.tailSet(s.first());s4:SortedSet sorted = (SortSet<String>)s.tailSet(s.first());分别插入到插入代码处,哪项可以编译?"答案:A.S2B.S2和S3C.S2和S4D.S2、S3和S420.以下哪些语句用于创建一个Map实例?答案: DA.Map m = new Map();B.Map m = new Map(init capacity,increment capacity);C.Map m = new Map(new Collection());D.以上都不对21."以下代码执行结果是?public class Example {public static void main(String[] args) {TreeMap<String, String> map = new TreeMap<String, String>(); map.put(""one"", ""1"");map.put(""two"", ""2"");map.put(""three"", ""3"");displayMap(map);}static void displayMap(TreeMap map) {Collection<String> c = map.entrySet();Iterator<String> i = c.iterator();while (i.hasNext()) {Object o = i.next();System.out.print(o.toString());}}}"答案:A.onetwothreeB.123C.one=1three=3two=2D.onethreetwo22.请问以下哪个程序代码体现了对象之间的is a关系?答案:A."public interface Color {}public class Shape {private Color color;}"B."public interface Component {}public class Cpmtaomer implements Component {private Component[] children;}"C."public class Species{}public class Animal{private Species species;}"D."public class Animal{public interface Species{}private Species species;}"23.下列哪些项是泛型的优点?答案:AA.不用向下强制类型转换B.代码容易编写C.类型安全D.运行速度快24.以下哪些描述是正确的?答案:CDA.try语句块后必须至少存在一个catch语句块B.try语句块后可以存在不限数量的finally语句块C.try语句块后必须至少存在一个catch语句块或finally语句块D.如果catch和finally语句块同时存在,则catch语句块必须位于finally语句块前25.以下哪些方法在Class类中定义?答案:A.getConstructors()B.getPrivateMethods()C.getDeclaredFields()D.getImports()26."现有以下代码:interface W {}class Z implements W {}class X extends Z {}class Y extends Z {}下列哪些代码段是正确的?"答案:A."X x=new X();Y y=new Y();Z z=new Z();y=(Y)x;"B."X x=new X();Y y=new Y();Z z=new Z();x=(X)y;"C."X x=new X();Y y=new Y();Z z=new Z();Z=(Z)x;"D."X x=new X();Y y=new Y();Z z=new Z();W w=(W)x;"27.Java语言中异常的分类是哪项?答案:CA.运行时异常和异常B.受检异常和非受检异常C.错误和异常D.错误和运行时异常28."现有代码:public class Example {public static void main(String[] args) {try {System.out.print(Integer.parseInt(""forty"")); } catch (RuntimeException e) {System.out.println(""Runtime"");}catch (NumberFormatException e) {System.out.println(""Number"");}}}执行结果是什么?"答案:CA.输出NumberB.输出RuntimeC.输出40D.编译失败29."对以下两个代码片段说法正确的是?代码片段1:int a = 3;int b = 0;int c = a / b;代码片段2:float a = 3.0f;float b = 0.0f;float c = a / b;"答案:CA.执行两端代码都会抛出异常B.执行两段代码都无异常抛出C.执行两段代码,只有代码片段1抛出异常D.执行两段代码,只有代码片段2抛出异常30."下列代码执行后的结果是?public class Example {public static void main(String[] args) {try {double x = 64.0;double y = 0.0;System.out.println(x % y);} catch (Exception e) {System.out.println(""Exception"");}}}"答案:DA.编译失败B.输出ExceptionC.输出InfinityD.输出NaN31."现有如下代码:public class Example extends Utils{public static void main(String[] args) {try {System.out.println(new Example().getInt(""42""));} catch (NumberFormatException e) {System.out.println(""NFExc"");}}int getInt(String arg) throws NumberFormatException{ return Integer.parseInt(arg);}}class Utils {int getInt(String arg) {return 42;}}该代码执行的结果是?"答案:BA.NFExcB.42C.42NFExcD.编译失败32.关于异常处理,说法错误的是?答案:CA.try…catch…finally结构中,必须有try语句块,catch语句块和finally语句块不是必须的,但至少要两者取其一B.在异常处理中,若try中的代码可能产生多种异常则可以对应多个catch语句,若catch 中的参数类型有父类子类关系,此时应该将子类放在后面,父类放在前面C.一个方法可以抛出多个异常,方法的返回值也能够是异常D.Throwable是所有异常的超类33."关于以下代码,说法正确的是?class Example {public static void main(String[] args) throws IOException {System.out.println(""Before Try"");try {} catch (Throwable e) {System.out.println(""Inside Catch"");}System.out.println(""At the End"");}}"答案:BA.代码编译失败,因为无异常抛出B.代码编译失败,因为未导入IOException异常类C."输出Before TryAt the End"D."输出Inside CatchAt the End"34."关于以下代码正确的说法是:1.public class Example {2. int x = 0;3.4. public Example(int inVal) throws Exception {5. if (inVal != this.x) {6. throw new Exception(""Invalid input"");7. }8. }9.10. public static void main(String[] args) {11. Example t = new Example(4);12. }13.}"答案:A.代码在第1行编译错误B.代码在第4行编译错误C.代码在第6行编译错误D.代码在第11行编译错误35."下列代码的执行结果是?class Example {public static void main(String[] args) throws IOException {int i = 1, j = 1;try {i++;j--;if (i == j) {j++;}} catch (ArithmeticException e) {System.out.println(0);} catch (ArrayIndexOutOfBoundsException e) {System.out.println(1);} catch (Exception e) {System.out.println(2);} finally {System.out.println(3);}System.out.println(4);}}"答案:CDA.输出1B.输出2C.输出3D.输出436."以下代码中,如果test()方法抛出一个NullPointException异常时,打印输出什么内容?class Example {public static void main(String[] args) throws IOException {try {test();System.out.println(""Message1"");} catch (ArrayIndexOutOfBoundsException e) {System.out.println(""Message2"");}finally{System.out.println(""Message3"");}}}"答案:A.打印输出Message1B.打印输出Message2C.打印输出Message3D.以上都不对37."请问以下代码的直接执行结果是?class Example{public static void main(String[] args) {try {System.out.println(args[0]);System.out.println(""I'm nomal"");if (true)return;} catch (Exception ex) {System.out.println(""I'm exception"");if (true)return;} finally {System.out.println(""I'm finally."");}System.out.println(""Out of try."");}}"答案:AA."I'm exceptionI'm finally."B.代码不能编译通过,因为最后一条语句位于return后,不可到达C.代码编译通过,但运行时输出异常信息D."I'm nomalI'm finally."38.假设有自定义异常类ServiceException,那么抛出该异常的语句正确的是哪项?答案:CA.raise ServiceExceptionB.throw new ServiceException()C.throw ServiceExceptionD.throws ServiceException39.在方法声明中,说明该方法可能会抛出的异常列表时使用哪个关键字?答案:DA.throwB.catchC.finallyD.throws40."如下代码执行后的输出结果是?public class Example {public static void main(String[] args) {try {throw new Exception();} catch (Exception e) {try {throw new Exception();} catch (Exception e2) {System.out.println(""inner"");}System.out.println(""middle"");}System.out.println(""out"");}}"答案:DA.inner outerB.middle outerC.inner middle outerD.编译失败41."下面代码的执行结果是?class Example extends Utils {public static void main(String[] args) {try {System.out.print(new Example().getlnt(""42""));} catch (Exception e) {System.out.println(""Exc"");}}int getlnt(String arg) throws Exception {return Integer.parseInt(arg);}class Utils {int getlnt() {return 42;}}"答案:BA.NFExcB.42C.42NFExcD.编译失败42.请问以下哪些关于try…catch…finally结构中的finally语句的描述是正确的?答案:CA.只有当一个catch语句获得执行后,finally语句才获得执行B.只有当catch语句未获得执行时,finally语句才获得执行C.如果有finally语句,return语句将在finally语句执行完毕后才会返回D.只有当异常抛出时,finally语句才获得执行43."关于以下代码,说法正确的是?class Example{public static void main(String[] args) throws IOException {if (args[0] == ""hello"") {throw new IOException();}}}"答案:AA.代码编译成功B.代码编译失败,因为main()方法是入口方法,不能抛出异常C.代码编译失败,因为IOException异常是系统异常,不能由应用程序抛出D.代码编译失败,因为字符串应该用equals方法判定一致性44."关于以下代码,说法正确的是?class Example {public static void main(String[] args) throws IOException {System.out.println(""Before Try"");try {} catch (java.io.IOException e) {System.out.println(""Inside Catch"");System.out.println(""At the End"");}}"答案:A.代码编译失败,因为无异常抛出B.代码编译失败,因为未导入IOException异常类C."输出Before TryAt the End"D."输出Inside CatchAt the End"45."给出以下代码:class Example {public static void main(String[] args) throws IOException {try {methodA();} catch (IOException e) {System.out.println(""caught IOException"");}catch (Exception e) {System.out.println(""caught Exception"");}}}如果methodA()方法抛出一个IOException异常,则该程序的运行结果是什么?" 答案:A.无内容输出B.代码编译失败C.输出caught IOExceptionD.输出caught Exception46."以下代码的执行结果是?public class Example {public static void main(String[] args) {File f = new File(""c:\\large.txt"");}}"答案:rge.txt文件在本地硬盘上被创建B.在Unix系统上运行失败,因为路径分割符不正确rge.txt文件在本地硬盘上没有被创建D.如果large.txt文件已经存在,则一个异常被抛出47."当fragile()方法抛出一个IllegalArgumentException异常时,下列代码的运行结果是什么?public static void main(String[] args) throws IOException {try {fragile();} catch (NullPointerException e) {System.out.println(""NullPointerException thrown"");} catch (Exception e) {System.out.println(""Exception thrown"");} finally {System.out.println(""Done with exceptions"");}System.out.println(""myMethod is done"");}}"答案:A.输出NullPointerException thrownB.输出Exception thrownC.输出Done with ExceptionD.输出myMethod is done48."给出下面代码:public class Example{static int arr[] = new int[10];public static void main(String a[]){System.out.println(arr[1]);}}那个语句是正确的?"答案:DA.编译时将产生错误B.编译时正确,运行时将产生错误C.输出0D.输出null49.Java语言中有多少个包装器类型?答案:BA.7B.8C.950."下列代码在JDK1.5以上版本执行的结果是?public class Example {public static void main(String[] args) {Integer i = 10;Integer j = 10;System.out.println(i == j);i = 210;j = 210;System.out.println(i == j); (超过-128~127为false)}}"答案:BA.抛出异常B.输出true falseC.输出true trueD.输出false false51.数组是什么类型?答案:AA.引用类型B.基本数据类型C.不能确定D.其他类型52.下面哪条语句不正确?答案:AA.int[4] a;B.int a[];C.int[] a;D.int[] a,b;53.存在Employee类,如何创建一个长度为3的Employee类型数组?答案:BA.Employee[3] e;B.Employee[] e=new Employee[3];C.Employee e[3];D.Employee[3] e=new Employee[];54.以下那种初始化数组的方式是错误的?A.String[] names = {"zhang","wang","li"};B."String names[] = new String[3];names[2] = ""li"";names[0] = ""zhang"";names[1] = ""wang"";"C.String[3] names = {"zhang","wang","li"};D.以上写法都正确55.数组索引从几开始?答案:AA.0B.1C.-1D.随便56.假设存在数组a,如何获得a的长度?答案:CA.a.length()B.a.len()C.a.lengthD.a.len57."以下给出代码运行后的结果是?public class Example {public static void main(String[] args) {int[] refToArray = { 10, 11 };int var = 1;refToArray[var - 1] = var = 2;System.out.println(refToArray[0] + "" "" + refToArray[1]); }}"答案:CA.编译失败B.编译通过,但运行时提示异常C.2 11D.10 258."现有如下类型:a - java.util.Hashtableb - java.util.Listc - java.util.ArrayListd - java.util.SortedSet和定义:1-使用本接口,允许用户控制集合中每个元素的插入位置2-使用本集合,确保用户可以按照递增或元素的自然顺序遍历集合3-本具体类型允许空元素及基于索引的访问4-本集合是同步的哪一组匹配是对的?"答案:A.2描述d,3描述bB.1描述b,3描述cC.3描述a,4描述bD.4描述a,2描述c59."下列代码的执行结果是什么?public class Example {public static void main(String[] args) {int index = 1;int[] foo = new int[3];int bar = foo[index];int baz = bar + index;System.out.println(baz);}}"答案:BA.打印输出0B.打印输出1C.打印输出2D.运行期间有异常抛出60."public class TestEquals {/*** @param args*/public static void main(String[] args) {String a=""a"";String b=""b"";String c=""a""+""b"";String d=a+b;System.out.println(a==""a"");System.out.println(c==""ab"");System.out.println(d==c);System.out.println(new String(""a"")+b==c);}}运行结果是?"答案:DA."truefalsefalsefalse"B."truetruefalsefalse"C."truetruetruefalse"D."falsefalsefalsefalse"61."以下代码执行的结果是:public class Example {public static void main(String[] args) {int[] x = { 1, 2, 3 };x[1] = (x[1] > 1) ? x[2] : 0;System.out.println(x[1]);}}"答案:CA.输出1B.输出2C.输出3D.输出462."以下程序执行结果是?public class Example {public static void main(String[] args) throws IOException { String s = ""x,yy,123"";Scanner sc = new Scanner(s);while (sc.hasNext()) {System.out.println(sc.next() + "" "");}}}"答案:A.x yyB.x,yy,123C.x yy 123D.x,yy63.以下哪个描述是正确的?答案:A.多线程是Java语言独有的B.多线程需要多CPUC.多线程要求一个计算机拥有单独一个CPUD.Java语言支持多线程64."以下代码的执行结果是?public class Example implements Runnable {public static void main(String args[]) {Example ex = new Example();Thread t = new Thread(ex);t.start();}void run() {System.out.print(""pong"");}}"答案:A.输出pongB.运行时输出异常信息C.运行后无任何输出D.编译失败65."现有:t是一个合法的Thread对象的引用,并且t的合法run()方法如下:public void run() {System.out.print(""go"");}执行:t.start();t.start();后结果是什么?"答案:A.go goB.go go goC.go之后跟着一个异常D.go go之后跟着一个异常66."下列代码的执行结果是?public class Example{public static void main(String args[]) {Thread t = new Thread() {public void run() {pong();}};t.run();System.out.print(""ping"");}static void pong() {System.out.print(""pong"");}}"答案:A.pingpongB.pongpingC.pingpong和pongping都有可能D.都不输出67.以下哪个关于Runnable的描述是正确的?答案:A.Runnable是Java语言的一个关键字,用于修饰类,来表明该类是一个独立线程B.Runnable是一个接口,实现该接口的类对象可以提供给Thread类构造器作为创建线程的依据C.Runnable是一个类,继承该类的子类可以作为独立的线程存在D.以上皆不对68.在服务器上提供了基于TCP的时间服务应用,该应用使用port为6666。
javase考试试题和答案一、单项选择题(每题2分,共20分)1. Java中,下列哪个关键字用于声明一个类?()A. classB. interfaceC. abstractD. final答案:A2. 在Java中,下列哪个选项是正确的字符串拼接方式?()A. "Hello" + "World"B. "Hello" + 5C. "Hello" + 5.0D. 5 + "Hello"答案:A3. Java中,下列哪个选项是正确的方法重载?()A. public void display() {}public void display(int x) {}B. public void display(int x) {}public void display(double x) {}C. public void display(int x) {}public void display(int x, int y) {}D. public void display() {}public void display() {}答案:C4. Java中,下列哪个选项是正确的继承关系?()A. class A extends B {}B. class A implements B {}C. class A implements B, C {}D. class A extends B, C {}答案:C5. Java中,下列哪个选项是正确的异常处理语句?()A. try { } catch { }B. try { } catch (Exception e) { }C. try { } catch (e) { }D. try { } catch (Exception) { }答案:B6. Java中,下列哪个选项是正确的泛型使用方式?()A. List list = new ArrayList();B. List<String> list = new ArrayList<String>();C. List list = new ArrayList<String>();D. List<String> list = new ArrayList();答案:B7. Java中,下列哪个选项是正确的线程创建方式?()A. Thread thread = new Thread();B. Thread thread = new Thread(Runnable r);C. Thread thread = new Thread(new Thread());D. Thread thread = new Thread(new Runnable() {});答案:D8. Java中,下列哪个选项是正确的集合初始化方式?()A. List list = new ArrayList();B. List list = new LinkedList();C. List list = new Vector();D. List list = new Stack();答案:A9. Java中,下列哪个选项是正确的文件读写方式?()A. FileReader fr = new FileReader("file.txt");B. FileWriter fw = new FileWriter("file.txt");C. BufferedReader br = new BufferedReader(new FileReader("file.txt"));D. BufferedWriter bw = new BufferedWriter(new FileWriter("file.txt"));答案:C10. Java中,下列哪个选项是正确的网络编程方式?()A. ServerSocket serverSocket = new ServerSocket(8080);B. Socket socket = new Socket("localhost", 8080);C. DatagramSocket socket = new DatagramSocket(8080);D. MulticastSocket socket = new MulticastSocket(8080);答案:A二、多项选择题(每题3分,共15分)1. Java中,下列哪些关键字用于修饰类?()A. publicB. abstractC. finalD. strictfp答案:ABCD2. Java中,下列哪些关键字用于修饰方法?()A. publicB. privateC. protectedD. synchronized答案:ABCD3. Java中,下列哪些关键字用于修饰变量?()A. publicB. privateC. protectedD. volatile答案:BCD4. Java中,下列哪些关键字用于修饰接口?()A. publicB. abstractC. finalD. strictfp答案:ACD5. Java中,下列哪些关键字用于修饰异常?()A. tryB. catchC. throwD. throws答案:BCD三、填空题(每题4分,共20分)1. Java中,一个类可以继承________个父类。
JAVASE基础题第一阶段题库1.JDK是什么?JRE是什么?a)答:JDK:java开发工具包。
JRE:java运行时环境。
2.什么是java的平台无关性?a)答:Java源文件被编译成字节码的形式,无论在什么系统环境下,只要有java虚拟机就能运行这个字节码文件。
也就是一处编写,处处运行。
这就是java的跨平台性。
3.在一台电脑上配置java环境,path起什么作用?如何配置?a)答:path的作用是在DOS环境下,能在任意位置使用JDK目录中bin文件夹中的可执行程序,来编译执行java程序。
b)在环境变量中找到path变量,把bin文件夹的绝对路径加上即可。
4.什么样的标识符是合法的?a)由字母、数字、_和$组成,长度不限。
其中字母可以是大写或小写的英文字母,数字为0到9。
b)标识符的第一个字符不能是数字。
c)标识符区分大小写。
d)标识符不能包含空格。
5.Java有几种基本数据类型?a)byte,short,int,long,char,boolean,float,double6.什么是隐式类型转换?什么是显示类型转换?a)当将占位数少的类型赋值给占位数多的类型时,Java自动使用隐式类型转换。
b)当把在级别高的变量的值赋给级别底变量时,必须使用显示类型转换运算。
7.&&,&区别。
||,|区别?a)&&和||是短路与,短路或,当左边的表达式能判断当前结果,则不判断右边的表达式。
8.break,continue区别?a)break结束最近的一个循环,continue结束当次循环,进入下次循环。
9.类的命名规则是什么?a)如果类名使用拉丁字母,那么名字的首写字母使用大写字母。
b)类名最好见名得意,当类名由几个单词复合而成时,每个单词的首写字母使用大写。
10.类体的内容由两部分构成,哪两部分?a)一部分是变量的定义,用来刻画属性。
b)另一部分是方法的定义,用来刻画功能。
1、数组操作(45分钟)
一、1.声明一个长度为8的int数组,完成初始化赋值(10分)
2.遍历数组(10分)
3.为数组排序:用你知道的任意一种排序方法进行排序(10分)
4.遍历排序后的数组(10分)
5.获取最大值(10分)
2、编写龟兔赛跑多线程程序,设赛跑长度为100米(60分钟)
1.创建两个线程分别代表乌龟和兔子(15分)
2.兔子速度为10m/s 每跑完10m输出一次结果(15分)
3.乌龟速度为5m/s 每跑完10m输出一次结果(15分)
4.当兔子跑到70m的时候休息2s(5分)
5.启动两个线程看运行结果。
3、面向对象(90分钟)
按要求实现下列问题:
1)封装一个新闻类,包含标题和内容属性,提供get、set方法,重写toString 方法,打印对象时只打印标题;(10分)
2)只提供一个带参数的构造器,实例化对象时,只初始化标题;并且实例化两个对象:
新闻一:中国多地遭雾霾笼罩空气质量再成热议话题
新闻二:春节临近北京“卖房热”
3)将新闻对象添加到ArrayList集合中,并且使用ListIterator倒序遍历
4)遍历时候如果新闻标题长度大于11 则显示...
4、集合操作(30分钟)
1)生成10个随机数,值在100到200之间;
2)将这十个数存入HashSet集合中(有可能集合的长度小于10)。
3)将这个HashSet集合转换成ArrayList集合
4)重新为ArrayList集合排序,按照从小到大的顺序;
5)使用foreach遍历集合;
5、集合操作(45分钟)
封装一个汽车类,包含String name、int speed属性,在测试类中实例化三个对象:c1,c2,c3,分别设置name为:“奥拓”,“宝马”,“奔驰”,速度分别设置为:100,200,300
1)使用Map集合对象m1将这三个汽车类对象保存成key,然后将int型的汽车价钱作为值保存在m1的value中,上述三款汽车分别对应的价钱是10000,500000,2000000
2)遍历m1的键,打印name属性
3)通过合适的方法,求出m1中“宝马”的价格,并打印结果;
4)经过折旧,所有汽车都降价到原来的80%,请打印降价后“宝马”的价格6、接口(45分钟)
请使用接口编码实现如下需求:
1)创建乐器(Instrument)接口:(10分)
2)创建两个实现类:钢琴(Piano)、小提琴(Violin))(15分)
3)各种乐器的弹奏( play )方法各不相同。
(15分)
4)编写一个测试类InstrumentTest,要求:(10分)
编写方法testPlay,对各种乐器进行弹奏测试。
要依据乐器的不同,进行相应的弹奏。
在main方法中创建不同的乐器对象,通过testPlay的弹奏测试方法进行测试。
7、继承(45分钟)
通过继承实现员工工资核算打印功能。
父类:员工类
子类:部门经理类、普通员工类
部门经理工资=1000+单日工资*天数*等级(1.2)。
普通员工工资=单日工资*天数*等级(1.0);
(1)员工属性:姓名,单日工资,工作天数(10分)
(2)员工方法(打印工资)(10分)
(3)普遍员工及部门经理都是员工子类,需要重写打印工资方法。
(20分)(4)定义并初始化普通员工对象,调用打印工资方法输入工资,定义并初始化部门经理对象,调用打印工资方法输入工资(10分)
8、面向对象(45分钟)
写一个汽车类:
属性:品牌;车长;颜色;价格;方法:跑的方法
提供无参的构造方法和一个有参的构造方法
1.创建五个对象:“捷达”,“宝马”,“劳斯莱斯”,“科鲁兹”,“迈锐宝”
2:要求设计一个学生类。
属性有:姓名、java成绩、android成绩、mysql成绩
3.所有属性要求使用private修饰。
4为每个属性设置setter和getter方法
5.添加有为全部属性赋值的构造方法
6有输出一个完整学生信息的方法
7.要求可以求学生的总分、平均分、最高分、最低分。
9、模拟用户注册:(60分钟)
1.创建一个User类有属性账号(userName)密码(passWord)(5分)
2.在项目中新建user.txt文档(5分)
3.在测试类中编写模拟注册:(5分)
欢迎来到积云教育注册:
4.输入1 之后提示:(5分)
请输入账号:
请输入密码:
请输入密码:
如果密码一致,提示注册成功如果密码不一致提示密码输入不一致。
注册成功之后将用户的信息通过IO流写入到user.txt文档中。
(如图:)(10分)
张三,123
李四,222
王五,456
5.注册成功之后通过IO流读取user.txt文档中的用户信息。
(10分)
通过用户信息利用字符串分割创建对应的用户对象,添加到ArrayList集合中。
(5分)
6.遍历集合,将用户信息打印到控制台;(5分)
10、模拟用户登录:(60分钟)
1.创建一个User类有属性账号(userName)密码(passWord)(5分)
2.在项目中新建user.txt文档并写入如下信息:(5分)
张三,123
李四,222
王五,456
3.在测试类中编写模拟登录:(5分)
欢迎来到积云教育:
4.输入1 之后提示:(5分)
请输入账号:
请输入密码:
5.IO流读取user.txt文档中的用户信息,如果账号与密码匹配并且在文档中存在则提示登录成功。
6.如果账号密码不存在,则提示是否修改密码输入Y 之后,提示:
请输入密码:
请再次输入密码:
两次密码一致则修改成功,并将新密码写入文档中替换掉之前的旧密码。
7.登录成功后将所有的用户信息添加到ArrayList集合中并打印到控制台(5分)
11、模拟商品购物车:(120分钟)
1.创建一个Shop类,有属性编号名称价格类型
2.在项目中新建一个shop.txt文档并写入如下信息:
1,电脑, 3000,电器
2,牛肉, 68,食物
3,桌子,200,家具
3.在测试类中编写模拟添加购物车,当程序运行时,读取shop.txt文档,并将文档中的所有商品信息创建对应的shop对象添加到ArrayList集合中。
4.遍历集合将商品信息显示到控制台并打印如下信息:
1,电脑, 3000,电器
2,牛肉, 68,食物
3,桌子,200,家具
5.控制台提示:
添加商品到购物车请输入1:
查看购物车请按2:
输入商品编号之后,创建Map集合每次输入一个编号就将商品作为键以及添加的次数作为值放入map集合中,并再次询问:
添加商品到购物车请输入1:
查看购物车请按2:
5.输入2 ,则遍历map集合并将购物车商品以及数量信息打印到控制台。
12、Io操作(90分钟)
按照题意完成:
1)使用File类,创建一个emp.txt文件
2)在文件中写入以下数据:效果图如下:(换行即可))
3)根据文件中的信息建立Person类:属性有:id,name,work,production(作品)
4)读取文件中的内容,解析,赋值给对象,并将对象添加到集合
5)遍历集合中的数据,查看是否成功添加到集合
6)将集合中的数据根据id排序
7)遍历排序后的集合,根据Person对象的个数,建立对应的person1.txt,person2.txt...文件
8)将集合中每个学生对象分别保存到不同的person.txt文件中;
13、从控制台获得数据: (45分钟)
如图请完成:
学生号姓名 Java核心基础 JavaWeb课程大数据
1 张学友 30 70 80
2 刘德华 40 90 20
3 黎明 50 77 33
4 郭富城 60 44 66
5 董家梁 80 65 28
有五个学生,每个学生有3门课的成绩,从键盘输入以上数据(包括学生号,姓名,三门课成绩),
计算出每个人的平均成绩,并按照他们的平均成绩从小到大添加到list集合
把原有的数据和计算出的平均分数存放在磁盘文件 "stud.txt "中。
14、求两个日期之间相隔的天数(20分钟)
java写一个方法(例如:fun3("2010-09-20","2010-09-21") ),
求输入的字符串2010-09-20 与 2010-09-21 之间相隔的天数,
(不考虑平年闰年)
15、请用递归方法完成对任意一个数字阶乘的计算:(30分钟)
如:输入3,得出3*2*1=6;
输入4,得出4*3*2*1=24。