1: What will happen when you attempt to compile and run the following code?
int Output = 10;
boolean b1 = false;
if((b1 == true) && ((Output += 10) == 20))
{
System.out.println("We are equal " + Output);
}
else
{
System.out.println("Not equal! " + Output);
}
Choices: A.Compilation error, attempting to perform binary comparison on logical data type B.Compilation and output of "We are equal 10". C.Compilation and output of "Not equal! 20". D.Compilation and output of "Not equal! 10".
2:Which declares for native method in a java class corrected?
A.public native void method(){} B.public native void method(); C.public native method(); D.public void native method();
3: Consider the class hierarchy shown below:
--------------------------------------------------------------------
class FourWheeler implements DrivingUtilities
class Car extends FourWheeler
class Truck extends FourWheeler
class Bus extends FourWheeler
class Crane extends FourWheeler
----------------------------------------------------------------------
Consider the following code below:
1.DrivingUtilities du;
2.FourWheeler fw;
3.Truck myTruck = new Truck();
4.du = (DrivingUtilities)myTruck;
5.fw = new Crane();
6.fw = du;
Which of the statements below are true?
Choices: A.Line 4 will not compile because an interface cannot refer to an object. B.The code will compile and run. C.The code will not compile without an explicit cast at line 6, because going down the hierarchy without casting is not allowed. D.The code will compile if we put an explicit cast at line 6 but will throw an exception at runtime.
4: 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
5:Which statement about the garbage collection mechanism are true? A.Garbage collection require additional programe code in cases where multiple threads are running. B.The programmer can indicate that a reference through a local variable is no longer of interest. C.The programmer has a mechanism that explicity and immediately frees the memory used by Java objects. D.The garbage collection mechanism can free the memory used by Java Object at explection time.
6: Give the following java class: public class Example{ static int x[]=new int[15]; public static void main(String args[]){ 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.
7: 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.
8: What will happen when you attempt to compile and run the following code?
(Assume that the code is compiled and run with assertions enabled.)
public class AssertTest{
public void methodA(int i){
assert i >= 0 : methodB();
System.out.println(i);
}
public void methodB(){
System.out.println("The value must not be negative");
}
public static void main(String args[]){
AssertTest test = new AssertTest();
test.methodA(-10);
}
} A.it will print -10 B.it will result in AssertionError showing the message-“the value must not be negative”. C.the code will not compile. D.None of these.
9: What happens when you try to compile and run the following program? class Mystery{ String s; public static void main(String[] args){ Mystery m=new Mystery(); m.go(); } void Mystery(){ s=”constructor”; } void go(){ System.out.println(s); } }
A.this code compliles but throws an exception at runtime B.this code runs but nothing appears in the standard output C.this code runs and “constructor” in the standard output D.this code runs and writes ”null” in the standard output
10:Which are not Java keywords?
A.TRUE B.const C.super D.void
11: The following code is entire contents of a file called Example.java,causes precisely one error during compilation: class SubClass extends BaseClass{ } class BaseClass(){ String str; public BaseClass(){ System.out.println(“ok”);} public BaseClass(String s){ str=s;}} public class Example{ public void method(){ SubClass s=new SubClass(“hello”); BaseClass b=new BaseClass(“world”); } }
Which line would be cause the error? A.9 B.10 C.11 D.12
12: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.
13:以下的C程序代碼片段運行后C和d的值分別是多少 Int a =1,b =2; Int c,d; c =(a&b)&&a; d =(a&&b)&a;
A.0,0 B.0,1 C.1,0 D.1,1
14: What results from attempting to compile and run the following code?
public class Ternary
{
public static void main(String args[])
{
int a = 5;
System.out.println("Value is - " + ((a < 5) ? 9.9 : 9));
}
}
Choices:
A.prints: Value is - 9 B.Compilation error C. prints: Value is - 5 D.None of these
15: Given the following class definition: class A{ protected int i; A(int i){ this.i=i; } } which of the following would be a valid inner class for this class? Select valid answer: A.class B{ } B.class B extends A{ } C.class B extends A{ B(){System.out.println(“i=”+i);} } D.class B{ class A{} }
簡答題 16:要在Tomcat 5.5容器里進行session復制,,必須完成哪些步驟,?
17:編寫一個截取字符串的函數(shù),輸入為一個字符串和字節(jié)數(shù),,輸出為按字節(jié)截取的字符串。 但是要保證漢字不被截半個,,如"我ABC"4,,應(yīng)該截為"我AB",輸入"我ABC漢DEF",,6,,應(yīng)該輸出為"我ABC"而不是"我ABC+漢的半個"。
18:編寫一個確定一字符串在另一字符串中出現(xiàn)次數(shù)的算法,。例如字符串“this”在字符串“this is my first program. this…”中出現(xiàn)了2次,,不要使用庫函數(shù)(方法)。
19:struts2的action需要繼承那個類?
20:有一篇英文文章(也就是說每個單詞之間由空格分隔),,請找出“csdn”著個單詞出現(xiàn)的次數(shù),,要求效率最高,并寫出算法的時間級。
21:已知數(shù)組 a 中的元素是從小到大排序的,,要求對于任意輸入的一個整數(shù) x ,,把它插到數(shù)組 a 后,仍保持數(shù)組 a 的排序次序不變,。
22:jsp有哪些動作?作用分別是什么?
23:確定模塊的功能和模塊的接口是在軟件設(shè)計的那個隊段完成的?
24:金額轉(zhuǎn)換,,阿拉伯數(shù)字的金額轉(zhuǎn)換成中國傳統(tǒng)的形式如: (¥1011)->(一千零一拾一元整)輸出文章來源:筆試網(wǎng) www.—專業(yè)的筆試、面試資料搜索網(wǎng)站
|