An introduction to Javascript

How Javascript was born ?

In 1993 the first web browser with a GUI was released. It was called Mosaic. Due to it’s GUI it made www quite popular.

It’s lead developers then founded Netscape which released an enhanced version called Netscape Navigator. The pages were static though. They lacked interaction.

To make the pages more interactive Netscape needed a scripting language. To do this they hired Brendan Eich. Same guy who later co-founded Mozilla project. His job was to put this language “in the browser”. The first version was completed in 10 days. It was called Mocha. Then renamed to Livescript and subsequently to Javascript.

What exactly is Javascript ?

Javascript is an interpreted or just in time compiled programming language. What this means is that the program you write is compiled at run time.
Unlike Java where you need to first compile the program and then run the generated byte code.

It is one of the core technologies of the World Wide Web (www) along with HTML and CSS. You can build interactive websites using JS. When you see some animations like page elements fading in and out or resizing then it’s more or less the work of JS.

All major web browsers have a dedicated JS engine which can execute the JS code.

Most of the websites you see use Javascript to handle client side behavior. But with the advent of technologies like Node JS we can now write code in JS which can be executed on Server side.

Why should you learn Javascript ?

To build any modern day website Javascript is required. And now JS can be used to build backend, like APIs. So whether you want to work for a company as a developer or you plan to build your pwn websites you will need JS.

Code –

PPT – Introduction to JavaScript from Ankur Srivastava

What are checked and unchecked Exceptions in Java?

What are Checked Exceptions?

If you write a piece of code that is logically correct but can fail in certain scenarios then you need to handle those scenarios. So for example if you write code which reads a File and suppose at run time the File is not available then it will throw an Exception. So you can handle this by catching a FileNotFoundException.

What are Runtime Exceptions?

Suppose you write a piece of code which is logically not correct. Say you write code that does not use an API correctly then your code is buggy. So no point handling exception here. Let the error be printed in the log so that you can make corrections to the code.

The application can catch this exception, but it probably makes more sense to eliminate the bug that caused the exception to occur.

What are Errors?

When the exception is beyond your application’s scope. Like some hardware issue. Say at runtime some I/O error occurs.

Both Runtime and Error are unchecked. You don’t need to handle them.

Top 5 features added to Java SE 9


Java has been evolving at a good pace ever since it was introduced in early 90’s. With every passing year and each release it has tried to keep pace with emerging market demands.Java has been evolving at a good pace ever since it was introduced in early 90’s. With every passing year and each release it has tried to keep pace with emerging market demands.

Let’s take a look at the top 5 features added to Java 9

1. Modules
The result of Project Jigsaw, modules are the most important addition to Java 9.

  • Java is now modular which means the library packages are now organized as modules.
  • It changes the way we design and build Java Applications.
  • It is different from OSGi.
  • It helps Programmers to be more productive.
  • Managing and evolving modules is easier.

2. JShell : Read-Eval-Print loop for Java
A tool that allows you to develop and test Java code interactively.


