Showing posts with label Programming Languages. Show all posts
Showing posts with label Programming Languages. Show all posts

Thursday, 6 March 2014

Difference between JDK ,JRE and JVM


Java Development Kit (JDK) 
  • it contains development tools like Java source compilers,Java debuggers
  • also contains Java libraries,bundling and deployment tools.
  • JDK is the Superset of JRE.


Java Runtime Environment (JRE):-
  • Implementation of the JVM.
  • It is an interpreter

JVM Java Virtual machine :-

  • JVM has an instruction set
  • JVM is acts like platform in which java program is executes
  • JVM translate the byteCode in to the native machine Code
  • It manupulates memory areas at run time




Which means JDK compile the Code and if you want to execute the compiled code you need JRE  (RunTime environemt) .
JVM executes and converts byte code into Native code format.

1.JAVAC Converts java source file to class file
2.Passing this .class file to class loader
3.class loader sends this file to JIT (just in time unit)unit of JRE area
4.JIT convert this class file to m/c executable form which can be directly 
executed by OS.





Thursday, 20 February 2014

Design view in Ecllipse

Windows builder option.

Windows builder option might not available in ecllipse setup
you have to explicitly download it from internet.


Inline image 1


If it is already present in eclipse then 
Right click on class file
open with windows builder.



Goto window - preferences - general - editors - file associations
choose *.jsp
and in associated editors choose "web page editor" as the first default




Wednesday, 13 June 2012

SimpleAudioPlayer in java


/*
|<---            this code is formatted to fit into 80 columns             --->|
*/

import java.io.File;
import java.io.IOException;

import javax.sound.sampled.AudioFormat;
import javax.sound.sampled.AudioInputStream;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.DataLine;
import javax.sound.sampled.LineUnavailableException;
import javax.sound.sampled.SourceDataLine;


/**    <titleabbrev>SimpleAudioPlayer</titleabbrev>
    <title>Playing an audio file (easy)</title>

    <formalpara><title>Purpose</title>
    <para>Plays a single audio file.</para></formalpara>

    <formalpara><title>Usage</title>
    <cmdsynopsis>
    <command>java SimpleAudioPlayer</command>
    <replaceable class="parameter">audiofile</replaceable>
    </cmdsynopsis>
    </formalpara>

    <formalpara><title>Parameters</title>
    <variablelist>
    <varlistentry>
    <term><option><replaceable class="parameter">audiofile</replaceable></option></term>
    <listitem><para>the name of the
    audio file that should be played</para></listitem>
    </varlistentry>
    </variablelist>
    </formalpara>

    <formalpara><title>Bugs, limitations</title>

    <para>Only PCM encoded files are supported. A-law, &mu;-law,
    ADPCM, ogg vorbis, mp3 and other compressed data formats are not
    supported. For playing these, see <olink targetdoc="AudioPlayer"
    targetptr="AudioPlayer">AudioPlayer</olink>.</para>

    </formalpara>
       
    <formalpara><title>Source code</title>
    <para>
    <ulink url="SimpleAudioPlayer.java.html">SimpleAudioPlayer.java</ulink>
    </para>
    </formalpara>

*/
public class record
{
    private static final int    EXTERNAL_BUFFER_SIZE = 128000;



