Most answers for [java] and [jvm]

Architect for Chronicle Software http://chronicle.software

Blog has had 3 million hits http://vanillajava.blogspot.com

Java Champion

16h
comment Easy way to keeping angles between -179 and 180 degrees
@letsdev-cwack -90 is what I would expect to get. What would you expect and why?
16h
comment Receiving wrong data on client side in socket communication
@effenok I assume the 4 bytes should be an int in binary.
16h
comment Does 'Encapsulation' help develop multiple modules parallely?
Correct. I am trying to think of an example of abstraction which breaks encapsulation. ... you could argue this is partially true of Map.putIfAbsent() as the Java doc for the interface includes the implementation.
1d
awarded Guru
2d
comment Saving two ints into one
Or (second_num << 8) | first_num
2d
comment Saving two ints into one
You have just given an example of " how can [you] save two ints into that one int " so what is your doubt? Is it that you have these instructions but you don't understand them?
2d
comment Does 'Encapsulation' help develop multiple modules parallely?
Using collections as an example, ArrayList.ensureCapacity(n) encapsulates the implementation of this method, you don't need to know how it is implemented, but it doesn't override a method in an interfaces, i.e. there is no abstraction involved.
2d
comment Does 'Encapsulation' help develop multiple modules parallely?
Encapsulation is hiding implementation details. Abstraction is defining common behaviour for multiple implementations. They are related but encapsulation doesn't require abstraction. e.g. class A { private int _x; public long getX() { return _x; } } I have used encapsulation as you can't see how I actually implemented getX but there is no abstraction.
2d
comment Does 'Encapsulation' help develop multiple modules parallely?
The key feature for encapsulation is shared contract designed to hide implementation details. Abstraction makes this easier but is not required.
2d
comment Receiving wrong data on client side in socket communication
The problem is I would do things completely differently. Having a look at your test, it appears to be a bandwidth measure. This is traditionally done by the client, not the server as it is bandwidth/delay the client sees which matters. Testing on the server alone is likely to give you an optimistic value. Also I would adjust the size of the transfer based on the bandwidth, Try a small message first and exponentially increase the size to improve the result. This is because you have no way to know if 1 MB is far too large or too small as you haven't measured the speed of the connection
2d
comment Does 'Encapsulation' help develop multiple modules parallely?
"interface" is the contract between components. Each side only has to work to the contract without needing to know about the details of the implementation, thus the developers can work in parallel as they don't need to know about each others, possibly incomplete implementations.
2d
comment Receiving wrong data on client side in socket communication
You appear to be writing more than one byte but you are only reading one byte. I suggest you read all the bytes sent. I also suggest you send the data as text as this much easier to check the protocol is correct. BTW (byte) 4282279 == 167 so I suspect it is reading the first correctly and the rest of the number you need just needs a bit more reading.
2d
answered Using Singleton in Constructor
2d
comment making a map in java in which third key value will be changed in every iteration
You need with a class instance which has a field which is a Set<String> or you need a List of you class instance. I don't see how using a Map is needed here.
2d
comment Java set private value out of class
I assume exit_timeout is a typo?
2d
comment making a map in java in which third key value will be changed in every iteration
I assume you know what a class is as it a basic principle of object orientated programming. I would have one field per key you have now, make then all final and set them in your constructor. You can use your IDE to generate most of the code.
2d
comment How to put a String to a byte array in Java without conversion
@SaHa Technically, the device has no idea what the 8-bit meant to you when you wrote them. It could be signed, unsigned, text characters, originally decimal, hexidecimal, binary. This information is recorded anywhere. The device just assumes the values are in the form it needs.
2d
comment Why does "big = big.add(..)" need to be used to sum BigIntegers?
@Charan To add an element to an ArrayList of one million elements could be as simple as a reference assignment and a counter increment. To copy and add, you have to copy all the references, all million of them just to add one. BTW CopyOnWriteArrayList does this and is very slow for modifying a large collection.
2d
comment making a map in java in which third key value will be changed in every iteration
What you should do instead exactly depends on what you are trying to do. When developers use a Map like this it almost certainly is an example of object denial. I.e. you should be using a class instead.
Aug
1
answered Why does "big = big.add(..)" need to be used to sum BigIntegers?
1 2 3 4 5