Anu Kalra

Greenhorn
+ Follow
since Dec 08, 2004
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 Anu Kalra

I would say Threads needs lots of practice.
Hi Gary,
The reason it won't compile is that the jvm looks for the method test(int) in the class, but does not get it (Since you dont have it!)
If you would like to call the constructor, you have to use 'this'.
Well, since you are only defining the local variable in 'Line1', everything is fine, the moment you try to use is...you will get a kick
I have a function, in which i copy a file from one drive to another drive. I have to copy 5 files. Now, the problem is that as soon as i run the applet, the files get copied, but the moment i minimise/maximise/change the size of the applet window, the function for copying the files again gets executed.
How can i avoid that.

Sample code is given below.

public class HelloApplet extends Applet
{
String s = null;

public void paint ( Graphics g )
{
g.setColor(Color.blue);
ShowMessage(g, s);

}
void ShowMessage(Graphics g, String s){
g.drawString(copy("http://.......","e:\\DataXML.xml"),0, size().height - 15);
g.drawString(copy("http://.......","e:\\toadfree.zip"),0, size().height - 35);
}
public String copy(String source_name, String dest_name)
{
.......
.......
.......
}



}
18 years ago
I have a function, in which i copy a file from one drive to another drive. I have to copy 5 files. Now, the problem is that as soon as i run the applet, the files get copied, but the moment i minimise/maximise/change the size of the applet window, the function for copying the files again gets executed.
How can i avoid that.
18 years ago
My question is that is it possible to run TOMCAT without JDK. I feel that during startup, TOMCAT looks for JAVA_HOME. Is there a way by which i can copy a few JAR file to Tomcat directory and run it.
I do not want to install JDK, but run TOMCAT.
I have WAR file ready, so i do not even require to compile my JSPs
Kindly suggest me.
18 years ago
Hello Amit,
Let me find an easy way to find a solution to your query.
size of byte = 8 bits
range of byte = -128 to 127
Since byte is a signed primitive, the MSB is the signed bit, which means that if the MSB is '1', then the number being represented is a negative number.
So, only 7 bits are required to represent the complete range of byte and MSB is used for indicating, if the number is positive or negative.
So far so good, now lets handle your question:

lets represent 128 in binary format : 10000000
As, i have explained earlier, that in byte if the MSB is '1', then it is a negative number.
now to represent 10000000 in decimal, we have to flip all the bits and add 1 to it (As it is a negative number) 01111111+1 = 10000000 = -128

Lets now solve your question:

Question 8
class Magenta {
static byte a = (byte)127, b = (byte)128, c = (byte)255, d = (byte)256;
public static void main(String args[]) {
System.out.print(a + " " + b + " " + c + " " + d);
}}

What is the result of attempting to compile and run the program?

a. Prints: 127 128 255 256
b. Prints: 127 128 255 0
c. Prints: 127 -1 -127 0
d. Prints: 127 -128 -1 0
e. Run-time error
f. Compile-time error
g. None of the above

a = byte(127) = 127, as this number is in range of byte.
b = byte(126) = -128, as explained above
c = byte(255) = 011111111 (byte representation). Now as byte can hold only 8 bits, we chop off the MSBs. So the resulting representation is 1111111. Now, since the MSB is '1', it is a negative number, so we flip all the bits and add 1 ==> 00000000 + 1 = 00000001. So, as it was a negative number, we get the answer as -1.
d = byte(256) = 100000000 (Byte representation).Now as byte can hold only 8 bits, we chop off the MSBs. So the resulting representation is 00000000. So, the answer is 0. Hence, the result is 0

Therefore 'd' is the correct answer.

I hope that new i am able to solve your query.

-Anu
Hi,
I passed my SUN CERTIFICATION last month on 29th December. I have moved from the address that i had provided for the delivery of the certificate.
The courier delivery person, hence returned back. I dont know what to do now!!!
Can anyone suggest me, how to now get the certificate, or give my new address.
19 years ago