SCJP認証試験問題


 /**
 *
 * @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を用いて2つのパラメータ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