Tag Archives: function

TimerTask vs Thread.sleep vs Handler postDelayed – most accurate to call function every N milliseconds?

Questions: What is the most accurate way to call a function every N milliseconds? Thread with Thread.sleep TimerTask Handler with postDelayed I modified this example using Thread.sleep and it’s not very accurate. I’m developing a music app that will play sounds at a given BPM. I understand it’s impossible to create an entirely accurate metronome… Read More »

Application vulnerability due to Non Random Hash Functions

Questions: Below excerpt is from an article that explains possibility of Denial Of Service(DoS) attack because of non random hash functions used in Hash Data Structures. […] the condition can be leveraged by exploiting predictable collisions in the underlying hashing algorithms. In order to verify it I went through reference implementation of Java HashMap from… Read More »

Are there inline functions in java?

Questions: Is there a concept of inline functions in java, or its replaced something else? If there is, how is it used? I’ve heard that public, static and final methods are the inline functions. Can we create our own inline function? Answers: In Java, the optimizations are usually done at the JVM level. At runtime,… Read More »

PHP Function with Optional Parameters

Questions: I’ve written a PHP function that can accepts 10 parameters, but only 2 are required. Sometimes, I want to define the eighth parameter, but I don’t want to type in empty strings for each of the parameters until I reach the eighth. One idea I had was to pass an abstracted function with an… Read More »

Use keyword in functions – PHP [duplicate]

Questions: Possible Duplicate: In Php 5.3.0 what is the Function “Use” Identifier ? Should a sane programmer use it? I’ve been examining the Closures in PHP and this is what took my attention: public function getTotal($tax) { $total = 0.00; $callback = function ($quantity, $product) use ($tax, &$total) { $pricePerItem = constant(__CLASS__ . “::PRICE_” .… Read More »