Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

My First Mock Exam question :)

 
Kathy Sierra
Cowgirl and Author
Rancher
Posts: 1589
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK, it's just ONE question, and a really EASY one at that but I'm doing this off the top of my head and we have to start SOMEwhere...

More to follow. This is from one of the objectives in Objective 1:
===================
Given this code in a stateful session bean business method:
try {
Socket s = new Socket(x,y);
} catch (Exception ex) {
ex.printStackTrace();
}
And assuming that x and y are the port and IP address of a running service running on the same server, what is the result?
(Assume all other bean code is correct and legal.)
A) Compilation fails
B) Deployment fails
C) An exception is thrown at runtime
D) Code compiles, deploys, and runs
E) Indeterminate. The code may deploy, but is not guaranteed to be portable to all EJB 2.0 containers.
===================
So, what is this question looking for?
Your knowledge of the programming restrictions. You'll see other questions testing your knowledge of what is and isn't allowed. But rather than simply asking: Is <some thing> allowed? The questions will offer scenarios or code examples.
Don't panic that this question assumes knowledge of the Socket API -- I figure you all know it (or can look it up); rest assured that the real exam will not include questions that require API knowledge about things unrelated to J2EE, unless it has been covered in the SCJP exam. (So, I might take a few liberties with my mock exam questions, that wouldn't be on the *real* exam. I'll let you know if and when I do that.)
Look in section 24.1.2 of the spec
cheers,
Kathy
 
Kathy Sierra
Cowgirl and Author
Rancher
Posts: 1589
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK, here's another one:
====================
Which two are guaranteed to be restored to their pre-passivated state when a passivated stateful session bean is activated with an ejbActivate() call? (Choose two.)
A) A reference to a non-serializable SessionContext object.
B) A reference to a UserTransaction object.
C) A transient reference variable.
D) A JDBC connection.
[hint: look in section 7.4 of the spec]
cheers,
Kathy
 
Sudd Ghosh
Ranch Hand
Posts: 191
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Kathy -
Answer to the 2nd is A, B.
I guess the answer to the first one is A - compilation fails. Is that correct or will it be B ?
BTW, r u coming for the Java One to SFO ? I guess I saw some name out there for the certification BOF sessions, but I don't remember seeing yours.
If you come there, I'll be just delighted to meet you. You are such a great help... always...
Regards, Sudd
 
Kathy Sierra
Cowgirl and Author
Rancher
Posts: 1589
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Howdy,
You're right on number two; it is A and B since the container is *required* to successfully passivate/activate a SessionContext reference, even if the reference is to a non-serializable object.
Now about number one... before I answer that, tell me what you're thinking when you say it wouldn't compile (or possibly deploy)?
By the way, THANK-YOU!! You're the first one to start answering a question
cheers,
Kathy
 
Sudd Ghosh
Ranch Hand
Posts: 191
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I went over the specs. I guess I was wrong. I took it for a network server, but your code has just created the socket. It did not establish to listen. So it can be a client too.
So I believe the correct answer should be D-compiles, deploys and runs.
Can you tell me one thing ? When the specs in this section (programming restrictions) is saying that "EJB architecture does not allow the EJB instance to be a network server" does it mean compile time checking or deployment time exception ? I think it is compile time, but I want to hear from you.
Also I've been seeing the 2.1 specs so far. How far is the 2.0 specs different from 2.1 (other than the new web-services stuffs added) ? Is there a big change in the existing stuffs too (like what we had between 1.1 and 2.0) ?
Regards, Sudd
 
Andrew Perepelytsya
Ranch Hand
Posts: 93
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Kathy Sierra:

Given this code in a stateful session bean business method:
try {
Socket s = new Socket(x,y);
} catch (Exception ex) {
ex.printStackTrace();
}
And assuming that x and y are the port and IP address of a running service running on the same server, what is the result?
(Assume all other bean code is correct and legal.)


A) Compilation fails
No, the code is legal.
B) Deployment fails
I guess, no. The container doesn't have the means to scan through your code, but it checks method signatures.

C) An exception is thrown at runtime
No, we are reading the socket, which is allowed. If we were to create a ServerSocket and listen for connections on it, then we would have violated the contract. Would it fail at deployment time? I think, it would give a runtime error.
Next, it depends largely on what socket we are reading. If it is running on the same host, but in a different virtual machine - no problem. If we are trying to deploy in EJB app, which is collocated (runs in the same JVM and container), then it will fail at runtime.
Besides, we do not close the socket explicitly - and socket is not a managed resource, thus the container will not be able to automatically close it for us. Only GC, and we cannot rely on it - don't know when it will run. Thus, it can depend on the system setting for available network sockets. Compare Win and *nix installations. So, one can say, it will deploy fine, but the runtime behaviour will be different because different number of initial network connections is set for different OSs.
D) Code compiles, deploys, and runs
Yes, to certain extent. I would add 'runs without errors' if you want to clarify the question.
E) Indeterminate. The code may deploy, but is not guaranteed to be portable to all EJB 2.0 containers.
I choose this answer, see option C description for more details. Though, it's very unclear what is meant by 'to be portable' here.
Not the best question you have, I'm sure Though forces one to reflect. (Hope not too muchu, and I didn't fail this one).
I would ask you to shed some light on EJB-QL syntax questions. As you know, there are tricky limitations in comparisons for the WHERE clause. And they are not described to the extent they should be in the spec. Thus, only practical experience (read - error and trial) will provide answers, and this is not the best way to build certification exams, perhaps.
OK, waiting for more input
 
