Java Programming Fundamentals
Test your knowledge of core Java programming concepts including OOP, collections, threading, exception handling, and basic language features
Questions
What happens when you compare two primitives of different numerical types?
- compiler error
- smaller type is promoted
- must explicitly cast
- none of the above
Are you allowed to have more than one top-level(non-inner) class definition per source file?
- True
- False
Assume the bit pattern of byte x is: 10110001. What will the sign of x be after x>>2?
- postive
- negative
- can't be find
- none of the above
A class can define two methods with the same name as long as the return types are different
- True
- False
All exceptions inherit from
- java.lang.Exception
- java.lang.Error
- java.lang.Throwable
- none of the above
What happens when you compare two primitives of different numerical types?
- compiler error
- smaller type is promoted
- must explicitly cast
- none of the above
public static void main(String [] args) { int x = 5; boolean b1 = true; boolean b2 = false; if ((x == 4) && !b2 ) System.out.print("1 "); System.out.print("2 "); if ((b2 = true) && b1 ) System.out.print("3 "); } } What is the result?
- 1,3
- 2,3
- Compilation Error
- Exception
interface I{ void f1(); // 1 public void f2(); // 2 protected void f3(); // 3 private void f4(); // 4 } which lines generate compile time errors?
- compiletime error at lines 1,2,3,4
- compiletime error at line 3
- compiletime error at line 1
- compiletime error at lines 3,4
class C1{ public void m1(){ // 1 } } class C2 extends C1{ //2 private void m1(){ } }
- compile time error at line1
- compile time error at line2
- Run time exception
- None Of the above
class A extends Thread { public void run() { System.out.print("A"); } } class B { public static void main (String[] args) { A a = new A(); a.start(); a.start(); // 1 } }
- Run Time Exception
- Compile Error
- the code compile and runs fail
- None of the above
What type of inheritance does Java have?
- Single Inheritence
- Double Inheritence
- Multiple Inheritence
- Class Inheritence
Java runs on.
- Windows
- Unix
- Solaris
- All of the above
The Java interpreter is used for the execution of the source code.
- True
- False
A Vector is declared as follows. What happens if the code tried to add 6 th element to this Vector new vector(5,10)
- The element will be successfully added
- ArrayIndexOutOfBounds Exception
- The Vector allocates space to accommodate up to 15 elements
- None of the above
Which is the data structure used to store sorted map elements
- HashSet
- Hashmap
- Map
- TreeMap
Which of the following is true ?
- Stateless session beans doesn’t preserve any state across method calls
- Stateful session beans can be accesses by multiple users at the same time
- None of the above
- Allof the above
Stateful Session beans contain
- Home Interface
- Remote Interface
- Bean Class
- All of the above
A method is defined in a class as : void processUser(int i) { } If this method is overriden in a sub class,
- the new method should return int
- the new method can return any type of values
- the argument list of new method should exactly match that of overriden method
- the return type of new method should exactly match that of overriden method
What is the output of following piece of code ? int x = 2; switch (x) { case 1:System.out.println(”1?); case 2: case 3:System.out.println(”3?); case 4: case 5:System.out.println(”5?);
- No output
- 3 and 5
- 1, 3 and 5
- 3
In the init(ServletConfig) method of Servlet life cycle, what method can be used to access the ServletConfig object
- getServletInfo()
- getInitParameters()
- getServletConfig()
- None of the above