Monday, 27 May 2013

How to make your own linux command


Hey guys....  Wanna create your own Linux command ???

Well, that's so simple:-)

Step 1 : First write a program
     
                                          ex:           #include<stdio.h>
                                                          int main()
                                                          {
                                                                    printf(" This is your new command" );
                                                                    return 0;
                                                           }

         
 Once the program is ready save it and compile it to get a.out file
 The output of a program will be your command output so, write program according to what                           you want your command should output..


Step 2 
: Place your executable file (a.out)  in "/usr/bin" path where all the binary files will be present as follows, before that you can change the name of the a.out to any name you like ...

               I have changed to "mycommand" using following command
                                                             
                                                                  gcc -o  mycommand  myprogram.c
                                                

                                                command: sudo cp mycommand  /usr/bin


Step 3 : Now execute "mycommand" as you use to do with built in Linux commands.



Congrats !!! You now have your own command



Download the complete source code from here

Feel Happy:-) and please leave your doubts or suggestions in comments section..

Instructions to compile and execute C/C++ program in linux




Step 1 : To compile any C/C++ program, C/C++ compiler like gcc or g++ are required, if you do not have  
              one you can download it by just typing below mentioned command in the terminal,

                                                  For C :      sudo  apt-get  install  gcc
                                                 For C++ :   sudo  apt-get  install  g++


Step 2 : Having downloaded C/C++ compiler, compile your program as

                                                  For C :       gcc  myprogram.c
                                                 For C++ :   g++  myprogram.cpp


Step 3
: Now since your program compiled successfully, a file by the name a.out being generated,                          
              which is your executable file. In order to execute this type
           
                                                                            ./a.out
             

As like me, I hope that you too don't like the name of your executable file to be a.out. In order to          
             give your own name for the executable file, type the following command in the terminal

                                              gcc  -o  <the name you wish to give>  <filename>



             ex:- gcc  -o  jamesbond  myprogram.c

             Now your executable file is jamesbond rather than a.out which can be executed as    

                                                                        ./jamesbond                     
             
             Note : use .c extension to store C files and .cpp for C++ files


Leave your doubts or suggestions in comments section..

C implementation of wc(word count) linux command


Type the below program as it is to implement wc command

int main(int argc , char *argv[])
{
 int character_count = 0;
           int space_count = 0;
           int word_count = 0;
           int line_count = 0;
           char ch;

           FILE *fp;

           if(argc == 0)
           {
   printf("Please specify the filename as argument\n");
                      exit(0);
           }

            if(fp != 0)
           {
                       printf("No such file or directory\n");
                       exit(0);
           }
           fp = fopen(argv[1],"r");

           while((ch=fgetc(fp))!=EOF)
           {
                       character_count++;
                       if(ch == ' ')
                       {
                             space_count++;
                             word_count++;
                       }
                       if(ch == '\n')
                       {
line_count++;
                       }
           }
           printf("character_count = %d\n",character_count);
           printf("space_count = %d\n",space_count);
           printf("word_count = %d\n",word_count+1);
           printf("line_count = %d\n",line_count);


}

Follow this to compile and execute the above  program


Step 1 : To compile any C/C++ program, C/C++ compiler like gcc or g++ are required, if you do not have
              one you can download it by just typing below mentioned command in the terminal,

                                                  For C :      sudo  apt-get  install  gcc
                                                 For C++ :   sudo  apt-get  install  g++


Step 2 : Having downloaded C/C++ compiler, compile your program as

                                                  For C :       gcc  myprogram.c
                                                 For C++ :   g++  myprogram.cpp


Step 3 : Now since your program compiled successfully, a file by the name a.out being generated,                        
              which is your executable file. In order to execute this type
         
                                                                            ./a.out
             

As like me, I hope that you too don't like the name of your executable file to be a.out. In order to          
             give your own name for the executable file, type the following command in the terminal

                                              gcc  -o  <the name you wish to give>  <filename>



             ex:- gcc  -o  jamesbond  myprogram.c

             Now your executable file is jamesbond rather than a.out which can be executed as  

                                                                        ./jamesbond                     
             
             Note : use .c extension to store C files and .cpp for C++ files


To make this code as a wc command , follow this



Step 1 : Save the program and compile it to get a.out file
             
