Vlado Zajac

Ranch Hand
+ Follow
since Aug 03, 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
3
Received in last 30 days
0
Total given
2
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Vlado Zajac

If the program terminates between "super intfinalize" and "superfinalize" you get only 2 lines of output

Finalization runs in daemon thread so ongoing finalization does not prevent termination of JVM.
Unnecessary synchronization slows that down.
In each task (which needs to be RecursiveTask not RecursiveAction) compute sum from start to end to local variable (using values from join()ed sub-tasks) and return that as result of the task. Set the last element only at the very end (using result of main task).

But since simple sum of an array is more limited by memory speed than computing power, parallel algorithm won't be faster than simple loop.

If new objects are being allocated, JVM will eventually run GC even if there are no objects eligible for GC (only way to determine if there are such objects is to run the garbage collector).

Also your code calls methods which may create extra objects and then throw them away.

1. When the ArrayList exceeds its capacity, it has to create new bigger array and copy items from old to new array. The old array then becomes eligible for GC.
2. Println may create temporary objects.


12 years ago
By definition compile-time constant expression can be only String or primitive type.
The reason for using char[] is that you can fill it with zeroes after use.
Check the javadoc for JPasswordField.

It can't be done with String because Strings are immutable.
12 years ago
parseChunks2 is incorrect.
I have made a test program which seems to work after I changed the method to:



It is still not 100% ok. It should use the lengths from chunk headers to determine where each chunk ends. Searching for CR LF is not reliable since the (unchunked) content may also contain CR LF.


12 years ago
It works same way as reading/writing from/to files using byte arrays. This method uses byte as unsigned.

112.217.200.12 will be this array:

2 middle elements will be negative but that is OK.

Or can use InetAddress.getByName which accepts IP address, too:
13 years ago

David Byron wrote:In that case, the unreachable statement must be that infinitely small gap between the closing paren and the semicolon! ;)


It is actually the semicolon.

In Java semicolon is part of preceding statement. Empty statement is just a semicolon.
The empty block is the unreachable statement.
The i++ is not a statement, the empty block is a statement.

Try this code and see which line will the compiler mark as error
There is no reason for Pattern.compile method to hang.

You wrote that it runs in a loop. Isn't the loop infinite?

You can use [.:] as separator (without the need for findSeparator):


The code does not compile, join() may throw InterruptedException which is not caught.

VuTuan Tran wrote:
Question 3 :what t1.join() does ?


t1.join() waits for t1 to complete.
13 years ago
If 6 can be turned upside down and used as 9 it is 43. (otherwise 32)
13 years ago
Byte order is only meaningful when working with data types larger than 1 byte. Setting byte order doesn't change the order of bytes inside ByteBuffer, it changes only conversion to and from longer data types.

Try this code:
13 years ago

Istvan Kovacs wrote:
You cannot extend an array class, which made me suspect that they are final. Upon examining their modifiers (see lines 25-27 of the original puzzle code where superIsFinalAbstractClass is calculated), I found they were also abstract, which just made for a confusing-enough puzzle to post here.



They may not be abstract in other JREs. According to getModifiers() API documentations, it is not defined if array classes have abstract modifier or not.
13 years ago