Monday, October 29, 2012

getObject from URL : JAVA

Get Object from a Valid URL using URL class in java  :

import java.net.MalformedURLException;

import java.net.URL;

public class getobject {
  public static void main(String args[]) {
    URL resourceURL;
    if(args.length > 0) {
      try {
        resourceURL = new URL(args[0]);
        try {
          Object o = resourceURL.getContent();
          System.out.println("Content in This URL is " + o.getClass().getName());
        } catch(Exception e) {
          System.err.println(e);
        }
      } catch(MalformedURLException e) {
        System.err.println(args[0] + " is not a parseable URL");
        System.err.println(e);
      }
    }
  }
}

If the URL passed as a parameter tends to be correct object will get retrieved.

IP and Machine Name of system in Java

Now Find your IP Address and Machine name with your domain in Java :

public class GetIPAddress {
  public static void main(String[] args) {
    try {
      InetAddress addressInstance = InetAddress.getLocalHost();
      System.out.println("IP Address : " + addressInstance.getHostAddress());
      System.out.println("System Name : " + addressInstance.getHostName());
      System.out.println("Canonical Host Name (Host name with the Domain): " + addressInstance.getCanonicalHostName());
      System.out.println("System Name with IP address : " + addressInstance.getLocalHost());
    } catch(Exception e) {
      e.printStackTrace();
    }
  }
}


Get Routing IP Address of a Domain In java

Normally if you ping a domain www.google.com from command prompt it doesn't directly reach the server from your location they might have a local server inside your country from there it will take several routes and reach the main server

For example : 
Google taken 5 hops when i ping from my local system :
www.google.com/74.125.236.52

www.google.com/74.125.236.49
www.google.com/74.125.236.51
www.google.com/74.125.236.50
www.google.com/74.125.236.48

To determine the hops here is the source code in java :


import java.net.*;

class GetAllHops {

  public static void main(String args[]) {

    try {
      InetAddress[] addresses = InetAddress.getAllByName("www.google.com");
      for(int i = 0; i < addresses.length; i++) {
        System.out.println(addresses[i]);
      }
    } catch(UnknownHostException e) {
      System.out.println("Could not find www.apple.com");
    }

  }

}



IP Address Of Domain in Java


How Do you get the IP Address of the domain in java  : 


The Domain Name System (DNS) is a hierarchical distributed naming system for computers, services, or any resource connected to the Internet or a private network. It associates various information with domain names assigned to each of the participating entities. A Domain Name Service resolves queries for these names into IP addresses for the purpose of locating computer services and devices worldwide. By providing a worldwide, distributed keyword-based redirection service, the Domain Name System is an essential component of the functionality of the Internet.
An often-used analogy to explain the Domain Name System is that it serves as the phone book for the Internet by translating human-friendly computer hostnames into IP addresses. For example, the domain name www.example.com translates to the addresses 192.0.43.10 (IPv4) and 2620:0:2d0:200::10 (IPv6). Unlike a phone book, however, DNS can be quickly updated and these updates distributed, allowing a service's location on the network to change without affecting the end users, who continue to use the same hostname. Users take advantage of this when they recite meaningful Uniform Resource Locators (URLs) and e-mail addresses without having to know how the computer actually locates the services.
Know More About DNS : Click Here
For example IP of  www.Google.com 

Source Code :

import java.net.*;

class GetAddressOfDomain {
  public static void main(String args[]) {

    try {
      InetAddress address = InetAddress.getByName("www.google.com");
      System.out.println(address);
    } catch(UnknownHostException e) {
      System.out.println("Could not find www.google.com");
    }

  }

}

Console : www.google.com/74.125.236.50


Tuesday, October 23, 2012

Change : Satellite and Street View

Drop Down to Change Between satellite and Street view using gmap3 jQuery Plugin:

Gmaps3 Plugin Provides us mapTypeControlOptions to change between the satellite view and street view in google maps which is demonstrated in this post , initially when the map is loaded the maps loads in satellite which is done is using static mapTypeId : 'google.maps.MapTypeId.SATELLITE' and then using map type control options drop down the view can be changed :


mapTypeControlOptions: {
  style: google.maps.MapTypeControlStyle.DROPDOWN_MENU
},




<html>
<head>
<script type="text/javascript" src="../jquery/jquery-1.4.4.min.js"></script>
<script src="http://maps.google.com/maps/api/js?sensor=false" type="text/javascript"></script>
<script type="text/javascript" src="../gmap3.js"></script>
<style>
.gmap3 {
  margin: 20px auto;
  border: 1px dashed #C0C0C0;
  width: 1000px;
  height: 500px;
}
</style>
<script type="text/javascript">
$(function(){
  $('#test1').gmap3({
    action: 'init',
    options:{
      center:[22.49156846196823, 89.75802349999992],
      zoom:2,
      mapTypeId: google.maps.MapTypeId.SATELLITE,
      mapTypeControl: true,
      mapTypeControlOptions: {
        style: google.maps.MapTypeControlStyle.DROPDOWN_MENU
      },
      navigationControl: true,
      scrollwheel: true,
      streetViewControl: true
    }
  });
});
</script>
</head>
<body>
  <div id="test1" class="gmap3"></div>