Step 2 : Place your executable file (a.out)  in "/usr/bin" path where all the binary files will be present as    
              follows, before that you can change the name of the a.out to any name you like ...

               I have changed to "mycommand" using following command
                                                           
                                                                  gcc -o  mycommand  myprogram.c
                                         

                                                command: sudo cp mycommand  /usr/bin


Step 3 Now execute "mycommand" as you use to do with built in Linux commands.


You can download the source code from here

Leave your doubts or suggestions in comments section..

Starting with JavaFX


Hi Folks,,,,  The much awaited feature from java and my favorite topic comes here

Yes!!! Its JavaFX from java to build rich user interfaces much better than swings and a most powerful framework ever:-)

Well learning and understanding it, is little tricky at beginning but bet me, as you learn more about it You will LOVE it (Take my word for it)

Want to know the power of JavaFX?????? Here we go...

1.Can build rich user interfaces

2. Some complex interfaces can be built easily

3.     JavaFX Scene builder helps to drag and drop the features

4.    XML based very easy to build web user interfaces

5.     Task and worker concept similar to threads but developed in view of designing interface, to update it dynamically

6.     It continues guys !!!!  

Lets Get into JavaFX

1.     First and foremost is, your Java should be configured properly with the version higher than Java 16

2.    You can get latest version from here and follow this post to verify and configure Java properly

3.     Next comes NetBeans IDE.. Get latest version of it (am using 7.3version) from here (As JavaFX JavaFX Scene builder can easily be integrated with Netbeans) and Select JavaSE - 80Mb

4.    Now get latest version of JavaFX  from here (JavaFX !!!) YES! Don’t be surprised you are yet to get more :P. (am using JavaFX 2 with Java 17) 

And guys, do remember
 JavaFX needs separate JDK... So if you have java then download Stand alone else download bundle of JavaFX with Java. (Latest version of Java has JavaFX built in, so     
no worries if you have latest one)

5.     Also get JavaFx Scene builder from here (As it still need to be made better) Scroll down

6.     That’s all, don’t be scared, nothing more to download so chill and  install all the above in this    order – JavaFX,JavaFX Scene Builder,NetBeans

Note: While installing NetBeans you may get warnig saying your java version should be higher than 16, as i said download latest version and point your netbeans to java and ignore the warning if it still exits


7.     Done?? Ok now, open NetBeans IDE
Integrate your installed JavaFX Scene Builder with Net Beans

8.     Goto Tools-> options in NetBeans

9.     Goto JavaFX tab under that select the JavaFX Scene Builder by browsing or if it appears already select it and click ok

10. Now, File -> New Project dialogue box appears

11. Select JavaFX->JavaFX FXML Application Project and click Next

12. Give your Project name and make sure platfrom is JavaFX and click finish 

13. Thats all!!! Now click run or Run-> run applicationXX

14. You can see your first JavaFX project running :)

15. To edit your front end browse your project and double click or open Sample.FXML 

16. It gets opened in JavaFX Scene Builder now edit it and Save it 

17. Run again to see the changes or right click on Sample.FXML and select edit the file which will be opened directly in NetBeans, now you can see the changes

18. Use Samplecontroller.java file to create events for your elements added in Sample.FXML(you can see the sample event)

Thats it read both Sample.FXML and Samplecontroller.java file and try to create good Interfaces :)




Leave your doubts or suggestions in comments section..

Sunday, 26 May 2013

Java Server Pages


JavaServer Pages (JSP)
                                            is a technology that helps software developers create dynamically generated web pages based on HTML, XML, or other document types.

1. The system pre requisites for working with JSP is to have your java environment and tomcat server set
                       
                          follow this post to set java environment and
                                    this post for tomcat

     If you are done, then come on.. explore yourself into cool stuffs :-)

2. The developer pre requisites for working with JSP is to have knowledge of java and HTML 

    Well you need not be an expert. Just go through this post and come back


Your First JSP program

1. Type the below given program in the text file

                         <HTML>
                                <BODY>
                                        Hello Developer !!!
                                </BODY>
                         </HTML>

2. Save the file with .jsp extension in the below path where all your .class and .jsp files should be    
    present

                           /apache-tomcat-7.0.37/webapps/ROOT/

