`
yuanyao
  • 浏览: 147210 次
  • 性别: Icon_minigender_1
  • 来自: 就那小山沟
社区版块
存档分类
最新评论

SCJP认证试题(二)

    博客分类:
  • Java
阅读更多
 /**
 *
 * @author yaoyuan
 */
public class Main implements Runnable{
	public void run(){
		System.out.print("running");
	}
	
	public static void main(String[] args){
		Thread t = new Thread(new Main());
		t.run();
		t.run();
		t.start();
		}
}

/**
* What is result ?
*
*
*A      compilcation fails
*B An Exception is thrown at runtime
*C The code executes and prints "running"
*D The code executes and prints "runningrunning"
*E The code executes and prints "runningrunningrunning"
*/


// Answer : E




/**API详解
*
public void start()

使该线程开始执行;Java 虚拟机调用该线程的 run 方法。
结果是两个线程并发地运行;当前线程(从调用返回给 start 方法)和另一个线程(执行其 run 方法)。
多次启动一个线程是非法的。特别是当线程已经结束执行后,不能再重新启动。


public void run()

如果该线程是使用独立的 Runnable 运行对象构造的,则调用该 Runnable 对象的 run 方法;否则,该方法不执行任何操作并返回。
Thread 的子类应该重写该方法。

*/




 /**
 *
 * @author yaoyuan
 */
public class Threads1{
	int x = 0;
	
	public class Runner implements Runnable{
		public void run(){
			int current = 0;
			for(int i=0;i<4;i++){
				current = x;
				System.out.print(current + ", ");
				x = current + 2;
			}
		}
		
	}

	public static void main(String[] args){
		new Thread1().go();
	}

	public void go(){
		Runnable r1 = new Runner();
		new Thread(r1).start();
		new Thread(r1).start();
	}
}


/**
*Which two are possible results?
*
*
*A      0,2,4,4,6,8,10,6,
*B 0,2,4,6,8,10,2,4,
*C 0,2,4,6,8,10,12,14
*D 0,0,2,2,4,4,6,6,8,8,10,10,12,12,14,14
*E 0,2,4,6,8,10,12,14,0,2,4,6,8,10,12,14
*/

// Answer : A C


/**解题帮助
*
*  int x = 0; x是全局变量,Thread1和Thread2公有一个x
*  int current = 0;  current是局部变量,每次都被初始化为0
*
*
*/


 /**
 *
 * @author yaoyuan
 */
void waitForSignal(){
	Object obj = new Object();
	synchronized (Thread.currentThread()){
		obj.wait();
		obj.notify();
	}
}


/**
* Which statement is true?
*
*
*A      This code may thorw an InterruptedException
*B This code may thorw 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 Reversing the order of obj.wait() and obj.notify() may cause this method to complete normally
*/

// Answer : B



 /**
 *
 * @author yaoyuan
 */
public class TestOne implements Runnable{
	public static void main(String[] args) throws Exception{
		Thread t = new Thread(new TestOne());
		t.start();
		System.out.print("Started");
		t.join();
		System.out.print("Complete");
	}
	
	public void run(){
		for(int i=0;i<4;i++){
			System.out.println(i);
		}
	}
}

/**
*What can be a result ?
*
*
*A      Compilation fails
*B An exception thrown at runtime
*C The code executes and prints "StartedComplete"
*D The code executes and prints "StartedComplete"
*E The code executes and prints "Started0123Complete"
*/

// Answer : E



/**
*
* @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
*/


/**
*Which three will compile and run without exception?(choose three)
*
*
*A      private synchronized object;
*
*B void go(){
* synchronized(){
* / code here  /
* }
* }
*
*C public synchronized void go(){
* / code here /
* }
*
*D private synchronized(this) void go(){
* / code here /
* }
*
*E void go(){
* synchronized(object.class){
* / code here /
* }
* }
*
*F void go{
* synchronized(o){
* / code here /
* }
* }
*/

// Answer : C E F

/**
*
*synchronized关键字的问题,这里不在多说了(敲的有点累^_^)
*
*/



/**
 *
 * @author yaoyuan
 */
class Computation extends Thread{
	private int num;
	private boolean isComplete;
	private int result;
	
	public Computation(int num){
		this.num = num;
	}
	
	public synchronized void run(){
		result = num * 2;
		isComplete = true;	
		notify();
	}
	
	public synchronized int getResult(){
		while(!isComplete){
			try{
				wait();
			}
			catch(InterruptedException e){
				
			}
		}
		return result;	
	}
	
	public static void main(String[] args){
		Computation[] computations = new Computation[4];
		for(int i=0;i<computations.length;i++){
			computations[i] = new Computation(i);
			computations[i].start();
		}
		for(Computation c : computations){
			System.out.print(c.getResult() + " ");
		}
	
	}
}

/**
*What is Result ?
*
*
*A The code will deadlock
*B The code may run with no output
*C An exception thrown at runtime
*D The code may run with output "06"
*E The code may run with output "2064"
*F The code may run with output "0246"
*/

// Answer : F


/**
 *
 * @author yaoyuan
 */
public class Main{

	public static void main(String[] args) throws Exception{
		Thread.sleep(3000);
		System.out.print("sleep");
	}

}

/**
*What is Result ?
*
*
*A Compilation fails
*B An exception is thrown at runtime
*C The code executes normally and prints "sleep"
*D The code executes normally, but nothing is printed
*/

// Answer : C



/**
*
* @author yaoyuan
*/

/**
*Which two statements are true about has-a and is a relationships?(choose two)
*
*
*A Inheritance represents an is-a relationship
*B Inheritance represents an has-a relationship
*C Inheritance must be used when creating a has-a relationship
*D Instance variables can be used when creating a has-a relationship
*/

// Answer : A D




 /**
 *
 * @author yaoyuan
 */
package yaoyuan;

class Target{
	public String name = "hello";
}


/**
*What can directly access and change the value of the variable name?
*
*
*A      any class
*B only the Target class
*C any class in the yaoyuan package
*D any class that extends Target
*/

// Answer : C



分享到:
评论
1 楼 JAVA_mentu 2008-11-12  
so good

相关推荐

    java认证试题 scjp模拟试题

    Java认证,全称为Sun Certified Programmer for the Java 2 Platform, Standard Edition ...以上这些知识点都是SCJP认证考试的重点,通过深入学习和大量练习,考生可以提升自己的Java编程技能,提高通过考试的可能性。

    scjp认证试题.rar

    这个压缩包文件包含了多个与SCJP认证相关的学习资源,包括试题、题库和答案,以及一些重要的复习资料。 1. **SCJP认证概述**:SCJP是Java初学者或初级开发者提升职业资质的重要途径。通过这个认证,开发者可以证明...

    SCJP试题SCJP试题SCJP试题

    关于SCJP(SUN Certified Programmer for the Java SE Platform)试题,这是Java编程语言的一个认证考试,旨在测试应试者对Java基础知识的理解和应用能力。以下是一些相关知识点的详细解释: 1. **方法(Method)**...

    JAVA认证-scjp模拟试题

    本压缩包文件提供了三个部分的"JAVA SCJP认证模拟试题",分别是"SCJP模拟试题(一).doc"、"SCJP模拟试题(二).doc"和"SCJP模拟试题(三).doc",这些文档可能包含了多个章节的练习题目,覆盖了Java语言的核心概念...

    scjp 认证 试题

    SCJP认证试题通常涵盖以下几个主要领域: 1. **Java语言基础**:包括基本语法、数据类型、变量、运算符、流程控制(如if-else、switch、for、while循环)、方法、数组等。这些是Java编程的基础,理解和熟练掌握它们...

    SCJP认证学习资料

    SCJP认证的学习资料通常会包含详细的理论讲解、实例演示、习题解答和模拟试题,帮助学习者全面掌握这些知识点。通过阅读这5本书,你将有机会深入理解Java语言的各个方面,为SCJP认证考试做好充分准备。同时,不断...

    java scjp模拟试题

    这份"java scjp模拟试题"包含三套模拟测试题,是准备SCJP认证考试的宝贵资源。通过这些试题,考生可以检验自己的知识掌握程度,熟悉考试的格式和题型,提高备考效率。 模拟试题通常涵盖以下几个关键知识点: 1. **...

    SCJP试题,SCJP试题

    SCJP,全称为Sun Certified Programmer for the Java 2 Platform,是Oracle公司(原Sun Microsystems)推出的针对Java程序员的认证考试。这个考试旨在测试考生对于Java SE平台基础编程的知识和技能。以下是一些SCJP...

    SCJP认证试题

    根据给定的文件信息,以下是对“SCJP认证试题”中的关键知识点的详细解析: ### SCJP认证概览 SCJP(Sun Certified Programmer for Java Platform)是Java领域中最具权威的专业程序员认证之一,由Sun Microsystems...

    scjp试题 java 认证 考证

    Java SCJP(SUN Certified Programmer for the Java Platform)是针对Java初学者的一项认证考试,它主要测试考生对Java基础知识的理解和应用能力。...熟悉并掌握这些知识点对于通过SCJP认证考试至关重要。

    JAVA国际认证(SCJP)典型试题1000例

    首先,我们要了解SCJP认证涉及的基础知识: 1. **Java语言基础**:包括数据类型(如整型、浮点型、字符型、布尔型)、变量声明、运算符(算术、关系、逻辑、位、赋值等)、流程控制(if-else、switch、循环、跳转...

    SCJP认证套题解析

    "SCJP认证套题解析"是一个针对这项认证的备考资源,通常包括一系列模拟试题、答案解析以及相关的知识点讲解。 SCJP认证覆盖的知识点广泛,主要包括以下几个方面: 1. **Java语言基础**:这部分内容涉及Java语法、...

    JAVA认证 scjp模拟试题.rar

    总的来说,准备SCJP认证需要系统学习Java语言的核心概念,并通过大量的实践和模拟试题来提高编程能力和应对考试的能力。这个压缩包文件很可能是备考SCJP的一个重要资源,考生应当充分利用其中的资源进行复习和准备。

    scjp模拟试题大全

    接着,"scjp模拟试题(二)思达网校.doc"和"scjp模拟试题(三)思达网校.doc"是另外两套模拟试题,它们同样会涵盖上述主题,但可能包含不同的题目,以提供更多的练习机会。每一套模拟试题都是对考生掌握Java编程概念...

    Java scjp考试试题

    ### Java SCJP考试知识点解析 #### 题目87: 命令行参数解析与输出 **题目描述:** 在给定的代码中,`Test` 类包含了一个 `main` 方法,该方法试图从命令行参数数组 `args` 中获取元素并将其赋值给 `String` 类型的...

    JAVA认证历年真题 SCJP认证套题解析

    【JAVA认证历年真题 SCJP认证套题解析】主要涵盖了JAVA语言的基础知识,包括数据类型、标识符规则、数值类型转换、字符串操作以及对象和类的使用等方面。以下是这些知识点的详细说明: 1. **数据类型**:题目中提到...

    《Java国际认证(SCJP)典型试题1000例 中文版

    首先,SCJP认证是Java程序员入门阶段的重要凭证,它证明了持有者具备编写和调试Java程序的基本技能。这个认证涵盖了语言特性、类库、内存管理以及异常处理等方面的基础知识。 1. **Java语言特性**:书中会涵盖Java...

    scjp模拟试题三套

    SCJP认证考试通常涵盖以下几个核心领域: 1. **Java语法**:包括基本的数据类型、变量、运算符、流程控制(if语句、switch、循环)、方法、类和对象的概念,以及异常处理。理解这些基础知识是编写任何Java程序的...

Global site tag (gtag.js) - Google Analytics