UPWORK TEST » October 30, 2015

Daily Archives: October 30, 2015

Upwork Java Technologies

Spring MVC Test 2016

Published by:

1. Which of the following code samples will get the ServletContext inside an Interceptor?

Answers:

  1. @Autowired ServletContext context;
  2. request.getSession().getServletContext();/li>
  3. setServletContext(ServletContext context) { this.context = context; }
  4. request.getSession().getServletContext();

2. How can an HTTP 404 status code be returned from a Spring MVC Controller?

Answers:

  1. Throwing a ResourceNotFoundException declared with the @ResponseStatus annotation.<>
  2. Throwing an HttpRequestMethodNotSupportedException.
  3. Configuring <context:annotation-config> in the Spring configuration XML document to send a 404 status for a controller via its “returnCode” argument.
  4. Having the method accept HttpServletResponse as a parameter, so that setStatus(404) can be called on it.

3. Which of the following interfaces can be implemented to interact with a container’s management of the bean lifecycle?

Answers:

  1. InitializingBean
  2. IntializeableBean
  3. DisposableBean
  4. DisposingBean

4. Which of the following can be used to serve static resources while still using DispatchServlet at the site’s root?

Answers:

  1. <mvc:default-resources/>
  2. <mvc:resources/>
  3. <mvc:default-servlet-handler/>
  4. <mvc:view-controller/>

5. Which of the following code samples will correctly return an image in @ResponseBody from a byte[] of image data?

Answers:

  1. @RequestMapping(“/photo”) public ResponseEntity<byte[]> testphoto() throws IOException { InputStream in = servletContext.getResourceAsStream(“/images/no_image.jpg”); final HttpHeaders headers = new HttpHeaders(); headers.setContentType(MediaType.IMAGE_PNG); return new ResponseEntity<byte[]>(IOUtils.toByteArray(in), headers, HttpStatus.CREATED); }
  2. @ResponseBody @RequestMapping(“/photo”, method = RequestMethod.GET, produces = MediaType.IMAGE_JPEG_VALUE) public byte[] testphoto() throws IOException { InputStream in = servletContext.getResourceAsStream(“/images/no_image.jpg”); return IOUtils.toByteArray(in); }
  3. @RequestMapping(“/photo”) public void photo(HttpServletResponse response) throws IOException { response.setContentType(“image/jpeg”); InputStream in = servletContext.getResourceAsStream(“/images/no_image.jpg”); IOUtils.copy(in, response.getOutputStream()); }
  4. @ResponseBody @RequestMapping(“/photo2) public byte[] testphoto() throws IOException { InputStream in = servletContext.getResourceAsStream(“/images/no_image.jpg”); return IOUtils.toByteArray(in); }

6. Which of the following annotations are supported by classes with the @Bean annotation?

Answers:

  1. @PostConstruct
  2. @PreDestroy
  3. @PreConstruct
  4. @PostDestroy

7. Which of the following statements is false?

Answers:

  1. Spring MVC provides both declarative and programmatic transaction management.
  2. The transaction-manager attribute in the transactional advice (<tx:advice/>) is required if the bean name of the
  3. PlatformTransactionManager that is being wired is transactionManager.
  4. By default, a transaction is only marked for rollback in the case of runtime unchecked exceptions.
  5. None of these.

8. Which of the following statements is true about the HandlerExceptionResolver class?

Answers:

  1. Any Spring bean that implements HandlerExceptionResolver will be used to intercept and process any exception raised that was handled by a Controller.
  2. @ExceptionHandler methods can be injected with the model.
  3. DefaultHandlerExceptionResolver converts standard Spring exceptions and converts them to HTTP Status Codes.
  4. None of these.

9. Which of the following statements is true about method arguments that have an @ModelAttribute annotation?

Answers:

  1. It indicates that the argument should be retrieved from the model.
  2. If the argument is not present in the model, it should be added to the model first, and then instantiated.
  3. If the argument is not present in the model, it should be instantiated first, and then added to the model.
  4. Model attributes have to be explicitly added when using @ModelAttribute.

10. Given the following method:

@RequestMapping(method=RequestMethod.GET, value=”/fooBar”)
public ResponseEntity<String> fooBar2() {
String json = “jsonResponse”;
HttpHeaders responseHeaders = new HttpHeaders();
responseHeaders.setContentType(MediaType.APPLICATION_JSON);
return new ResponseEntity<String>(json, responseHeaders, HttpStatus.CREATED);
}

Which of the following statements is correct?

Answers:

  1. It allows access to request and response headers.
  2. It doesn’t allow access to request and response headers.
  3. It returns a JSON String and sets the mimetype to text/plain.
  4. It returns a JSON String and sets the mimetype to text/javascript.

11. Which of the following classes provides built-in pagination functionality in SpringMVC?

Answers:

  1. PageListSorter
  2. PageListContext
  3. PagedListHolder
  4. Spring MVC doesn’t include a built-in class for handling pagination.

12. Given the method below:

@RequestMapping(value = “/foo”, method = RequestMethod.GET)
public final String foo(HttpServletRequest request, BindingResult bindResult, ModelMap model) {
model.addAttribute(“abc”, 123);
return “foo”;
}

When the view is displayed in the browser, it’s URL is “http://mydomain/foo?abc=123”.

Which of the following statements is true?

Answers:

  1. The attribute appears as string name-value pairs in the URL because the @ModelAttribute annotation is used in the controller.
  2. Adding “model.asMap().clear();” will prevent the attribute name-value pair from appearing in the URL.
  3. The attribute name-value pair will be included in the URL, regardless of the use of @ModelAttribute in the controller.
  4. The attribute name-value pair cannot be excluded from being displayed in the URL.

13. Which of the following is true about the use of <context:annotation-config /> in a servlet?

Answers:

  1. <context:annotation-config> activates many different annotations in beans, whether they are defined in XML or through component scanning.
  2. <context:annotation-config> declares explicit support for annotation-driven MVC controllers.
  3. <context:annotation-config> adds support for declarative validation via @Valid.
  4. All statements are false.

14. Which of the following are valid sets of constructor arguments for the ModelAndView class? (Select all correct answers.)

Answers:

  1. String viewName
  2. String viewName, Map<String,?> model
  3. String modelName, Map<String,?> model
  4. View view, Map<String,?> model, Object modelObject

15. Which of the following are possible validation methods for user input in Spring MVC?

Answers:

  1. XPath validation
  2. Annotation validation
  3. Programmatic validation
  4. Mixed annotation and programmatic validation

16. Fill in the blank:
The _______ enables the use of the bean element’s attributes, instead of nested <property/> elements, to describe property values and/or collaborating beans.

Answers:

  1. default namespace
  2. c-namespace
  3. p-namespace
  4. namespace

17. Which of the following statements is true about the @RequestMapping annotation?

Answers:

  1. It has a single String parameter.
  2. It has a String[] paramater.
  3. It supports ant-style paths.
  4. It doesn’t support wildcard input.

18. Which of the following statements is true for the configuration of the Spring handler adapter(s) in a Spring MVC application context?

Answers:

  1. Spring MVC defines 2 different request handler adapters by default: HttpRequestHandlerAdapter and SimpleControllerHandlerAdapter.
  2. Request handler adapters need to be defined in the context files.
  3. If at least one request handler adapter is defined the context files, Spring will not create the default adapters.
  4. Using <mvc:annotation-driven /> causes the context to define both AnnotationMethodHandlerAdapter and SimpleControllerHandlerAdapter.

19. What does the following code do?

