0

programming languages Online Quiz - 201

Description: programming languages Online Quiz - 201
Number of Questions: 20
Created by:
Tags: programming languages
Attempted 0/20 Correct 0 Score 0

Which of the following are illegal names for the business methods defined in an entity bean home interface?

  1. findAllCustomers(…)

  2. removeTheCustomer(…)

  3. createCustomer(…)

  4. create()

  5. retrieveCustData(…)


Correct Option: A,B,C,D

How many create methods can you declare in the entity bean home interface?

  1. One or more

  2. Zero or more

  3. Exactly one

  4. Zero


Correct Option: B

A client calls a finder method whose return type is a Collection of references to the remote interface of an entity bean. Assume no match for that entity is found. Which of the following will be the result of this call?

  1. ObjectNotFoundException.

  2. An empty Collection will be returned.

  3. An entity would be created and a reference to that entity would be returned.

  4. EntityNotFoundException.


Correct Option: B

Which of the following are true statements about what happens when a remove() method is called using the component interface of an entity bean representing a specific entity in the database?

  1. The entity bean instance is deleted.

  2. The entity in the database is deleted.

  3. Both the entity and the entity bean instance survive, but that entity bean instance does not represent that entity anymore.

  4. Nothing happens; the container simply ignores the call.


Correct Option: B

Which of the following statements are true about a CMP entity bean?

  1. You cannot write JDBC code in the bean class to make a connection and send queries to any database.

  2. You cannot write JDBC code in the bean class to change the values of virtual persistent fields of your bean.

  3. You can write JDBC code and get connected to any database you want.

  4. You can write JDBC code to read the virtual persistent fields, but you cannot change their values.


Correct Option: B

Which methods of the EntityContext interface can be called from within an ejbPostCreate of an entity bean class?

  1. getEJBObject()

  2. getPrimaryKey()

  3. getEJBHome()

  4. getRollbackOnly()

  5. getUserTransaction()


Correct Option: A,B,C,D

Which of the following statements about the entity bean are true?

  1. All entity bean instances of the same type (say CustomerBean) have the same Home, that is, an instance of an object that implements the home interface of this bean.

  2. A specific entity bean instance can be accessed by only one client at a time.

  3. If two clients wanted to access the same entity in the database concurrently, the container would make two entity bean instances to represent that entity.

  4. If two clients wanted to access the same entity in the database concurrently, the container would make one entity bean to represent that entity, and the two clients would get their own references to the same EJBObject correspondtwo clients would get their


Correct Option: A,D

Consider the method getUserTransaction() of the interface Entity- Context. From which methods of an entity bean class can this method be called?

  1. ejbCreate

  2. Home business methods

  3. Business methods exposed in the component interface

  4. ejbStore()

  5. None of the above


Correct Option: E

Given: import java.util.regex.; class Regex2 { public static void main(String[] args) { Pattern p = Pattern.compile(args[o]); Matcher m = p.matcher(args[1]); boolean b = false; while(b = m.find()) { System.out.print(m.start() + m.group()); } } } And the command line: java Regex2 "\d" ab34ef What is the result?

  1. 234

  2. 334

  3. 2334

  4. 0123456

  5. 01234456

  6. 12334567


Correct Option: E

Given: import java.io.*; class Player { Player() { System.out.print("p"); } } class CardPlayer extends Player implements Serializable { CardPlayer() { System.out.print("c"); } public static void main(String[] args){ CardPlayer cl = new CardPlayer(); try { FileOutputStream fos = new FileOutputStream("play.txt"); ObjectOutputStream os = new ObjectOutputStream(fos); os.writeObject(c1); os.close() ; FileInputStream fis = new FileInputStream("play.txt"); ObjectInputStream is = new ObjectInputStream(fis); CardPlayer c2 = (CardPlayer) is.readObject(); is.close(); } catch (Exception x ) { } } } What is the result?

  1. pc

  2. pcc

  3. pcp

  4. pcpc

  5. Compilation fails

  6. An exception is thrown at runtime


