When I try to compile a java program with
The program 'javac' can be found in the following packages:
Try: sudo apt-get install <selected package
java version "1.7.0_21"
OpenJDK Runtime Environment (IcedTea 2.3.9) (7u21-2.3.9-1ubuntu1)
OpenJDK 64-Bit Server VM (build 23.7-b01, mixed mode)
As mentioned by @Blorgbeard you most likely do not have a Java JDK (Java Development Kit) installed. See this web page for more information about the various versions of Java available for Ubuntu.
The following command will install the OpenJDK version of the Java JDK:
apt-get install default-jdk