@RequestMapping(“/{id}/**”)
public void foo(@PathVariable(“id”) int id, HttpServletRequest request) {
String restOfTheUrl = (String) request.getAttribute(
HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE);

}

Answers:

  1. It retrieves the complete path value after the @RequestMapping and @PathVariable values have been parsed.
  2. It retrieves the complete path value before the @RequestMapping and @PathVariable values have been parsed.
  3. It retrieves the partial path value (after “**”) after the @RequestMapping and @PathVariable values have been parsed.
  4. It retrieves the partial path value (after “**”) before the @RequestMapping and @PathVariable values have been parsed.

20. Which of the following statements is true about the HandlerInterceptor interface?

Answers:

  1. It gets called after the appropriate HandlerAdapter triggers the execution of the handler itself.
  2. It allows exchanging the request and response objects that are handed down the execution chain.
  3. It gets configured in the application context.
  4. It is well-suited for request content and view content handling, such as multipart forms and GZIP compression.

21. Which of the following dependency injection (DI) methodologies are available in Spring MVC?

Answers:

  1. Constructor-based dependency injection
  2. Setter-based dependency injection
  3. Prototype-based dependency injection
  4. Manual dependency injection

22. Which of the following is the default bean scope in Spring MVC?

Answers:

  1. global session
  2. local session
  3. prototype
  4. singleton

23. True or false: a factory class can hold more than one factory method.

Answers:

  1. True
  2. False

24. Which of the following enables custom qualifier annotation types to be registered even if they are not annotated with Spring’s @Qualifier annotation?

Answers:

  1. CustomQualifier
  2. CustomAutowireConfigurer
  3. CustomQualifierType
  4. CustomAutowire

25. Which of the following statements is correct?

Answers:

  1. Explicitly declared handler mappings or declaring <mvc:annotation-driven> are optional when using <mvc:resources>.
  2. <mvc:resources> declares BeanNameUrlHandlerMapping by default.
  3. <mvc:resources> doesn’t declare its own handler mapping.
  4. <mvc:resources> declares only DefaultAnnotationHandlerMapping by default.

26. Which of the following statements is true about the @RequestParam annotation?

Answers:

  1. Providing a “defaultValue” optional element sets the “required” optional element to true.
  2. It indicates that a method parameter should be bound to a web request parameter.
  3. It is unsupported for annotated handler methods in Servlet and Portlet environments.
  4. None of these.

27. Select all authentication methods that are supported by Spring Security by default:

Answers:

  1. Basic Authentication
  2. Digest Access Authentication
  3. Remember-me Authentication
  4. Multi-factor authentication

28. In an annotation-based Spring MVC controller, which of the following are valid ways to set cache headers for a specific path?

Answers:

  1. Ensuring the instance of “AnnotationMethodHandlerAdapter” does not have the “cacheSeconds” property set, and adding an instance of “WebContentInterceptor”.
  2. Adding “final HttpServletResponse response” as a parameter, then setting the header “Cache-Control” to “all-cache”.
  3. Using a Handler Interceptor and using the “postHandle” method provided by it.
  4. Cache headers cannot be set for a specific path.

29. What is the difference between the @Repository and the @Controller annotations in Spring?

Answers:

  1. “@Repository” is used as a stereotype for the persistence layer, while “@Controller” is used as a stereotype for the presentation layer.
  2. “@Repository” is used as a stereotype for the presentation layer, while “@Controller” is used as a stereotype for the persistence layer.
  3. “@Repository” is used as a stereotype for the service layer, while “@Controller” is used as a generic stereotype for any Spring-managed component.
  4. “@Controller” is used as a stereotype for the service layer, while “@Repository” is used as a generic stereotype for any Spring-managed component.

30. Which of the following statements are correct, with respect to using the @PreAuthorize annotation in Spring controller methods?

Answers:

  1. @PreAuthorize does not work with Spring controller methods.
  2. @PreAuthorize works with Spring controller methods.
  3. The “pre-post-annotations” expression should be set to “disabled” in the servlet.xml file.
  4. Using CGLIB proxies are optional when using @PreAuthorize in Spring controller methods.

31. Which of the following is not a built-in Spring MVC bean scope?

Answers:

  1. singleton
  2. request
  3. global session
  4. local session

32. Fill in the blank: _______ is a class-level annotation indicating that an object is a source of bean definitions.

Answers:

  1. @Configuration
  2. @Definition
  3. @Bean
  4. @Scope

33. Regarding the @Resource annotation, which of the following statements is false?

Answers:

  1. It is part of the JSR-250 specification.
  2. By default, Spring interprets its name attribute as the bean name to be injected.
  3. If no name attribute is specified, the default name is derived from the field name or setter method.
  4. It supports injection on bean property setter methods only.

34. Fill in the blank:
When defining a bean that is created with a static factory method, the ______ attribute is used to specify the class containing the static factory method.

Answers:

  1. class
  2. class-name
  3. factory-class
  4. factory-method

35. Which of the following statements is true about the @ModelAttribute annotation?

Answers:

  1. It binds a method parameter or method return value to an anonymous model attribute.
  2. It can be used to expose reference data to a web view.
  3. It is not supported for controller classes with @RequestMapping methods.
  4. It cannot be used to expose command objects to a web view.

36. Fill in the blank:
In Spring’s XML-based configuration, the _______ attribute of the <property/> element specifies a property or constructor argument as a string representation.

Answers:

  1. namespace
  2. name
  3. class
  4. value

37. Which of the following statements is/are true about autowiring in Spring?

Answers:

  1. Multiple constructors a given class may carry the @AutoWired annotation.
  2. Only one constructor of any given class may carry the @AutoWired annotation.
  3. Fields are injected before the construction of a bean.
  4. Fields are injected after the construction of a bean.

38. Regarding dependency resolution, which of the following statements is false?

Answers:

  1. The ApplicationContext is created and initialized with configuration metadata that describes all the beans.
  2. Configuration metadata can only be specified via XML or annotations.
  3. Each property or constructor argument is an actual definition of the value to set, or a reference to another bean in the container.
  4. For each bean, its dependencies are expressed in the form of properties, constructor arguments, or arguments to the static-factory method.

1,661 total views, 5 views today

Upwork Java Technologies

JSP 2.0 Test 2016

Published by:

1. If cookies are turned off on the client, which two methods still work with the session ID?

Answers:

  1. response.getSessionId()
  2. encodeRedirectURL()
  3. sessionRedirectURL()
  4. encodeURL()

2. Which two of the following statements are best associated with the HTTPPOST method?

Answers:

  1. This HTTP method is the one most frequently used by browsers
  2. There is no limit on how much data this HTTP method can send
  3. There is a limit on how much data this HTTP method can send
  4. This method is most often used to submit form data

3. Which two statements among the following apply to redirecting a HTTP request to another URL?

Answers:

  1. The path must be absolute
  2. The path must be relative
  3. The redirect method must be called before the response body is committed, otherwise an IllegalStateException is thrown
  4. The path may be relative or absolute

4. Which of the following statements are true regarding the HTTP GET method?

Answers:

  1. There is a limit on how much data this HTTP method can send
  2. There is no limit on how much data this HTTP method can send
  3. This HTTP method is the fastest
  4. This HTTP method is used when you click on an HTML link

5. Which of the following statements are true regarding declaring a servlet instance in a deployment descriptor?

Answers:

  1. The tags are nested within <web-app> tags
  2. The tags do not define parameters
  3. The tags are <servlet-instance></servlet-instance>
  4. It specifies the fully qualified class name of the servlet

6. Which of the following statements are true regarding the structure of a WebArchive file?

Answers:

  1. It has a jar extension
  2. It is a JAR archive of the WebApplication structure
  3. It has a war extension
  4. It is extracted by the container upon the first call to any�servlet it contains

7. With regard to the service() lifecycle method, identify two correct statements about its purpose or about how and when it is invoked.

Answers:

  1. Upon completion it calls the destroy method
  2. It is called whenever the servlet is requested
  3. It is called after the init method is called
  4. It is only called when the servlet is first requested

8. Read the following code snippet and answer the question based upon it:

<taglib>
<taglib-uri>
http://www.yourcompany.com/you TagLibrary
</taglib-uri>
<taglib-location>
/WEB-INF/yourTagLibrary.tld
</taglib-location>
</taglib>

From the statements given below, which one applies to the code snippet?

Answers:

  1. The taglib directive can reference a TLD by name
  2. This tag goes into the WEB-INF/myApplication/web.xml file
  3. This definition is incorrect because the taglib-uri should have been uri
  4. This definition is incorrect because the taglib should have been tag

9. Which method is called by the servlet container just after the servlet is removed from service?

Answers:

  1. public void finalize() {// code…}
  2. public void destroy() {// code…}
  3. public void destroy()throws ServletException {// code…}
  4. public void finalize()throws ServletException {// code…}

10. Which statement is true regarding ServletContext Initialization Parameters in the deployment descriptor?

Answers:

  1. They are accessible by all servlets in a given web application
  2. They are accessible by all servlets in a given session
  3. They are accessible by all servlets in a given HTTP request
  4. They are accessible by all servlets in a given container

11. Which method in the HttpServlet class corresponds to the HTTPPOST method?

Answers:

  1. postHttp
  2. doPost
  3. post
  4. getPost

12. What is the file name of the WebApp deployment descriptor?

Answers:

  1. web.xml
  2. deploy.xml
  3. init.xml
  4. config.xml

13. What is the WebApp deployment descriptor element name for the Servlet Context Initialization Parameters?

Answers:

  1. <context-init-param>
  2. <context-param>
  3. <init-param>
  4. <context-init>

14. With regard to the destroy lifecycle method, identify the correct statements about its purpose or about how and when it is invoked.

Answers:

  1. It gives the servlet an opportunity to clean up resources
  2. Like try-catch, it is called upon an exception
  3. It is rarely used but can be called to remove a servlet from memory
  4. It isn’t called if the server crashes

15. How would you use a bean in a JSP page?

Answers:

  1. <jsp:useBean name=”houseLotBean” scope=”response” class=”session.Realestate”/>
  2. <jsp:useBean id=”houseLotBean” scope=”session”><jsp:useBean>
  3. <jsp:useBean id=”houseLotBean” scope=”session” class=”session.Realestate”/>
  4. <jsp:useBean scope=”session” class=”session.Realestate”/>

16. Which of the following is the name of the cookie used by Servlet Containers to maintain
session information?

Answers:

  1. SESSIONID
  2. SERVLETID
  3. JSESSIONID
  4. CONTAINERID

17. Which design pattern reduces network traffic by acting as a caching proxy of a remote object?

Answers:

  1. DataAccess Object
  2. Model-View-Controller
  3. Value Object
  4. Business Delegate

18. Assuming the tag library is in place and the tag handler is correct, which of the following is the correct way to use a custom tag in a JSP page?

Answers:

  1. <yourLibrary=”whatColorlslt” color=”red”/>
  2. <yourLibrary:whatColorlslt color=”red”/>
  3. <yourLibrary color=”red”/>
  4. <yourLibrary.whatColorlslt color=”red”/>

19. What output will be sent to the browser by the following code snippet?

<!–
Que <%=”Reader”%>
–>

Answers:

  1. ‘Que Reader’ within HTML comment markers
  2. This will cause an error
  3. Que <%=”Reader”%> within HTML comment markers
  4. This is a comment so it is ignored by the container

20. Which of the following are used by Servlet Containers to maintain session information?

Answers:

  1. Cookies
  2. Hidden form fields
  3. HTTPS protocol information
  4. URL rewriting

21. Read the following code snippet:

1 <libraryPrefix:handlerName parameterNAme=”value”>
2 <%=23*counter %>
3 <b>Congratulations!</b>

Which of the following is the correct way to complete the above code snippet?

Answers:

  1. </libraryPrefix:handlerName>
  2. </libraryPrefix:handlerName paremeterName=”value”>
  3. </handlerName>
  4. <libraryPrefix>

22. In which directory do you place any auxiliary JAR files?

Answers:

  1. WEB-INF/servlets
  2. WEB-INF/jar
  3. WEB-INF/classes
  4. WEB-INF/lib

23. Which statements are true regarding ServletContext Init Parameters in the deployment descriptor?

Answers:

  1. They are set at deployment-time, but accessed at run-time
  2. They are accessible from any session within that context
  3. They are not set at deployment-time, but accessed at run-time
  4. They are set at deployment-time and can be updated at run-time

24. With regard to the servlet context listener, which of the following methods is valid?

Answers:

  1. contextListenerEvent
  2. contextListenerInitialized
  3. contextInitialized
  4. contextListenerDestroyed

25. Assuming the servlet method for handling HTTPGET requests is doGet(HttpServletRequest req, HTTPServletResponse res), how do you get a request parameter in that servlet?

Answers:

  1. String value=req.getInitParameter(10);
  2. String value=req.getInitParameter(“product”);
  3. String value=res.getParameter(“product”);
  4. String value=req.getParameter(“product”);

26. Assume the custom tag is GLOOP and the prefix is TWONG. Which of the following is the syntax for an empty custom tag?

Answers:

  1. <TWONG:GLOOP/>
  2. <GLOOP:TWONG/>
  3. <GLOOP:TWONG></GLOOP:TWONG>
  4. <TWONG:GLOOP></TWONG:GLOOP>

27. Which of the following is not a JSP implicit object?

Answers:

  1. out
  2. in
  3. response
  4. page

28. Which of the following is the listener interface for servlet context attributes?

Answers:

  1. ContextAttributeListener
  2. ServletContextAttributeListener
  3. ServletAttributeListener
  4. ServletContextListener

29. What is Template Data?

Answers:

  1. The JSP blueprint or pattern
  2. The plain text (such as HTML) outside JSP tags(non java) in a JSP page
  3. The taglib XML namespace

30. Which of the following options is a valid declaration?

Answers:

  1. <%! String name=”Patricia” %>
  2. <%! String name=”Patricia”; %>
  3. <% String name=”Devyn” %>
  4. <% public String name=”Devyn”; %>

31. Which of following interfaces can make a servlet thread safe?

Answers:

  1. Runnable
  2. synchronization
  3. Servlets can’t be made thread safe
  4. None of the above

32. Which statement is true regarding a servlet context listener?

Answers:

  1. An object that implements a context listener is notified when its request objects are created or destroyed
  2. An object that implements a context listener is notified when its Web App context is created or destroyed
  3. An object that implements a context listener is notified when its Web App deployment descriptor defines it to be notified
  4. An object that implements a context listener is notified when its sessions are created or destroyed

33. Which of the following options is a valid expression?

Answers:

  1. <%! String name=”Patricia” %>
  2. <%! String name=”Patricia”; %>
  3. <%=(new java.util.Date()).toLocaleString() %>
  4. <% public String name=”Devyn”; %>

34. What does the container do with the following code snippet?

<!–#include file=”somefile.html”–>

Answers:

  1. The container passes this line of code through to the client
  2. The container includes this file statically
  3. The container includes this file dynamically
  4. The container will throw an exception

35. Which method in the HttpServlet class corresponds to the HTTPPUT method?

Answers:

  1. put
  2. doPut
  3. httpPut
  4. putHttp

36. Which of the following is a JSP implicit object?

Answers:

  1. objRequest
  2. Request.send
  3. request
  4. servlet

37. Which design pattern is used to decouple presentation from core data access functionality?

Answers:

  1. BusinessDelegate
  2. DataAccess Object
  3. ModelView Controller
  4. Value Object

38. In which directory do you place servlet class files?

Answers:

  1. WEB-INFservlets
  2. webappservlets
  3. WEB-INFclasses
  4. WEB-INF

39. Which design pattern did technical designers of JSP use to provide centralized dispatching of requests via a controller servlet?

Answers:

  1. Model-view-Controller
  2. Facade
  3. Server-Client
  4. Publish-Subscribe

40. Which interface and method name should be used to retrieve HTTP request header information?

Answers:

  1. HttpServletRequest.getHeaderNames
  2. ServletRequest.getNames
  3. ServletRequest.getHeadNames
  4. None of the above

41. Which interface provides access to request scoped attributes?

Answers:

  1. ServletContext
  2. ServletRequest
  3. ServletConfig
  4. None of these

42. Which JSP action retrieves the value of a property from a properly declared JavaBean in a JSP page?

Answers:

  1. jsp:getProperty
  2. jsp:getParameter
  3. jsp:getAtrribute
  4. jsp:getValue

43. Suppose you had a servlet that simply returned an error message because that resource was forbidden to that user. Read the following code snippet:

1.public void service(HttpServletRequestrequest,
2.HttpServletResponseresponse)
3.throws ServletException, IOException
4. {
5.
6. }

What code would you type on line 5 to return an error message to the requesting client?

Answers:

  1. response.sendError(HTTPServletResponse.SC_FORBIDDEN,”Error”);
  2. response.setStatus(HTTPServletResponse.SC_FORBIDDEN,”Error”);
  3. response.sendError(Response.SC_FORBIDDEN,”Error”);
  4. response.setStatus(SC_FORBIDDEN);

44. Which interface and method name should be used to acquire a text stream for the response?

Answers:

  1. ServletResponse.getOutputStream
  2. ServletResponse.getWriterStream
  3. ServletResponse.getTextStream
  4. ServletResponse.getWriter

45. Which among the following objects is the best choice to share information between pages for a single user?

Answers:

  1. application
  2. page
  3. request
  4. session

1,278 total views, 8 views today

Upwork Java Technologies

JDBC 2.1 Test 2016

Published by:

1. Under which category does the following driver fall:

WebLogic’s Tengah “all Java Type-3 driver”

Answers:

  1. JDBC-ODBC Bridge Driver
  2. Native-API Partly-Java Driver
  3. Net-Protocol All-Java Driver
  4. Native-Protocol All-Java Driver
  5. Native-Protocol Part-Java Driver

2. Which JDBC driver is considered best in terms of performance and efficiency?

Answers:

  1. Type-1 Driver
  2. Type-2 Driver
  3. Type-3 Driver
  4. Type-4 Driver

3. Please select all the correct options. JDBC Driver Manager is:

Answers:

  1. Able to activate registered drivers
  2. Able to activate unregistered drivers
  3. Not required for activation of drivers with DataSource
  4. Required for activation of drivers with DataSource

4. Consider the following statement:

PreparedStatement ps=con.prepareStatement(“INSERT INTO ORDER (CUSTOMER_ID ,PRICE) VALUES(?,?)”);

Which of the following should come after this statement?

Answers:

  1. ps.clearParameters(); ps.setInt(1,3); ps.setDouble(2,790.50); ps.executeUpdate(sql);
  2. ps.clearParameters(); ps.setInt(1,3); ps.setDouble(2,790.50); ps.executeUpdate();
  3. ps.clear(); ps.setInt(1,3); ps.setDouble(2,790.50); ps.executeUpdate(sql);
  4. ps.clearParameters(); ps.setInt(1,3.09); ps.setDouble(2,790.50); ps.execute(sql);
  5. ps.clearParameters(); ps.setDouble(2,790.50); ps.execute(sql);

5. You want to start a transaction for bank account processing. Which of the following methods will you execute on the Connection object to begin it?

Answers:

  1. con.setAutoCommit(false);
  2. con.setCommit(false);
  3. con.setAutoCommit();
  4. con.setAutoCommit(true);
  5. con.autoCommit();

6. You need to use a third party driver for establishing a connection with the database. The subprotocol is “webx” and the DSN is “webdsn”. What is the syntax of the URL?

Answers:

  1. jdbc:odbc:webx:webdsn
  2. odbc:jdbc:webx:webdsn
  3. jdbc:webx:webdsn
  4. thin:jdbc:odbc:dsn:webdsn
  5. thick:jdbc:odbc:dsn:webdsn
  6. None of the above

7. You have to handle an erroneous situation in a transaction. Which method comes handy in this case?

Answers:

  1. con.commit(false);
  2. con.commit();
  3. con.rollback();
  4. con.revertback();
  5. con.rollback(true);

8. How will you create a new instance of a JDBC driver explicitly?

Answers:

  1. Class.forName(“driver”);
  2. Class.newInstance(“driver”);
  3. Class.driver(“driver”);
  4. Class.getDriver(“driver”);
  5. Class.forName(“driver”).newInstance();

9. JDBC is based on:

Answers:

  1. X/Open CLI (Call Level Interface)
  2. JDBC/Open CLI
  3. Java/Open CLI
  4. V/OPEN CLI
  5. X/Close CLI

10. You are developing a shopping cart for your client. Where would you like to put your business logic?

Answers:

  1. Inside the database
  2. Inside the client application
  3. In middleware servlets
  4. In COM / DCOM components
  5. Inside the code for the cart

11. You want to execute the following query string, using the connection named “con”:

String query = “SELECT * FROM CUSTOMER”;

What should the syntax be?

Answers:

  1. Statement stmt=con.createStatement(); ResultSet rs=stmt.executeQuery(query);
  2. Statement stmt=new Statement(); ResultSet rs=stmt.executeQuery(query);
  3. Statement stmt=con.createStatement(); ResultSet rs=stmt.execute(query);
  4. Statement stmt=con.getStatement(); ResultSet rs=stmt.executeQuery(query);
  5. Statement stmt=con.getStatement(); ResultSet rs=con.executeQuery(query);

12. Which exception will be thrown in your code, if the specified driver could not be loaded?

Answers:

  1. ActivationException
  2. ClassNotFoundException
  3. ClassNotAvailableException
  4. ClassUnavailableException
  5. InstantiationException

13. A process allows you to group multiple SQL statements. Commit or Rollback can be performed on the group together. This process is known as:

Answers:

  1. Binding
  2. Synchronization
  3. Registry
  4. Transaction
  5. Late binding

14. Which of the following JDBC methods is used for retrieving large text strings?

Answers:

  1. getBinaryStream
  2. getText
  3. getAsciiStream
  4. getString
  5. getObjectStream

15. Open Database Connectivity is:

Answers:

  1. Platform independent
  2. Platform dependent
  3. Architecture neutral
  4. Network independent
  5. Machine independent

16. Which of the following methods eliminates the need to call wasNull() method to handle null database fields?

Answers:

  1. getObject();
  2. getInt();
  3. getString();
  4. getFloat();
  5. getNull();

17. Transactions have a property called atomicity, which means:

Answers:

  1. Everything takes place one by one
  2. Everything takes place once
  3. Everything takes place randomly
  4. Everything takes place twice
  5. Everything takes place thrice

18. What should the syntax be to establish a connection with a Database?

Answers:

  1. Connection con = DriverManager.getConnection(url,”myLogin”, “myPassword”);
  2. Connection con = DriverManager.getConnection(“myLogin”, “myPassword”,url);
  3. Connection con = DriverManager.getConnection(“myLogin”, “myPassword”);
  4. Connection con = DriverManager.setConnection(url,”myLogin”, “myPassword”);
  5. Connection con = DriverManager.createConnection(url,”myLogin”, “myPassword”);

19. ResultSet objects follow index patterns of:

Answers:

  1. Array standard
  2. Java standard
  3. RDBMS standard
  4. C++ standard
  5. PL/SQL standard

20. When you are handling user-submitted SQL, you may retrieve a ResultSet or a count. Which of the following methods is handy in this situation?

Answers:

  1. executeQuery()
  2. exceuteUpdate()
  3. execute()
  4. executeQueryUpdate()
  5. update()

21. You want to execute a CallableStatement named ‘cs’. It is expected to return multiples results. Which of the following methods will you choose?

Answers:

  1. ResultSet rs=cs.execute()
  2. ResultSet rs=cs.executeQuery()
  3. ResultSet rs=cs.executeUpdate()
  4. ResultSet rs=cs.executeQuery(sql)
  5. ResultSet rs=execute()

22. Your project leader has asked you to improve the performance of JDBC connectivity by reusing objects in your Servlet’s code. Which of the following is an appropriate solution?

Answers:

  1. Reuse the database connection and reuse PreparedStatement objects
  2. Reuse the database connection and use PreparedStatement objects with synchronized blocks
  3. Reuse the database connection only
  4. Reuse the PreparedStatement objects only
  5. Reuse the GetPreparedStatement objects only

23. Which of the following methods will you use to execute INSERT, UPDATE and DELETE SQL statements?

Answers:

  1. executeQuery();
  2. executeUpdate();
  3. executeQueryUpdate();
  4. update();
  5. query();

24. How do you register a JDBC driver?

Answers:

  1. Class.forName(“driver”);
  2. Class.newInstance(“driver”);
  3. Class.driver(“driver”);
  4. Class.getDriver(“driver”);
  5. Class.postDriver(“driver”);

25. Which of the following JDBC methods is used for retrieving large binary objects?

Answers:

  1. getBinaryStream
  2. getText
  3. getAsciiStream
  4. getString
  5. getObjectStream

26. Name the interface you will use to retrieve the underlying structure of the query result:

Answers:

  1. ResultSet
  2. ResultSetMetaData
  3. ResultStructure
  4. Result
  5. ResultMetaData

27. Which type of statement object will you use to execute a stored procedure?

Answers:

  1. Statement
  2. PreparedStatement
  3. CallableStatement
  4. StoredStatement
  5. Stat

28. A warning can be thrown by a Connection object, a Statement object or a ResultSet object. Which method is used to retrieve the warning:

Answers:

  1. getWarnings()
  2. getWarned()
  3. getWarning()
  4. getError()
  5. getErrorsWarning()

29. You have obtained a ResultSet object named ‘rs’ after executing the following query:

SELECT * FROM CUSTOMER

Which loop can you use to return all the records in the ResultSet?

Answers:

  1. while(rs.next())
  2. while(rs.hasNext())
  3. while(true)
  4. while(rs.nextElement())

30. You executed a query to retrieve 40 products from the database and obtained a scrollable ResultSet named ‘scrollrs’. You started scrolling the ResultSet as follows:

scrollrs.next();
scrollrs.absolute(-10);
scrollrs.relative(-6);

At which row number is the cursor currently located?

Answers:

  1. 16
  2. 24
  3. 26
  4. 17
  5. 6

31. The code segment below defines a query:

String qry=”SELECT CUS_NAME, PRICE FROM CUSTOMER”;

Which of the following code snippets will create a scrollable ResultSet?

Answers:

  1. Statement st=con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_READ_ONLY); ResultSet srs=st.executeQuery(qry);
  2. Statement st=con.createStatement(qry,ResultSet.CONCUR_READ_ONLY,ResultSet.TYPE_SCROLL_SENSITIVE); ResultSet srs=st.executeQuery();
  3. Statement st=con.createStatement(qry,ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY); ResultSet srs=st.executeQuery();
  4. Statement st=con.createStatement(ResultSet.CONCUR_READ_ONLY,ResultSet.TYPE_SCROLL_SENSITIVE); ResultSet srs=st.executeQuery(qry);

32. Which of the following is the syntax for creating a CallableStatement?

Answers:

  1. CallableStatement cs=con.prepareCall(“{call SHOW_ORDER}”)
  2. CallableStatement cs=con.prepareCall(‘{call SHOW_ORDER}’)
  3. CallableStatement cs=con.prepareCall(“(call SHOW_ORDER)”)
  4. CallableStatement cs=con.prepareCall(“call SHOW_ORDER”)
  5. CallableStatement cs=prepareCall(“call SHOW_ORDER”)

33. Which of the following is not true?

Answers:

  1. CallableStatement is a subclass of PreparedStatement
  2. CallableStatement can take PreparedStatement as an input parameter
  3. CallableStatement can use executeUpdate() method
  4. CallableStatement can use execute() method
  5. CallableStatement cannot take INOUT parameters

34. Which of the following is not true for a ResultSet?

Answers:

  1. JDBC 2.0 API supports Scrollable ResultSets
  2. ResultSet cursors are moved forward using next() method
  3. ResultSet cursors are moved backwards using previous() method
  4. Methods next() and previous() return -1 beyond the ResultSet

35. Java Database Connectivity (JDBC) is a:

Answers:

  1. Database-dependent API
  2. Database-independent API
  3. Machine-dependent API
  4. Network-dependent database API

36. Servlet developers should avoid using JDBC-ODBC bridge driver because:

Answers:

  1. Drivers are bundled with JDK
  2. The driver’s native code can crash the entire server
  3. The driver is not secure
  4. The driver is of Type-1
  5. The driver is of Type-2

37. You have obtained a scrollable ResultSet named ‘srs’ by executing a query. Which of the following methods will you use to verify the position of the cursor?

Answers:

  1. srs.relative(-4)
  2. srs.relative()
  3. srs.absolute(-4)
  4. srs.getRow()
  5. srs.postRow()

38. A user leaves an online shopping cart without checking out. Which of following interfaces will notify to Rollback the transaction?

Answers:

  1. HttpSession
  2. HttpSessionBindingListener
  3. HttpServlet
  4. SingleThreadModel
  5. FtpSession

39. After executing the following code, resultvar contains false. What should the next step be?

boolean resultvar=stmt.execute(sql);
Answers:

  1. stmt.getResultSet();
  2. stmt.getUpdateCount();
  3. stmt.executeUpdate();
  4. stmt.executeQuery();
  5. stmt.executeUpdateQuery();

40. SQLException has a method, which provides the feature of chaining or encapsulation of additional Exception objects. Identify the method from the following:

Answers:

  1. getEncapsulatedException()
  2. getEncapException()
  3. getMessage()
  4. getNextException()
  5. getException()

41. Your project leader has given you a new task. You have to work on a module in which the transaction has to be extended across multiple page requests and multiple servlets. How will you implement this?

Answers:

  1. By synchronizing the doPost() method
  2. By creating a new connection for each transaction
  3. By session tracking and using HttpSession to hold a connection for each user
  4. By creating a single connection in the init() method and implementing SingleThreadModel
  5. By synchronizing doGet ()

42. SQLWarning object deals with database access warnings. It is a subclass of:

Answers:

  1. SQLWarn
  2. SQLException
  3. SQLError
  4. SQLWarning
  5. SQLErrorsWarning

43. Will the below script execute properly?

1.CREATE TABLE CUSTOMER
2.(
3.CUS_NAME VARCHAR(32), SUP_ID INTEGER, PRICE FLOAT, SALES INTEGER
4.)

Answers:

  1. Yes. The table will be created successfully.
  2. No. Line 3 should be modified to: VARCHAR(32) CUS_NAME,INTEGER SUP_ID ,FLOAT PRICE , INTEGER SALES
  3. No. Line 3 should be modified to: ‘CUS_NAME VARCHAR(32)’,’SUP_ID INTEGER’,’ PRICE FLOAT’, ‘SALES INTEGER’
  4. No. Line 3 should be modified to: ‘CUS_NAME’ VARCHAR(32),’SUP_ID’ INTEGER,’PRICE’ FLOAT, ‘SALES’ INTEGER

44. You are trying to connect to a database through JDBC. There is a problem with one of the methods immediately after the driver has been loaded. Which exception will be thrown?

Answers:

  1. ClassNotFoundException
  2. SQLException
  3. SQLNotFoundException
  4. ActivationException
  5. JDBCException

946 total views, 10 views today

Upwork Internet Programming

XML 1.0 Test 2016

Published by:

1. Which of the following can store negative values?

Answers:

  1. int
  2. i1
  3. i2
  4. ui1
  5. ui2

2. Which of the following attributes are optional in xsl:sort command?

Answers:

  1. Select
  2. order
  3. datatype
  4. None of the above

3. Which of the following are methods of formatting of XML documents?

Answers:

  1. CSS
  2. XSLT
  3. DTD
  4. Schema

4. Which of the following data types are allowed in xsl:sort command?

Answers:

  1. Text
  2. Number
  3. Date
  4. None of the above

5. Which of the following patterns are correct for ‘select’ attribute
of xsl:sort command?

Answers:

  1. text() for any text
  2. node() for any node including root node and attribute node
  3. / for the root node
  4. @* for any parent node

 

6. Which elements in the following extract contain Mixed Content?

1 <?xml version=”1.0″?>
2 <folder>
3 <file>
4 <name>Accounts Reports</name>
5 <contents>These are the contents of the file
6 <report>This is the first report</report>
7 </contents>
8 End of the file
9 </file>
10 </folder>

Answers:

  1. folder
  2. file
  3. name
  4. contents
  5. report

7. Which element in the following extract contains Simple Content (Text Content)?

1 <?xml version=”1.0″?>
2 <folder>
3 <file>
4 <name>Accounts Reports</name>
5 <contents>These are the contents of the file
6 <report>This is the first report</report>
7 </contents>
8 End of the file
9 </file>
10 </folder>

Answers:

  1. folder
  2. file
  3. name
  4. contents
  5. report

8. What are the possible values for the actuate attribute of an XLink?

Answers:

  1. onLoad
  2. onClick
  3. onRequest
  4. onDisplay

9. Which of the following statements is not correct about schema?

Answers:

  1. The Schema element can contain any number of top-level declarations
  2. The XML schema language is based on the Worldwide Web Consortium (W3C)
  3. The definitions in an XML schema are contained within the top-level Schema element
  4. The Schema element in an XML Schema document can not use a namespace

10. Which of the following is an invalid operator?

Answers:

  1. / is used for child operator
  2. // is used for recursive descent
  3. . indicates the current context
  4. None of the above

11. When is the DOM event ‘onreadystatechange’ fired?

Answers:

  1. When state event is fired
  2. When state attribute of schema Element is ready
  3. When the readyState method changes
  4. None of the above

12. What are the requirements for an Extended XLink element?

Answers:

  1. You must specify at least two locators and two arcs
  2. You must specify at least two locators and one arc
  3. You must specify at least one locator and one arc
  4. You must specify at least one locator and two arcs

13. Is the following statement correct?
You can use XSL Transformations (XSLT) to merge simple regular XML data with an HTML template for display.

Answers:

  1. Yes
  2. No

14. What is the Root element of an XSL file?

Answers:

  1. The stylesheet element
  2. The template element
  3. The html element
  4. Any XSL element can be the Root element

15. What does the following XPath expression represent?

/addressbook/address[@id=’1′]

Answers:

  1. The address having an id attribute with a value of 1
  2. The id attribute of the address with an id of 1
  3. The address having a child element named id with a value of 1
  4. The address having an attribute named @id with a value of 1

16. Select the appropriate statement to find all books that have an
excerpt and a title.

Answers:

  1. book(excerpt)(title)
  2. book[excerpt][title]
  3. book[excerpt/title]
  4. None of the above

17. Which line will generate an error in the following XML file?

1.<?xml version=”1.0″?>
2.<folder>
3.<file><name><contents></contents></name></file>
4.<file><name/><contents></contents><name/></file>
5.<file><name/><contents></contents></name></file>
6.<file><name><contents/><name/></file>
7.</folder>

Answers:

  1. 3
  2. 4
  3. 5
  4. 6
  5. 4,5
  6. 4,5,6
  7. there are no errors

18. Which of the following is an attribute of the locator element in an Extended XLink?

Answers:

  1. from
  2. to
  3. href

19. What are the relative advantages of Schemas over DTDs?

Answers:

  1. XML Schemas support data types
  2. XML Schemas support namespaces
  3. XML Schemas are written in XML
  4. All of the above

20. Which is the correct method for declaring the xml version?

Answers:

  1. <?xml version=”1.0″?>
  2. <xml version=”1.0″>
  3. <?XML version=”1.0″?>
  4. <? xml version=”1.0″?>
  5. <?xml version=1.0 ?>
  6. <?Xml Version=1.0 ?>
  7. <?xmlversion=”1.0″?>

21. Which line will generate an error in the following XML code?

1 <?xml version=”1.0″?>
2 <f_ns:folder dt=”1/1/2000″>
3 <file f_id=”1″ >
4 <name>Accounts Reports</name>
5 <contents />
6 <!– Note: This file does not contain anything yet –>
7 </file>
8 </f_ns:folder>

Answers:

  1. 1
  2. 2,8
  3. 3
  4. 4
  5. 5
  6. 6
  7. there are no errors

22. Select the appropriate statement to find all bookstores where thevalue of the specialty attribute is equal to “textbooks”.

Answers:

  1. /bookstore[@specialty = “textbooks”]
  2. /bookstore[specialty = “textbooks”]
  3. /bookstore[@specialty = textbooks]
  4. /bookstore(@specialty = “textbooks”)

23. How is an External Unparsed General entity defined in a DTD?

Answers:

  1. <!ENTITY entity-name EXTERNAL “file-name” NDATA notation-name>
  2. <!ENTITY entity-name SYSTEM “file-name” >
  3. <!ENTITY entity-name SYSTEM “file-name” notation-name>
  4. <!ENTITY entity-name SYSTEM “file-name” NDATA notation-name>

24. What are the possible values for the show attribute of an XLink?

Answers:

  1. new
  2. embed
  3. replace
  4. All of the above

25. State whether the following statement is correct?Attributes must have both a name and a value.

Answers:

  1. True
  2. False

26. State whether the following statement is correct?XPath can be used directly from the Document Object Model (DOM).

Answers:

  1. True
  2. False

27. Which of the following are XHTML DTDs?

Answers:

  1. Strict
  2. Transitional
  3. Frameset
  4. All of the above

28. Which of the following is not a parameter of DOM event ontransformnode?

Answers:

  1. nodeType
  2. nodeData
  3. nodeCode

29. Which limitation of HTML links is overcome by XLink?

Answers:

  1. HTML links must be embedded in the source document whereas XLinks may be stored outside the source document
  2. HTML links only allow navigation in one direction
  3. HTML links only link two resources
  4. All of the above

30. What does the following XPath expression represent?

/addressbook//phone

Answers:

  1. All phone elements that are at the next level from the addressbook element
  2. All phone elements that are present beneath the addessbook element (at any level)
  3. All phone elements that are two levels below the addressbook element
  4. This is an incorrect expression

31. What does depth method of DOM do?

Answers:

  1. Returns the depth of attributes
  2. Creates the number of attributes as per passed parameters
  3. Creates the number of nodes as per passed parameter
  4. Returns the depth within the document tree where the specified node appears

32. Which of the following statements are true about the number data
type in xml?

Answers:

  1. Can store only integer values
  2. Can store only decimal values
  3. Can not store integer or decimal values
  4. can store integer and decimal values

33. Choose the correct DTD Element definition:

Answers:

  1. <ELEMENT country (#PCDATA)>
  2. <!ELEMENT country (#PCDATA)>
  3. <!ELEMENT country #PCDATA>
  4. <ELEMENT country #PCDATA>
  5. <!ELEMENT country (PCDATA)>

34. Which of the following statements is true with regard to XHTML?

Answers:

  1. XHTML tags are different from HTML tags
  2. XHTML is used in combination with XSL for converting XML files to HTML format
  3. XHTML documents need not satisfy any of the syntax rules of XML
  4. XHTML documents must satisfy all the syntax rules of XML

35. Which of the following is not an advantage of DOM?

Answers:

  1. Performs complex XPath filtering
  2. Retrieves small amounts of information
  3. Random access
  4. None of the above

36. CDATA sections provide a way to tell the parser that there is no markup in the characters contained by the C DATA section. Which of the following is the correct syntax for C DATA?
Answers:

  1. <CDATA(applications with XML using <, >,)>
  2. <[CDATA[applications with XML using <, >,]]>
  3. <![CDATA[applications with XML using <, >,]]>
  4. <(CDATA(applications with XML using <, >,))>

37. Which of the following is not a type of attribute?

Answers:

  1. CDATA
  2. PCDATA
  3. ID
  4. IDREF
  5. IDREFS
  6. NMTOKEN

38. Which of the following XPath functions is not a string function?

Answers:

  1. concat
  2. substring
  3. translate
  4. namespace-uri

39. Which of the following is not a DOM method?

Answers:

  1. add
  2. clone
  3. object
  4. cloneNode
  5. createElement

40. Which of the following is not an XSL element?

Answers:

  1. for-each
  2. template
  3. select
  4. value-of

41. What does the following DTD imply?

<!DOCTYPE messagelist [
<!ELEMENT messagelist(message*)>
<!ELEMENT message(sender?,receiver,subject,body,attachment+)>
<!ELEMENT sender (#PCDATA)>
<!ELEMENT receiver (#PCDATA)>
<!ELEMENT subject (#PCDATA)>
<!ELEMENT body (#PCDATA)>
<!ELEMENT attachment (#PCDATA)>
]>

Answers:

  1. The sender element cannot be empty
  2. There need not be any attachments
  3. There will be only one message within the messagelist element
  4. There must be one or more attachments

42. Which element in the following extract contains Element Content?

1 <?xml version=”1.0″?>
2 <folder>
3 <file>
4 <name>Accounts Reports</name>
5 <contents>These are the contents of the file
6 <report>This is the first report</report>
7 </contents>
8 End of the file
9 </file>
10 </folder>

Answers:

  1. folder
  2. file
  3. name
  4. contents
  5. report
  6. none of them contain Element Content
  7. all of them contain Element Content

43. What does the following XPath expression represent?

/addressbook/*/phone

Answers:

  1. The phone element which is two levels below the addressbook element
  2. The phone attribute which is two levels below the addressbook element
  3. The phone attribute which is immediately below the addressbook element
  4. This is an incorrect expression

44. What are XML Namespaces used for?

Answers:

  1. They are used to associate an External DTD with an XML document
  2. They prevent element naming conflicts when more than one XML vocabulary is being used in an XML document
  3. They are used to improve the readability of XML documents by assigning a meaningful prefix to element names
  4. They do not have any purpose right now, but future XML standards will use them in the same way that DTDs are used

45. What is the purpose of XPointer?

Answers:

  1. It has the same purpose as an HTML link
  2. It has the same purpose as an Extended XLink
  3. It is used when you want a link to point to a particular part of an XML document
  4. It has the same purpose as a Simple XLink

46. State whether the following statement is correct?
Conditional templates are output only if certain conditions exist
within the source document.

Answers:

  1. True
  2. false

47. Is the following statement correct?
Inner tags in XML must be closed first.

Answers:

  1. True
  2. False

48. An XML document has a root element named <folder>. The DTD for this document is stored in an External file called folder.dtd. How will you declare this external DTD in the XML document?

Answers:

  1. <!DOCTYPE folder EXTERNAL “folder.dtd”>
  2. <!DOCTYPE folder SYSTEM [“folder.dtd”]>
  3. <!DOCTYPE folder SYSTEM “folder.dtd”>
  4. The DTD must be stored in the same file as the XML document

49. Which of the following statements is true?

Answers:

  1. An XML Namespace can only be associated with the Root element of an XML document
  2. An XML Namespace can be associated with any element in the XML document and its scope is limited to that element only
  3. An XML Namespace can be associated with any element in the XML document and its scope is limited to that element along with its child elements
  4. An XML Namespace can be associated with any element in the XML document and its scope is limited to the entire XML document

50. How is an entity used within an XML document?

Answers:

  1. %entity-name%
  2. <!–entity-name–>
  3. &entity-name;
  4. <entity-name/>

51. Read the following statements carefully.
1. <xsl:for-each select=”portfolio/stock”>
2. <TR>
3. <TD><xsl:value-of “symbol”/></TD>
4. </TR>
5. </xsl:for-each>

Which statement is incorrect in above rows?

Answers:

  1. 1
  2. 2
  3. 3
  4. 4

52. State whether the following statement is correct?
Inline schema is useful when it is inconvenient to physically separate
the schema and the instance.

Answers:

  1. True
  2. False

53. When is the DOM event ‘ondataavailable’ fired?

Answers:

  1. When new data is available
  2. When user set an attribute
  3. When XML is NULL
  4. None of the above

54. What is wrong with this XML code?

1 <?xml version=”1.0″?>
2 <folder dt=”1/1/2000″>
3 <file id=”1″ >
4 <name>Accounts Reports</name>
5 <contents />
6 <!– Note: This file does not contain anything yet –>
7 </file>
8 </folder>
9 <folder dt=”1/2/2000″>
10 <file id=”2″ >
11 <name>Marketing Reports</name>
12 <contents />
13 <!– Note: This file does not contain anything yet –>
14 </file>
15 </folder>

Answers:

  1. the version declaration is incorrect
  2. it doesn’t have a root element
  3. an attribute named id cannot be used because id is a reserved word
  4. the comments are incorrect
  5. there is nothing wrong

55. Which of the following is false when you use XSL to convert an XML document to HTML format?

Answers:

  1. The XSL file must be wellformed
  2. A Namespace must be used within the XSL file
  3. The document generated after transformation will also satisfy all XML syntax requirements
  4. The document generated after transformation may or may not satisfy all XML syntax requirements

56. Which of the following is correct about SAX2?

Answers:

  1. SAX2 is an xml Parser
  2. SAX2 is used for event-based xml implementation
  3. SAX2 is used for xml schema
  4. None of the above

57. Which is the correct way to declare an XML Namespace?

Answers:

  1. <body xmlns:hns=”http://www.w3.org/TR/html4/”>
  2. <hns:body xmlnamespace:hns=”http://www.w3.org/TR/html4/”>
  3. <hns:body hns=”http://www.w3.org/TR/html4/”>
  4. <hns:body xmlns:hns=”http://www.w3.org/TR/html4/”>

58. Which of the following statements define ‘prolog’ in xml?

Answers:

  1. The prolog refers to the information that appears before the start tag of the document or root element
  2. The prolog creates is used to create the structure of the xml document
  3. The prolog is a query language for xml
  4. The prolog is an xml parser

59. When are you most likely to use XML?

Answers:

  1. You have created a Java-based data-oriented application which will be used on several different platforms
  2. You want to exchange information between a web based Java application and a Visual Basic application running on your PC
  3. You want to create a personal web site for yourself which will consist of a few static pages
  4. You are writing a software for an old mainframe computer

60. What is an ENTITY attribute type?

Answers:

  1. It can contain the name of any External Unparsed entity
  2. It can contain the name of any External Unparsed entity or Internal Unparsed entity
  3. It can contain the name of any External Parsed entity or Internal Parsed entity
  4. It can contain the name of any Parameter entity

61. Which of the following is an XML declaration?

Answers:

  1. <?xml version=”1.0″?>
  2. <xmlns:h br/>
  3. <!IGNORE ……..>
  4. <!DOCTYPE ……>
  5. <!INCLUDE …….>

62. Which of the following is not a reason for using DTDs?

Answers:

  1. DTDs speed up the parsing of an XML document
  2. With DTDs, your XML files carry a description of their own format.
  3. Independent groups of people can agree to use a common DTD for interchanging data.
  4. Your application can use a standard DTD to verify that the data you receive from outside is valid.

63. What is an IDREFS attribute type?

Answers:

  1. It is the same as an ID attribute
  2. It is the same as an IDREF attribute
  3. It can contain letters and numbers and it must contain unique values
  4. Its value must match the value of one or more ID attributes separated by whitespace

64. Which of the following is the correct way to define an attribute named size of an element named shoe. The attribute should have a default value of 0?

Answers:

  1. <!ATTLIST shoe size CDATA “0”>
  2. <!ATTLIST shoe size CDATA 0>
  3. <!ATTLIST shoe size #PCDATA “0”>
  4. <!ATTLIST shoe size DATA “0”>

65. Which attribute is not used when specifying a Simple XLink element?

Answers:

  1. locator
  2. show
  3. actuate
  4. role
  5. title

66. What is an NMTOKEN attribute type?

Answers:

  1. It is the same as a CDATA attribute
  2. It can only contain letters and digits
  3. It can only contain letters and digits, hyphens, colons and a few other characters
  4. It can only contain letters and digits, hyphens, colons and a few other characters including spaces

67. Which of the following are the elements used to define an XML Schema?

Answers:

  1. complexType
  2. attribute
  3. element
  4. All of the above

68. Which of the following is not an attribute of AttributeType element of schema?

Answers:

  1. default
  2. name
  3. required
  4. optional

69. What is the difference between General entities and Parameter Entities?

Answers:

  1. They are the same
  2. There is no such thing as a Parameter entity
  3. Parameter entities are used within DTDs and General entities are used within XML documents
  4. General entities are the predefined entities such as <, > etc whereas Parameter entities are user defined

70. What is XML DOM used for?

Answers:

  1. Writing DTDs
  2. Writing Schemas
  3. Programmatically accessing the elements within an XML file
  4. Parse the XML Data

71. What is an ID attribute type?

Answers:

  1. It is the same as a CDATA attribute
  2. It can only contain numbers and it must contain unique values
  3. It can only contain letters and it must contain unique values
  4. It can contain letters and numbers and it must contain unique values

72. Select the correct XML from following options.

Answers:

  1. <Customer><ID></ID><Customer><Customer><Name></Name></Customer>
  2. <Customer><ID><Name></Customer><Customer><ID><Name></Customer>
  3. <Customers><Customer><ID></ID><Customer><Customer><Name></Name></Customer></Customer></Customer>
  4. </Customers>
  5. <Customers><Customer><ID><Name>></Customer><Customer><ID><Name></Customer></Customers>

73. What is the correct value of order attribute for sorting the string in ascending order?

Answers:

  1. ASC
  2. ascend
  3. ascending
  4. ascendingorder

74. What does the following XPath expression represent?

/addressbook/address

Answers:

  1. All addresses within the addressbook element
  2. The first address within the addressbook element
  3. The last address within the addressbook element
  4. All addresses within the addressbook element and their sub children

75. When are you likely to use an XML Namespace?

Answers:

  1. When writing an XHTML document
  2. When creating an XSL template
  3. When writing an XML document containing tags from multiple XML vocabularies
  4. All of the above

76. Which of the following is a required namespace in xml schema?

Answers:

  1. xmlns=”urn:schemas-microsoft-com:xml-data”
  2. xmlns=”urn:schemas-microsoft-com”
  3. xmlns=”urn:schemas-microsoft-com:xml-database”
  4. None of the above

77. Comments describe statements in a better way. What is the correct syntax of comments in XML?

Answers:

  1. Begin with /* and end with a */
  2. Begin with <!– and end with –>
  3. Begin and end with //
  4. None of the above

78. Which of the following is not a schema element?

Answers:

  1. Attribute
  2. AttributeType
  3. ElementGroup
  4. DataType

79. Which of the following is not a primitive data type?

Answers:

  1. entity
  2. date
  3. id
  4. idref

80. Which of the statements are correct?

(a)Attributes added with <xsl:attribute> must appear before children are added to the element.
(b)You can add an attribute to an element that already has an attribute of that name.

Answers:

  1. Only (a) is true
  2. Only (b) is true
  3. Both (a) and (b) are true
  4. Both (a) and (b) are false

1,212 total views, 4 views today

Upwork Java Technologies

Java Test v3 2016

Published by:

1. Which statements are true regarding ServletContext Init Parameters in the deployment descriptor?

Answers:

  1. They are set at deployment-time, but accessed at run-time.
  2. They are accessible from any session within that context.
  3. They are not set at deployment-time, but accessed at run-time.
  4. They are set at deployment-time and can be updated at run-time.

2. Which of the following symbols are metacharacters supported by the java.util.regex API?

Answers:

  1. .
  2. @
  3. #

3. SQLException has a feature of chaining – identify the right code to execute the same from the following options:

Answers:

  1. catch(SQLException e) { out.println(e.getMessage()); while((e=e.getNextException())!=null) { out.println(e.getMessage()); } }
  2. catch(SQLException e) { out.println(e.getNextException()); while((e=e.getMessage())!=null) { out.println(e.getMessage()); } }
  3. catch(SQLException e) { out.println(e.getMessage()); while((e=e.getEncapsulatedException())!=null) { out.println(e.getMessage()); } }
  4. catch(ClassNotFoundException e) { out.println(e.getMessage()); while((e=e.getNextException())!=null) { out.println(e.getMessage()); } }
  5. catch(ClassNotFoundException e){ { out.println(e.getMessage()); } }

4. What is the result of an attempt to compile and run the given program?

public class Test107 {
public static void main(String[] args) {
System.out.println(test());
}
private static int test() {
return (true ? null : 0);
}
}

Answers:

  1. It gets a compiler error, because of an attempt to return null from the method with return type “int”.
  2. It compiles, but throws NullPointerException at run-time.
  3. It compiles, runs, and prints “null” (without quotes).
  4. It compiles, runs, and prints “0” (without quotes).

5. Which of the following methods are members of the Vector class and allow you to input a new element?

Answers:

  1. addItem
  2. append
  3. insert
  4. addElement

6. In which class is the notify method defined?

Answers:

  1. Thread
  2. Applet
  3. Runnable
  4. Object

7. What is the output of the given program?

public class Test93 {
private int x = 0;

public static void main(String[] args) {
new Test93().test();
}

private int f(int x) { return ++x; }
private int g(int y) { return x++; }

private void test() {
System.out.print( f(x)==f(x) ? “f” : “#” );
System.out.print( g(x)==g(x) ? “g” : “#” );
}
}

Answers:

  1. ##
  2. #g
  3. f#
  4. fg

8. Which design pattern reduces network traffic by acting as a caching proxy of a remote object?

Answers:

  1. DataAccess Object
  2. Model-View-Controller
  3. Value Object
  4. Business Delegate

9. What is the output of the given program?

public class Test89 {
public static void main(String[] args) {
T x = new T(“X”, null); x.start();
T y = new T(“Y”, x); y.start();
T z = new T(“Z”, y); z.start();
}
}
class T extends Thread {
private Thread predecessor;
private String name;
public T(String name, Thread predecessor) {
this.predecessor = predecessor;
this.name = name;
}
public void run() {
try {
Thread.sleep((int)(Math.random()*89));
System.out.print(name);
} catch (InterruptedException ie) {
ie.printStackTrace();
}
}
}

Answers:

  1. always XYZ
  2. always ZYX
  3. any of the following: XYZ, XZY, YXZ, YZX, ZXY, ZYX
  4. any of the following: XYZ, ZYX

10. The principal finder method that must be implemented by every entity bean class is:

Answers:

  1. findByPrimaryKey()
  2. ejbGetByPrimaryKey()
  3. ejbFindPrimayKey()
  4. getPrimaryKey()
  5. getFinder()

11. Which option lists Java access modifiers in the right order from the most permissive to the most restrictive?

Answers:

  1. public, protected, <i>no modifier/default/package</i>, private
  2. public, <i>no modifier/default/package</i>, protected, private
  3. <i>no modifier/default/package</i>, public, protected, private
  4. public, protected, private, <i>no modifier/default/package</i>

12. What should be the replacement of “//ABC” in the following code?

class Krit
{
String str= new String(“OOPS !!! JAVA”);
public void KritMethod(final int iArgs)
{
int iOne;
class Bicycle
{
public void sayHello()
{
//ABC
}
}
}
public void Method2()
{
int iTwo;
}
}

Answers:

  1. System.out.print(str);
  2. System.out.print(iOne);
  3. System.out.print(iTwo);
  4. System.out.print(iArgs);

13. Assuming that val has been defined as an int for the code below, which values of val will result in “Test C” being printed?

if( val > 4 ) {

System.out.println(“Test A”);

} else if( val > 9 ) {

System.out.println(“Test B”);

} else

System.out.println(“Test C”);

Answers:

  1. val < 0
  2. val between 0 and 4
  3. val between 4 and 9
  4. val > 9
  5. val = 0
  6. No values for val will result in “Test C” being printed.

14. What is the output of the given program?

public class Test118 extends _Test118 {
{
System.out.print(“_INIT”);
}
static {
System.out.print(“_STATIC”);
}
Test118() {
System.out.print(“_CONST”);
}
public static void main(String[] args) {
System.out.print(“_MAIN”);
new Test118();
}
}
class _Test118 {
_Test118() {
System.out.print(“_BASE”);
}
}

Answers:

  1. _STATIC_MAIN_BASE_INIT_CONST
  2. _STATIC_MAIN_INIT_BASE_CONST
  3. _INIT_STATIC_MAIN_BASE_CONST
  4. _INIT_STATIC_MAIN_BASE_CONST

15. What will be the output, if the following program is run?public class Test8 {
public static void main(String[] args) {
System.out.println(Math.sqrt(-4));
}
}

Answers:

  1. null
  2. 2
  3. NaN
  4. -2.0

16. What will be the output of this program?

public class Test {

public static void main(String args[]) {

int a, b;
a = 2;
b = 0;
System.out.println(g(a, new int[] { b }));
}

public static int g(int a, int b[]) {

b[0] = 2 * a;
return b[0];
}
}

Answers:

  1. 0
  2. 1
  3. An exception will occur
  4. 4

17. There are three classes named A, B, and C. The class B is derived from class A and class C is derived from B. Which of the following relations are correct for the given classes?

Answers:

  1. Any instance of A is an instance of B.
  2. Any instance of B is an instance of A.
  3. Any instance of C is an instance of B.
  4. Any instance of B is an instance of C.

18. What is the output of the given console application?

public class Test19 {
public static void main(String[] args) {
final int X = 9;
int[][] a = {{5, 4, 3}, {9, 7, 2}, {1, 6, 8}};
for (int i=0; i<3; i++) {
for (int j=0; j<3; j++) {
if (a[i][j] == X) break;
System.out.print(a[i][j] + “” “”);
}
}
}
}

Answers:

  1. ‘5
  2. 5 4 3
  3. 5 4 3 1 6 8
  4. 5 4 3 7 2 1 6 8

19. Which of the following statements is true?

Answers:

  1. public interface RemoteTrain extends java.rmi.Remote
  2. public class RemoteTrain extends java.rmi.Remote
  3. public interface RemoteTrain extends java.net.Remote
  4. public class RemoteTrain extends java.net.Remote
  5. private class RemoteTrain extends java.net.Remote

20. The JDK comes with a special program that generates skeleton and stub objects that is known as:

Answers:

  1. java.rmi.Remote
  2. rmi
  3. rmic
  4. rmijava
  5. javac

21. How many objects are created by the following code?

Object a, b, c, d, e;

e = new Object ();

b = a = e;

e = new Object ();

Answers:

  1. 2
  2. 5
  3. 4
  4. That code is invalid.

22. Which of these interfaces is the most applicable when creating a class that associates a set of keys with a set of values?

Answers:

  1. Collection
  2. Set
  3. Map
  4. SortedSet

23. Which of the following is the correct syntax for creating a Session object?

Answers:

  1. HttpSession ses=request.getSession(true);
  2. HttpSession ses=getSession(true);
  3. HttpSession ses=request.getSession();
  4. HttpSession ses=request.getSessionObject(true);
  5. HttpSession ses=response.getSession(true);

24. Which statement is true about the given code?

public class Test78 {
public static void main(String[] args) throws Exception {
new JBean().setHeight(1).setWidth(2).setDepth(3).setDensity(9);
}
}
class JBean {
private int height, width, depth, density;
public JBean setHeight (int h) { this.height = h; return this; }
public JBean setWidth (int w) { this.width = w; return this; }
public JBean setDepth (int d) { this.depth = d; return this; }
public JBean setDensity (int d) { this.density = d; return this; }
}

Answers:

  1. The code does not compile, because two setters have a formal parameter with the same name.
  2. The setters of the JBean class are JavaBean-compliant.
  3. The code compiles, but throws a NullPointerException at run-time.
  4. The code compiles and runs.

25. Choose all valid forms of the argument list for the FileOutputStream constructor shown below:

Answers:

  1. FileOutputStream( FileDescriptor fd )
  2. FileOutputStream( String n, boolean a )
  3. FileOutputStream( boolean a )
  4. FileOutputStream()
  5. FileOutputStream( File f )

26. Which of the following methods should be invoked by the container to get a bean back to its working state?

Answers:

  1. EJBPassivate()
  2. EJBActivate()
  3. EJBRemove()
  4. EJBOpen()
  5. EJBActivation()

27. Select all true statements:

Answers:

  1. An abstract class can have non-abstract methods.
  2. A non-abstract class can have abstract methods.
  3. If a non-abstract class implements interface, it must implement all the methods of the interface.
  4. If a non-abstract class inherits abstract methods from its abstract superclass, it must implement the inherited abstract methods.

28. Which option could be used to see additional warnings about code that mixes legacy code with code that uses generics?

Answers:

  1. -Xlint:unchecked
  2. -Xlint:-unchecked
  3. -Xswitchcheck or -Xlint:fallthrough depending on the version of Java
  4. -classpath or -cp

29. Assuming the servlet method for handling HTTPGET requests is doGet(HttpServletRequest req, HTTPServletResponse res), how can the request parameter in that servlet be retrieved?

Answers:

  1. String value=req.getInitParameter(10);
  2. String value=req.getInitParameter(“product”);
  3. String value=res.getParameter(“product”);
  4. String value=req.getParameter(“product”);

30. Which of these is not an event listener adapter defined in the java.awt.event package?

Answers:

  1. ActionAdapter
  2. MouseListener
  3. WindowAdapter
  4. FocusListener

31. What would be the result of compiling and running the following code class?

public class Test {

public static void main(String args[]) {

Test t = new Test();
t.start();
}

public void start() {

int i = 2;
int j = 3;
int x = i & j;
System.out.println(x);
}
}

Answers:

  1. The code will not compile.
  2. The code will compile but will give a runtime error.
  3. The code will compile and print 2.
  4. The code will compile and print 1.

32. Which of the following are the methods of the Thread class?

Answers:

  1. stay()
  2. go()
  3. yield()
  4. sleep(long millis)

33. What protocol is used by the DatagramSocket class?

Answers:

  1. STCP
  2. UDP
  3. TCP
  4. FTP
  5. None of the above

34. Which statements are true? Select all true statements.

Answers:

  1. A member variable can be declared synchronized.
  2. A class can be declared transient.
  3. A class be declared synchronized.
  4. A method can be declared synchronized.

35. Which exception must a setter of a constrained JavaBean property throw to prevent the property value from changing?

Answers:

  1. PropertyVetoException
  2. IllegalArgumentException
  3. IllegalComponentStateException
  4. InvalidAttributeValueException

36. X.509 version 3 specifies which of the following?

Answers:

  1. A format and content for digital certificates.
  2. The IPSec standard.
  3. The Secure Socket Layer.
  4. The Data Encryption Standard.
  5. A file for digital certificates.

37. What will be the output when this code is compiled and run?
public class Test {

public Test() {

Bar b = new Bar();
Bar b1 = new Bar();
update(b);
update(b1);
b1 = b;
update(b);
update(b1);
}

private void update(Bar bar) {

bar.x = 20;
System.out.println(bar.x);
}

public static void main(String args[]) {

new Test();
}

private class Bar {

int x = 10;
}
}

Answers:

  1. The code will fail to compile.
  2. 10 10 10 10
  3. 20 20 20 20
  4. 10 20 10 20

38. Which of the following methods can be used for reporting a warning on a Connection object, Statement object & ResultSet object?

Answers:

  1. getWarnings()
  2. getWarned()
  3. getWarning()
  4. getError()
  5. getErrors()

39. Which of the following are valid ways to define a thread in Java?

Answers:

  1. Create a subclass of java.lang.Thread class
  2. Create a class that implements java.lang.Runnable
  3. Define method run() in a class
  4. Define method call() in a class

40. JDBC is based on:

Answers:

  1. X/Open CLI (Call Level Interface)
  2. JDBC/Open CLI
  3. Java/Open CLI
  4. V/OPEN CLI
  5. V/CLOSE CLI

41. Which of the following statements regarding abstract classes are true?

Answers:

  1. All methods declared in an abstract class must be abstract.
  2. Any subclass (abstract or concrete class) of an abstract class must implement all the methods declared in the parent abstract class.
  3. Any concrete class must implement all the methods of the parent abstract class which are not implemented in the super hierarchy tree.
  4. The abstract class may have method implementation.

42. Which of the following is the name of the cookie used by Servlet Containers to maintain session information?

Answers:

  1. SESSIONID
  2. SERVLETID
  3. JSESSIONID
  4. CONTAINERID

43. Which method is called by the servlet container just after the servlet is removed from service?

Answers:

  1. public void finalize() {// code…}
  2. public void destroy() {// code…}
  3. public void destroy()throws ServletException {// code…}
  4. public void finalize()throws ServletException {// code…}

44. Which method in the HttpServlet class corresponds to the HTTPPUT method?

Answers:

  1. put
  2. doPut
  3. httpPut
  4. putHttp

45. Which of the following illustrates correct synchronization syntax?

Answers:

  1. public synchronized void Process(void){}
  2. public void Process(){ synchronized(this){ } }
  3. public void synchronized Process(){}
  4. public synchronized void Process(){}

46. The transaction attribute of a bean is set to ‘TX_REQUIRES_NEW.’ What can be inferred about its behavior?

Answers:

  1. It initiates a new transaction only when the previous one is concluded.
  2. It initiates a new transaction without waiting for the previous one to conclude.
  3. It sends the request to the EJB container for initiating a new bean.
  4. The bean manages its own transaction.

47. How many objects are created in the given code?

Object x, y, z;
x = new Object();
y = new Object();

Answers:

  1. 0
  2. 1
  3. 2
  4. 3

48. How does the set collection deal with duplicate elements?

Answers:

  1. Duplicate values will cause an error at compile time.
  2. A set may contain elements that return duplicate values from a call to the equals method.
  3. An exception is thrown if you attempt to add an element with a duplicate value.
  4. The add method returns false if you attempt to add an element with a duplicate value.

49. What is the output of the given program?

public class Test106 {
public static void main(String[] args) {
Integer x = 0;
Integer y = 0;
Integer a = 1000;
Integer b = 1000;
System.out.println( (a==b) + “; ” + (x==y) );
}
}

Answers:

  1. The code will not compile, because Integer is a class, and an object must be created by calling its constructor: Integer a = new Integer(1); or, alternatively, a primitive type must be used: int a = 1;
  2. true; true
  3. false; false
  4. false; true

50. 1 <libraryPrefix:handlerName parameterNAme=”value”>
2 <%=23*counter %>
3 <b>Congratulations!</b>

Which of the following is the correct way to complete the code snippet above?

Answers:

  1. </libraryPrefix:handlerName>
  2. </libraryPrefix:handlerName paremeterName=”value”>
  3. </handlerName>
  4. <libraryPrefix>

51. Which of the following transaction modes are supported by Enterprise Java Beans?

Answers:

  1. TX_NOT_SUPPORTED
  2. TX_BEAN_MANAGED
  3. TX_REQUIRED
  4. TX_MANDATORY
  5. All of the above

52. What is the output of the given program?

public class Test120 extends _Test120 {
{
System.out.print(“_INIT”);
}
static {
System.out.print(“_STATIC”);
}
Test120() {
System.out.print(“_CONST”);
}
public static void main(String[] args) {
System.out.print(“_MAIN”);
new Test120();
}
}
class _Test120 {
{
System.out.print(“_BIN”);
}
static {
System.out.print(“_START”);
}
_Test120() {
System.out.print(“_BASE”);
}
}

Answers:

  1. _START_STATIC_MAIN_BIN_BASE_INIT_CONST
  2. _STATIC_START_MAIN_BIN_BASE_INIT_CONST
  3. _STATIC_MAIN_START_BIN_BASE_INIT_CONST
  4. _START_MAIN_STATIC_BIN_BASE_INIT_CONST

53. Which distributed object technology is most appropriate for systems that consist entirely of Java objects?

Answers:

  1. RMI
  2. CORBA
  3. DCOM
  4. COM
  5. JDBC

54. The following code was written to save a handle to an EJBObject named ‘bookEJBObject’ for an online book shop:

javax.ejb.Handle bookHandle = _____________;

ObjectOutputStream stream = new ObjectOutputStream(newFileOutputStream(fileName));
stream.writeObject(bookHandle);
stream.close();

Which of the following methods should be filled in the blank?

Answers:

  1. (Handle) bookEJBObject()
  2. bookEJBObject.getHandle()
  3. bookEJBObject.getEJBHandle()
  4. newHandleInstance()

55. Which sequence will be printed when the following program is run?

import java.util.*;

public class Test {

public static void main(String str[]) {

List l = new ArrayList();
l.add(”1”);
l.add(”2”);
l.add(1,”3”);
System.out.println(l);
}
}

Answers:

  1. [1, 3, 2]
  2. [1, 3, 1]
  3. [1, 1, 3]
  4. [1, 1, 2]
  5. This code will generate an error.

56. Conventionally, which directory do servlet class files get placed on?

Answers:

  1. WEB-INFservlets
  2. webappservlets
  3. WEB-INFclasses
  4. WEB-INF

57. Which is a proper way to declare and throw exception of class XYException?

Answers:

  1. class XYException extends Exception {} … throw new XYException();
  2. class XYException implements Exception {} … throw new XYException();
  3. class XYException extends Exception {} … throw new Exception(“”XYException””);
  4. class XYException implements Exception {} … throw new Exception(“”XYException){};

58. Which of the following JDBC methods is used to retrieve large binary objects?

Answers:

  1. getBinaryStream()
  2. getText()
  3. getAsciiStream
  4. getString()
  5. getUniStream()

59. What is the output of the given program?

public class Test129 {
public static void main(String[] args) {
A a = new A2();
B b = new B2();
System.out.println(a.a + “” + b.b);
}
}
class A { int a = 1; }
class A2 extends A { int a = 2; }
class B { public int b = 1; }
class B2 extends B { public int b = 2; }

Answers:

  1. 1
  2. 2
  3. 11
  4. 22

60. What exception is thrown by this code, if arr[j]>arr[j+1]:

public static void main(String[] args) {
int []arr={12,23,43,34,3,6,7,1,9,6};
{
int temp;
for (int i=0;i<arr.length;i++)
{
for (int j=0;j<arr.length-i;j++ )
{
if (arr[j]>arr[j+1])
{
temp=arr[j];
arr[j+1]=arr[j];
arr[j+1]=temp;
}
}
}
}
for(int i=0; i<arr.length; i++)
{
System.out.print(arr[i] + ” “);
}
}

Answers:

  1. NumberFormatException
  2. ArrayIndexOutOfBoundException
  3. IOException

61. Which of the following is a well-known HTTP port?

Answers:

  1. 21
  2. 25
  3. 8080
  4. 80
  5. 137

62. What is the output of the given console application?

public class Test31 {
public static void main(String[] args) {
test();
}
public static void test() {
try {
System.out.print(“-try”);
return;
} catch (Exception e) {
System.out.print(“-catch”);
} finally {
System.out.print(“-finally”);
}
}
}

Answers:

  1. -try
  2. -try-catch
  3. -try-finally
  4. -try-catch-finally

63. Which of these interfaces are used by implementations of models for JTable?

Answers:

  1. TableModel
  2. TableColumnModel
  3. TableSelectionModel
  4. ListModel

64. Which of the following require explicit try/catch exception handling by the programmer?

Answers:

  1. Accessing a method in another class
  2. Attempting to open a network socket
  3. Attempting to open a file
  4. Traversing each member of an array

65. What is the output of the given program?

public class Test89 {
public static void main(String[] args) {
T x = new T(“”X””, null); x.start();
T y = new T(“”Y””, x); y.start();
T z = new T(“”Z””, y); z.start();
}
}
class T extends Thread {
private Thread predecessor;
private String name;
public T(String name, Thread predecessor) {
this.predecessor = predecessor;
this.name = name;
}
public void run() {
try {
Thread.sleep((int)(Math.random()*89));
System.out.print(name);
} catch (InterruptedException ie) {
ie.printStackTrace();
}
}
}

Answers:

  1. Always XYZ
  2. Always ZYX
  3. Any of the following: XYZ, XZY, YXZ, YZX, ZXY, ZYX
  4. Any of the following: XYZ, ZYX

66. Which of the following code snippets will take transform input string “2012/06/05” to output string “05 – 06 – 2012”?

Answers:

  1. String dateString = “2012/06/05”; Date date = new SimpleDateFormat(“yyyy/MM/dd”).parse(dateString); SimpleDateFormat sdf = new SimpleDateFormat(“dd – MM – yyyy”); System.out.println(sdf.format(date));
  2. String dateString = “2012/06/05”; Date date = new SimpleDateFormat(“yyyy/MM/dd”).format(dateString); SimpleDateFormat sdf = new SimpleDateFormat(“dd – MM – yyyy”); System.out.println(sdf.parse(date));
  3. String dateString = “2012/06/05”; Date date = new SimpleDateFormat(“dd – MM – yyyy”).format(dateString); SimpleDateFormat sdf = new SimpleDateFormat(“yyyy/MM/dd”); System.out.println(sdf.parse(date));
  4. String dateString = “2012/06/05”; Date date = new SimpleDateFormat(“dd – MM – yyyy”).parse(dateString); SimpleDateFormat sdf = new SimpleDateFormat(“yyyy/MM/dd”); System.out.println(sdf.format(date));

67. Which statement is true regarding ServletContext Initialization Parameters in the deployment descriptor?

Answers:

  1. They are accessible by all servlets in a given web application.
  2. They are accessible by all servlets in a given session.
  3. They are accessible by all servlets in a given HTTP request.
  4. They are accessible by all servlets in a given container.

68. Which of the following statements is true of the HashMap class?

Answers:

  1. It stores information as key/value pairs.
  2. Elements are returned in the order they were added.
  3. It does not permit null keys.
  4. It does not permit null values.

69. Which distributed object technology is most appropriate for systems that consist of objects written in different languages and that execute on different operating system platforms?

Answers:

  1. RMI
  2. CORBA/li>
  3. COBRA
  4. DCOM
  5. COM

70. What is the output of the given code?

public class Test15 {
public static void main(String[] args) {
VO a = new VO(2);
VO b = new VO(3);
swapONE(a, b);
print(a, b);
swapTWO(a, b);
print(a, b);
}

private static void print(VO a, VO b) {
System.out.print(a.toString() + b.toString());
}

public static void swapONE(VO a, VO b) {
VO tmp = a;
a = b;
b = tmp;
}
public static void swapTWO(VO a, VO b) {
int tmp = a.x;
a.x = b.x;
b.x = tmp;
}
}

class VO {
public int x;
public VO(int x) {
this.x = x;
}
public String toString() {
return String.valueOf(x);
}
}

Answers:

  1. 2332
  2. 3232
  3. 3223
  4. 2323

71. What would happen on trying to compile and run the following code?

class House {

public final void MaintainMethod() {
System.out.println(“MaintainMethod”);
}
}

public class Building extends House {

public static void main(String argv[]) {
House h = new House();
h.MaintainMethod();
}
}

Answers:

  1. A runtime error will occur because class House is not defined as final.
  2. Successful compilation and output of “MaintainMethod” at run time.
  3. A compilation error indicating that a class with any final methods must be declared final itself.
  4. A compilation error indicating that you cannot inherit from a class with final methods.

72. Which of the following code snippets will generate five random numbers between 0 and 200?

Answers:

  1. Random r = new Random(); for (int i = 0; i < 5; i++) { System.out.println(r.nextInt(0,200)); }
  2. Random r = new Random(200); for (int i = 0; i < 5; i++) { System.out.println(r.nextInt()); }
  3. Random r = new Random(); for (int i = 0; i < 5; i++) { System.out.println(r.nextInt(200)); }
  4. Random r = new Random(200); for (int i = 0; i < 5; i++) { System.out.println(r.nextInt(0)); }

73. What will be the output when this code is compiled and run?

public class Test {

public Test() {

Bar b = new Bar();
Bar b1 = new Bar();
update(b);
update(b1);
b1 = b;
update(b);
update(b1);
}

private void update(Bar bar) {

bar.x = 20;
System.out.println(bar.x);
}

public static void main(String args[]) {

new Test();
}

private class Bar {

int x = 10;
}
}

Answers:

  1. The code will fail to compile.
  2. 10 10 10 10
  3. 20 20 20 20
  4. 10 20 10 20

74. Which class contains a method to create a directory?

Answers:

  1. File
  2. DataOutput
  3. Directory
  4. FileDescriptor
  5. FileOutputStream

75. What is the output of the given program?

public class Test130 {
public static void main(String[] args) {
A a = new A2();
B b = new B2();
System.out.println(a.a + “””” + b.b());
}
}
class A {
public int a = 1;
}
class A2 extends A {
public int a = 2;
}
class B {
public int b() { return 1; }
}
class B2 extends B {
public int b() { return 2; }
}

Answers:

  1. 11
  2. 12
  3. 21
  4. 22

76. Which of the following is the correct syntax for suggesting that the JVM perform garbage collection?

Answers:

  1. System.setGarbageCollection();
  2. System.out.gc();
  3. System.gc();
  4. System.free();

77. Why can’t a Graphics object be created using the following statement?

Graphics g = new Graphics();

Answers:

  1. The Graphics class is a final class.
  2. The Graphics class is an abstract class.
  3. The constructor of the Graphic class needs a color object to be passed as a parameter, e.g Graphics g = new Graphics(new Color());.

78. Select all correct statements:

Answers:

  1. Vector is synchronized, ArrayList is not synchronized
  2. Hashtable is synchronized, HashMap is not synchronized
  3. Vector is not synchronized, ArrayList is synchronized
  4. Hashtable is not synchronized, HashMap is synchronized

79. What is the output of the given program?

public class Test97 {
public static void main(String[] args) {
int[][] a = new int[2][2];
System.out.println(a.length);
}
}

Answers:

  1. 0
  2. 2
  3. 3
  4. 4

80. Which of the following is false?

Answers:

  1. A scrollable ResultSet can be created in JDBC 2.0 API.
  2. The cursor is moved forward using next().
  3. The cursor is moved backward using previous().
  4. A while loop can be used because next() & previous() methods return false beyond the resultset.
  5. A while loop can be used because next () & previous () methods return -1 beyond the resultset.

81. Consider the following code:

public class Jam {

public void apple(int i, String s) {
}

//ABC

}

Choose possible valid code replacements of “//ABC” among the choices:

Answers:

  1. public void apple(String s, int i) {}
  2. public int apple(int i, String s) {}
  3. public void apple(int i, String mystring) {}
  4. public void Apple(int i, String s) {}

82. RMI allows remote communication between:

Answers:

  1. C++ and Java
  2. C and Java
  3. Pascal and Java
  4. Java and Java
  5. Java and TCP/IP

83. Which of the following interfaces makes it possible for Java to save an object to a file and turn it into a data stream?

Answers:

  1. java.io.Serialization
  2. java.net.Serializable
  3. java.net.Serialization
  4. java.io.Serializable
  5. java.net.io.Serializable

84. How many objects are created in the given code?

Object x, y, z;
x = new Object();
y = new Object()

Answers:

  1. 0
  2. 1
  3. 2
  4. 3

85. As part of the type erasure process, when compiling a class or interface that extends a parameterized class or implements a parameterized interface, the compiler may need to create a synthetic method, called a _________.

Answers:

  1. bridge method
  2. helper method
  3. stub method
  4. raw method

86. Consider the following code:

public static void main(String bicycle[])
{
System.out.println(bicycle[0]);
}

What would be the result if “java TwoTyre one two” is entered in the command line?

Answers:

  1. one
  2. two
  3. TwoTyre
  4. None of the above

87. With regard to the destroy lifecycle method, identify the correct statements about its purpose or about how and when it is invoked.

Answers:

  1. It gives the servlet an opportunity to clean up resources.
  2. Like try-catch, it is called upon an exception.
  3. It is rarely used but can be called to remove a servlet from memory.
  4. It isn’t called if the server crashes.

88. What is the term to describe a situation where two or more threads are blocked forever, waiting for each other?

Answers:

  1. deadlock
  2. starvation
  3. livelock
  4. liveness

89. What will be the output of the following code?
public class MyTest {

public static void main(String[] args) {
for (int i=0; i > 10; i+=2) {
System.out.println(i);
}
}
}

Answers:

  1. Nothing will be printed.
  2. It will print the following output: 0 2 4 6 8
  3. Compile time error
  4. It will print the following output: 0 1 2 3 4 5 6 7 8 9

90. Which of the following cannot apply to constructors?

Answers:

  1. Name same as class name
  2. Void return type
  3. Can have parameters
  4. Overloading

3,917 total views, 22 views today