论坛首页 入门技术论坛

SCJP认证试题

浏览 2013 次
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
作者 正文
   发表时间:2008-11-11  
 /**
 *
 * @author yaoyuan
 */
public class Foo implements Serializable{
    
    public int x, y;
    
    public Foo(int x, int y){
        this.x = x;
        this.y = y;
    }
    
    private void writeObject(ObjectOutputStream s) throws Exception{
        s.writeInt(x);
        s.writeInt(y);
    }
    
    private void readObject(ObjectOutputStream s) throws Exception{
        
    }
}

/**
*which code,inserted ay line 14,will allow this class to correctly serialized
*and desterilize?
*
*A      S.defaultReadObject();
*B This = s.defaultReadObject();
*C y = s.default();    x = s.readInt();
*D x = s.readInt();    y = s.readInt();
*/

// Answer : D


/**
 *
 * @author yaoyuan
 */
String test = "This is a test";
String[] tokens = test.split("\s");
System.out.println(tokens.length);


/**
*
*what is the result ?
*
*
*A 0
*B 1
*C 4
*D Compilation fails
*E An Exception is thrown at runtime
*/

/**Answer: D*/

/*API详解

public String[] split(String regex)

根据给定正则表达式的匹配拆分此字符串。
该方法的作用就像是使用给定的表达式和限制参数 0 来调用两参数 split 方法。因此,所得数组中不包括结尾空字符串。
例如,字符串 "boo:and:foo" 使用这些表达式可生成以下结果:
Regex
结果
:
{ "boo", "and", "foo" }
o
{ "b", "", ":and:f" }
参数:
regex - 定界正则表达式
返回:
字符串数组,它是根据给定正则表达式的匹配拆分此字符串确定的
抛出:
PatternSyntaxException - 如果正则表达式的语法无效
*/

"/s"不是有效的字符串


 /**
 *
 * @author yaoyuan
 */

12. Date date = new Date();
13. df.setLocale(LocalIaly);
14. String s = df.Format(date);


/**
*The variable df is an Object of type DateFormat that has been initialized in line 11.
*What is the result if this code is run on December 142000?
*
*A      The value of S is 14-dic-2004
*B The value of S is Dec 142000
*C An exception is thrown at runtime
*D Compilation fails because of an error in line 13
*/

// Answer : D


DateFormat抽象类没有setLocale(Object object);方法.


/**
*
* @author yaoyuan
*/

The does File Exist method takes an array of directory names representing a path from the root
file system and a file name. The method returns true if the file exists, false if does not.

Place the code fragments in position to complete this method.


/**
* [place here]
* for(String dir : directories){
* [place here]
* }
*
* [place here]
*
* [place here]
*
* }
*
*
* Code fragments
*
* [path=path.getSubdirectory(dir);] [return !file.isNew();] [return (file != null);]
* [String path = "";] [path = path.getFile(filename);] [File path = new File("");]
* [return file.exists();] [return path.isFile();] [File file = new File(path, filename);]
* [path = new File(path, dir);] [File path = new File(File.separator);]
* [path = path + File.separator + dir;]
*
*/




/**	Answer:
*
*	String path = "";
*	for(String dir : directories){
*		path = path + File.separator + dir;
*	}
*	File file = new File(path, filename);
*	return file.exists();
*
*/


/** Example Code:

public class Test {

    public static void main(String[] args) {
        Test test = new Test();
        String[] d = new String[2];
        d[0] = "C:";
        System.out.println(test.doesFileExist(d, "test"));
    }

    public boolean doesFileExist(String[] directories, String filename) {
        String path = "";
        for (String dir : directories) {
            path = path + File.separator + dir;
        }
        System.out.println(path);
        File file = new File(path, filename);
        return file.exists();
    }
}

*
*/



/**
*
* @author yaoyuan
*/



