C and Java Programming Fundamentals
Test your knowledge of C programming (operators, arrays, pointers, recursion) and Java concepts (OOP, collections, generics, servlets, JSP)
Questions
The process of writing the state of an object to a byte stream is called as
- Deserialization
- Serialization
- Interface
- All of the Above
servlet.xml is the file used to define a servlet mapping
- True
- False
Through _________ , you can control what parts of a program can access the members of a class
- Encapsulation
- Class
- Inheritance
- Polymorphism
In order for a source code file, containing the public class Test, to successfully compile, which of the following must be true?
- It must have a package statement
- It must be named Test.java
- It must import java.lang
- It must declare a public class named Test
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?
- String x = (String) pageContext.getAttribute("foo");
- String x = (String) pageContext.getRequestScope("foo");
- It is NOT possible to access the pageContext object from within doStartTag.
- String x = (String)
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?
- Collections.reverseSort(list, new MyComparator());
- Collections.sort(list, new MyComparator());
- Collections.sort(list, new InverseComparator(
- Collections.sort(list, Collections.reverseOrder(
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?
- 42
- 0042
- An exception is thrown at runtime
- Compilation fails because of an error in line 13
Given: classA {} class B extends A {} class C extends A {} class D extends B {} Which three statements are true? (Choose three.)
- The type List is assignable to List<A>.
- The type List<Object> is assignable to List<?>.
- The type List<D> is assignable to List<? extends B>.
- The type List<? extends B> is assignable to List<? extends A>.
- The type List<Object> is assignable to any List reference.
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?
- java.util.Queue
- java.util.ArrayList
- java.util.LinearList
- java.util.LinkedList
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?
- HttpSession
- ServletConfig
- ServletContext
- HttpServletRequest
- HttpServletResponse
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]); }
- mmmmaaaannnn
- aaaammmmnnnn
- aaaannnnmmmm
- Compilation Error
main() { static int var = 5; printf("%d ",var--); if(var) main(); }
- 1 2 3 4 5
- 5 4 3 2 1
- compilation error
- None
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; } }
- 3 4 6 5 2 2 2 2 2 2
- 4 6 5 2 2 2 2 2 2 3
- 2 2 2 3 4 6 5 2 2 2
- 2 2 2 2 2 2 3 4 6 5
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 3 1 0 0
- 0 1 0 1 3
- 0 0 3 1 1
- 0 0 1 3 1