Andrew Perepelytsya
Ranch Hand
Posts: 93
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Next, it depends largely on what socket we are reading. If it is running on the same host, but in a different virtual machine - no problem. If we are trying to deploy in EJB app, which is collocated (runs in the same JVM and container), then it will fail at runtime.

Guess, need to be more clear here. By different VM I meant a Java app (not EJB) running NOT in the JVM of the EJB container. Though it could be just a network service running on the same machine - SMTP server, SSH connections daemon, etc.
By collocated I meant an enterprise bean. By the way, I think if it were an EJB server socket even on a different machine, the other EJB container would through us a RemoteException, and we would still fail at the end of the day.
Yeah, now I feel better about the answer
 
Carl Trusiak
Sheriff
Posts: 3341
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As I read the specs, the answer to 2 is D) compiles, Deploys and Runs.
The reason for my accessment, the Required security setting a container must provide a component. One is java.net.SocketPermission grant "connect", "*"
 
Kathy Sierra
Cowgirl and Author
Rancher
Posts: 1589
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK, good ones
You are prevented from making a ServerSocket, but not a client Socket, so yes -- D is correct.
But you *will* get a question or two about programming restrictions (like this one).
When we say "portable to all EJB 2.0 containers", we mean that you are adhering to the specification.
In other words, you might be developing on a container that allows certain features, but if those features are outside the spec or violate the programming restrictions (or other spec "rules"), then you have not written EJB 2.0 portable code.
The exam is about knowing exactly what is and is not guaranteed by the spec, so that regardless of your current vendor's server, you will always know exactly when you are stepping outside the spec and reducing your deployment portability.
Yeah, not my finest question
And as I said, on the real exam , it would be more likely to just ASK you to choose from a list which things are restricted and which are not. But where's the fun in that?
cheers,
Kathy
Stay tuned... many more questions tomorrow.
 
Kimberly Bobrow Jennery
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Andrew Perepelytsya:

I would ask you to shed some light on EJB-QL syntax questions. As you know, there are tricky limitations in comparisons for the WHERE clause. And they are not described to the extent they should be in the spec. Thus, only practical experience (read - error and trial) will provide answers, and this is not the best way to build certification exams, perhaps.
OK, waiting for more input

What sort of light would you like shed on the EJB-QL stuff? I did a lot of those, I'm happy to try to shed some light on what the test objectives are trying to test, etc.
--Kimberly
 
Andrew Perepelytsya
Ranch Hand
Posts: 93
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, I'd like to know if exams tries you in the following areas:
e.g. EJB-QL 2.0 had no comparisons (< , >, etc.) for string literals. (though it is quite natural to compare the ones)
then, dates. to make use of the sql Date class as an entity bean field type, you have to compare only like this: WHERE b.date = ?1 . if you wanna go with something more intelligent, like WHERE b.date < ?1, then it will not work. (one has to use long or Timestamp).

i'm not talking about LIKE limitations (though they can be tricked, btw), aggregate functions.
you name it
just give us examples of the kind of questions you came up with for EJB-QL.
cheers
 
Milan Romasini
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Andrew's got the point and I agree with him.
And we defintelly need more mock questions.
Thanks, Milan
 
Kimberly Bobrow Jennery
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I just posted a mock EJB-QL exam question in another topic here. The formatting could have been prettier, but hopefully it'll still be useful
 
Jack Yang
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi Kathy
If just change your code like this:
try{
ServerSocket ss = new ServerSocket(1000);
}catch(Exception e){
}
what's the answer?
 
Kathy Sierra
Cowgirl and Author
Rancher
Posts: 1589
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ahhh... good suggestion!
if you change it to ServerSocket, I would have to alter the answers somewhat. The closest answer would be "E: indeterminate -- the code may deploy but is not guaranteed to be portable." But I don't reallly like that answer either. So I probably would have had different answers like:
A) Guaranteed to work correctly
B) Will not compile
C) Is not permitted by the EJB specification
In which case, C would be the answer.
Most of the questions that involve programming restrictions (and though on the *real* exam you would probably only have ONE question like that... on the beta you might have several) are very careful to ask whether this code... or this action... is guaranteed to be portable across all EJB 2.0 containers.
So the question and answers would be pretty obvious.
Cheers,
-Kathy
 
Jack Yang
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Kathy.
I think for this kind of question's answer is not clearly,but I agree with you C is the best one.
I just tried another code for java.io.*,it can work but still not follow the EJB spec.
public java.lang.String testIO(String str) {
try{
FileWriter w = new FileWriter("c:\\test.txt");
w.write(str);
w.close();
FileReader f = new FileReader("c:\\test.txt");
StringBuffer s = new StringBuffer();
int c;
while((c = f.read()) != -1)
s.append((char)c);
f.close();
return "OK " + s.toString();
}catch(Exception e){
e.printStackTrace();
return "Cannot read file";
}
}
In the spec,
An enterprise bean must not use the java.io package to attempt to access files and directories
in the file system.
This code can read and write,so does this mean we can use it?what's the spec use for?
But one this is a question,is the answer is still C?
thank you very much
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic