By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,470 Members | 1,907 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,470 IT Pros & Developers. It's quick & easy.

help with these practice questions!!

P: 45
Hi again,

I've been solving these questions from past exam papers, and im not entirely confident about my answers. Im hoping that you guys can double check them for me.

These are the questions:

1- Which of the following methods must be over-ridden in order to tell the system how to execute a Thread?
(A) thread()
(B) execute()
(C) start()
(D) run()

2- Which of the following is a correct event handling method?

(A) mousePressed(MouseEvent e){}
(B) MousePressed(MouseClick e){}
(C) functionKey(KeyPress k){}
(D) ComponentAdded(keyPress e){}



(3) A monitor called mon has 5 threads in its waiting pool; all these waiting threads have the same priority. One of the threads is thread1. How can you notify thread1 so that it alone moves from Waiting state to Ready State?
(A) Execute notify(thread1); from within synchronized code of mon.
(B) Execute mon.notify(thread1); from synchronized code of any
object.

(C) Execute thread1.notify(); from any code(synchronized or not) of
any object.
(D) You cannot specify which thread will get notified.

(4) How can you retrieve a circle’s radius value that’s passed to an applet?
(A)
public void init() {
String s = getParameter("radius");
doSomethingWithRadius(s); }
(B)
public static void main(String[] args) {
String s = getParameter("radius");
DoSomethingWithRadius(s); }
(C)
public void init() {
int radius = getParameter("radius");
doSomethingWithRadius(radius); }
(D)
public void init() {
int radius = getParameter();
doSomethingWithRadius(radius); }


true/false

1- The method drawRect(int a, int b, int c, int d) defined in
java.awt draws the outline of a rectangle with a, b being the x,y coordinates of top left corner, and c,d being the x,y co-ordinates of the
bottom right corner.
TRUE

2- There is no statement in Java to free storage.
FALSE //finalize() is used

Once again im really hoping that you guys may help me figure out if my answers are correct or not.

Thanks in advance
Jan 5 '07 #1
Share this Question
Share on Google+
11 Replies


10K+
P: 13,264
Hi again,

I've been solving these questions from past exam papers, and im not entirely confident about my answers. Im hoping that you guys can double check them for me.

These are the questions:

1- Which of the following methods must be over-ridden in order to tell the system how to execute a Thread?
(A) thread()
(B) execute()
(C) start()
(D) run()

2- Which of the following is a correct event handling method?

(A) mousePressed(MouseEvent e){}
(B) MousePressed(MouseClick e){}
(C) functionKey(KeyPress k){}
(D) ComponentAdded(keyPress e){}



(3) A monitor called mon has 5 threads in its waiting pool; all these waiting threads have the same priority. One of the threads is thread1. How can you notify thread1 so that it alone moves from Waiting state to Ready State?
(A) Execute notify(thread1); from within synchronized code of mon.
(B) Execute mon.notify(thread1); from synchronized code of any
object.
(C) Execute thread1.notify(); from any code(synchronized or not) of
any object.
(D) You cannot specify which thread will get notified.

(4) How can you retrieve a circle’s radius value that’s passed to an applet?
(A)
public void init() {
String s = getParameter("radius");
doSomethingWithRadius(s); }
(B)
public static void main(String[] args) {
String s = getParameter("radius");
DoSomethingWithRadius(s); }
(C)
public void init() {
int radius = getParameter("radius");
doSomethingWithRadius(radius); }
(D)
public void init() {
int radius = getParameter();
doSomethingWithRadius(radius); }

true/false

1- The method drawRect(int a, int b, int c, int d) defined in
java.awt draws the outline of a rectangle with a, b being the x,y coordinates of top left corner, and c,d being the x,y co-ordinates of the
bottom right corner.
TRUE

2- There is no statement in Java to free storage.
FALSE //finalize() is used

Once again im really hoping that you guys may help me figure out if my answers are correct or not.

Thanks in advance
Well unfortunately my friend you got none of the questions right. You really need to put in a bit more work.

1) There is no execute method in the thread class. The method you override is public void run():Answer D

2) Even the method mousePressed exists, it is spelled like I've done with small letter m and so Java being case sensitive your answer was wrong. Also mousePressed takes a MouseEvent object not a MouseClick. In fact there is no MouseClick class but a mouseClicked method. The correct answer was mousePressed(MouseEvent e){} :Answer A

3) The method notify() in the class Object takes no arguments and wakes up a single thread that is waiting on this object's monitor. If there are more than one threads waiting on this object, one of them is chosen arbitrarily and the choice occurs at the discretion of the implementation. Remember in Java Thread handling and garbage collection are platform dependent: Answer D

4)The thing about retrieving parameters from applets is that they come as Strings i.e the method getParameter(String s) returns a String Object and requires a String specifying the name of the parameter to be retrieved. So the only 2 possible solutions are A and B. B is wrong because it attempts to retrieve the parameters in the main method which is static and cannot reference the non-static variable getParameter. Answer A.

