GeeCON Prague 2014*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Interesting Ques SJCP Must See Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Interesting Ques SJCP Must See" Watch "Interesting Ques SJCP Must See" New topic
Author

Interesting Ques SJCP Must See

Rahul123 Khanna
Greenhorn

Joined: Jan 16, 2001
Posts: 11


Can anyone tell me is GridbagLayout and Stop Suspend Resueme method covered in JCP Exam

Ques 1) It is written in JLS that NaN is unordered. So comparing it with another NaN always results in False.
However look at this code:
class t {
public static void main(String args[]){
Double a = new Double(Double.NaN);
Double b = new Double(Double.NaN);
System.out.println(b.equals(b));
}
}
It produces output TRUE. How is this possible . We know that equals compare the contents of Objects meaning here it should check for the Values of a & b, but as they are unordered therefore it should return false.
-------------------------------------------------------------------------------------
import java.applet.*;
2: import java.awt.*;
3:
4: public class Q20 extends Applet
5: {
6: Button okButton = new Button("Ok");
7:
8: public void init()
9: {
10: setLayout(new BorderLayout());
11:
12: add("South", okButton);
13: add("North", okButton);
14: add("East", okButton);
15: add("West", okButton);
16: add("Center", okButon);
17:
18: setSize(300,300);
19: }
20: }

A) Five Buttons with label "Ok" at Top, Bottom, Right, Left and Center of the Applet.
B) Only one Button with label "Ok" at the Top of the Applet.
C) Only one Button with label "Ok" at the Bottom of the applet.
D) Only one Button with label "Ok" at the Center of the Applet.

Ans is D but How
----------------------------------------------------------------------------------------------
Ques 3). import java.applet.*;
import java.awt.*;
public class t extends Applet
{
Button okButton = new Button("Ok");
public void init()
{
setLayout(new GridLayout(2,2));
add( okButton);
add(okButton);
add( okButton);
add( new Button("4"));
add( new Button("5"));
setSize(300,300);}
}

This shows only 3 buttons with captions OK,4,5.Can anyone tell what basically happens when we add a single object reference to a Component as here we have added the same object reference okButton 3 times.What is the concept behind this.
HELP ???/
Sean Casey
Ranch Hand

Joined: Dec 16, 2000
Posts: 625
GridbagLayout is on the exam. Those are deprecated methods, so they are not on the exam.
Your first question was already answered today so look at the previous messages.
In your second question one button is created and it is positioned five times, and the last time it is positioned in the center.
In your third question, repeated add call's to the same reference won't do anything special. Since you create one ok Button and two other buttons with the keyword "new", you end up with three buttons overall.
Cherry Mathew
Ranch Hand

Joined: Dec 26, 2000
Posts: 159
[code]

import java.applet.*;
2: import java.awt.*;
3:
4: public class Q20 extends Applet
5: {
6: Button okButton = new Button("Ok");
7:
8: public void init()
9: {
10: setLayout(new BorderLayout());
11:
12: add("South", okButton);
13: add("North", okButton);
14: add("East", okButton);
15: add("West", okButton);
16: add("Center", okButon);
17:
18: setSize(300,300);
19: }
20: }

[code]
itz true that only one components is shown bcoz itz the same component thatz is added but
my question is why.I think borderlayout has got 5 variables in which they store the components.It is the same case in all layout managers they add the variables to an array or vector or whatever.R they checking whther it is the same object. i dont find any other way they can do this . Discussions always welcome
Cherry
[This message has been edited by Cherry Mathew (edited January 18, 2001).]
Janine Williams
Greenhorn

Joined: Jan 01, 2001
Posts: 6
Originally posted by Rahul123 Khanna:


Can anyone tell me is GridbagLayout and Stop Suspend Resueme method covered in JCP Exam

Ques 1) It is written in JLS that NaN is unordered. So comparing it with another NaN always results in False.
However look at this code:
class t {
public static void main(String args[]){
Double a = new Double(Double.NaN);
Double b = new Double(Double.NaN);
System.out.println(b.equals(b));
}
}
It produces output TRUE. How is this possible . We know that equals compare the contents of Objects meaning here it should check for the Values of a & b, but as they are unordered therefore it should return false.

The reason why it prints out true is becuase you are comparing the same object.
Double b = new Double(Double.NaN);
System.out.println(b.equals(b));
Janine
Sean Casey
Ranch Hand

Joined: Dec 16, 2000
Posts: 625
Cherry,
There is only one button shown because you only create one button. All those calls are just effecting the one object. In order to have multiple buttons shown, you're going to have to create multiple buttons.
Cherry Mathew
Ranch Hand

Joined: Dec 26, 2000
Posts: 159
Hi Sean,
I agree with u. that only one button is shown.
but how do they do that. they keep the reference of the object and i can have multiple variables pointing to the same object.
I want to know whether this done by checking whether itz the same object or is it bcoz of some OOps concept which i missed.
Any answers Ajith ,Bill,jane,Mahana
Cherry
[This message has been edited by Cherry Mathew (edited January 18, 2001).]
 
GeeCON Prague 2014
 
subject: Interesting Ques SJCP Must See