Thursday, April 26, 2012

Java exception : NullPointerException

So suppose you are coding and this "NullPointerException" on the way so what should understand or derive from the exception or moreover how you should proceed for debugging, or getting rid of the exception, to do this lets understand due to what all problems it may cause :

Thrown when an application attempts to use null in a case where an object is required. These include:

  1. Calling the instance method of a null object.
  2. Accessing or modifying the field of a null object.
  3. Taking the length of null as if it were an array.
  4. Accessing or modifying the slots of null as if it were an array.
  5. Throwing null as if it were a Throwable value.
So just check in your code, and

Categories of exceptions in Java


                    +--------+
                    | Object |
                    +--------+
          |
          |
                   +-----------+
     | Throwable |
                   +-----------+
                    /         \
     /           \
          +-------+          +-----------+
          | Error |          | Exception |
          +-------+          +-----------+
    /  |  \           / |        \
         \________/   \______/      \
                   +------------------+
 unchecked  checked | RuntimeException |
     +------------------+
       /   |    |      \
      \_________________/
        
        unchecked


  1. Checked exceptions: A checked exception is an exception that is typically a user error or a problem that cannot be foreseen by the programmer. For example, if a file is to be opened, but the file cannot be found, an exception occurs. These exceptions cannot simply be ignored at the time of compilation.
  2. Errors: These are not exceptions at all, but problems that arise beyond the control of the user or the programmer. Errors are typically ignored in your code because you can rarely do anything about an error. For example, if a stack overflow occurs, an error will arise. They are also ignored at the time of compilation.
  3. Runtime exceptions: A runtime exception is an exception that occurs that probably could have been avoided by the programmer. As opposed to checked exceptions, runtime exceptions are ignored at the time of compliation.

trimToSize or trimTolength

This method is sometime very useful for memory management suppose you know value you have assigned to an array list will be final means no more element addition to the array list you can use this to make the memory smaller for that array list


Trims the capacity of this ArrayList instance to be the list's current size. An application can use this operation to minimize the storage of an ArrayList instance.


An application can use this operation to minimize the storage of an ArrayList instance. 


Example: 

     ArrayList myAL = new ArrayList();
      myAL.Add( "Shashwat" );
      myAL.Add( "Shriparv" );
So now you know that no more element will be added to myAl, so you can apply:

myAl.trimToSize() to make memory alocation smaller and efficient.

Call an Object Member Dynamically

Why it is required ?????

You need to call method or property dynamically....

What you can do for that????

Simple : Use dynamic keyword, this will disable the static checking for an object instance.

What is the logic behind it??? you know ha ha no right  ?? if yes you wouldn't be here :)

Use Optional Parameters c#

What is the need for that ??

You need to define a method with some optional parameters......

So what will you do for that ???

Simple : Supply some default parameter in the method arguments. :)

Here is the example for that :


Wednesday, April 25, 2012

How to create Tar.gz / zip / on ubuntu

For creating tar.gz right click on folder and select compress and file format you need,

or

if you need to do it through terminal you can issue this command


tar cvvzf /folder-name.tar.gz
zip -a -r /folder-name.zip








Tuesday, April 24, 2012

How to set alternative java : set default java to use in linux

Start terminal (ctrl+alt+t) and type the following command :



sudo update-alternatives --config java



This will print option as follows :


Case-insensitive XPath query search on XML c#




XmlDocument doc = new XmlDocument();
try
{
    doc.Load(Server.MapPath("/XML/people.xml"));
    string caseInsensitiveQuery = "root/people/person/*[translate(local-name(),"+
        "'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz')='name']";

    XmlreturnedNodeFromNodesList returnedreturnedNodeFromNodess = doc.SelectreturnedreturnedNodeFromNodess(caseInsensitiveQuery);
    foreach (XmlreturnedNodeFromNodes returnedNodeFromNodes in returnedreturnedNodeFromNodess)
    {
        Response.Write(returnedNodeFromNodes.InnerText + "<br />");
    }
}
catch (XmlException ex)
{
    Response.Write(ex.toString());
}
catch (FileNotFoundException ex)
{
   Response.Write(ex.toString());
}