</body>
</html>

Add Info Window in Google Maps

Adding an info window forms a integral part in the places where some note has to be placed , so inorder to use that inside Google maps this post will aid you !!!




<html>
<head>
<script type="text/javascript" src="../jquery/jquery-1.4.4.min.js"></script>
<script src="http://maps.google.com/maps/api/js?sensor=false" type="text/javascript"></script>
<script type="text/javascript" src="../gmap3.js"></script>
<style>
.gmap3{margin: 20px auto;border: 1px dashed #C0C0C0;width: 500px;height: 250px;}
</style>
<script type="text/javascript">
$(function(){
  $('#test1').gmap3({
    action: 'addInfoWindow',
    address: "Coimbatore,India",
    map:{
      center: true,
      zoom: 14
    },
    infowindow:{
      options:{
        size: new google.maps.Size(50,50),
        content: 'Hello World !'
      },
    events:{
      closeclick: function(infowindow){
        alert('closing : ' + $(this).attr('id') + ' : ' + infowindow.getContent());
      }
    },
    apply:[
      {action:'setContent', args:['Here is a new content !']}
    ]
    }
    },
    {action: 'setOptions', args:[{scrollwheel:true}]}
    );
  });
</script>
</head>

<body>
<div id="test1" class="gmap3"></div>
</body>
</html>

Use Forms in Maps

Fill in an address, a marker will be added and the map will be centered on it :


Show places on the button click event, that is achieved using jQuery $('#test-ok').click(function(){}  once its done the value in the text box is passed to the gmaps3 plugin and action 'getlatlng' is done , In the call back method of that action marker is added to the respective address typed its actually center it which makes the map look Cool :) :) 

<html>
<head>
<script type="text/javascript" src="../jquery/jquery-1.4.4.min.js"></script>
<script src="http://maps.google.com/maps/api/js?sensor=false" type="text/javascript"></script>
<script type="text/javascript" src="../gmap3.js"></script>
<style>
body {text-align: center;}
#ctrl {width: 500px;margin: 0 auto;}
.gmap3 {margin: 20px auto;border: 1px dashed #C0C0C0;width: 500px;
        height: 250px;}
</style>
<script type="text/javascript">
$(function(){
  $("#test").gmap3();
  $('#test-ok').click(function(){
  var addr = $('#test-address').val();
  if ( !addr || !addr.length ) return;
  $("#test").gmap3({
    action:   'getlatlng',
    address:  addr,
    callback: function(results){
      if ( !results ) return;
      $(this).gmap3({
      action:'addMarker',
      latLng:results[0].geometry.location,
      map:{
        center: true
      }
      });
    }
   });
  });
  $('#test-address').keypress(function(e){
  if (e.keyCode == 13){
    $('#test-ok').click();
  }
  });
});
</script>
</head>
<body>
<div id="ctrl">Address : <input type="text" id="test-address" size="60">
<button type="button" id="test-ok">Ok</button>
</div>
<div id="test" class="gmap3"></div>
Fill in an address, a marker will be added and the map will be centered on it
</body>
</html>




Fix Panel to take boundaries

Use Fix Panel to Take Boundaries in Google Maps :


This post is intended in using fix panel to determine the boundaries from Google maps !!!


<html>
<head>
<script type="text/javascript" src="../jquery/jquery-1.4.4.min.js"></script>
<script src="http://maps.google.com/maps/api/js?sensor=false" type="text/javascript"></script>
<script type="text/javascript" src="../gmap3.js"></script>
<style>
.gmap3{margin: 20px auto;border: 1px dashed #C0C0C0;width: 500px;height: 250px;}
#box{border: 1px solid #FF0000;background-color: #AFAFAF;width: 160px;height: 64;font-size: 11px;}
#box .line{border-bottom: 1px solid #FF0000;overflow: auto;clear: both;height: 16px;}
#box #lng-west{border-bottom: 0px;}
#box .name{width: 30px;border-right: 1px solid #FF0000;float: left;}
#box .value{float: left;}
</style>
<script type="text/javascript">
$(function(){
  var box = '<div id="box">' +
  '<div id="lat-north" class="line"><div class="name">North</div><div class="value"></div></div>' +
  '<div id="lng-east" class="line"><div class="name">East</div><div class="value"></div></div>' +
  '<div id="lat-south" class="line"><div class="name">South</div><div class="value"></div></div>' +
  '<div id="lng-west" class="line"><div class="name">West</div><div class="value"></div></div>' +
  '</div>';
  $('#test1').gmap3(
    {action: 'addFixPanel',options:{content: box,middle: true},
      events:{
        bounds_changed: function(map){
        var bounds = map.getBounds();
        var ne = bounds.getNorthEast();
        var sw = bounds.getSouthWest();
        $("#lat-north .value").html(ne.lat());
        $("#lng-east .value").html(ne.lng());
        $("#lat-south .value").html(sw.lat());
        $("#lng-west .value").html(sw.lng());
      }
    }
  });
 });
</script>
</head>
<body>
<div id="test1" class="gmap3"></div>
</body>
</html>