Correct Option: C

AI Explanation

To determine the result of the given code, let's go through each step:

  1. The CardPlayer class extends the Player class and implements the Serializable interface.
  2. In the main method, a new CardPlayer object c1 is created, which invokes the default constructor of CardPlayer.
  3. The code then tries to write the c1 object to a file named "play.txt". This is done using FileOutputStream and ObjectOutputStream.
  4. After writing the object to the file, the code tries to read the object from the file. This is done using FileInputStream and ObjectInputStream.
  5. The object read from the file is assigned to a new CardPlayer object c2.
  6. Finally, the code closes the input and output streams.

Now let's analyze the output:

  • The Player class has a default constructor that prints "p" when called.
  • The CardPlayer class has a default constructor that prints "c" when called.

Based on the code execution:

  1. When the CardPlayer object c1 is created, the output is "c".
  2. When the c1 object is written to the file, the output is not printed.
  3. When the c1 object is read from the file and assigned to c2, the output is "p".
  4. Since the output statement is within the Player class constructor, it is not executed during object serialization and deserialization.

Therefore, the correct answer is option C: "pcp".

Given that bw is a reference to a valid BufferedWriter And the snippet: 15. BufferedWriter b1 = new BufferedWriter(new File("f")); 16. BufferedWriter b2 = new BufferedWriter(new FileWriter("f1")); 17. BufferedWriter b3 = new BufferedWriter(new PrintWriter("f2")); 18. BufferedWriter b4 = new BufferedWriter(new BufferedWriter(bw)); What is the result?

  1. Compilation succeeds

  2. Compilation fails due only to an error on line 15

  3. Compilation fails due only to an error on line 16

  4. Compilation fails due only to an error on line 17

  5. Compilation fails due only to an error on line 18

  6. Compilation fails due to errors on multiple lines


Correct Option: B

AI Explanation

To answer this question, let's go through each option to understand why it is correct or incorrect:

Option A) Compilation succeeds - This option is incorrect because the compilation does not succeed. There are errors in the code.

Option B) Compilation fails due only to an error on line 15 - This option is correct. The error on line 15 is that the constructor for the BufferedWriter class expects a Writer object as an argument, not a File object. Therefore, the code fails to compile.

Option C) Compilation fails due only to an error on line 16 - This option is incorrect. Although the constructor for the BufferedWriter class expects a Writer object as an argument, the FileWriter class is a subclass of Writer. So, there is no error on line 16.

Option D) Compilation fails due only to an error on line 17 - This option is incorrect. Although the constructor for the BufferedWriter class expects a Writer object as an argument, the PrintWriter class is a subclass of Writer. So, there is no error on line 17.

Option E) Compilation fails due only to an error on line 18 - This option is incorrect. The code on line 18 is valid. It creates a BufferedWriter object and passes another BufferedWriter object as an argument to its constructor.

Option F) Compilation fails due to errors on multiple lines - This option is incorrect. The code fails to compile only due to an error on line 15.

The correct answer is B. Compilation fails due only to an error on line 15. This option is correct because the constructor for the BufferedWriter class expects a Writer object as an argument, not a File object.

Given: 1. import java.text.*; 2. class DateOne { 3. public static void main(String[] args) { 4. Date d = new Date(1123631685981L); 5. DateFormat df = new DateFormat(); 6. System.out.println(df.format(d)); 7. } 8. } And given that 1123631685981L is the number of milliseconds between Jan. 1, 1970, and sometime on Aug. 9, 2005, what is the result? (Note: the time of day in option A may vary.)

  1. 8/9/05 5:54 PM

  2. 1123631685981L

  3. An exception is thrown at runtime.

  4. Compilation fails due to a single error in the code.

  5. Compilation fails due to multiple errors in the code.


Correct Option: E

AI Explanation

