1.What will happen when you attempt to compile and run the following code?( )
public class Test
{
public static void main(String argv[])
{
Test test = new Test();
}
Test()
{
boolean b = false;
if(b = true)
{
System.out.println("The value of b is " + b);
} }}
A) Run time error, a boolean cannot be appended using the + operator.
B) prints : The value of b is true.
C) Compile time error, cannot simultaneously create and assign value for boolean value.
D) Compilation and run with no output.
2.What will happen when you compile and run the following code?( )
class Test
{
int i = 5;
i++;
public static void main(String args[])
{
Test t = new Test();
System.out.println(t.i);
}}
A) 5 B) 6 C) Compilation error D) None of these
3.What will happen if you compile/run the following code?( )
public class Test
{
public static void main(String[] args)
{
boolean b1 = false ;
boolean b2 = true ;
int k = (int)b1 + (int)b2;
System.out.println(k);
}}
A.0 B.1 C. This code causes run-time error D.This code causes compile-time error
4.What results from compiling and running the following code fragment?( )
Byte myByte = new Byte("111");
if(myByte.toString() == myByte.toString())
System.out.println("True");
else
System.out.println("False");
A) Compilation error, toString() is not available for Byte.
B) Prints "True" C.Prints "False" D.None of the above
5.What will happen when you attempt to compile and run the following code?( )
1. public class TestEqual
2. {
3. public static void main(String args[])
4. {
5. Object obj1 = new Boolean("false");
6. Object obj2 = new String("false");
7. Object obj3 = obj1;
8. obj1 = null;
9. Object obj4 = obj3.toString();
10. System.out.println(obj2.equals(obj4));
11. } }
A) It will print-false B) It will print-true
C) It will throw NullPointerException at runtime D) The code will not compile
6.What will happen if you compile and run the following code?( )
public class Test
{
static String str1 = "main method with String[] args";
static String str2 = "main method with int[] args";
public static void main(String[] args) // line :6
{
System.out.println(str1);
}
public static void main(int[] args) // line:11
{
System.out.println(str2);
} }
A) Duplicate method main(), compilation error at line 6.
B) Duplicate method main(), compilation error at line 11.
C) Prints "main method with main String[] args".
D) Prints "main method with main int[] args"
7. Consider the following line of code( )
char y[] = new char[5];
After execution, which of the following are true?
A. y[4] = '0' B. y[4] = '/u0000' C. y[5] = '/u0000' D. y[5] = '0'
8.What will happen on compiling and executing the following code fragment?( )
Boolean[] b1 = new Boolean[10];
boolean[] b2 = new boolean[10];
System.out.println("The value of b1[1] = " + b1[1]);
System.out.println("The value of b2[1] = " + b2[1]);
A) Prints "The value of b1[1] = false"
"The value of b2[1] = false".
B) Prints "The value of b1[1] = null"
"The value of b2[1] = null".
C) Prints "The value of b1[1] = null"
"The value of b2[1] = false".
D) Prints "The value of b1[1] = false"
"The value of b2[1] = null".
9.What will happen when you compile and run the following code?( )
class Test
{
public static void main(String args[])
{
System.out.println(0.0 == -0.0);
}}
A. true B. Compilation error C. None of these
10.The following line of code is equivalent to which of the codes given as choices?( )
if(x > y) z = x;
else z = y;
A) z = x < y ? x : y B.z = x < y ? y : x
C z = y < x ? x : y D.z = y < x ? y : x E. None of the above
11.What will be output by the following statement?( )
System.out.println(1 << 32);
A) 1 B -1 C.32 D.-2147483648
12.What will happen if you try to compile and run the following code?( )
public class Q
{
public static void main(String argv[])
{
int anar[] = new int[]{1, 2, 3};
System.out.println(anar[1]);
} }
A) 1 B.2 C. Error anar is referenced before it is initialized
B) Error: size of array must be defined
13.What will happen when you attempt to compile and run the following code?( )
1. public class Test
2. {
3. public static void main(String args[])
4. {
5. Boolean b1 = new Boolean("Yes");
6. Boolean b2 = new Boolean("No");
7. Object obj = new Boolean(b2.equals(b1));
8. System.out.println(obj);
9. }}
A) Compilation error at line 5 B) Compilation error at line 6
C) Compilation error at line 7 D) It will print – true
E) It will print – false
14.What String instance method would return true when invoked as follows?( )
a.method(b);
where a equals "GROUNDhog" and b equals "groundHOG"?
A) equals() B.toLowerCase() C.toUpperCase() D.equalsIgnoreCase()
15. In Struts achieve pages Jump main use any method?( )
A) erver.transfer B) response.redirect C) mapping.findForward
D) response.sendRedirect
16.which object can be used to be sent at the request of the browser( )
A) HttpServletRequest B) HttpServletResponse C) HttpServlet D) Http
17. From Which of the following is an option available in the Servlet initialization parameters.( )
A)Servlet B)ServletContext C)ServletConfig D)GenericServlet
18. How to obtain the data source.( )
A) Through Http B) Through ftp C) Through JNDI D) Through Connection
19. Which of the following item appeared only in Struts( )
A) JavaBean B) Web.xml C) struts-config.xml D) application.propertyes
20. Http default request methods is?( )
A) PUT B) GET C) POST D) TRACE
21. JDBC, for the object of that database connections is.( )
A) Statement B) Connection C) DriverManager D) PreparedStatement
22. EJB Class inventory in which version of Java?( )
A) J2SE B)J2EE C)J2ME D)J2NE
23. When the JSP was running, what’s the results?( )
<html><body>
<% for (int i=0;i<3;i++){ %>
out.print(i*2);
<% } %>
</body></html>
A) 0,2,4 B.0,2,4,6 C. out.print(i*2) out.print(i*2) out.print(i*2)
D) This JSP grammatical mistakes, can not run
24.What will happen when you compile and run the following code?( )
public class MyClass
{
public static void main(String args[])
{
System.out.println("Before Try");
try
{
}
catch(Throwable th)
{
System.out.println("Inside Catch");
}
System.out.println("After Try");
} }
A) Compilation error B) Runtime error C) Before Try D.After Try
E) None of these
25.If you want to output "<", then <c: out> tags which should be set in a property?( )
A) value B) escapeXml C) default D) entity
26.Which is the Web components of J2EE( )
A) HTML B) EJB C) Applet D) JSP
27.Following what can be achieved on the interface of Web visitors authentication?( )
A) Http Servlet Request B) Http Servlet Response
C) Http Session D) Http Servlet
28.What will be the result of executing the following code?( )
1. class TestClass
2. {
3. public static void main(String args[])
4. {
5. System.out.println(maximum(new int[] {1, 2, 3, 4, 5}));
6. }
7.
8. public static int maximum(int[] myData)
9. {
10. int max = 0;
11. for (int i = 0; i < myData.length; i++)
12. if (max < myData[i])
13. max = myData[i];
14. return max;
15. }
16. }
A) The code will not compile at line 5 as arrays cannot be passed without creation
B) The code will compile but a runtime exception will be thrown at line 11
C) The code will compile and print 5 D) None of these
二.多项选择题
1.which of the following lines will compile without warning or error.( )
A) float f=1.3; B) char c='a'; C) byte b=257; D) boolean b=null; E) int i=10;
2.which of the following lines of code will compile without error? ( )
A)
int i=0;
if (i) {
system.out.println(“hi”);
}
B)
boolean b=true;
boolean b2=true;
if(b==b2) {
system.out.println(“so true”);
}
C)
int i=1;
int j=2;
if(i==1|| j==2)
System.out.println(“ok”);
D)
int i=1;
int j=2;
if (i==1 &| j==2)
System.out.println(“ok”);
3.Which of the following collection classes from java.util package are Thread safe?( )
A) Vector B) ArrayList C) HashMap D) Hashtable
4.Which of the following are valid ways to define a constructor for class Test?( )
A) public void Test(){} B) public Test(){} C) private Test(){}
D) public static Test(){} E) final Test(){}
5.Which of the following classes have "is-a" relationship with java.lang.Number?( )
A) java.lang.Byte B) java.lang.Void C) java.lang.Double
D) java.lang.Boolean E) java.lang.Short F) java.lang.Character
6.Which of the following are recommended ways a Thread may be blocked?( )
A) sleep() B) wait()/notify() C) suspend() D) pause()
7. What are the expression of operation JSTL tags.( )
A) <c:out> B) <c:if> C) <c:url> D) <c:catch>