true/false
1)The first two arguments are the x,y co-ordinates of the top left corner alright but the next two are the length and height of the rectangle:Answer false
2)Calling finalize does not free memory. The finalize method is run when an object is being garbage collected, a process which will have been started by the underlying OS not by a command from the Java program. You can only suggest that the system garbage collects using System.gc() but this is only a suggestion which can be ignored.:Answer true
Jan 6 '07 #2

P: 45
This is unfair! :( I've been studying java all week and i cant seem to get anything right :( Thanks for your help!!! Hope i pass the exam :(
Jan 6 '07 #3

10K+
P: 13,264
This is unfair! :( I've been studying java all week and i cant seem to get anything right :( Thanks for your help!!! Hope i pass the exam :(
What kind of an exam do you want to write?
Jan 6 '07 #4

P: 45
What kind of an exam do you want to write?
Im going to do my final exam for my java course this week :( and its such a difficult subject :( I've been preparing myself for it for so long. I've been solving all kinds of questions, but it seems that it cant sink in yet............<sigh> :(
Jan 6 '07 #5

10K+
P: 13,264
Im going to do my final exam for my java course this week :( and its such a difficult subject :( I've been preparing myself for it for so long. I've been solving all kinds of questions, but it seems that it cant sink in yet............<sigh> :(
Just make sure you understand the concepts you know very well. By this I mean that there is no point in knowing 50% of every concept of Java. Rather it's better to know 100% of 50% of Java so that you know that you are really comfortable (and will get full marks) with any questions that might come in those areas that you know well.
Jan 6 '07 #6

100+
P: 157
Im going to do my final exam for my java course this week :( and its such a difficult subject :( I've been preparing myself for it for so long. I've been solving all kinds of questions, but it seems that it cant sink in yet............<sigh> :(
Helo,
I too have just started my training in Java/J2EE and have to appear for a similar exam at the end of my course, if you have Java installed on your machine then try reading the documentation for the methods that are a part of your question... it really helps a lot to clear all doubts..

I also came across the "Head First" series in Java/J2EE by O'Reilly publications. ... the way things are explained in these books + the mock-tests that they have...what can I say, it really makes learning Java simple and fun..

All The Best !
Jan 8 '07 #7

10K+
P: 13,264
Helo,
I too have just started my training in Java/J2EE and have to appear for a similar exam at the end of my course, if you have Java installed on your machine then try reading the documentation for the methods that are a part of your question... it really helps a lot to clear all doubts..

I also came across the "Head First" series in Java/J2EE by O'Reilly publications. ... the way things are explained in these books + the mock-tests that they have...what can I say, it really makes learning Java simple and fun..

All The Best !
Apparently no one seems to be suggesting my Java classes notes. But abctech is making a good point about the documentation. A good Java programmer should always check with the API specifications so that their methods are doing exactly what they think they are doing.
Jan 8 '07 #8

100+
P: 157
Apparently no one seems to be suggesting my Java classes notes. But abctech is making a good point about the documentation. A good Java programmer should always check with the API specifications so that their methods are doing exactly what they think they are doing.
Hi r0,

The Java-classes that you are posting makes for a fantastic read for many newcomers like myself and others, in fact I have all of that saved on my desktop..nothing helps more than getting the foundation right !

I just felt that outofmymind must have already browsed through that material and advanced towards slightly higher topics like 'Threads' ,'Graphics', 'Event-Handling' etc..

Well and I must thank outofmymind for posting practice questions like these in the forum and you for taking out the time to answer them with such precision, it helps understand the seemingly complex concepts very clearly !

Looking forward to many more classes in Java as well as other languages from the experts of 'thescripts', Thankyou guys for all your efforts!

Cheers,
Jan 8 '07 #9

10K+
P: 13,264
Hi r0,

The Java-classes that you are posting makes for a fantastic read for many newcomers like myself and others, in fact I have all of that saved on my desktop..nothing helps more than getting the foundation right !

I just felt that outofmymind must have already browsed through that material and advanced towards slightly higher topics like 'Threads' ,'Graphics', 'Event-Handling' etc..

Well and I must thank outofmymind for posting practice questions like these in the forum and you for taking out the time to answer them with such precision, it helps understand the seemingly complex concepts very clearly !

Looking forward to many more classes in Java as well as other languages from the experts of 'thescripts', Thankyou guys for all your efforts!

Cheers,
I was beggining to think I was wasting time putting together all that stuff.
Jan 8 '07 #10

P: 45
I was beggining to think I was wasting time putting together all that stuff.

No your not wasting your time, I seriuosly went through your classes before you even recomended them to me. I agree with abctech -> thanks for taking out the time to answer my problems, I must've been a pain for the last couple of days. Thanks for bearing with me :) Things are much clearer now, just have to see myself tomorrow :s
Jan 8 '07 #11

Ispep
P: 4
I was beggining to think I was wasting time putting together all that stuff.
Man this is going to sound really dumb, and I can't stop laughing now I've realised, but I think the title might put off beginners somewhat.

When you say "Free Java Classes", to me it sounded like it was something to download for advanced programmers, like a Java class that handled some complex arithmetic or something similar :D Being new to Java of course it never clicked!

But just got to reading a bit at a glance, it looks great and I'll be sure to find it extremely helpful :)
May 17 '07 #12

Post your reply

Sign in to post your reply or Sign up for a free account.