Thursday 13 February 2014

Playing with Map

My first time confusion about Map :

  1. Map is a interface not a class, so we can't create a Object of Map.
  2. Map are quite different from List , they contains key - value pair.
   import java.util.Collection;
   import java.util.HashMap;
   import java.util.Map;
   import java.util.Set;


      public class TestClass implements Map<String,String>{
          public static void main(String ...strings){
              Map<String,String> map = new HashMap<String,String>();
              map.put("1" , "first");
              map.put("2", "second");
              map.put("2", null); Map can't have duplicate elements last value override previous value.
              map.put(null, null); Key and Value both can be null.
         System.out.println(map);
         System.out.println(map.size());
     
    }
}

Output : 

{null=null, 2=null, 1=first}
3

Playing with List

Confusion which I have first time and require attention :
  1. Sometimes we confused about List that it is a class and try to create a Object of it.(First time I did this :) ). After that I realize that List is a interface.
  2. Use generic types whenever using any collection like List. Why ? According to Java doc : Generics add stability to your code by making more of your bugs detectable at compile time. (I was not aware of this first time.)

   import java.util.ArrayList;
   import java.util.Collection;
   import java.util.Iterator;
   import java.util.List;
   import java.util.ListIterator;


   public class TestClass implements List<String>{
       public static void main(String ...strings){
           List<String> list = new ArrayList<String>();
       list.add(null);      null is allowed in List.
       list.add("Ram");
       list.add("Ram"); duplicate elements are allowed in List.
       list.add(1,"Shyam"); inserts "Shyam" at position 1 and also it change index of all elements after that index.
          list.get(0);
     System.out.println(list);
     System.out.println(list.size());
   
    }
}

Tuesday 2 April 2013

JavaScript Object Creation

/*
 * JavaScript object functional constructor.
 */
var constructStudent = function(name, age, caddress, paddress) {
    this.name = name;
    this.age = age;
  
    Object.defineProperties(this, {
        "Caddress" : {
            enumerable : false,
            value : caddress
        },
        "Paddress" : {
            enumerable : true,
            value : paddress
        },
        "University" : {
            value : "UPTU",
            writable : false
        },
        "Country" : {
            value : "India",
            configurable : false,
        },
    });
    return this;
}

function kick() {
    console.log('kick');
}
/*
 * prototype of javaScript object.
 */
constructStudent.prototype = {
    collegeName : "GLBITM",
    markCalculator : function(math, science) {
        var totalMarks = math + science;
        return totalMarks;
    },
    resultCalculator : function(totalMarks) {
        var total = totalMarks;
        if (total > 33) {
            console.log("pass");
        } else {
            console.log("fail");
        }

    }

}
var firstBoy = new constructStudent('anshul', '23', 'bangalore', 'mahoba');
firstBoy.name = "rahul";
firstBoy.University = "MTU";
console.log(firstBoy.name);
console.log(firstBoy.University);
var total = firstBoy.markCalculator(22, 56);
firstBoy.resultCalculator(total);
console.log(total);
console.log(firstBoy.collegeName);
console.log(Object.keys(firstBoy));
console.log(Object.getOwnPropertyNames(firstBoy));
console.log(firstBoy.hasOwnProperty('collegeName'));
var result = [];
for ( var propName in firstBoy) {
    result.push(propName);
}
console.log(result);
delete firstBoy.Country;
console.log(Object.getOwnPropertyNames(firstBoy));
console.log(firstBoy.propertyIsEnumerable('collegeName'));

Monday 25 March 2013

Website start-up terms

How to start a website :
1. choose a registrar company, buy a domain name.
2. choose a web- host company, they will provide some server space and web interfaces to your website.
3.go back to your registrar and provide your server space address.By doing this you told your resistrar that whose DNS server you are using.






Now when website hit first time, my request will propagate to the root servers, those root servers do know  who knows where all the .com mappings taken, and finally you get your response, thats what registrar do for you.


MX- mail server setup. go to google.com, reach at appropriate choice that I want to host my mail here.than they give you some MX records list by saying that tell your resister that your are going to use these MX records for your website mails.Now when an email is sent it may be go to your DNS server but then finally it reaches to google server and your mail finally  outsourced.


CNAME - CNAME maps from one domain name to another domain name.

A - A maps from IP address to domain name.

If I have a website and wants to tell world about my website than what I need to do.for example if I have firstemission.com as my website than first I need to create  A map for my website.
After that If I want to open my mails as mail.firstemission.com despite of that we have our MX records at google server than we need to map CNAME mapping for that.

Virtual Private Server(VPS)- for more control in our server.we can buy VPS.it is good for learning purpose.