Java Programming and EJB Fundamentals Quiz
Test your knowledge of Java programming concepts including collections, exceptions, generics, threading, and Enterprise Java Beans (EJB) including session beans, entity beans, transaction management, and callback methods.
Questions
Which of the following call back method belongs to Entity bean?
- void setContext()
- void ejbLoad()
- void ejbDelete()
- void ejbEvict()
----- cannot have local or remote interfaces?
- EntityBean
- StatefulSession Bean
- MessageDrivenBean
- StatelessSessionBean
What should be the return type of the method using @PrePassivate?
- Object
- void
- String
- Boolean
Which of the following call backs are called for the stateful session bean?
- construction
- destruction
- activation
- passivation
- All the above
Who is allowed to override the transaction attribute in the deployment descriptor?
- Bean Provider
- Application Assembler
- Deployer
- System Administrator
Which of the following statements are correct w.r.t. entity bean?
- Every entity must have a primary key
- It is not necessary to define primary key for an Entity
- @Primary annotation is used for denoting a simple primary key
- All the above
Both CMT and BMT may be used with Entity and Session Beans. True or False?
- True
- False
Which of the following is valid life cycle state for a Stateless Session Bean?
- Does not exist
- Pooled State
- Passive
- None
Most EJB servers show high degree of availability. Server clusters are an example of how this is functionality is achieved. What key advantages might server clusters offer in an EJB environment?
- Load distribution, Load balancing capability
- Location transparency
- Caching capability
- 2PC (Two phase commit) capability
The following block of code creates a Thread using a Runnable target: Runnable target = new MyRunnable(); Thread myThread = new Thread(target); Which of the following classes can be used to create the target, so that the preceding code compiles correctly?
- public class MyRunnable extends Runnable{public void run(){}}
- public class MyRunnable extends Object{public void run(){}}
- public class MyRunnable implements Runnable{public void run(){}}
- public class MyRunnable implements Runnable{void run(){}}
import java.util.Scanner; public class ScannerTest { public static void main(String[] args) { Scanner scanner = new Scanner("hello 1 2.00 false"); scanner.useDelimiter(" "); String str = scanner.next(); int anInt = scanner.nextInt(); float aFloat = scanner.nextFloat(); boolean booleanValue = scanner.nextBoolean(); System.out.println(str + ":" + anInt + ":" + aFloat + ":" + booleanValue); } } what is the output?
- The program will output 'hello:1:2.0:false'
- The program will throw Input Mismatch exception at the run-time
- The program will output nothing.
- The program will ouput ':1:2.0:false'
public class Gen
- Compile time Error at line 1
- Compile time Error at line 3
- Compile time Error at line 4
- Compile time Error at line 5
- Run Time Error
What will be printed out if you attempt to compile and run the following code? int i=9; switch (i) { default: System.out.println("default"); case 0: System.out.println("zero"); break; case 1: System.out.println("one"); case 2: System.out.println("two"); }
- default
- default, zero
- error default clause not defined
- no output displayed
Which of the following statements are true?
- Methods cannot be overridden to be more private
- static methods cannot be overloaded
- private methods cannot be overloaded
- An overloaded method cannot throw exceptions not checked in the base class
Which of the following is not keyword or reserved word in Java?
- if
- then
- goto
- while
- case
What will happen if you try to compile and run the following code? public class Q { public static void main(String argv[]){ int anar[]=new int[5]; System.out.println(anar[0]); } }
- Error: anar is referenced before it is initialized
- null
- 0
- 5
What will be output if you try to compile and run the following code, but there is no file called Hello.txt in the current directory? import java.io.*; public class Mine { public static void main(String argv[]){ Mine m=new Mine(); System.out.println(m.amethod()); } public int amethod() { try { FileInputStream dis=new FileInputStream("Hello.txt"); }catch (FileNotFoundException fne) { System.out.println("No such file found"); return -1; }catch(IOException ioe) { } finally{ System.out.println("Doing finally"); } return 0; } }
- No such file found
- No such file found ,-1
- No such file found, Doing finally, -1
- 0
You need to create a class that will store unique object elements. You do not need to sort these elements but they must be unique. What interface might be most suitable to meet this need?
- Set
- List
- Map
- Vector
Which of the following statements are true?
- At the root of the collection hierarchy is a class called Collection
- The collection interface contains a method called enumerator
- The interator method returns an instance of the Vector class
- The Set interface is designed for unique elements