/**
* System.out.println("Pi is approximately %f and E is approximately %b, Math.PI, Math.E");
* place the values where they would appear in the output.
*
* output:
* pi is approximately [place here]
* and E is approximately [place here]
*
*
* Values
* [3] [2] [3.141593] [2.718282] [true]    [false]
* [Math.E] [Math.PI]
*
*/




/** Answer:
*
* Pi is approximately [3.141593]
* and E is approximately [true]
*
*/


/**API详解
* Math.E 比任何其他值都更接近 e(即自然对数的底数)的 double 值。
* Math.PI 比任何其他值都更接近 pi(即圆的周长与直径之比)的 double 值。
*
*/



/**
*
* @author yaoyuan
*/


/**
* When comparing java.io.BufferedWriter to java.io.FileWriter, which capability exist as a method in only
* one of the two?
*
*
*A      close the stream
*B flushing the stream
*C writing to the stream
*D making a location in the stream
*E writing a line separator to the stream
*/

// Answer : E



/**
 *
 * @author yaoyuan
 */
1.public class Main{
2.	public static void main(String[] args){
3.		//[insert Code here]
4.		System.out.println(s);
5.	}
6.}

/**
* Which two code fragments, inserted independently at line 3, generate the output 4247?(choose two)
*
*A      String s = "123456789";
* s = (s-"123").replace(1,3,"24")-"89";
*
*B StringBuffer s= new StringBuffer("123456789");
* s.delete(0, 3);
* s.replace(1,3,"24");
* s.delete(4,6);
*
*C StringBuffer s = new StringBuffer("123456789");
* s.subString(3,6);
* s.delete(1,3);
* s.insert(1,"24");
*
*D StringBuffer s = new StringBuffer("123456789");
* s.subString(3,6);
* s.delete(1,2);
* s.insert(1,"24");
*
*E StringBuffer s = new StringBuffer("123456789");
* s.delete(0,3);
* s.replace(1,3,"");
* s.delete(2,5);
* s.insert(1, "24");
*
*/

// Answer : B E



/**
*
* @author yaoyuan
*/


/**
*Which three statements concerning the use of the java.io.Realizable interface are true?(choose three)
*
*A      Object from classes that use aggregation cannot be serialized
*B An Object serialized on one JVM can be successfully desterilized on a different JVM.
*C The values in fields with the Volatile modifier will not survive serialization and desterilization
*D The values in fields with the transient modifier will not survive serialization and desterilization
*E It is legal to serialize an Object of a type that has a super type that does not implement
* java.io.Serialization
*/

// Answer : B D E


/**
 *
 * @author yaoyuan
 */
public class Main{
	
	public static void go(short n){
		System.out.println("short");
	}
	
	public static void go(short n){
		System.out.println("SHORT");
	}

	public static void go(Long n){
		System.void.println("LONG");
	}

	public static void main(String[] args){
	
		Short y = 6;
		int z = 7;
		go(y);
		go(z);
	}
}


/**
*What is the result?
*
*
*A      shortlong
*B SHORTLONG
*C Compilation fails
*D An exception is thrown at runtime
*/

// Answer : C

go(short n)已经定义



/**
*
* @author yaoyuan
*/

/**
*D is valid,non-null Date object
*df is valid,non-null DateFormat object set to the current local
*
*what outputs the current;local's country name and the appropriate version of d's date
*
*A      Locale loc = new Locale();
* System.out.println(loc.getDisplayCountry());
*
*B Locale loc = new Locale();
* System.out.println(loc.getDisplayCountry() + " " + df.format(d));
*
*C Locale loc = new Locale();
* System.out.println(loc.getDisplayCountry() + " " + df.setDateFormat(d));
*
*D Locale loc = new Locale();
* System.out.println(loc.getDisplayCountry() + " " + df.seDateFormat(d));
*/

// Answer : B







论坛首页 入门技术版

跳转论坛:
Global site tag (gtag.js) - Google Analytics