Mack Stevens

Greenhorn
+ Follow
since Aug 31, 2007
Merit badge: grant badges
For More
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 Mack Stevens

Hi............................
Try this interesting code,it will add to your knowledge.
code:
class FloatExample
{
public static void main(String ar[])
{
System.out.println(2.0/0);
}
}
HI.........................

First of all make it clear that we can call a run() method explicitly.
But sun microsystem programmers have written a lots of code in start() method in native languauges for allocation of memory and for certain other important criteria.So they suggest using start() method for invoking a thread.If we are using run() method for invoking thread there might occur some problem with your code in the operating syatem environment.
Hi.................
No you cant declare main as abstract
Solution:
Provide two classes for your application,one(having main method)extending Frame and other class extending WindowAdapter,because you cant extend two classes.
HI
When you are implementing WindowListener in your code you need to override all the abstract methods of WindowListener ,else you need to declare your class as abstract.
Alternative solution is to use extend WindowAdapter class which provides empty declarations for the abstract methods in WindowListener.
HI.................
For setting environmental path do the following
1)Go to the Bin folder of Java installation folder
2)Copy it in the environmental variables and add something like..

C:\Program Files\Java\jdk1.6.0_02\bin;%path%;.

And then your JDK tools will run anywhere.
There will be no need of explicit classpath setting.

For setting classpath use:

set classpath=path
where path can be:
"." if your source code is in current location
else mention the path
Hi...............................
Try this:
class Sample
{
void test() throws Exception
{}
}

class SampleTest extends Sample
{
void test() throws Exception
{}
public static void main(String ar[])
{
Sample s=new Sample();
s.test(); //Exception
Sample t=new SampleTest();
t.test();//Exception
}
}


The above code follows as what I said.
..................................................
Regards,
Mack
HI........
The functionality of "==" operator and equals() method is different.

1)."==":returns true if both the references are pointing to the same object.
2).equals():returns true if both the references point to objects that are equal in their context(Value).

So in your question trim() method is creating another object and is being applied to "==" operator which will return false.

when you apply equals() method it will return true.

So follows the output.
..............................................................
Regards,
Mack

Originally posted by Tony Smith:
Seems like it's smart enough to autobox and add it to the set, however it is not smart enough to autobox and remove from the set if you don't specify it's (short). I tried ss.remove((short)0); and that seems to do the job. Is that more like a security feature or?



..............................................
Thanks for your work on it,what you said is true.
Good question.....
See there is no bug as you think in virtual method invocation technique.
When you are writing "a.eat()" in Dog2 class ,it refers to Animal class at Compiletime and Dog2 class at runtime.So your code is generating an exception(as it refers to Animals add() method at compiletime) in the main method and its is not thrown.You have handled the exception in Animal class,but here the exception is generated in main method.
SOLUTION:throw exception in main method

...........................................................................
Regards,
Mack.
Sorry to say that I dont know the exact answer, but i can clarify it to some extent.You are forgetting the concepts of Garbage Collection and also you are not noticing that return statement in your code is also returning a String object(i.e toString() method).so i think the answer is "2".

Regards,
Mack.
Remember friends,these concepts come under Collection Framework.In this we add objects to the collection, not primitive values.so that you can place heterogenous object in any collection.

Originally posted by dolly shah:


Here why add() method allows s++ entry two times?
I thought the answer is runtime error but answer is 3. I thought ss.remove(1) gives nullPointer exception, as ss.add(s++) 2nd time in add() method gives false.



HI.........
You are mistaken by the way add() and remove() methods works.
Its actually due to AutoBoxing feature.When we supply s++ as agument to add() method{i.e add(s++)},it will automatically create an object and add it to "set".

Now ,your code has got some remove() method.
remove() will remove an object from "set" if it exists and returns true.
If it doesnt exist ,it will return false and does nothing.

So in your code the remove() methods are ineffective,size of "set" remains "3".

Hope you got it.
Regards,
Mack.
See when you declare something as final,its value will be same throughout the class.So when you declare a local varaible as final,it is available throughout the class,so it is available to the inner class also.when it is not declared as final,its scope is till that method only,so it is not accessible in inner class.
The thing that is important is the object ,not the reference type.Even if you are creating sub-class object using super class referenc variable,the sub-class copy is called.

Originally posted by B Misra:
This may be a foolish question, but i am suddenly confused with the instance variables & overriding(rather hiding) them in subclasses of any class.....
while accessing hidden/overridden instance variables the accessed depends on the object's reference type only?