Monday, April 23, 2012

Different ways of accessing SharePoint list.

TYPE OF SERVICE/API
WHEN TO USE
Server-side object model
Core SharePoint DLL that is used for building  applications that aredeployed to or reside (or consumed) on the server.
Client object model

Client-based DLL used for coding against SharePoint on remote clients. It is supported in .NET, Silverlight, and JavaScript applications.
WCF Data

Services REST-based service that provides lightweight GET and POST functionality
against a SharePoint list. You use this service to interact with Excel spreadsheets. (Note that the WCF Data Services were formerly called ADO.NET Data Services.)

Implement your own custom provider to generate unique IDs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Office.DocumentManagement;
  
namespace CustomDocIDProvider
{
    class CustomDocIDProvider :
Microsoft.Office.DocumentManagement.DocumentIdProvider
    {
        public override bool DoCustomSearchBeforeDefaultSearch
        {
           //property used to trigger our custom search first.If false then we will use the SharePoint search when retreiving
            Document IDs
            get
            {
                return false;
            }
        }
  

Installing and configuring OpenSSH (SSHD) server on Linux/Ubuntu

Go to Terminail (Shortcut -> ctrl + alt +t) and type the following command
 
sudo apt-get install openssh-server openssh-client

This ssh is required when suppose you are trying to ssh to localhost or from one machine to other machine and connection refused error comes, so you need to install sshd server to be able to connect to the other machind :)

Thursday, April 19, 2012

how to calculate median in Hive

Use the following function which is built in 


percentile(BIGINT col, p)

and set p to be 0.5



and will calculate the median




credit : roberto@stumbleupon.com

Tuesday, April 17, 2012

What is the difference between HDFS and NAS ?

    The Hadoop Distributed File System (HDFS) is a distributed file system designed to run on commodity hardware. It has many similarities with existing distributed file systems. However, the differences from other distributed file systems are significant. Following are differences between HDFS and NAS
    • In HDFS Data Blocks are distributed across local drives of all machines in a cluster. Whereas in NAS data is stored on dedicated hardware.
    • HDFS is designed to work with Map Reduce System, since computation are moved to data. NAS is not suitable for Map Reduce since data is stored separately from the computations.
    • HDFS runs on a cluster of machines and provides redundancy using replication protocol. Whereas NAS is provided by a single machine therefore does not provide data redundancy.

What is a Job Tracker in Hadoop? How many instances of Job Tracker run on a Hadoop Cluster?

    Job Tracker is the daemon service for submitting and tracking Map Reduce jobs in Hadoop. There is only One Job Tracker process run on any hadoop cluster. Job Tracker runs on its own JVM process. In a typical production cluster its run on a separate machine. Each slave node is configured with job tracker node location. The Job Tracker is single point of failure for the Hadoop Map Reduce service. If it goes down, all running jobs are halted. Job Tracker in Hadoop performs following actions(from Hadoop Wiki:)
    • Client applications submit jobs to the Job tracker.
    • The JobTracker talks to the NameNode to determine the location of the data
    • The JobTracker locates TaskTracker nodes with available slots at or near the data
    • The JobTracker submits the work to the chosen TaskTracker nodes.
    • The TaskTracker nodes are monitored. If they do not submit heartbeat signals often enough, they are deemed to have failed and the work is scheduled on a different TaskTracker.
    • A TaskTracker will notify the JobTracker when a task fails. The JobTracker decides what to do then: it may resubmit the job elsewhere, it may mark that specific record as something to avoid, and it may may even blacklist the TaskTracker as unreliable.
    • When the work is completed, the JobTracker updates its status.
    • Client applications can poll the JobTracker for information.

Sunday, April 15, 2012

Hadoop modes of operation


·       
            STAND ALONE
·         PSEUDO DISTRIBUTED
·         FULLY DISTRIBUTED (Cluster)

The STAND ALONE and PSEUDO DISTRIBUTED modes of operations are development modes of operations used by development teams to carry out development of Map Reduce jobs.
The stand-alone mode of development does not use HDFS but uses local operating system files system. Hadoop and all application code runs inside a single Java process. This is on a Single machine.
The pseudo – distributed mode of Hadoop runs all the processes like Name node, Data node, Job Tracker and Task Tracker as separate processes. HDFS file system is used in this mode of operation. This is again on a single machine.
Both the above approaches are used by developers to carry out development activities.
The third mode of Hadoop operation is FULLY DISTRIBUTED Cluster. HDFS file system is used. This is over a cluster of machines. Read / write processes are balanced over a cluster of nodes.  There are several daemon threads of Name node, Data node, Task Tracker and Job Tracker.


Different components of hadoop system



·         Hadoop Common – The common utilities that support the other Hadoop sub – projects
·         HDFS – A distributed file system that provides high throughput access to application data
·         MapReduce – A software framework for distributed processing of large data sets on compute clusters.
·         Avro – A data serialization system.

Scp command in linux (Secure copy)

Do you need to copy some files from on Linux machine to other or from one Linux use to other user??? so here is the Linux command which you can use to copy files from one Linux machine to other only if you know the password :) for sure, as using this command you can copy file without need of any messenger of such kind of utility so i am giving this any way you can always install "iptux" using which you can transfer files inside LAN.
Any how lets talk about the command which I was talking the command is called SCP which means secure copy.

