You are on page 1of 9

Java Fundamentals

Question: 1

From a memory usage/performance perspective, is it better to use


String/Stringbuffer?

a. String
b. Stringbuffer

Question: 2

Which option doesn't have valueOf(String) method

a. Integer
b. Long
c. Boolean
d. Character

Question: 3

Which is the example of Time Slicing in Threading

a. join, wait
b. sleep, join
c. wait, join
d. sleep, wait

Question: 4

What is true about Garbage Collector?

1) It’s a Daemon Thread


2) Garbage collection cannot be forced
3) It runs in low memory situation and releases all unreachable object.

a. 1
b. 2
c. 3
c. 1 & 2
d. 1 & 3
e. 2 & 3
f. All of the above

Question: 5

Choose the correct answer base on the below code snippet:

public class StaticTest {


{
System.out.println(" Instance ");
}
static{
System.out.println(" Static ");
StaticTest st = new StaticTest();
}
public static void main(String[] args) {
StaticTest st = new StaticTest();
}
}

a. The code compiles and runs,with output Instance Static


b. The code compiles and runs,with output Static Instance
c. The code compiles and runs,with output Static Instance Instance
d. Compilation Error

Question: 6

Which of these classes defined in java.io and used for file-handling are abstract.
Select the two correct answers.

a. InputStream
b. PrintStream
c. Reader
d. FileInputStream
e. FileWriter

Question: 7

Which of the following options are true for the below code snippet?

Class Test
{
public static void printMessage(String msg)
{ System.out.println(msg); }

public static void main(String[] args)


{
Test t=new Test();
t.printMessage(“First Message”);
t=null;
t.printMessage(“Second Message”);
}
}

a. Will not print anything and Runtime Exception


b. Will print First Message and Runtime Exception
c. Code will not compile
d. Code will compile and execute successfully and print First Message and Second
Message.
e. None of above

Question: 8
Name the Collection interface implemented by the Hashtable class.

a. List
b. Map
c. Set

Question: 9

What will be the output when we try to compile and run following code.
Assume that this main method is written in proper java class.

public static void main(String args[])


{
int x=10, y=20;
byte b = x + y;
System.out.println(b);
}

a. 30
b. Unpredictable
c. Compile time error
d. run time error

Question: 10

What is the result for the below code snippet?

class Base
{
Base() { System.out.print(“Base”); }
}

public class Alpha extends Base


{
public static void main( String[] args )
{
new Alpha();
new Base();
}
}

a. Base
b. BaseBase
c. Compilation fails.
d. The code runs with no output.
e. An exception is thrown at runtime.

Question: 11

What if user didn't add the String array as the argument to the method.

a. compile time exception


b. runtime exception
c. compile and run successfully
d. none

Question: 12

Garbage Collector Thread belongs to which priority

a. Max
b. Min
c. Low

Question: 13

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);}

a. Compile 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"

Question: 14

Suppose, One class is using TreeMap to store the Key-Value pairs and four key-value
pairs are inserted into the TreeMap where as keys are :- abcd, 111a, a111, 1111.

What is the key sequence into the TreeMap Memory?

a. 1111, 111a, a111, abcd


b. abcd, a111, 1111, 111a
c. abcd, a111, 111a, 1111
d. abcd, 111a, a111, 1111

Question: 15

Can you define a variable inside an Interface?

a. No.
b. Yes. It should be static
c. Yes. It should be final
d. Yes. It should be final and static

Question: 16
If you are not sure that whether your collection needs to be thread safe or not then
which out the following is better to use :-

a. Vector
b. Use Arraylist and convert it to thread safe using
Collections.synchronizedList(ArrayList object)

Question: 17

What is the legal range of values for a variable declared as a byte?

a. 0 to 256
b. -128 to 127
c. -128 to 128
d. 0 to 255

Question: 18

What is the result of the below snippet

String s1 = new String("test");


System.out.println(s1.replace('e','r'));
System.out.println(s1);
String s3="trst";
String s4="trst";
String s2 = s1.replace('e','r');
System.out.println(s2==s3);
System.out.println(s3==s4);

a. trst, test, false, true


b. trst, trst, false, true
c. test, test, false, true
d. trst, test, true, true

