rehan hamid

Greenhorn
+ Follow
since Feb 13, 2001
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 rehan hamid

I am new to JSP and need some help regarding selecting a value from Drop down list. Based on the selection I want to display some information on the page but dont want to refresh the page either. What could be the alternates I can do and which one is the best and why? If any one of you can help, thats appreciated.
Thanks in advance.
Rehan.
SCJP
19 years ago
any examples??? not clear yet.
20 years ago
class Base{}
class sub extends Base{}
class sub1 extends Base{}
public class cex
{
public static void main(String args[])
{
Base b = new Base();
sub s = (sub) b;
}
}

Why?? Runtime cast exception at "sub s = (sub)b"?
To my understanding b has been assigning to a subclass s with proper casting.
Rehan.
20 years ago

Originally posted by ryan burgdorfer:
I beleive a double can be assigned to a float or an int...it just loses precision. In the int case, anything after the decimal point is dropped, so it ends up benig 0. And in the float case, there is a chance of losing precision in larger numbers, but in this case it keeps the same value.
Correct me if I am wrong...


I dont think that you can assign more broden data types to less broden data types unless type casted.
Which of the following are legal statements?
1) float f=1/3;
2) int i=1/3;
3) float f=1.01;
4) double d=999d;
----------------------
I could not understand y opt) 1,2 are also correct in addition to option 4.
What I understand is / operator has more precedence then assigment so first 1/3 should be evaluated. Then it will become "0.33" that should be treeted as double by default. And double value can not be assigned to float or int. So only option 4 should be correct...
Any explanation???
Rehan
public class Inc{
public static void main(String argv[]){
Inc inc = new Inc();
int i =0;
inc.fermin(i);
System.out.println(
i = i++;
System.out.println(i);
}
void fermin(int i){
i++;
}
}
Can any body tell me how output is 0. I think after execution of (i = i++) i must be 1.
Rehan.
In addition, If you remvoe setLayout(new BorderLayout()) code line, you should be able to see last added component (button having caption center). Remember this is cover all your form. and all other button would be beneath this, those you wont be able to see without specifying position to add. Hope this will help.
Gagan,
Below is some test code for you, I have written an actionListener for capturing your exit click and then kick off the application. I know there is a better way to pull out of application but can not implement. Hope this will help.
//code start
import java.awt.AWTEvent.*;
import java.awt.*;
import java.awt.event.*;

public class exit implements ActionListener
{
public Frame f;
public void actionPerformed(ActionEvent ae)
{
System.out.println("Action performed.");
}
public exit()
{
f = new Frame();
MenuBar mb = new MenuBar();
Menu m = new Menu("Test");
m.add("Exit");
mb.add(m);
f.setMenuBar(mb);
f.setSize(200, 300);
f.setVisible(true);

m.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent ae)
{
System.exit(0);
}
}
);
}
public static void main (String args[])
{
exit e = new exit();

}
}
// code End
20 years ago
Cindy ia correct, I just want add a note into it.
You should assign null to objects that are no longer in use. Otherwise if you allow live, accessable reference to un-needed objects, this will not allow garbage collector to collect those references. Therefore it is always a good idea to explicity assign null to those references. This avoids memory leaks.
20 years ago
In general, Reference is an address to some object/variable, While getting or setting value for that variable you need to de-reference that (means you need to get to that location where it is actually laying in the memory).
Dereference is a common operation done by C++ programers.
Hope this will clear Dereferencing.
20 years ago
In addition to all, think about main(String argv[]), you can see, main exhibits variable arguments in-take from command line. This has been implemented by Arrays that is one of the best solution for this problem.
This was just to share my thoughts as solution has been unveiled by many here
20 years ago
In addition to Peter's answer, you should always assign null to object refernces that you dont need any more. Otherwise you are allowing memory leaks by not letting these locaitons eligible for garbage collection.
20 years ago
Thanks Joe, You are creating a String var into string pool when creating string variable jeo2. I wud like to hear an answer that explains why option 2 is also correct with ref. to my question.
There its not a string var rather a "static"(not java static) text.
Rehan.
20 years ago