Here is the explanation about the command :

Name node or Data node not starting


If you come across these problems :
Data node not starting :

          Solution you can try :
              1.  "chown" of hdfs folderr to the current user
              2.  " chmod" of hdfs folder to 755 to the current user
              3.  delete the hdfs folder and reformat (hadoop namenode -format) if 1 and 2 does not work
     Note : Problem with data node generally occurs due to file permission.

Name node not starting

          Solution you can try:
               1. Comment out or remove the entry 127.0.1.1
               2. Check your ip/dns setting, name node problem generally related to domain/IP
              3. Also check if you name/IP you are specifying in the hadoop setting xml can be resolved. you can do this bye pinging/ or telnetting the IP/Domain you have specified for the hadoop settings.
     Note : Problem related to name node generally occurs due to domain/IP related problems.
     

Ubuntu installed inside windows maximum size 30 gb how to get more disk space


So you have installed ubuntu inside windows and due to maximum size of 30Gb restriction you are worried then let me suggest you an option to get more space without formatting or reinstalling the ubuntu.. here it is

when ever you are installing any new software, or need to store some file just create on folder in /host/somefolder  and start putting your files here, since this is the drive where you have installed the ubuntu it will have all the space available in C: or what ever drive you have installed ubuntu in. and you can use this space for what ever you want.

So Simple and easy solytion right.... :)

Find command in Ubuntu

Find (find) searches any set of directories you specify for files that match the supplied search criteria. You can search for files by name, owner, group, type, permissions, date, and other criteria. The search is recursive in that it will search all subdirectories.

 Usage: find [-H] [-L] [-P] [-Olevel] [-D help|tree|search|stat|rates|opt|exec] [path...] [expression]

uname command in ubuntu

Print certain system information.  With no OPTION, same as -s.

  -a, --all                print all information, in the following order,
                             except omit -p and -i if unknown:
  -s, --kernel-name        print the kernel name
  -n, --nodename           print the network node hostname
  -r, --kernel-release     print the kernel release
  -v, --kernel-version     print the kernel version
  -m, --machine            print the machine hardware name
  -p, --processor          print the processor type or "unknown"
  -i, --hardware-platform  print the hardware platform or "unknown"
  -o, --operating-system   print the operating system
      --help     display this help and exit
      --version  output version information and exit

sh eclipse eclipse: 5: Syntax error: "(" unexpected

Error Reason :

Your are trying to install eclipse 64 version on ubuntu 32 version,
Verify it by giving command " uname -a " at shell,

Solution :

Go and download eclipse of 32 bit version  :) simple right.....

Featured Posts

#Linux Commands Unveiled: #date, #uname, #hostname, #hostid, #arch, #nproc

 #Linux Commands Unveiled: #date, #uname, #hostname, #hostid, #arch, #nproc Linux is an open-source operating system that is loved by millio...