Aparna Narayanan

Ranch Hand
+ Follow
since Nov 07, 2000
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Aparna Narayanan

Hi,
I am using JBuilder for my Java Code. I have a PushConsumer sitting at one end and it has to communicate across the Jacorb-TAO to a C++ PushSupplier at the other end. I included jacorb.properties and jacorb.jar in my classpath, but I get the following error:
<CODE>
[ InterceptorManager started with 0 SIs, 0 CIs and 1 IORIs ]
[ MapToDefaultDomainsPolicy: pathnames null ]
[ POA RootPOA - ready ]
[ Set BasicListener address string to 130.100.27.155 ]
[ New connection to 130.100.140.77:10000 ]
[ Releasing one connection to 130.100.140.77:10000 ]
org.omg.CORBA.TRANSIENT: Unknown host xxxxx minor code: 0 completed: No
at org.jacorb.orb.connection.ConnectionManager._getConnection(ConnectionManager.java:149)
at org.jacorb.orb.connection.ConnectionManager._getConnection(ConnectionManager.java:117)
at org.jacorb.orb.connection.ConnectionManager.getConnection(ConnectionManager.java:366)
at org.jacorb.orb.Delegate.bind(Delegate.java:187)
at org.jacorb.orb.Delegate.bind(Delegate.java:234)
at org.jacorb.orb.Delegate.invoke(Delegate.java:863)
at org.jacorb.orb.Delegate.is_a(Delegate.java:1043)
at org.omg.CORBA.portable.ObjectImpl._is_a(ObjectImpl.java:76)
at org.omg.CosNaming.NamingContextExtHelper.narrow(NamingContextExtHelper.java:46)
at Push.<init>(Push.java:35)
at Push.main(Push.java:21)
</CODE>
xxxxx is the hostname to which I am supposed to connect. But, the problem is I have changed xxxxx to IP address in all places, but still when I run the program, it complains of xxxxx not being able to be reached. I don't understand from where it picks up this xxxxx. Could someone tell me if I have missed any of the environment settings?
Thanks,
Aparna
17 years ago
Can any of you illustrate with an example the concept of Persistence related to I/O and Streams?
Thanks,
Aparna
17 years ago
Can any of you please tell me what's the difference between SCWCD and SCJD? Aren't they the same? If different, in what way? I am an SCJP with 96%. Which of the above two should one pursue after SCJP?
Thanks & Regds,
Aparna
Hi All,
Can you please tell me if there is a recognised Certification for Unix/Linux? I know Brainbench does this, but now, I guess, it is not free. Could any of you tell me of any recognised certification for linux/unix(a free one)?
Thanks & Regds,
Aparna
18 years ago
Hi!
Can any of you please tell me how to download applets from sites? I require this to download some mock exams and do the test offline, and presently, I am not able to download these applets. Your valuable help in this regard would be greatly appreciated.
Thanks in advance,
Aparna
Hi Kamakshi,
I guess the answer you gave is also incorrect:
1. Which statements are true about GridbagLayout?
1. Weightx and weighty should be 0 and 1.0
WRONG. Weightx and weighty can be any valid double value
2. If fill is both anchor does not make sense
CORRECT
3. It divides its territory into array of cells
CORRECT
4. While constructing GridBagLayout, you wont tell how many rows and columns the underlying grid has.
CORRECT. The question asked is "While constructing GridBagLayout", which means, in the constructor, you don't specify the number of rows and columns. Hence 4th option is CORRECT.
Any other opinions?
Thanks,
Aparna
18 years ago
Hi,
I guess the answer is correct. You can use the adapter classes with enableEvents. It is true that you cannot subclass Adapter class when you use enableEvents since Java doesn't support multiple inheritance. But you can do it the following way.
<code><pre>
import java.awt.*;
import java.awt.event.*;
class demoAdapter extends Frame
{
demoAdapter()
{
myButton btn=new myButton("Click Me!");
add(btn);
}
public static void main(String args[])
{
demoAdapter frameobj=new demoAdapter();
frameobj.setSize(50,50);
frameobj.setVisible(true);
}

class myButton extends Button
{
public myButton(String label)
{
super(label);
enableEvents(AWTEvent.KEY_EVENT_MASK);
addKeyListener(new KeyAdapter()
{
public void keyTyped(KeyEvent e)
{
System.out.println("Listener Invoked");
}
});
}
public void processKeyEvent(KeyEvent e)
{
System.out.println("processKeyEvent for myButton called");
super.processKeyEvent(e);
}
}
}
</pre></code>
In the above case, you can use an adapter class for the listener object and this is a case wherein you can use both enableEvents and Adapter class together.
Hope it answers your query.
Regds,
Aparna
Hi Sam,
StringBuffer does not have any equals() method for itself. It inherits this method from that of java.lang.Object. The following is an extract taken from javadoc api specification:
The equals method for class Object implements the most discriminating possible equivalence relation on objects; that is, for any reference values x and y, this method returns true if and only if x and y refer to the same object (x==y has the value true).
So, sb1.equals(sb2) will return true only if both these point to the same object. Hence, when their references are the same, you will have the value "true" returned.
Hope this solves your problem.
Regds,
Aparna
Hi Randall,
Mebbe I'll have to be more clear.
Take Michael's code wherein he's specified
method(int) in superclass
and
method(double) in the subclass.
When he creates an object of the subclass and calls the method(i) this matches most exactly with that of the superclass constructor
method(int) [So by rule 3, it has to call the superclass constructor with int parameter]
but then, by rule 2, a subclass constructor has to be given more preference if the argument is able to be converted to one of the formal parameter types of the subclass. Now, since an int can be converted to a double, it can call the subclass constructor with double parameter, but the problem is that it is NOT AN EXACT MATCH. Hence, an ambiguity arises.
But, consider the examples I have provided in my previous post. In both of them, the rules 2 and 3 are taken care of, the subclass constructors themselves are more exact as far as the actual arguments are concerned. Hence, these examples would compile/execute fine.
Hope I am clear now.
Thanks,
Aparna
Hi Randall,
Yeah, I know that super(), super(some args), this(), this(some args) are all mutually exclusive. But my requirement is not uncommon. What should I do when I need to call both from the same constructor? Consider the code I have posted in my question. Such a requirement can commonly arise. How can I take care of such a situation?
Thanks,
Aparna
Hi Randall,
Thanks for ur reply. But then, such a thing is not discussed even in JLS, where else to look for answers? Everywhere, the examples comfortably declare an object inside the method itself. There has been no example/ no mention of how that object can be accessed outside. Any help from anyone would be well appreciated.
Thanks,
Aparna
Hi Michael,
A very good and interesting question, indeed. It's a subtle point. These are the rules you need to look upon:
1. A class can have two methods with the same name, but with different set of arguments/arg types[overloaded methods] in any of the following 3 cases:
a. both methods are in the same subclass
b. both methods are in the super class
c. one is in superclass and one in subclass
2. If there are two methods with the same name, one in the superclass and one in the subclass, then, the method in the subclass should be given more preference.
3. If there are two methods available with the same name in a class, the method that is called is the method which has arguments that most exactly matches with the set of arguments passed upon.
Now, let us look at your example:
In your main, you call the subclass method with int argument. Now, since by Rule (2), the subclass method with double argument should be given more preference.
But, by Rule (3), the superclass method which takes int argument itself should be given more preference.
Hence, it is now not able to decide between Rules 2 and 3. Hence it results in a compilation error complaining of ambiguity.
Now, consider the following code:
<CODE>
class one
{
void method(float e)
{
System.out.println("one - float");
}
}
class two extends one
{
void method(int e)
{
System.out.println("two - int");
}
void method(String s)
{
System.out.println("two - string");
}
public static void main(String []a)
{
int i=5;
two r=new two();
r.method("hi");
r.method(i);
}
}
</CODE>
In the above case, you call subclass method with int as argument. Here none of the rules clash with each other. Hence, the subclass method with int argument is called.
Similarly, consider the following code:
<CODE>
class one
{
void method(int e)
{
System.out.println("one - int");
}
}
class two extends one
{
void method(int e)
{
System.out.println("two - int");
}
void method(String s)
{
System.out.println("two - string");
}
public static void main(String []a)
{
int i=5;
two r=new two();
r.method("hi");
r.method(i);
}
}
</CODE>
Here, too, there is no ambiguity as none of the 3 rules clash with one another, hence, it doesn't give a compilation error.
Hope I am clear. A good question, indeed!
Thanks,
Aparna
Hi,
We know that either the "super" or "this" statement should be the first statement in a constructor. What should be done in case I want to invoke both of these from the same constructor?
For eg., consider the following code
<CODE>
class superclass
{
superclass()
{
System.out.println("In superclass() constructor");
}
superclass(int i)
{
System.out.println("In superclass(int) constructor");
}
superclass(String s)
{
System.out.println("In superclass(String) constructor");
}
}
class subclass extends superclass
{
subclass()
{
System.out.println("In subclass() constructor");
}
subclass(int i)
{
super(i);//problem here
this(""+i);//and problem here too!
System.out.println("In subclass(int) constructor");
}
subclass(String s)
{
super(s);
System.out.println("In subclass(String) constructor");
}
}
class superthis
{
public static void main(String args[])
{
subclass obj=new subclass(30);
}
}
</CODE>
When I create an object of the subclass with an int parameter, there occur problems in the lines mentioned in the code. Both "super" and "this" compete for being the first line of the constructor and hence a compiler error results. Is there any way I can take care of this case?
Thanks,
Aparna

Hi,
If I declare and define a class inside a method, I can access only the final local variables of the method, isn't it? The reason given in RHE for this is that the object of the class declared inside method should be able to outlive the method and this is possible only if variables that can be accessed from the method are final. But then, I am not able to create/access an object of the class declared inside the method outside the method at all!!! Then, what's the big deal in allowing only final variables of the method to be able to be accessed??? Or is there any way that I can create/access an object of the class declared inside a method outside the method??
Thanks,
Aparna
Hi,
whatever may be the case with HTML or UBB, here is my explanation. I am not posting the code for the fear of it not appearing properly and my reply going waste.
Shift Operators don't do an automatic type promotion, instead they depend on unary promotion of the left hand argument of the shift operator.
If the left hand operand of the shift operator is int, then it does a %32 of the right hand operand and does the shift, if the left hand operand is long, then it does a %64 of the right hand operand and does the shift. Hence in your code,
i left shifted by 99 would give 8 as the result, since
i is the left hand operand of this shift and its type is int. Hence, 99%32=3 would be done and 1 left shifted by 3 is nothing but 8.
Hope it is clear.
Regds,
Aparna