Question: 19

Can we predict the garbage collection process

a. Yes
b. No

Question: 20

What is the output of the below snippet?

String temp = null;


if(temp !=null & temp.length() > 10)
{ System.out.println("Length - " +temp.length()) }

a. compile time exception


b. runtime exception
c. Length - 0
d. none
Section: 2 - Java Server Pages (JSP)

Question: 21

The total number of implicit objects in JSP are

a. 8
b. 10
c. 11
d 7
e. None of the above

Question: 22

Which of the following implicit objects does not represent a scope container?

a. application
b. session
c. request
d. page
e. pageContext

Question: 23

Identify the right class for PageContext Implicit object in JSP

a. java.lang.PageContext
b. javax.servlet.jsp.PageContext
c. javax.servlet.PageContext
d. javax.servlet.http.PageContext

Question: 24

What is the default scope for <jsp:useBean>

a. application
b. session
c. page
d. request

Question: 25

What will be the output of the following code?

<html><body>
<% x=3: %>
<% int x = 5; %>
<%! Nt x = 7; %>
x= <%=x %>, <%= this.x %>
</body></html>
a. x =3, 5
b. x = 3,7
c. x= 5, 3
d. x = 5, 7
e. Compilation Error

Question: 26

How many phases are there in JSP life cycle

a. 7
b. 6
c. 5
d. 8
e. None of the above

Question: 27

Which are true about <jsp:useBean> standard action?

a. The id attribute is optional.


b. The scope attribute is required.
c. Either the class or type attribute may be specified, but at least one.
d. It is valid to include both the class attribute and the type attribute, even if their
values are NOT the same.

Question: 28

Is the following statement correct?

<jsp:setProperty name="myBean" property="*" />

a. Yes
b. No

Question: 29

Which of the implicit objects is not available to a JSP page by default?

a. application
b. session
c. exception
d. config

Question: 30

Which statements about jspInit() are true?

a. It has access to ServletConfig.


b. It has access to ServletContext.
c. It is only called once.
d. It can be overridden
e. all of the above

Question: 31

What will be the output of the page source for the below comment:

<%-- Code changes Starts --%>

a. <!-- Code changes Starts --!>


b. Code changes Starts
c. <%-- Code changes Starts --%>
d. None of the above

Question: 32

Which of the following exceptions may be thrown by the _jspService() method?

a. javax.servlet.ServletException
b. javax.servlet.jsp.JSPException
c. javax.servlet.ServletException and javax.servlet.JSPException
d. javax.servlet.ServletException and java.io.IOException
e. javax.servlet.jsp.JSPException and java.io.IOException

Question: 33

How to tell the browser not to cache the JSP output?Select all that are applicable

a. response.setHeader("Pragma", "No-cache");
b. response.setHeader("Cache-Control", "no-cache");
c. response.setDateHeader("Expires",0);
d. response.setcache(false);
e. none

Question: 34

The page directive is used to convey information about the page to JSP container.
Which of these are legal syntax of page directive. Select the two correct statement

a. <% page info="test page" %>


b. <%@ page info="test page" session="false"%>
c. <%@ page session="true" %>
d. <%@ page isErrorPage="errorPage.jsp" %>
e. <%@ page isThreadSafe=true %>

Question: 35

What's a better approach for enabling thread-safe servlets and JSPs in high volume
sites?

a. SingleThreadModel Interface
b. Synchronization?
Question: 36

Which of the following is a valid way of getting a bean's property?

a. <jsp:useBean action="get" id="address" property="city" />


b. <jsp:getProperty id="address" property="city" />
c. <jsp:getProperty name="address" property="city" />
d. <jsp:getProperty bean="address" property="*" />

Question: 37

Default value for session attribute in page directive is set to true.

a. True
b. False

Question: 38

Which of the following will evaluate to true?

a. page == this
b. pageContext == this
c. out instanceof ServletOutputStream
d. application instanceof ServletContext

Question: 39

Which of the following can not be used as the scope when using a JavaBean with
JSP?

a. application
b. session
c. request
d. response
e. page

Question: 40

"exception" is an implicit object.

a. Yes
b. No

You might also like