/**
*
* @author yaoyuan
*/
1 import java.util.*;
2 public class TestSet{
3 enum Example{ONE,TWO,THREE}
4 public static void main(String[] args){
5 Collection coll = new ArrayList();
6 coll.add(Example.Three);
7 coll.add(Example.Three);
8 coll.add(Example.Three);
9 coll.add(Example.TWO);
10 coll.add(Example.TWO);
11 coll.add(Example.ONE);
12 Set set = new HashSet(coll);
13 }
14 }
/**
*Which statements is true about the set variable on line 12?
*
*
*A The set variable contains all six elements from the coll collection, and the order is guaranteed to be preserved
*B The set variable contains only three elements from the coll collection, and the order is guaranteed to be preserved
*C The set variable contains all six elements from the coll collection, but the order is NOT guaranteed to be preserved
*D The set variable contains only three elements from the coll collection, but the order is NOT guaranteed to be preserved
*/
// Answer : D
/**
*
* @author yaoyuan
*/
11 public class Person{
12 private String name, comment;
13 private int age;
14 public Person(String n,int a, String c){
15 name = n; age = a, comment = c;
16 }
17 public boolean equals(Object o){
18 if(!(o instanceof Person)) return false;
19 Person p = (Person)o;
20 return age == p.age && name.equals(p.name);
21 }
22 }
/**
*What is the appropriated definition of the hashCode method in class Person?
*
*
*A return super.hashCode();
*B return super.hashCode() + 7* age;
*C return name.hashCode() + comment.hashCode()/2;
*D return name.hashCode() + comment.hashCode()/2 - age*3;
*/
// Answer : B
/**
*
* @author yaoyuan
*/
1 public class Person{
2 private String name;
3 public Person(String n){ this.name = name;}
4 public boolean equals(Person p){
5 return p.name.equals(this.name);
6 }
7 }
/**
*Which statements is true?
*
*
*A The equals method does not properly override the Object equals method
*B Compilation fails because the private attribute p.name cannot be accessed in line 5
*C to work correctly with hash-based data structures, this class must also implement the hashCode method
*D When adding Person objects to java.util.Set collection, the equals method in line 4 will prevent duplicates
*/
// Answer : A
/**
*
* @author yaoyuan
*/
1 import java.util.*;
2 public class Example{
3 public static void main(String[] args){
4 //insert code here
5 set.add(new Integer(1));
6 set.add(new Integer(2));
7 System.out.println(set);
8 }
9 }
/**
*Which code , inserted at line 4, guaranteed that this program will output[1,2]?
*
*
*A Set set = new TreeSet();
*B Set set = new HashSet();
*C Set set = new SortedSet();
*D List set = new SortedList();
*E Set set = new LinkedHashSet();
*/
// Answer : A
/**
*
* @author yaoyuan
*/
34 HashMap props = new HashMap();
35 props.put("key45", "some value");
36 props.put("key12", "some other value");
37 props.put("key39", "yet another value");
38 Set s = props.ketSet();
39 //insert code here
/**
*What inserted at line 39, will sort the keys in the props HashMap?
*
*A Array.sort(s);
*B s = new TreeSet(s);
*C Collections.sort(s);
*D s = new SortedSet(s);
*/
// Answer : B
/**
*
* @author yaoyuan
*/
/**
*Which two code fragments will execute the method doStuff() in a separate thread?
*
*
*
*A new Thread(){public void run(){doStuff();}};
*B new Thread(){public void start(){doStuff();}};
*C new Thread(){public void start(){doStuff();}}.run();
*D new Thread(){public void run(){doStuff();}}.start();
*E new Thread(new runnable(){public void run(){doStuff();}}).run();
*F new Thread(new runnable(){public void run(){doStuff();}}).start();
*/
// Answer : D F
/**
*
* @author yaoyuan
*/
1 public class Threads2 implements Runnable{
2
3 public void run(){
4 System.out.println("run.");
5 throw new RuntimeException("Problem");
6 }
7 public static void main(String[] args){
8 Thread t = new Thread(new Threads2());
9 t.start();
10 System.out.println("End of method");
11 }
12 }
/**
*Which to can be results?(Choose two)
*
*
*A java.lang.RuntimeException:Problem
*B run.
java.lang.RuntimeException:Problem
*C End of method
java.langRuntimeException:Problem
*D End of method
run
java.langRuntimeException:Problem
*E run.
* java.langRuntimeException:Problem
* End of method
*/
// Answer : D E
/**
*
* @author yaoyuan
*/
public class NamedCounter{
private final String name;
private int count;
public NamedCounter(String name){this.name = name};
public String getName(){return name;}
public void increment(){count++;}
public int getCount(){return count;}
public void reset(){count=0;}
}
/**
*Which three changes should be made to adapt this class to be used safely by multiple threads?(Choose three)
*
*
*
*A declare reset() using the synchronized keyword
*B declare getName() using the synchronized keyword
*C declare getCount() using the synchronized keyword
*D declare the constructor using the synchronized keyword
*E declare increment() using the synchronized keyword
*/
// Answer : A C E
/**
*
* @author yaoyuan
*/
1 public class TestSeven extends Thread{
2 private static int x;
3 public synchronized void doThings(){
4 int current = x;
5 current++;
6 x = current;
7 }
8 public void run(){
9 doThings();
10 }
11 }
/**
*Which statements is true?
*
*
*A Compilation fails
*B An exception is thrown at runtime
*C Synchronizing the run() method would make the class thread-safe
*D The data in variable "x" are protected from concurrent access problems
*E Declaring the doThings() method as static would make the class thread-safe
*F Wrapping the statements with in doThings() in a synchronized (new Object()){} block would make the class thread-safe
*/
// Answer : E
/**
*
* @author yaoyuan
*/
7 void waitForSignal(){
8 Object obj = new Object();
9 synchronized (Thread.currentThread()){
10 obj.wait();
11 obj.notify();
12 }
13 }
/**
*What statement is true?
*
*
*A This code may throw an InterruptedException
*B This code may throw an IllegalStateException
*C This code may throw a TimeoutException after ten minutes
*D This code will not compile unless "obj.wait()" is replaced with "((Thread)obj).wait()"
*E A call to notify() or notifyAll() from another thread may cause this method to complete normally
*/
// Answer : B
分享到:
- 2008-11-24 09:23
- 浏览 1990
- 评论(0)
- 论坛回复 / 浏览 (0 / 2038)
- 查看更多
相关推荐
这个压缩包文件包含了多个与SCJP认证相关的学习资源,包括试题、题库和答案,以及一些重要的复习资料。 1. **SCJP认证概述**:SCJP是Java初学者或初级开发者提升职业资质的重要途径。通过这个认证,开发者可以证明...
Java认证,全称为Sun Certified Programmer for the Java 2 Platform, Standard Edition ...以上这些知识点都是SCJP认证考试的重点,通过深入学习和大量练习,考生可以提升自己的Java编程技能,提高通过考试的可能性。
本压缩包文件提供了三个部分的"JAVA SCJP认证模拟试题",分别是"SCJP模拟试题(一).doc"、"SCJP模拟试题(二).doc"和"SCJP模拟试题(三).doc",这些文档可能包含了多个章节的练习题目,覆盖了Java语言的核心概念...
SCJP认证试题通常涵盖以下几个主要领域: 1. **Java语言基础**:包括基本语法、数据类型、变量、运算符、流程控制(如if-else、switch、for、while循环)、方法、数组等。这些是Java编程的基础,理解和熟练掌握它们...
SCJP认证的学习资料通常会包含详细的理论讲解、实例演示、习题解答和模拟试题,帮助学习者全面掌握这些知识点。通过阅读这5本书,你将有机会深入理解Java语言的各个方面,为SCJP认证考试做好充分准备。同时,不断...
这份"java scjp模拟试题"包含三套模拟测试题,是准备SCJP认证考试的宝贵资源。通过这些试题,考生可以检验自己的知识掌握程度,熟悉考试的格式和题型,提高备考效率。 模拟试题通常涵盖以下几个关键知识点: 1. **...
SCJP,全称为Sun Certified Programmer for the Java 2 Platform,是Oracle公司(原Sun Microsystems)推出的针对Java程序员的认证考试。这个考试旨在测试考生对于Java SE平台基础编程的知识和技能。以下是一些SCJP...
Java SCJP(SUN Certified Programmer for the Java Platform)是针对Java初学者的一项认证考试,它主要测试考生对Java基础知识的理解和应用能力。...熟悉并掌握这些知识点对于通过SCJP认证考试至关重要。
根据给定的文件信息,以下是对“SCJP认证试题”中的关键知识点的详细解析: ### SCJP认证概览 SCJP(Sun Certified Programmer for Java Platform)是Java领域中最具权威的专业程序员认证之一,由Sun Microsystems...
首先,我们要了解SCJP认证涉及的基础知识: 1. **Java语言基础**:包括数据类型(如整型、浮点型、字符型、布尔型)、变量声明、运算符(算术、关系、逻辑、位、赋值等)、流程控制(if-else、switch、循环、跳转...
"SCJP认证套题解析"是一个针对这项认证的备考资源,通常包括一系列模拟试题、答案解析以及相关的知识点讲解。 SCJP认证覆盖的知识点广泛,主要包括以下几个方面: 1. **Java语言基础**:这部分内容涉及Java语法、...
总的来说,准备SCJP认证需要系统学习Java语言的核心概念,并通过大量的实践和模拟试题来提高编程能力和应对考试的能力。这个压缩包文件很可能是备考SCJP的一个重要资源,考生应当充分利用其中的资源进行复习和准备。
### Java SCJP考试知识点解析 #### 题目87: 命令行参数解析与输出 **题目描述:** 在给定的代码中,`Test` 类包含了一个 `main` 方法,该方法试图从命令行参数数组 `args` 中获取元素并将其赋值给 `String` 类型的...
【JAVA认证历年真题 SCJP认证套题解析】主要涵盖了JAVA语言的基础知识,包括数据类型、标识符规则、数值类型转换、字符串操作以及对象和类的使用等方面。以下是这些知识点的详细说明: 1. **数据类型**:题目中提到...
SCJP(Sun Certified Programmer for the Java 2 Platform, Standard Edition)是Oracle公司为Java程序员提供的一项认证考试,旨在验证考生对Java编程语言的基础知识和理解。这个认证在Java社区中非常受到重视,因为...
首先,SCJP认证是Java程序员入门阶段的重要凭证,它证明了持有者具备编写和调试Java程序的基本技能。这个认证涵盖了语言特性、类库、内存管理以及异常处理等方面的基础知识。 1. **Java语言特性**:书中会涵盖Java...
SCJP认证考试通常涵盖以下几个核心领域: 1. **Java语法**:包括基本的数据类型、变量、运算符、流程控制(if语句、switch、循环)、方法、类和对象的概念,以及异常处理。理解这些基础知识是编写任何Java程序的...
SCJP试题详析(中文版)作为一本经典的Java认证准备书籍,不仅涵盖了广泛的Java知识点,还提供了深入的试题分析和解题技巧,对于希望深入了解Java或准备SCJP认证的读者来说,是一份宝贵的资源。同时,作者通过多种...