- 相關(guān)推薦
java軟件開發(fā)工程師筆試題
選擇題
1:
In the following code, which is the earliest statement, where the object originally held in e, may be garbage collected:
1.public class Test {
2. public static void main (String args []) {
3. Employee e = new Employee("Bob", 48);
4. e.calculatePay();
5. System.out.println(e.printDetails());
6. e = null;
7. e = new Employee("Denise", 36);
8. e.calculatePay();
9. System.out.println(e.printDetails());
10. }
11.}
Only One:
In the following code, which is the earliest statement, where the object originally held in e, may be garbage collected:
1.public class Test {
2. public static void main (String args []) {
3. Employee e = new Employee("Bob", 48);
4. e.calculatePay();
5. System.out.println(e.printDetails());
6. e = null;
7. e = new Employee("Denise", 36);
8. e.calculatePay();
9. System.out.println(e.printDetails());
10. }
11.}
Only One:
A.Line 10
B.Line 11
C.Line 7
D.Line 8
2:Exhibit :
1. public class test (
2. private static int j = 0;
3.
4. private static boolean methodB(int k) (
5. j += k;
6. return true;
6. )
7.
8. public static void methodA(int i) {
9. boolean b:
10. b = i < 10 | methodB (4);
11. b = i < 10 || methodB (8);
12. )
13.
14. public static void main (String args[] } (
15. methodA (0);
16. system.out.printIn(j);
17. )
18. )
What is the result?
A.The program prints “0”
B.The program prints “4”
C.The program prints “8”
D.The program prints “12”
3:What is written to the standard output given the following statement:System.out.println(4|7);
Select the right answer:
A.4
B.5
C.6
D.7
4:
Select valid identifier of Java:
Select valid identifier of Java:
A.%passwd
B.3d_game
C.$charge
D.this
5:設(shè)有變量說明語句int a=1,b=0;
則執(zhí)行以下程序段的輸出結(jié)果為( )。
switch (a)
{
case 1:
switch (b)
{
case 0:printf("**0**");break;
case 1:printf("**1**");break;
}
case 2:printf("**2**");break;
}
printf(" ");
A.**0**
B.**0****2**
C.**0****1****2**
D.有語法錯誤
6:In the following pieces of code, which one will compile without any error?
A.StringBuffer sb1 = "abcd";
B.Boolean b = new Boolean("abcd");
C.C: byte b = 255;
D.float fl = 1.2;
7:
What is the result when you compile and run the following code?
public class ThrowsDemo
{
static void throwMethod()
{
System.out.println("Inside throwMethod.");
throw new IllegalAccessException("demo");
}
public static void main(String args[])
{
try
{
throwMethod();
}
catch (IllegalAccessException e)
{
System.out.println("Caught " + e);
}
}
}
Choices:
What is the result when you compile and run the following code?
public class ThrowsDemo
{
static void throwMethod()
{
System.out.println("Inside throwMethod.");
throw new IllegalAccessException("demo");
}
public static void main(String args[])
{
try
{
throwMethod();
}
catch (IllegalAccessException e)
{
System.out.println("Caught " + e);
}
}
}
Choices:
A.Compilation error
B.Runtime error
C.Compile successfully, nothing is printed.
D.Inside throwMethod. followed by caught:java.lang.IllegalAccessExcption: demo
8:Which of the following statements are not legal?
A.long l = 4990;
B.int i = 4L;
C.double d = 34.4;
D.double t = 0.9F.
9:
Give the following java class:
public class Example{
public static void main(String args[]){
static int x[] = new int[15];
System.out.println(x[5]);
}
}
Which statement is corrected?
Give the following java class:
public class Example{
public static void main(String args[]){
static int x[] = new int[15];
System.out.println(x[5]);
}
}
Which statement is corrected?
A.When compile, some error will occur.
B.When run, some error will occur.
C.Output is zero.
D.Output is null.
10:下面關(guān)于變量及其范圍的陳述哪些是錯的。
A.實(shí)例變量是類的成員變量。
B.實(shí)例變量用關(guān)鍵字static聲明。
C.在方法中定義的局部變量在該方法被執(zhí)行時創(chuàng)建
D.局部變量在使用前必須被初始化。
11:
public class X{
public Object m(){
Object o = new Float(3.14F);//line 3
Object [] oa = new Object[1];//line 4
oa[0] = o;//line 5
o=null;//line 6
return oa[0];//line 7
}
}
When is the Float object, created in line 3,eligible for garbage collection?
public class X{
public Object m(){
Object o = new Float(3.14F);//line 3
Object [] oa = new Object[1];//line 4
oa[0] = o;//line 5
o=null;//line 6
return oa[0];//line 7
}
}
When is the Float object, created in line 3,eligible for garbage collection?
A.just after line 5.
B.just after line 6
C.just after line 7(that is,as the method returns)
D.never in this method
12:
Which is the most appropriate code snippet that can be inserted at line 18 in the following code?
(Assume that the code is compiled and run with assertions enabled)
1. import java.util.*;
2.
3. public class AssertTest
4. {
5. private HashMap cctld;
6.
7. public AssertTest()
8. {
9. cctld = new HashMap();
10. cctld.put("in", "India");
11. cctld.put("uk", "United Kingdom");
12. cctld.put("au", "Australia");
13. // more code...
14. }
15. // other methods ....
16. public String getCountry(String countryCode)
17. {
18. // What should be inserted here?
19. String country = (String)cctld.get(countryCode);
20. return country;
21. }
22. }
Which is the most appropriate code snippet that can be inserted at line 18 in the following code?
(Assume that the code is compiled and run with assertions enabled)
1. import java.util.*;
2.
3. public class AssertTest
4. {
5. private HashMap cctld;
6.
7. public AssertTest()
8. {
9. cctld = new HashMap();
10. cctld.put("in", "India");
11. cctld.put("uk", "United Kingdom");
12. cctld.put("au", "Australia");
13. // more code...
14. }
15. // other methods ....
16. public String getCountry(String countryCode)
17. {
18. // What should be inserted here?
19. String country = (String)cctld.get(countryCode);
20. return country;
21. }
22. }
A.assert countryCode != null;
B.assert countryCode != null : "Country code can not be null" ;
C.assert cctld != null : "No country code data is available";
D.assert cctld : "No country code data is available";
13:
Give the following code:
public class Example{
public static void main(String args[] ){
int l=0;
do{
System.out.println(“Doing it for l is:”+l);
}while(--l>0)
System.out.println(“Finish”);
}
}
Which well be output:
Give the following code:
public class Example{
public static void main(String args[] ){
int l=0;
do{
System.out.println(“Doing it for l is:”+l);
}while(--l>0)
System.out.println(“Finish”);
}
}
Which well be output:
A.Doing it for l is 3
B.Doing it for l is 1
C.Doing it for l is 2
D.Doing it for l is 0
14:Which statements about Java code security are not true?
A.The bytecode verifier loads all classes needed for the execution of a program.
B.Executing code is performed by the runtime interpreter.
C.At runtime the bytecodes are loaded, checked and run in an interpreter.
D.The class loader adds security by separating the namespaces for the classes of the local file system from those imported from network sources.
15:A class design requires that a member variable should be accessible only by same package, which modifer word should be used?
A.protected
B.public
C.no modifer
D.private
16:Character流與Byte流的區(qū)別是
A.每次讀入的字節(jié)數(shù)不同
B.前者帶有緩沖,后者沒有
C.前者是塊讀寫,后者是字節(jié)讀寫
D.二者沒有區(qū)別,可以互換使用
簡答題
17:找出兩個字符串中最大子字符串,如"abractyeyt","dgdsaeactyey"的最大子串為"actyet"
18:假設(shè)你有一個用1001個整數(shù)組成的數(shù)組,這些整數(shù)是任意排列的,但是你知道所有的整數(shù)都在1到1000(包括1000)之間。此外,除一個數(shù)字出現(xiàn)兩次外,其他所有數(shù)字只出現(xiàn)一次。假設(shè)你只能對這個數(shù)組做一次處理,用一種算法找出重復(fù)的那個數(shù)字。如果你在運(yùn)算中使用了輔助的存儲方式,那么你能找到不用這種方式的算法嗎?
19:到底在哪里使用cascade="..."?
20:使用tomcat部署應(yīng)用程序 遇到過java.lang.OutOfMemoryError 嗎?如何解決的。
21:請寫一個java程序?qū)崿F(xiàn)數(shù)據(jù)庫緩沖池的功能?
22:有200個正整數(shù),且每個數(shù)均在1000至9999之間。請編制函數(shù),其函數(shù)的功能是:要求按每個數(shù)的后三位的大小進(jìn)行升序排列,然后取出滿足此條件的前10個數(shù)依次存入數(shù)組bb中,如果后三位的數(shù)值相等,則按原先的數(shù)值進(jìn)行降序排列。
23:Anonymous Inner Class (匿名內(nèi)部類) 是否可以extends(繼承)其它類,是否可以implements(實(shí)現(xiàn))interface(接口)?
24:找出字符串A中包含的字符可以進(jìn)行的所有不同組合。例如:abccd中,ab,ac,bc,cc,abd等都是可能的組合。
25:下面的代碼在絕大部分時間內(nèi)都運(yùn)行得很正常,請問在什么情況下會出現(xiàn)問題?問題的根源在哪里?
import java.util.LinkedList;
public class Stack {
LinkedList list = new LinkedList();
public synchronized void push(Object x) {
synchronized(list) {
list.addLast( x );
notify();
}
}
public synchronized Object pop()
throws Exception {
synchronized(list) {
if( list.size() <= 0 ) {
wait();
}
return list.removeLast();
【java軟件開發(fā)工程師筆試題】相關(guān)文章:
Java工程師面試題03-29
java軟件開發(fā)工程師簡歷范文12-06
java中級工程師面試題03-30
java軟件開發(fā)簡歷11-30