Write Java code to count number of nodes in a binary tree?

int countNodes(Node root)
{
int count = 1; //Root itself should be counted
if (root ==null)
return 0;
else
{
count += count(root.left);
count += count(root.right);
return count;
}
}