class Sample{
	public static void main(String[] a){
		System.out.println("Hello World");

And now using JShell you can print Hello without writing other stuff.
You can type JShell at command line to get started.
And write

System.out.println(“Hello !!”);

3. Private Methods in Interfaces

You can now add private methods to your Interfaces. This can help you to create  reusable code.


public interface Sample {

private void printMyStuff(String abc){




4. Collections
Earlier you would write

List<Employee> empList = new ArrayList<>();

empList.add(new Employee(1, “Ankur”));

empList.add(new Employee(2, “Rohan”));

Now you can write

List<Employee> empList = List.of(new Employee(1, “Ankur”), new Employee(2, “Rohan”));

Reason – Thanks to changes in Java 8. Interfaces can now have default methods.

5. Concurrency Updates

Java 8 introduced Streams. Java 9 has gone a step ahead and added

  • Reactive Streams publish-subscribe framework
  • Enhancements to CompletableFuture class which was introduced in Java 8.

Other Notable Changes

HTTP Client API to support HTTP/2 and WebSocketThe new incubator HTTP Client is capable of working with both HTTP/1.1 and HTTP/2


3 Key Updates in Java SE 8

What is new in Java 8?

Java has been evolving at a good pace since it was introduced in early 90’s. With every passing year it has tried to keep pace with emerging market demands.

Let’s take a look at 3 key updates introduced in Java 8:
1. Lambda Expression  

Lambda Expression adds functional programming features to Java. It changes the way programming solutions are conceptualized and the way code is written in Java. It reduces the amount of code needed to create certain constructs like Anonymous Classes.

2. Stream API

The Stream API supports pipeline operations on data. Stream API is designed with Lambda Expression in mind.Powerful way to handle data in an efficient way.You can perform very sophisticated operations that search, filter or manipulate data. Plus it can be done in Parallel.

3. Interface Methods

Another Lambda inspired feature is the ability to define a default implementation for a method in the Interface. This feature helps you to update the codebase without impacting the classes that implement an interface.

Other new features

1. New Date and Time API

2. Ability to use parallel processing when sorting an Array.

Key Considerations in Java Design

What Java intends to provide?

  • Simple
    Java should be simple to learn and use by the Professional Programmers.
  • Object Oriented Features
    The Object Model in Java is simple and easy to extend.
  • Robust
    Programs written in Java should be able to run reliably in any Environment.
  • Multithreading
    To support Concurrency and Parallelism
  • Architecture Neutral
    Thanks to Java Virtual Machine  
  • Interpreted and High Performance
  • Distributed
    Java supports Remote Method Invocation.

Apart from these Java is a strictly typed language so it checks your program at both compile and run time.

It also frees you from Memory Management activities which can cause major errors at run time, if not managed properly.

An Engineering Approach to Build Websites

Sunny’s E-Commerce Website

Sunny owns a bookshop, which is doing reasonably well, and he wants to offer his services online via an e-commerce website. He starts to do some research on how to build a website.

After few days of searching and reading blogs he puts down his options.

1. Hire a freelance developer who can create a website for him.
2. Use a website builder and try to create a website on his own with some help from a freelancer, which may cost him less.
3. Learn programming and start building a website from scratch.

In your view which approach makes sense?

Continue reading “An Engineering Approach to Build Websites”

A quick introduction to Distributed Systems

What are Distributed Systems?

In this article I will try to explain distributed systems in simple words. So that you can understand what they are and how they can help.

At a high level distributed systems are a group of computers working together towards a common goal. For an end user or client it’s just one computer. But behind the scenes the work gets distributed among a set of computers or servers.

Continue reading “A quick introduction to Distributed Systems”

Why study Relational Algebra?

I am familiar with SQL so when I had to study Relational Algebra(RA) I found it difficult to understand why should I study RA or how is it related to SQL? Ideally it should have been other way round, not quite in my case.

I couldn’t find good analogies so I came up with a couple of them. Hope this helps you get an idea.

I present two simple analogies here

  1. Say you need an Algorithm to sort a set of numbers. And you write an algorithm, say a version of quick sort. Next you need to implement it. You can code it in any programming language – Java/C etc. using language specific constructs. As long as the idea is retained the code should get you the desired result. Similarly you can think of RA as the theoretical model to query a relational databases. It defines operations like Select, Project etc. This idea has been implemented by a query language like SQL.
  2. Consider specification document written for a Server. Any vendor who plans to build a server should comply with this specification document. As long as the server follows the rules / guidelines specified in the document it’s all good. On similar lines you can think of RA and SQL

The dangers of AI are far more than that of a Nuclear War — Elon Musk

We know Elon Musk is pretty close to the cutting edge stuff in Artificial Intelligence (AI). In this talk he discusses his concerns about AI.

He answers some of the pressing questions and concerns and why some kind of regulation is much needed.

He understands the threats that the so called AI experts fail to see. And he admits that it scares the hell out of him.

Just 5 mins into this talk and you get an idea of the kind of impact AI can have. Let me add here that he mention the difference between Narrow or Weak AI and Digital Super Intelligence, discussed later.

I am sharing some of the highlights from his talk.

Several AI “experts” think more than they do and they think they are smarter than they actually are. They don’t understand the repercussions. He mentions that the rate of improvement is exponential in this area.

  1. Consider this AlphaGO, in a span of 6–9 months, was able to defeat the champions in the Game. AlphaGo Zero crushed AlphaGo. It learnt by playing itself. You can put in rules for any game and it can pretty much beat the best players in that. Question is did the experts predict that?
    Similarly for self driving cars. They are predicting it to be 100–200% safer in an year or two.
  2. Narrow or Weak AI does not pose a risk to species. It will result in lost jobs, better weaponry etc. But Digital Super Intelligence does. Thats why we need to do it very very carefully.

A super intelligence is a hypothetical agent that possesses intelligence far surpassing that of the brightest and most gifted human minds. –Wiki

3. He talks about regulations to ensure everyone is developing AI safely. Even though the dangers of AI are far more why no regulations?

To conclude he wishes that these developments are symbiotic with Humanity. And that we don’t create systems that pose a threat to us.

I will highly recommend that you watch this talk.