Posts

Java 8, Default methods, Diamond Problem and the Solution!

Java 8 has introduced default methods (methods with body) in interfaces. But doesn't this introduce the diamond problem? The very problem with C, that Java solved by not having multiple inheritance. Java has given a solution to this !!!!!! If you have two interfaces with same method signature, and a class implements it.. the class will give you compilation error saying there is ambiguity. It is now the developers responsibility to solve this problem by overriding the method in its body. It can call the super interfaces method by SuperInterface.super.methodName(). Let us see an example: public class MultipleInheritanceEg { public static void main(String[] args) { C c = new C(); c.A(); } } interface A{ public default void A(){ //Some implementation }; } interface B{ public default void A(){ //Some implementation }; } interface D extends A, B{ public default void A(){ A.super.A(); }; } ...

Linked List implementation in Java

This is a simple implementation of linked list in java.  ===== package collections; public class LinkedListMyImpl { Node startNode; Node endNode; void add(int i){ if(startNode == null){ Node n = new Node(); n.i = i; startNode = n; }else{ Node n = new Node(); n.i = i; if(endNode == null){ startNode.nextNode = n; endNode = n; endNode.previousNode = startNode; }else{ endNode.nextNode = n; n.previousNode = endNode; endNode = n; } } } void remove(int i){ Node n = startNode; while( n != null){ if(n.i == i){ Node previousNode = n.previousNode; Node nextNode = n.nextNode; if(previousNode != null) previousNode.nextNode = nextNode; if(nextNode != null) nextNode.previousNode = previousNode; n = null; break; } if(n.nextNode != null) n = n.nextNode; } } void print(){ Node n = startNode; while( n != null){ System.out...

On the path to become a MEAN Developer - 2 (The N)

Part 1 is here:  On the path to become a MEAN Developer - 1 Lets start by creating our very own node server. Check if npm and node is properly installed on your machine Go to the location of your choice. Create a directory myapp. Goto myapp. Type npm init . It will give you certain options. Default options are good to go. A package.json file will be created. Create a server.js file. var http=require("http"), port=1234; var server=http.createServer(function(request, response){ response.writeHeader(200, {"Content-Type" : "text/plain"}); response.write("Hello world!"); response.end(); }); server.listen(port); console.log("server is listening on http://localhost:" + port); To run the server, >> node server.js server is listening on http://localhost:1234 Hit http://localhost:1234 from your web browser, you should get Hello World as the output.

On the path to become a MEAN Developer - Misc

Check if node and npm is properly installed on your machine. Firstly add the path (upto bin) of your node installation. > npm --version > node --version These commands should return some values. Node and npm are installed on your machine.

On the path to become a MEAN Developer - 1

Image
I always wondered, But MEAN-ness rescued me! Yay! Oh well, not "being MEAN to somebody" but the MEAN Stack. ;) I am going to blog about the entire learning curve. I have a windows development machine. You get it right! I am in for a lot of challenges coming up the way to installation on my windows machine. Lets start with a brief on what a MEAN Stack is, what, who and why? MEAN is a Full Stack for Web Application Development. M - Mongo DB, a NoSQL database E - Expressjs, a web application framework that runs on Nodejs A - AngularJS, Javascript MVC framework that runs in browser Javascript engines N - NodeJS, an execution environment for event-driven server side and networking application. Did you get the best part of this stack? you need to know Java script to code to use this Stack! Only Javascript. One language to build it all. Client is a browser with javascript engine. Thats it! Though I say Javascript, I will be using Typescript. Typescript is modul...

typings error following Angularjs 2 quickstart tutorial

I got the following error when i tried npm install on the Angularjs 2/ng2 quickstart example: typings ERR! message Unable to connect to "https://api.typings.org/entries/dt/core-js/tags/0.0.0%2B20160317120654" typings ERR! caused by connect ECONNREFUSED 104.24.112.177:443 When i tried connecting to https://api.typings.org/entries/dt/core-js/tags/0.0.0%2B20160317120654 from my browser, it works fine. So the issue? Proxy problem! Create a .typingsrc file in the root directory of the project with the following content: proxy="http://proxy:port/" rejectUnauthorized=false and npm install will install with Warning, which as the quickstart example suggests can be ignored. ng2 quickstart example can be found at: https://angular.io/docs/ts/latest/quickstart.html

Running ol3cesium using nodejs on desktop

Image
I was trying to run ol3-cesium as a desktop application. I downloaded the latest code with examples from the official site : http://openlayers.org/ol3-cesium/. When I tried opening the main.html (from examples folder) in my web browser..........  And as soon as I hit the enable/disable button view the map in 3D looks like this....... Debug and you will get an error similar to this: Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https, chrome-extension-resource. How did I solve it? Its a CORS issues and can be solved by using a web server. I used nodejs server to host the directory. Create a server.js file in your ol3-cesium root directory. The content of my server.js: =========== var http = require('http'); var fs = require('fs'); var url = require('url'); // Create a server http.createServer( function (request, response) {    // Parse the request containing file name   ...