Chandra Sekar's Blog

Java's CompletableFuture and Threads

19 May, 2017 · 2 min read · #java #multithreading

Quiz time. How many threads (other than main) will this program create on a dual-core machine?

public class App {
    public static void main(String[] args) {
        for (int i = 0; i < 10; i++) {
            CompletableFuture.runAsync(() -> {

 Read more

Timing Equity MFs with PE

08 May, 2017 · 4 min read · #equity #timing #mutual-fund #pe

The rule of thumb for equity investments is to not time the market, but there are also several analyses correlating investing at high index PE levels with lower returns. So can we use the PE levels of indices to generate better returns than SIP and reduce volatility of the portfolio?

 Read more

Arena Allocation in Go

07 Jul, 2014 · 2 min read · #golang #allocation #arena

One of the weaknesses of Go’s runtime today is the relatively naive GC implementation. This is evident from go performing consistently worse than most other languages in the binary trees benchmark. However, the language can make designing programs that reduce GC cost fairly straightforward.

 Read more

Go Does Delegates Beautifully!

06 Apr, 2012 · 2 min read · #golang #ruby #delegates #java

When working with object-oriented languages, there are many instances when one would want to implement an interface re-using code from another implementation of the interface. While inheritance will work, it couples the new implementation to the specific other implementation. Composition with delegation will be a better way of doing this.

 Read more

How Git Outshines Subversion at Merging

22 Jan, 2010 · 3 min read · #git #svn

I’ve recently started getting my head around Git having been a Subversion (sadly even CVS) user all along. While I liked the fact that it was distributed and way faster than Subversion at most operations, I couldn’t understand why many claimed it was better at merging than Subversion (1.5 and above). Even the “Branch Handling” section in Git’s wiki talks only about better history tracking but not about how Git is better at merging the content themselves.

 Read more

Simple Layouts with JSP in Spring MVC

13 Dec, 2009 · 2 min read · #java #spring

Every web application has elements common to all its pages which are good candidates for re-use. While Spring MVC provides integration with Tiles, it can be an overkill for simple applications and needs using Spring’s client side JS library for AJAX (correct me if I’m wrong).

 Read more

Mocking Math.random() Using PowerMock

01 Nov, 2009 · 3 min read · #java #testing

Let’s consider the below Game class in a guessing game where a random target is chosen by the system and the user guesses the target. The system returns an appropriate message based on whether the guess was higher, lower or equal to the random target.

 Read more

ScriptEngineBuilder for Java

28 Aug, 2009 · 2 min read · #java #javascript

Java 6 allows you to execute and communicate with scripts written in any scripting language, using the Scripting API. However, the code needed to create a ScriptEngine and evaluate a set of script files within it, is quite verbose and throws several checked exceptions.

 Read more

Keyboard Shortcuts in JSF Using AJAX4JSF

06 Oct, 2008 · 2 min read · #java #jsf

AJAX4JSF is library of JSF components which can be used to easily add AJAX capabilities to JSF web applications. AJAX4JSF is available as part of the Richfaces component library.

 Read more

Python's String Translations for Java

14 Sep, 2008 · 2 min read · #java #python

Just as I started poking my nose into Python, I came across two really interesting functions in its string module.

 Read more

← Newer Posts   Older Posts →