SathishVJ

Greenhorn
+ Follow
since Sep 07, 2000
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
In last 30 days
0
Forums and Threads

Recent posts by SathishVJ

Hi Sean,
Thanks for the attempt but I think there is a problem there. The slider can be moved without using a mouse, i.e. with the keyboard. Handling all those events is quite a convoluted method to achieve the result.
I tried out the following code - this time using a JScrollBar which supports a AdjustmentListener.
import javax.swing.*;
import javax.swing.event.*;
import java.awt.*;
import java.awt.event.*;
public class TestScroll extends JFrame {

public TestScroll(){
Container cp = getContentPane();
JScrollBar sb = new JScrollBar();
cp.add(sb, BorderLayout.EAST);
sb.addAdjustmentListener(new AdjustmentListener(){
public void adjustmentValueChanged(AdjustmentEvent e){
JScrollBar jsb = (JScrollBar) e.getAdjustable();
if (!jsb.getValueIsAdjusting())
System.out.println("Value: "+ jsb.getValue());
else System.out.println("Still moving");
}
});
}

public static void main(String args[]){
TestScroll t = new TestScroll();
t.pack();
t.show();
}
}

It works just the way I want it. But it works with the wrong component. Pls see if you can get a similar functionality for me with the JSlider.
Regds
Sathish
24 years ago
Hi,
What should I do to force the JSlider component to fire a ChangeEvent only when the component's knob has come to rest. i.e. I do not want it to fire a slew of events while the knob of the slider is being dragged.
There are functions setValueIsAdjusting and getValueIsAdjusting(boolean) that allows us to do this. However I need help on its usage or any other method.
Thanks in advance
Sathish
24 years ago
Hi pam,
The java.io. classes ending in Stream are for reading/writing bytes while those ending in Reader/Writer are for working with characters. Use them judiciously to get your stuff working.
Yet I don't think that is your exact problem. Anyways try it out.
Regds
Sathish
24 years ago
Hi,
I am looking for a class that will provide me simple mathematical expression evaluation. Do any of you have any idea whether any of the standard java classes support this or any other class elsewhere on the web/
Regds
Sathish
24 years ago
Sorry to be posting a reply to my own question. But I found this answer to the question at a different site. I guess somebody could corroborate this or give me another answer.
{
There is no easy way to tell since ASCII characters are binary. Depending upon how you read the file determines how you treat the data. For instance, the text "CAFE" if read as an int is the value 1128351301. Since Java also deals with Unicode and not just ASCII, you get to worry about 8-bit vs. 16-bit characters, too.
}
Thanks
Sathish
24 years ago
Hi all,
Is it possible for me to know whether a file is an ascii file or a binary file using any Java method.
My intention is to display the contents of the file if the file is a text file (whether it is .txt, .java, .html etc) and not do anything if it is a binary file (.bmp, .gif, .class, .doc etc.)
Thank you
Sathish
24 years ago
Hi,
I don't know exactly why it works the way it does. Anyways, try out this piece of code. Apparently the JVM is approximating the the long to fit it into the float. The normal representation of floats and doubles being sign*mantissa*2^exponent, it allows the JVM to approximate (incorrectly) the long value into a certain number in the exponent.
So point is conversion is possible but is erroneous on large values.
public class test {
public static void main(String args[]){
long l = 123455432123456789l;
float f = 3.2f;
f = l;
System.out.println(f); //prints 1.23455433E17 or something similar
l = (long)f;
System.out.println(l); //prints 123455433309421568 or something similar
}
}
Hope I was able to help.
Regds
Sathish
I'm not very sure abt this but aren't 1, 2 and 4 right?
1 is definitely right.
4 also is right.
Isn't 2 also right? When the component is loaded the no. of rows and columns are decided by the gridwidth and gridheight variables in the GridBagConstraints instance.
Quoted from TIJ


A simple but slow GC technique is reference counting. This means that each object contains a reference counter, and every time a reference is attached to an object the reference count is increased. Every time a reference goes out of scope or is set to null, the reference count is decreased. ... The garbage collector moves through the entire list of objects and when it finds one with a reference count of zero it releases that storage. ... Reference counting is commonly used to explain one kind of garbage collection but it doesn't seem to be used in any JVM implementations.


The answer hence, I believe, is the line of code:
e=null;

When :
Employee e = new Employee("Bob", 48);
is executed, the object is created and the reference count for it is increased to 1. When :
e = null;
is executed the ref count for the object Employee is decreased by 1 and thus becomes 0. This causes it to be made available for gc.
Regds
Sathish
Hi Sheri,
Ans 4 is correct. Note the question. The question does not ask you which are 'legally overloading' methods. It simply asks you which methods are legal at that point in code. Hence like
public void foo(int i, String s)
would be legal at that point,
even public void Amethod(int i, String s) is also legal.
Ans 3 is incorrect. This is because Java requires that the signatures of method be different. And a method signature includes the name of the method, and the order and data type of the parameters; which means that 1) parameter names are insignificant (2) return types are insignificant. Hence Ans 3 is incorrect.
I hope I have been able to help you.
Regds
Sathish
The Java VM expects the function with signature
public static void main(String args[])
to be necessarily present when running an application. The VM calls this particular method to run your program.
When you compile your code, the VM has no idea that you are going to run the application using this class. So it compiles assuming that the method
public static void main(){...}
is simply another method like
public static void someMethod(){ ... }
But then you hit an exception when you attempt to run it coz the method required to start it is not present.
That's a long ans.
Regds
Sathish
Hi Shallender,
I had seen a similar qn at another place and they had warned me to be careful abt it; allow me to pass on the piece of advice to you.
As you might already know, the finally block is always executed whether an exception was raised or not. The only situation when the finally block is not executed is when the VM stops within a try or catch block. i.e. unless u do a System.exit() within a try or a catch block, the finally block is definitely executed.
Even though there is a return statement within the try block, the finally block is executed. Once (say) 'return someValue;' is executed, 'someValue' is returned to the calling statement only after the finally block is executed. Or as in your case the method simply returns after printing out "We love Java" of the finally block. And hence the answer that u get.
I hope I've been able to help.
Regds
Sathish
Hi rainbow,
It's is a 32 bit world these days.
Integral types and ranges:
For byte, from -128 to 127, inclusive
For short, from -32768 to 32767, inclusive
For int, from -2147483648 to 2147483647, inclusive
For long, from -9223372036854775808 to 9223372036854775807, inclusive
For char, from '\u0000' to '\uffff' inclusive, that is, from 0 to 65535
Regds
Sathish
Hi Shilpa,
You cannot assign the static modifier and access permissions like private, protected, public etc. to variables within a local method. These are applicable only to class variables.
If you want to print h which is defined within the static method main(), you need not declare h as static. A simple 'int h =0;' will do.
Regds
Sathish
Hi Aman,
If we take the code you have given verbatim, then none of the answers are right. Assuming the value of size is 20 then ans e is indeed right.
The J Lang Specs says


Sec: 10.3 Array Creation
An array initializer creates an array and provides initial values for all its components.


(even if they are local variables).
I don't know if what I am assuming henceforth is right, but I guess that the values the array elements are initialized with will be the values they will be assigned in case they were class variables.
i.e. null for all derivatives of Object, false for boolean and 0 for the numeric types.
Regards
Sathish