A Agr

Ranch Hand
+ Follow
since Feb 10, 2009
Merit badge: grant badges
For More
Cows and Likes
Total received
In last 30 days
Total given
Total received
Received in last 30 days
Total given
Given in last 30 days
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by A Agr

I have 4 ServerSockets running at say port 1,2 ,3 4

A ServerSocket at port 1 listens for incoming connection from different clients and read from and write to clients. A socket connection can be created at any ServerSocket to write at other ServerSocket

Main class x creates serversocket and passes it to thread and waits for client connection and if got any , processes it. Along with this at same while(true){}loop next to it in class x also executes.Both should work simultaneously

When I run it, I get some problems

1. After a while I get Connection refused exception/// like it works for say 1 min and starts throwing exception
2. while true() loop is also continously writing to ServerSocket at say port 2. Output at port 2 becomes..print java..print java..
but i want it work like print jsp print java print jsp print java
14 years ago
I tried but didnt work .

My objective is to,

Store hexadecimal nos in either String[] or String or int[].
for ex : String[] s = {"0x09","0x800"}
or int[] i ={0x09,0x800};

Now I want to convert it to byte array to write to an OutputStream. If I do String.getBytes() ,it encodes.
But what I want is my InputStream to read the byte array I send as

byte array containing 090800

How can I do the conversion ? Also in java it is signed byte whose upper limit is 127 so how can I deal with hexadecimal nos greater than 127 ?
But it suppresses 0 . How can I get output of 0x01 as 0001 and want a byte array rather than String.
How to convert a hex representation ?

Suppose There are some values ,

a= 0x40

How can I convert it into 04080006 representation which should be a byte array ?
Does anyone know good tutorial on ch-10 of K&B ?
Its working now. Seems like it wasnt working when I added it in Classpath variable but it worked on adding in Path variable.

K&B book says ,

javac -help

as valid command.

But when I tried running it in command prompt ,it says "its not recognized as internal/external command....."

But java -help works and gives list of all valid options available.
Thanks Ruben,I got it.

I have a quick question here that will the following 2 method calls be same ?


When I tried to call method as it printed "Var args method" as output . But why didn't it give compiler error as in printUs method takes 2 arguments and i am calling method with just 1 argument.
Here I have 2 Questions :

1. Why does it print 12 and not 22 ?

2. When I try running code by replacing Integer by say Short

It gives compiler error as Short(int) is undefined .Short has 2 constructors ,one that takes short and other that takes string . But why is it giving error with value '1' wherein 1 is permissible value for short.

If Integer overrides hashcode and equals method,then there is still possible for 2 objects to have same hashcode and different values.So output as 12 is still not clear ?

It prints 12. How does it work ?

When I tried to put other wrapper class in place of Integer like Short or Byte ,it does not compile .Why ?
hey I got it. I know conversions and shift operator too..

what wrong I was doing is ,I was converting hexadecimal to decimal rather than converting it directly to binaryb...