C and Java Programming Fundamentals

Test your knowledge of C programming (operators, arrays, pointers, recursion) and Java concepts (OOP, collections, generics, servlets, JSP)

14 Questions Published

Questions

Question 1 Multiple Choice (Single Answer)

The process of writing the state of an object to a byte stream is called as

  1. Deserialization
  2. Serialization
  3. Interface
  4. All of the Above
Question 2 True/False

servlet.xml is the file used to define a servlet mapping

  1. True
  2. False
Question 3 Multiple Choice (Single Answer)

Through _________ , you can control what parts of a program can access the members of a class

  1. Encapsulation
  2. Class
  3. Inheritance
  4. Polymorphism
Question 4 Multiple Choice (Single Answer)

In order for a source code file, containing the public class Test, to successfully compile, which of the following must be true?

  1. It must have a package statement
  2. It must be named Test.java
  3. It must import java.lang
  4. It must declare a public class named Test
Question 5 Multiple Choice (Single Answer)

Given the JSP code: <% request.setAttribute("foo", "bar"); %> and the Classic tag handler code: 5. public int doStartTag() throws JspException { 6. // insert code here 7. // return int 8. } Assume there are no other "foo" attributes in the web application. Which invocation on the pageContext object, inserted at line 6, assigns "bar" to the variable x?

  1. String x = (String) pageContext.getAttribute("foo");
  2. String x = (String) pageContext.getRequestScope("foo");
  3. It is NOT possible to access the pageContext object from within doStartTag.
  4. String x = (String)
Question 6 Multiple Choice (Single Answer)

Given: 11. List list = // more code here 12. Collections.sort(list, new MyComparator()); Which code will sort this list in the opposite order of the sort in line 12?

  1. Collections.reverseSort(list, new MyComparator());
  2. Collections.sort(list, new MyComparator());
  3. Collections.sort(list, new InverseComparator(
  4. Collections.sort(list, Collections.reverseOrder(
Question 7 Multiple Choice (Single Answer)

Given: 11. public static void append(List list) { list.add(”0042”); } 12. public static void main(String[] args) { 13. List intList = new ArrayList(); 14. append(intList); 15. System.out.println(intList.get(0)); 16. } ‘What is the result?

  1. 42
  2. 0042
  3. An exception is thrown at runtime
  4. Compilation fails because of an error in line 13
Question 8 Multiple Choice (Multiple Answers)

Given: classA {} class B extends A {} class C extends A {} class D extends B {} Which three statements are true? (Choose three.)

  1. The type List is assignable to List<A>.
  2. The type List<Object> is assignable to List<?>.
  3. The type List<D> is assignable to List<? extends B>.
  4. The type List<? extends B> is assignable to List<? extends A>.
  5. The type List<Object> is assignable to any List reference.
Question 9 Multiple Choice (Single Answer)

A programmer has an algorithm that requires a java.util.List that provides an efficient implementation of add(0,object), but does NOT need to support quick random access. What supports these requirements?

  1. java.util.Queue
  2. java.util.ArrayList
  3. java.util.LinearList
  4. java.util.LinkedList
Question 10 Multiple Choice (Single Answer)

Servlet A receives a request that it forwards to servlet B within another webapplication in the same web container. Servlet A needs to share data with servlet B and that data mustnot be visible to other servlets in A's web application. In which object can the data that A shares with Bbe stored?

  1. HttpSession
  2. ServletConfig
  3. ServletContext
  4. HttpServletRequest
  5. HttpServletResponse
Question 11 Multiple Choice (Single Answer)

1.main() { char s[ ]="man"; int i; for(i=0;s[ i ];i++) printf("%c%c%c%c",s[ i ],(s+i),(i+s),i[s]); }

  1. mmmmaaaannnn
  2. aaaammmmnnnn
  3. aaaannnnmmmm
  4. Compilation Error
Question 12 Multiple Choice (Single Answer)

main() { static int var = 5; printf("%d ",var--); if(var) main(); }

  1. 1 2 3 4 5
  2. 5 4 3 2 1
  3. compilation error
  4. None
Question 13 Multiple Choice (Single Answer)

main() { int c[ ]={2.8,3.4,4,6.7,5}; int j,*p=c,*q=c; for(j=0;j<5;j++) { printf(" %d ",*c); ++q; } for(j=0;j<5;j++){ printf(" %d ",*p); ++p; } }

  1. 3 4 6 5 2 2 2 2 2 2
  2. 4 6 5 2 2 2 2 2 2 3
  3. 2 2 2 3 4 6 5 2 2 2
  4. 2 2 2 2 2 2 3 4 6 5
Question 14 Multiple Choice (Single Answer)

main() { int i=-1,j=-1,k=0,l=2,m; m=i++&&j++&&k++||l++; printf("%d %d %d %d %d",i,j,k,l,m); }

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