To answer this question, let's go through each option to understand why it is correct or incorrect:

Option A) 8/9/05 5:54 PM - This option is incorrect because the output of the code is not specified to be a specific date and time format. The code may have errors that prevent it from printing the desired output, but if it does print anything, it won't necessarily be in the format specified in this option.

Option B) 1123631685981L - This option is incorrect because the code is trying to format the date using the DateFormat class, which is incorrect. The DateFormat class is an abstract class and cannot be instantiated directly. The correct class to use for formatting dates is SimpleDateFormat. Therefore, the code will not print the milliseconds value as the output.

Option C) An exception is thrown at runtime. - This option is incorrect because the code does not contain any syntax or logical errors that would result in an exception being thrown at runtime.

Option D) Compilation fails due to a single error in the code. - This option is incorrect because the code does not contain any single error that would cause the compilation to fail.

Option E) Compilation fails due to multiple errors in the code. - This option is correct because there are multiple errors in the code that would result in a compilation failure.

The correct answer is E. Compilation fails due to multiple errors in the code.

Given: class Polish { public static void main(String[] args) { int x = 4 ; StringBuffer sb = new StringBuffer("..fedcba"); sb.delete(3,6); sb.insert(3, "az"); if(sb.length() > 6) x = sb.indexOf("b"); sb.delete((x-3), (x-2)); System.out.println(sb); } } What is the result?

  1. .faza

  2. .fzba

  3. ..azba

  4. .fazba

  5. ..fezba

  6. Compilation fails


Correct Option: C

AI Explanation

To determine the result of the given code, let's go through the code step by step:

  1. The code initializes an integer variable x with the value 4.
  2. It creates a StringBuffer object sb with the initial value "..fedcba".
  3. The code deletes the characters at positions 3, 4, and 5 from sb.
    • After deletion, sb becomes "..fba".
  4. The code inserts the string "az" at position 3 in sb.
    • After insertion, sb becomes "..azfba".
  5. The code checks if the length of sb is greater than 6. Since it is, the code executes the following:
  6. It assigns x the value of the index of the first occurrence of the character "b" in sb.
    • The first occurrence of "b" is at index 6.
    • Therefore, x is set to 6.
  7. The code deletes the characters at positions (x-3) and (x-2) from sb.
    • This translates to deleting characters at positions 3 and 4 from sb.
    • After deletion, sb becomes "..azba".
  8. Finally, the code prints the value of sb, which is "..azba".

Therefore, the result is "..azba".

The correct answer is option C.

JPD is deployed in weblogic as (Choose the best answer)

  1. Servlet in web application

  2. Record in a database

  3. Enterprise java bean

  4. File record


Correct Option: C

In a Weblogic Development environment…. (Choose the best answer):

  1. A Workspace can contain multiple applications and projects ….

  2. Module can have projects ,library and application

  3. Library can have modules and projects

  4. Application can have one or more projects, library and module


Correct Option: D

What will be the syntax for the Perform node created by the developer

  1. public void perform() { }

  2. public boolean perform() { }

  3. static public boolean perform() { }

  4. public void perform() throws Exception { }

  5. public boolean perform() throws Exception { }


Correct Option: D

Of the following which has got the broadest scope (Choose the best answer):

  1. Application

  2. Library

  3. Project

  4. Module

  5. Process


Correct Option: A

If the method to be overridden has access type protected, choose access types among the following that a subclass can have,

  1. Protected

  2. Private

  3. Public

  4. 2&3

  5. 1&3


Correct Option: E

While serializing a class whose Base class is serializable, which of the following fields are ignored?

  1. Non Static field

  2. Base class fields

  3. Transient Fields.

  4. Static Field


Correct Option: C

What is the rule of anonymous class

  1. Can have only one constructor

  2. a.Cannot have a constructor

  3. Can have more than one constructor

  4. May or May not have constructors


Correct Option: B
- Hide questions