3. In order to execute the program, you need to start your tomcat server, its so simple 
 
       - open your terminal and traverse  to the bin folder in tomcat which you had 
          downloaded by following this post
 
       - type ./catalina.sh start and ./catalina.sh stop to stop the server
 
     Example : root@localhost:/home/vignesh/Desktop/apache-tomcat-7.0.37/bin# ./catalina.sh start
 
     Note: Once you have started the catalina server, you can verify it by typing 
                                                  
                                                    http://localhost:8080 
               on the address bar of your browser.

               Tats it !!!!! 
 
4. Now, from browser open the file you just created :-) Yeah its you who did it !!!!!
 

But I guess you may be wondering what's the difference between 
HTML and JSP??? well  

HTML is client side but JSP is server side. 

confused?? relax
  • HTML provides a means to describe the structure of text-based information in a document - by denoting certain text as links, headings, paragraphs, lists, and so on.

  • The JSP syntax adds additional XML-like tags, called JSP actions, to be used to invoke built-in functionality.


Please leave your doubts or suggestions in comments section..

Using Xampp to install apache to use PHP , MySql


Xampp - 
                   cross platfrom software bundle to  install Apache webserver, MySql database management system and PHP server side scripting language.

 Xampp is a open software platform to install apache, tomcat, mysql

If you are using any Linux distributions follow this post to install apache for php and mysql with or with out Lampp

1. Download xampp from here.

2. Install xampp by double clicking and remember where you are installing it

               (I have installed it in c:\xampp)

3. Goto-> start and type xampp control panel or find Apache Friends in Start->Programs and select    
    xampp control panel

4. Good! you are almost done, xampp has every thing you need, you just need to pick up what you   
    want!
Apache webserver, installing Apache in windows, installing mysql in windows, installing php in windows, Lampp, MYSQL, PHP, server side scripting, tomcat, Xampp, Xampp in windows,


    The right mark under Services indicates the following service is been installed .

  •     In my above xampp, Apache and MySQL are installed and running on port numbers 80,443 and 3306  (It may vary in your system)
  • The Tomcat have been installed but its not running (As It is not required right now!)
  • The FileZilla has not been installed (It is not required at all :P)
  • The Mercury we need additional things to be done to run it
  • Click the “X” mark under services to install and “right mark” to uninstall any service
  • To start/stop any service click the button which is under Action.

     1. To test php just type 127.0.0.1 or http://localhost in your browser and you will see index of php    
         files or success message from Apache. That’s all, your done with apache. 
     
     2. To see complete information about php, try this:-
                                       In xampp control panel click admin button of Apache module under actions

          That’s the phpadmin page where you can see complete information about php
      3. Now, the question is where to save php files ?

          Wait! Go to your installed xampp directory ex: C:\xampp\htdocs
          Save all your php files here

      4. Then open browser and type 127.0.0.1/yourfilename.php or http://localhost/yourfilename.php
      5. Now the other question is How to open mysql ?

          Well every question have an answer, do this :

  •           Open command prompt
  •           Change directory to your xampp->mysql->bin installed directory
                                              cd  C:\xampp\mysql\bin
  •          Now type
                                             mysql –u root –p (if you changed password then it asks for passwords! )

                  Then you will get your MySql prompt like this,
 
                                             Mysql>

Although i have mentioned about Tomcat, for understanding and using tomcat

                refer this post Using Xampp to install apache-tomcat
                        to use JSP, Windows users and linux users refer this post


Leave your doubts or suggestions in comments section..

Saturday, 25 May 2013

Installing tomcat in linux


Welcome Folks.. This post will guide you in the installation and configuration of the apache tomcat server

In order to work with the tomcat server, you need to have the Java environment set, if you haven't done it yet then follow this post


Installation and configuration of the apache tomcat server

Steps to download and install the tomcat server

Step 1 : Download the tomcat sever from http://tomcat.apache.org/ .
             Once downloaded, you should have a folder named 

                                           apache-tomcat-6.0.29.tar.gz (similar to this).

Step 2 : Extract the folder you just downloaded by using the below command
                                          
                                           tar -xvfz apache-tomcat-6.0.29.tar.gz

Step 3 :  Now the next step is to set up the paths for catalina as below

export CATALINA_HOME=/location where you have extracted the tomcat

 ex : export CATALINA_HOME = /home/vignesh/Desktop/apache-tomcat-7.0.37

 Add the following lines to your /etc/profile file so that it can set the CATALINA_HOME variable automatically when the system restarts.

profile 

Step 4 : Run the following command to start the Tomcat server: 
      
                        $CATALINA_HOME/bin/startup.sh 

