Java Coding Standards

Traditionally Sun Java coding standards is followed ( http://www.oracle.com/technetwork/java/codeconventions-150003.pdf ). However the document hasn’t been updated since 1997. So these day most companies follow the Google Style guide which well-maintained and smaller in size: https://google.github.io/styleguide/javaguide.html

I recommend companies today follow the Google Style Guide as Coding Standard for Java based code.

IDE’s can be easily configured to format existing code in the adopted coding style, thereby making maintenance easier.

Verdict: Subfolder versus Subdomain SEO

Previously many Webmasters thought that subdirectories provide Search-Engine-Optimization benefits. However several renowned authorities disagreed lately. John Mueller, from Google Webmaster Central, categorically stated that Google is indifferent towards subdomains vs subfolders:

Subdomain is like an independent domain and can be even on a different server. So there is a slight benefit as down the road the website can be easily hosted on a different server than the Application. This improves security to some extent by compartmentalizing it. Secondly, Corporate Website performance is never affected by the performance of the Application(s). This is very important for new client acquisition as many people judge a book by its cover.

In case a penalty is imposed on the main domain, it may weaken the sub-domain though it may not directly carry to them. This relation is implied by Google.

Additionally the sub-domain may be independently penalized from the main domain including manual penalties. So there is a degree of independence which can be beneficial in the event the website runs foul of Google due to possibly aggressive marketing practices.

In conclusion, subdomain may be slightly better choice.

How to Easily Replace Slf4J with java.util.logging Framework

SLF4J is becoming complex by the day (Marker feature for instance) while JUL (java.util.logging) is becoming more powerful and better. It is easy to replace SLF4J from any existing codebase without having to change anything but internally it will use JUL. Let’s see how.

Create org/slf4j (org\slfj for windows users) directory under your source tree and place the following files:

Logger.java
// Licensed under Apache License version 2.0
package org.slf4j; // Mimicked slf4j package structure to avoid changing existing codebase or usage

import java.util.StringTokenizer;
import java.util.logging.Level;
import java.util.logging.Handler;
/** 
 * Replacement for slf4j Logger. Uses java.util.logging framework.
 */
public class Logger {
    private static java.util.logging.Logger logger;
    // DO NOT CHANGE
    public Logger(java.util.logging.Logger l) { logger = l; }
    
    // DO NOT CHANGE
    /**
     * Clean room implementation of slf4j delayed evaluation of Strings
     */
    public void log(Level level, String message, Object ... args) {
        if(logger.isLoggable(level)) {
            int aL = args.length;
            int index = 0;
            StringBuilder b = new StringBuilder();
            StringTokenizer st = new StringTokenizer(message, "{}");
            while(st.hasMoreTokens()) {
                if(index < aL) b.append(args[index++]);
                b.append(st.nextToken());                
            }
            logger.log(level, b.toString());
        }
    }
    
    // Add additional mapping methods below
    public void addHandler(Handler handler) { logger.addHandler(handler); }
    
    public boolean isInfoEnabled()  { return logger.isLoggable(Level.INFO); }
    public boolean isErrorEnabled() { return logger.isLoggable(Level.SEVERE); }
    public boolean isDebugEnabled() { return logger.isLoggable(Level.FINE);    }
    public boolean isTraceEnabled() { return logger.isLoggable(Level.FINEST); }
    
    public void  info(String message, Object ... args) { log(Level.INFO,    message, args);    }
    public void debug(String message, Object ... args) { log(Level.FINE,    message, args); }
    public void  warn(String message, Object ... args) { log(Level.WARNING, message, args); }
    public void error(String message, Object ... args) { log(Level.SEVERE,  message, args); }
    public void trace(String message, Object ... args) { log(Level.FINEST,  message, args); }
}
LoggerFactory.java
package org.slf4j;

import java.util.HashMap;
import java.util.Map;

/** Replacement for slf4j package */
public class LoggerFactory {
    private static final Map<String, Logger> loggers = new HashMap<String, Logger>();
    
    public static Logger getLogger(String name) {
        Logger l = loggers.get(name);
        if(l == null) {
            l = new Logger(java.util.logging.Logger.getLogger(name));
            loggers.put(name, l);
        }
        return l;
    }
}

The much vaunted capability of Slf4j – delayed evaluation of Strings substitutions has been implemented in the log() method. The String substitutions will be made only if required for output. It improves performance.

You can also pass Objects whose toString() method will be called only if required.

Logger implements most of the common methods used in Slf4j. If you need to add any method, follow the examples shown in Logger.java. It should be one line of code, calling log() or a method in logger. Marker feature has not been implemented. Does anyone use it!?

How to use dd (Linux copy tool) with progress indicator

/dev/sdcdd, the ubiquitous copy tool of Unix/Linux, now comes in with a decent built-in progress indicator.

You can run it by the command-line option: status=progress

Example:

dd status=progress if=/dev/sda of=/dev/sdb

Notice how I didn’t add the bs option and used the default. In my experiences the default works best.

Tested on: Ubuntu

Top 15 Countries by Coders

I have analyzed the data from HackerRank (December 7 2016) to find out the Top 15 countries in the world by cumulative ranking as well as by the number of Institutions in Top 50.

In order to figure out which colleges have the best coders, HackerRank hosted a major University Rankings Competition. Over 5,500 students from 126 schools from around the world participated in the event.

Cumulative Coder Rank of Top 15 Countries

India is the clear leader with cumulative score of 2901.04, more than double of US with cumulative rank of 1113.22. Russia is a distant third with less than 1/2 of US rank. But how does it fare in the total number of Institutions in the Top 50?

Country Sum – Rank
India 2901.74
US 1113.22
Russia 668.07
Romania 412.35
Canada 398.8
China 387.18
Vietnam 321.99
Ukraine 255.83
Sweden 231.23
Czech Republic 188.67
Turkey 157.56
Kazakhstan 138.87
Poland 130.34
Belgium 125.91
South Korea 124.65

Note: The score / rank of a College is weighted average and hence can be summed to get cumulative scores.

Top 15 Countries by Total Count of Institutions in Top 50

22 Institutions in India rank in the Top 50. US, second placed, is by contrast can boast of only 8 Institutions, almost 1/3 of India.

Country Count – Rank
India 22
US 8
Romania 3
Canada 2
Russia 2
Belgium 1
Bosnia & Herzegovina 1
China 1
Czech Republic 1
Estonia 1
Kazakhstan 1
Mexico 1
Poland 1
South Korea 1
Sweden 1

No wonder India is the top destination for outsourcing across the world. It produces very large number of Top Coders according to HackerRank data.

Within India the top 2 Institutions are IIT, Indore followed by IIT, Kanpur.

Java: The Most Popular Programming Language Today

Several research independently confirms Java as the most popular programing language today and as such can be considered the safest bet for someone looking to make a career in programming or looking for a career change. Let’s look in details below.

The TIOBE Index

The TIOBE Index for February 2017 indicates Java is the most popular programming language today. Java’s popularity is almost double that of the next contender C.

The TIOBE Programming Community index is an indicator of the popularity of programming languages. The index is updated once a month. The ratings are based on the number of skilled engineers world-wide, courses and third party vendors. Popular search engines such as Google, Bing, Yahoo!, Wikipedia, Amazon, YouTube and Baidu are used to calculate the ratings. It is important to note that the TIOBE index is not about the best programming language or the language in which most lines of code have been written.

PYPL PopularitY of Programming Language

The PYPL PopularitY of Programming Language Index is created by analyzing how often language tutorials are searched on Google.

The more a language tutorial is searched, the more popular the language is assumed to be. It is a leading indicator. The raw data comes from Google Trends.

If you believe in collective wisdom, the PYPL Popularity of Programming Language index can help you decide which language to study, or which one to use in a new software project.

PYPL too indicates Java as the leading programming language.

CodingDojo

CodingDojo diligently compiled job data from indeed in 2016 which shows Java is the top in-demand programming language, unless you consider SQL as programming language.http://www.inc.com/larry-kim/10-most-popular-programming-languages-today.html

Inc.com

Inc.com does not cite sources but states Java as the most popular programming language. Larry Kim, Founder and CTO of WordStreaam, gives a nice summary:

Java is top pick as one of the most popular programming languages, used for building server-side applications to video games and mobile apps. It’s also the core foundation for developing Android apps, making it a favorite of many programmers. With its WORA mantra (write once, run anywhere), it’s designed to be portable and run happily across multiple software platforms.

So if you are searching for a programming language to learn to build your career then look no further and start coding in Java.

Footnote: Glassdoor data indicates Software Architect is the highest paying job in this field, followed closely by Software Development Manager.

Key differences between Understanding and Learning (Memorization)

Many Educational Institutes, even today, do not focus on understanding. Their tests can be easily passed with memorization. This weakens the foundation of the students and adversely affects his future performance in professional engagements. Let’s look at the key differences between understanding and memorization and why understanding should be the priority for all students.

Memorization is simple. We all know that by repeated reading of any subject matter we can remember it by heart and be able to regurgitate (repeat information without analyzing or comprehending it) on demand, even matching similar sounding questions with the answer you have learned. And that is pretty much all you need to get through in most school systems and even most colleges.

Understanding, on the other hand, is knowing the underlying ideas and concepts so well that you can then explain them in your own words, even if you do not remember any of the terminology used. It allows you to develop insights that comes from inductive or deductive reasoning on the concepts.

You know you have understood something well when you can apply it to real life situations and clearly explain it to a layman with ease.

With understanding your can identify the similarities and differences between similar sounding ideas on your own.

Understanding is the key to advancing knowledge and discovering new knowledge.

Understanding is what is useful in real life, learning alone takes us nowhere.

Today computers can store much more facts than you will ever learn and can regurgitate it faster, even for complex queries (like Google). Instead of focusing your energies on memorization, which is anyways a losing and pointless battle, why not focus on understanding the topic at hand?

You will find that when you understand any topic, you tend to remember the key words and phrases too, thereby serving both the purposes of your exams as well as much bigger purpose of excelling real life and profession.

How to Easily Configure WiFi in Raspberry Pi

Any version of Raspberry Pi can be very easily configured with WiFi access. Coupled with ssh or vnc, it allows you to manage your Pi remotely. Here is the simplest way I could think of, illustrated by a screenshot and detailed below.

Once your Raspberry Pi boots up, you will get to this shiny screen. Now open a Terminal by clicking on the black square icon on top-left of the screen.Screenshot from 2017-01-04 11-29-18

This opens a Terminal where you type in:

sudo leafpad /etc/network/interfaces

This opens up a notepad-like editor. Make three changes to the text as shown in the highlighted section:

  1. Change manual to dhcp in the line starting with “iface wlan0”
  2. Replace wifi_id with the Wireless Access ID / SSID
  3. Replace password with your actual password for Wireless Access

Now save it (Ctrl-S) like notepad and exit it. The terminal should still remain open.

Now either reboot the Pi or restart the network with the following command on Terminal (don’t forget to press <Enter> after you typed):

sudo service networking restart

Wait for a few minutes for the WiFi to come up. On latest Raspbian with PIXEL, you can verify by seeing the two blue arrows in opposite direction, as can be seen from the screenshot.

Steps to secure and protect your Skype account from Hacking

Skype accounts are being hacked since at least August last year. Breached Skype accounts are used to send thousands of spam messages before they’re locked by Microsoft. The owners then have to regain access and that is when most find out about it. Skype has fallen victim to similar attacks before, and hackers were able to spoof messages on the system in 2015 after using lists of stolen usernames and passwords to gain access to accounts.

Problem

This wave of attack appears to be growing in size, and Skype users who opted for Microsoft’s two-factor security are also vulnerable. Microsoft offers the ability to link a Skype and Microsoft Account together to make sign-in and security easier. It turns out that Microsoft keeps your original Skype account password separate so that it can still be used to access the service with a Skype username. If that password isn’t secure then hackers can use it to gain access to your Skype account, bypassing any two-factor authentication provided by Microsoft. Essentially Microsoft has left a backdoor open to their vaunted two-factor security! It can be safely assumed that the new wave of attack is dictionary based and Skype / Microsoft allows unlimited login tries at some entry point.

Solution

The solution, in brief, is to switch to Microsoft’s two-factor security and then disable access by old method.

1. Update your Skype account to a Microsoft account:

  • Go to https://account.microsoft.com, if you’re already signed in, sign out.
  • Enter your Skype name and password when prompted and then select
  • Sign in.
  • If your Skype account is not updated already, you will be notified to update your account.
  • Select Next to continue.
  • You will be asked to add an email to your account, and verify that email.
  • Congrats, your Skype account is also a Microsoft account.

2. Ensure that your Accounts are fully merged:

  • Go to https://account.microsoft.com, if you’re already signed in, sign out.
  • Enter your Skype name, not your Microsoft Account email address, and use your Skype password to sign-in
  • If you’ve linked your Microsoft Account previously, you’ll be prompted to sign-in and merge the accounts to create a Skype alias

3. Disable Skype alias:

Once the two accounts are properly merged, Microsoft creates a Skype alias to let you keep signing in with a Skype username. Disable it under the aliases preferences, to ensure complete protection.