Wednesday, June 23, 2010

How to run a Java program in Linux

Java (JDK) installation:
Download the latest jdk from sun's website http://java.sun.com/javase/downloads/index.jsp
e.g.; 
jdk-6u20-linux-i586.bin

now make this bin file executable.
chmod +x jdk-6u20-linux-i586.bin
To execute the bin file, type
./jdk-6u20-linux-i586.bin
Agree the License agreement. It will extract the content of bin file into a directory named jdk1.6.0_20
rename this directory to jdk1.6
mv  jdk1.6.0_20  jdk1.6
Now move this directory to /usr/share/
sudo mv jdk1.6 /usr/share/
set path to the java bin directory
export PATH=$PATH:/usr/share/jdk1.6/bin
or make it permanent in .bashrc file of your user's home directory
vim .bashrc
export PATH=$PATH:/usr/share/jdk1.6/bin
save and close this file
reread .bashrc file using source command
source .bashrc
Write a program in java: 
Open your favorite editor in Linux. Type a sample Hello world program 
/*
java Hello World example.
*/
class HelloWorldExample 
{ 
public static void main(String args[]) 
{ 
/* 
Use System.out.println() to print on console. 
*/ 
System.out.println("Hello World !"); 
} 
} 
/* 
OUTPUT of the above given Java Hello World Example would be : 
Hello World ! 
*/ 
Save it as HelloWorldExample.java
Now compile it
javac HelloWorldExample.java
it will create a file named HelloWorldExample.class. Now you can run the HelloWorldExample.class file.
java HelloWorldExample
*** Important!!!!! this is HelloWorldExample not HelloWorldExample.class

  
   

Monday, June 7, 2010

How to run a C program in Linux

To run a C program in Linux:

1. Verify the gcc program is installed on system
gcc --version

2. Write a test program
cat > mycprog.c
#include <stdio.h>
     int main (void)
        { printf ("My C Program \n");
            return 0;
         }

Save the program using ^D

3. Compile the C program
gcc mycprog.c

The output will be a.out compile file. Now run the compiled file by typing
./a.out

Output of a C program can be renamed
e.g.;
gcc mycprog.c -o firstprog

Now execute as
./firstprog

  

Friday, June 4, 2010

bash: rsync: command not found

problem: 
bash: rsync: command not found
          rsync: connection unexpectedly closed.......
          rsync error: remote command not found code (127) at ioc

solution: 
rsync should be installed on both the local and remote computer
To install rsync:
yum install rsync

if rsync installed in both local and remote machines it is complaining about rsync unavailability. What happened here is that it was not able to find rsync in standard path in remote machine. The solution for this problem is:
         --rsync-path=/path/to/rsync
In this type of problem we need to explicitly suggest the rsync path of remote machine through  --rsync-path argument.