However, it may
be in the PATH already – especially if you are root.
Exercise 1
Attempt to write and compile the following
c++ program
#include
<iostream>
using namespace std;
int
main()
{
cout << "hello world"
<< endl;
return 0;
}
Ø Create a new file e.g. vi prog1.cc – l add ‘.cc’ to
the suffix of each program to indicate that it’s a c++ program, C programs
usually end in ‘.c’.
Ø Write the program as above.
Ø The command to run the c++ compiler is g++.
Ø To compile prog1.cc, type g++ prog1.cc –o prog1.out.
Ø List your files (type ls) and you will see a new file prog1.out
has been created.
Ø This new file - prog1.out is executable and you can run it
e.g. ./prog1.out
Ø Do a detailed listing (ls –l), compare the size of prog1.cc
and prog1.out.
ls -l prog1.out
-rwx--x--x 1 joe dcom2 710716 Mar 19 13:00 prog1.out
ls -l prog1.cc
-rw------- 1 joe dcom2 90 Mar 19 12:59 prog1.cc
#include <stdio.h>
int main(int argc, char* argv[])
{
printf ("hello world\n");
return 0;
}
Java
programs
A Linux Java JDK can be downloaded to your clone. It’s easy to write,
compile and execute simple java programs.
or alternatively google java jdk downloads
Select JDK Download
Accept the License agreement
From the list of versions -
Select jdk-7u15-linux-i586.tar.gz
This is a compressed archive and when you
click download, it will probably go to the Downloads directory in root's home.
Create a new directory for java e.g. /java and move the compressed archive
here
Decompress the file – use gzip -d
De-archive the file – use tar xvf
This should result in a directory which
contains the java jdk. Change to
this directory and go to the subdirectory bin.
Note the javac and java files. We will use these to
develop and run programs.
Add this bin directory to your PATH e.g. PATH=$PATH:/java/jdkDir/bin
(substitute the directory name for jdkDir)
Create your own java programs e.g.
public class HelloWorld {
public
static void main (String[] args) {
System.out.println
("Hello World!");
}
}
Ideally place this in your home directory (/root if you are root) using any
editor. Remember save the file with the name of the class followed by .java
e.g. HelloWorld.java.