Step 5 : Verify that the Tomcat server is running by browsing to

                        http://Your_IP_Here:8080/

        ex : http://localhost:8080 on doing this, you should see something like below

APACHE, catalina, configuring apache tomcat server, Installing tomcat in linux, java environment, jsp, server, tomcat, webapps,
 

Congratulations you have now installed the TOMCAT SERVER successfully !!!

let us have a check by running a simple program


1. Type the below given program in the text file

                         <HTML>
                                <BODY>
                                        Hello Developer !!!
                                </BODY>
                         </HTML>

2. Save the file with .jsp extension in the below path where all your .class and .jsp files should be  
    present

                           /apache-tomcat-7.0.37/webapps/ROOT/

3. In order to execute the program, you need to start your tomcat server, its so simple 
 
- open your terminal and traverse to the bin folder in tomcat which you had downloaded by 
following this post
 
- type ./catalina.sh start and ./catalina.sh stop to stop the server
  
Example:root@localhost:/home/vignesh/Desktop/apache-tomcat-7.0.37/bin# ./catalina.sh start
 
Note: Once you have started the catalina server, you can verify it by typing  
 
http://localhost:8080 on the address bar of your browser.Tats it !!!!! 
 
4 . Now from the browser open the file you just created . 

    Example : http://localhost/apachetesting.jsp

    You should see the text Hello Developer on your browser.




Leave your doubts or suggestions in comments section..

Installing LAMP in LINUX


L - LINUX (the OS)  

      A - APACHE ( the Web server )  

             M - MYSQL ( the database management system ) 

                     P - PHP

LAMP can be installed with just one command 



sudo apt-get install lamp-server
  
But if you want to know what exactly is happening, go through the entire post 
 

Installing Lamp Server components individually

 
STEP 1 : Installing APACHE

Open the terminal (ctrl+alt+t) and type the below command .

sudo apt-get install apache2 .

(if asked to enter the password , type it and press enter) .

 Now let us check whether apache has been installed successfully .

 Open any web browser and enter http://localhost/ in the address bar .
                                              
                                (you should see the page as in the image below) .
APACHE, database management system, install apache, install MySQL, install php, Installing LAMP in LINUX, LAMP, libapache, LINUX, MYSQL, PHP, phpinfo, phptesting, sudo, ubuntu, web server,

Congrats you have now installed APACHE !

STEP 2 : Installing PHP

Open the terminal (ctrl+alt+t) and type the below command

 sudo apt-get install php5 libapache2-mod-php5

 (you will be asked to enter the password , type it and press enter)


For  PHP to work correctly and be compatible with apache , we need to restart it , it can be done using command


sudo /etc/init.d/apache2 restart


Now let us check whether php has been installed successfully, to do this, type the following command in the terminal

                                                                                      
                                        sudo /var/www/phptesting.php

Type the following line in the phptesting.php file that has been opened

<?php phpinfo(); ?> 


(this will show you a page having the details of PHP as in the image below) 

APACHE, database management system, install apache, install MySQL, install php, Installing LAMP in LINUX, LAMP, libapache, LINUX, MYSQL, PHP, phpinfo, phptesting, sudo, ubuntu, web server,

Congrats you have now installed both APACHE and PHP !!

STEP 3 : Installing MYSQL


 In the terminal (ctrl+alt+t) type the below command

                   sudo apt-get install mysql-server

 (you will be asked to enter the password , type it and press enter) .



 Enter the user name and password  that you wish to use for mysql .


Once done with the installation, you can verify the successful installation by typing the below command .

                    mysql -u <username> -p


Congrats you have now installed APACHE, PHP and MYSQL !!!

As an alternative you can use the below command for quick installation :-)


sudo aptitude install apache2 php5 mysql-server php5-mysql libapache2-mod-php5


Leave your doubts or suggestions in comments section..

Wednesday, 22 May 2013

Setting up android in Ubuntu unix or linux




-> Know whether you have installed 32 bit or 64 bit operating system by typing the following in the Terminal (to open the terminal type ctrl+alt+T)

                                                        Command : file /sbin/init


        If your OS is 32 bit then you should see something similar to the below 2 lines
 
         /sbin/init: ELF 32-bit LSB shared object, Intel 80386, version 1 (SYSV), dynamically linked (uses shared libs), for     
         GNU/Linux 2.6.15, stripped

 
       If your OS is 64 bitthen you should see something similar to the below 2 lines
 
         /sbin/init: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for    
          GNU/Linux 2.6.15, stripped