    public static void main(String[] args)
    {
        /*
          We check that there is exactely one command-line
          argument.
          If not, we display the usage message and exit.
        */
        if (args.length != 1)
        {
            printUsageAndExit();
        }

        /*
          Now, that we're shure there is an argument, we
          take it as the filename of the soundfile
          we want to play.
        */
        String    strFilename = args[0];
        File    soundFile = new File(strFilename);
   
        /*
          We have to read in the sound file.
        */
        AudioInputStream    audioInputStream = null;
        try
        {
            audioInputStream = AudioSystem.getAudioInputStream(soundFile);
        }
        catch (Exception e)
        {
            /*
              In case of an exception, we dump the exception
              including the stack trace to the console output.
              Then, we exit the program.
            */
            e.printStackTrace();
            System.exit(1);
        }

        /*
          From the AudioInputStream, i.e. from the sound file,
          we fetch information about the format of the
          audio data.
          These information include the sampling frequency,
          the number of
          channels and the size of the samples.
          These information
          are needed to ask Java Sound for a suitable output line
          for this audio file.
        */
        AudioFormat    audioFormat = audioInputStream.getFormat();

        /*
          Asking for a line is a rather tricky thing.
          We have to construct an Info object that specifies
          the desired properties for the line.
          First, we have to say which kind of line we want. The
          possibilities are: SourceDataLine (for playback), Clip
          (for repeated playback)    and TargetDataLine (for
          recording).
          Here, we want to do normal playback, so we ask for
          a SourceDataLine.
          Then, we have to pass an AudioFormat object, so that
          the Line knows which format the data passed to it
          will have.
          Furthermore, we can give Java Sound a hint about how
          big the internal buffer for the line should be. This
          isn't used here, signaling that we
          don't care about the exact size. Java Sound will use
          some default value for the buffer size.
        */
        SourceDataLine    line = null;
        DataLine.Info    info = new DataLine.Info(SourceDataLine.class,
                                                 audioFormat);
        try
        {
            line = (SourceDataLine) AudioSystem.getLine(info);

            /*
              The line is there, but it is not yet ready to
              receive audio data. We have to open the line.
            */
            line.open(audioFormat);
        }
        catch (LineUnavailableException e)
        {
            e.printStackTrace();
            System.exit(1);
        }
        catch (Exception e)
        {
            e.printStackTrace();
            System.exit(1);
        }

        /*
          Still not enough. The line now can receive data,
          but will not pass them on to the audio output device
          (which means to your sound card). This has to be
          activated.
        */
        line.start();

        /*
          Ok, finally the line is prepared. Now comes the real
          job: we have to write data to the line. We do this
          in a loop. First, we read data from the
          AudioInputStream to a buffer. Then, we write from
          this buffer to the Line. This is done until the end
          of the file is reached, which is detected by a
          return value of -1 from the read method of the
          AudioInputStream.
        */
        int    nBytesRead = 0;
        byte[]    abData = new byte[EXTERNAL_BUFFER_SIZE];
        while (nBytesRead != -1)
        {
            try
            {
                nBytesRead = audioInputStream.read(abData, 0, abData.length);
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
            if (nBytesRead >= 0)
            {
                int    nBytesWritten = line.write(abData, 0, nBytesRead);
            }
        }

        /*
          Wait until all data are played.
          This is only necessary because of the bug noted below.
          (If we do not wait, we would interrupt the playback by
          prematurely closing the line and exiting the VM.)
       
          Thanks to Margie Fitch for bringing me on the right
          path to this solution.
        */
        line.drain();

        /*
          All data are played. We can close the shop.
        */
        line.close();

        /*
          There is a bug in the jdk1.3/1.4.
          It prevents correct termination of the VM.
          So we have to exit ourselves.
        */
        System.exit(0);
    }


    private static void printUsageAndExit()
    {
        out("SimpleAudioPlayer: usage:");
        out("\tjava SimpleAudioPlayer <soundfile>");
        System.exit(1);
    }


    private static void out(String strMessage)
    {
        System.out.println(strMessage);
    }
}

8080 port number has encountered some problem ....


   While running the .jsp,.html,.js any web program on the eclipse through tomcat .If you are facing the problem like ...
8080 port number has encountered some problem ....

this means 8080 port has been used by any other web services...
then don't take any tension

1.Go to the run/console prompt of the ecllipse..


2.select the server
3.Double click on it..
4.Are you able to see port option.............................(if not mail me.....)
5.change the HTTP /1.1  port number to 8085 or any port number you want
Run it again....

2]

                      If you are using standalone tomcat server without any IDE like ecllipse and you are facing the port problem.i.e
same problem:port number has been used by another service ...............oh then it is serious problem........not at all...

Solution:-
1.Go to apache tomcat installable  search for the server.xml file....
In my machine it is in
              C:\apache-tomcat-6.0.32\conf\server.xml

2.edit the server.xml file

3.search for the following string..
              <Connector port="8089" protocol="HTTP/1.1" >
change the port number, you like .
4.Run the pages...


Note:If you want to add anything extra ,If you have any doubt then reply back...

C program without main keyword


Hello, 
                   Save the following program as *.c and run it.


//simple c program:-


#include<stdio.h>
#define usethis(h,c,e,t,o,p,q)t##e##c##h
#define begin usethis(n,i,a,m,a,t,p)
int begin()
{
printf("Program without main keyword...\n");
}

                    
Are u able to see the output.

Reason:-
1]## operators acts as token merging operator..we can merge two or more character in it.

2]#define usethis(h,c,e,t,o,p,q)t##e##c##h

The macro usethis(h,c,e,t,o,p,q) is being expanded as "tech" (the ## operator merges t,e,c & h into tech).
The logic when you pass (h,c,e,t,o,p,q) as argument it merges the 4th,3rd,2nd & 1st chacter

3]Now see the #define begin usethis(n,i,a,m,a,t,p)

The preprocessor macro begin replaces with expansion of the usethis(n,i,a,m,a,t,p)
The argument must be expanded so that that  4th,3rd,2nd & 1st character must be merged.

In the argument (n,i,a,m,a,t,p)  4th,3rd,2nd & 1st character are 'm','a','i','n'
thats it.

Cool Blue Outer Glow Pointer