String, text, numbers, I/O II part
serializable you ignore.
You have to provide a no argument constructor that reconstructs anything you aren t
going to serialize (for example, opening a new socket). Read about the
Externalizable interface for more details.
Frank LaRosa
Q: Is it possible to send Vector class in socket communication. If it is, what
function can make it.
Answer: Make sure the objects contained in the Vector are Serializable. Look at
java.io.ObjectOutputStream for serializing the Vector by wrapping the output stream
from socket with the ObjectOutputStream...
Q: How can you tell if an integer is odd or even?
I know an even number is divisible by 2 but I m thinking then how can I detect
if a resulting number after dividing 2 ints has a remainder?
Answer: Basically the method is simple, if a variable contains an odd number
I want to return the value zero , and on the other hand if the
variable contains an even number I want to return the value one .
Check out the % (modulus) operator, it computes the remainder.
public int modMethod(int div){
if(div%2==0){
return 1;
} else{
return 0;
}
}
Q: How can I round a number to specified precision?
I have a double field that I would like to round to 2 places of precision, however, it
seems like the documentation on the round function only rounds to
closest integers. So that I would not be able say .3658585859 = .37 as
I would like.
Answer: can you scale the number up and then down again when you are finished?
e.g. 0.3658585859 * 100 = 36.58585859
round(36.58585859) = 37
37 / 100 = 0.37
I understand that bitwise operations change the 0/1 bits of a number. Question is
why?
I suppose it s interesting that you can manipulate numbers this way, but I can t think
of a practical use for doing that.
Can anyone help me understand when are bitwise operations used and why you
would use them?
Answer: Bitwise manipulation is often used where memory consumption is critical,
and a piece of information may be encoded in less that one byte, for instance. In
communication software and protocols, information may be interpreted as a stream
of bits where the information is encoded at the bit level, and you use bitwise
file:///F|/a_jsite/350_tips/stings_text__date_numbers_io II.htm (5 of 7) [2001 07 08 11:25:00]
footer
Visionwebhosting.net Business web hosting division of Web
Design Plus. All rights reserved