-> If you have Java installed already then carry on with the following steps else get Java installed by following this post

-> Once you have Java , the next step is to  download the adt bundle from here.
     Click on Download Sdk and select I Agree and then select your 32 bit or 64 bit according to step 1.


  1. Extract it where ever you want.

  2. now open that folder as it will be adt-bundle-linux-x86-20130219 (similar to it)

      you should see two folders sdk and eclipse

  3. go to eclipse find eclipse.exe and double click


That's all now every thing is ready for you ...



For creating your first android project go here.


Leave your doubts or suggestion in comments section ....

Setting up java in linux

Check if you have Java installed on your system. To do this, you have to run the Java version command from terminal.

                                                          Command :  java -version 

If java is already present in your system then you will see something like the below

                                   Java HotSpot(TM) Server VM (build 23.6-b04, mixed mode)
 
If you don't have java installed then you can install it by following this post

-> Download the Oracle Java JDK/JRE for Linux from here.

    Make sure you select the correct compressed binaries for your system architecture 32-bit or 64-bit  
    (which end in tar.gz).

-> Copy the Oracle Java binaries into 
                                                 /usr/local/java directory

     In most cases, the Oracle Java binaries are downloaded to:
                                                /home/"your_user_name"/Downloads

-> Once you have downloaded , the next step is to install it. The following lines will guide you in the  installation process.


Installation instructions for 32-bit Oracle Java on 32-bit Ubuntu Linux
    
Type the following commands in the terminal

1. Command to traverse to the location where you have downloaded the Oracle java binaries
cd /home/"your_user_name"/Downloads  

2. Command to copy the downloaded jdk into an appropriate location for easy installation and configuration

sudo cp -r jdk-7u21-linux-i586.tar.gz /usr/local/java  

3. Command to copy the downloaded jre into an appropriate location for easy installation and configuration 
  
sudo cp -r jre-7u21-linux-i586.tar.gz /usr/local/java

4. Now traverse to the directory where you have copied the jre and jdk by typing the following command. 

cd /usr/local/java


Installation instructions for 64-bit Oracle Java on 64-bit Ubuntu Linux
Type the following commands in the terminal

1. Command to traverse to the location where you have downloaded the Oracle java binaries


cd /home/"your_user_name"/Downloads  

2. Command to copy the downloaded jdk into an appropriate location for easy installation and configuration
sudo cp -r jdk-7u21-linux-x64.tar.gz /usr/local/java  

3. Command to copy the downloaded jre into an appropriate location for easy installation and configuration 
  
sudo cp -r jre-7u21-linux-x64.tar.gz /usr/local/java

4. Now traverse to the directory where you have copied the jre and jdk by typing the following command. 

cd /usr/local/java


The next step is to Unpack the compressed Java binaries, in the directory /usr/local/java
For 32-bit : Type the following commands


sudo tar xvzf jdk-7u21-linux-i586.tar.gz 
sudo tar xvzf jre-7u21-linux-i586.tar.gz

For 64-bit : Type the following commands

 sudo tar xvzf jdk-7u21-linux-x64.tar.gz 
sudo tar xvzf jre-7u21-linux-x64.tar.gz

By now, you should have two uncompressed binary directories in /usr/local/java for the Java JDK/JRE
Type ls -a to check it  , it should display as shown below
jdk1.7.0_21  
jre1.7.0_21

Now Edit the system PATH file /etc/profile and add the following system variables to your system path

note:- you can use nano, gedit or any other text editor, as root, open up /etc/profile. 

For gedit: Type the following command
sudo gedit /etc/profile


For nano: Type the following command
sudo nano /etc/profile

Scroll down to the end of the file using your arrow keys and add the following lines to the end of your /etc/profile file:

JAVA_HOME=/usr/local/java/jdk1.7.0_21 

PATH=$PATH:$HOME/bin:$JAVA_HOME/bin

JRE_HOME=/usr/local/java/jre1.7.0_21 

PATH=$PATH:$HOME/bin:$JRE_HOME/bin

export JAVA_HOME

export JRE_HOME

export PATH

Save the /etc/profile file and exit. 

Reload your system wide PATH /etc/profile by typing the following command:


. /etc/profile


leave your doubts or suggestions in comments section..