Sunday, January 9, 2011

Introduction to JAVA

A programming language is an artificial language designed to express instructions that can be performed by a machine , computer.
JAVA is 4th generation programming language.
James Gosling is generally credited as the inventor of the JAVA programming language in 1994. He create the original design of JAVA and implemented its original compiler and virtual machine.
JAVA is original platform independent programming language and was called 'OAK' and later renamed 'JAVA' in 1995.
Today JAVA owns by ORACLE.


Click here for more information about JAVA history 
http://www.java.com/en/javahistory/   


JAVA Architecture



JAVA program Patterns

  • Stand Alone application
  1.  Application with GUI(awt/swing) 
  2. JAVA programs which run in command console.
  • Web based JAVA applications
  1. Applets
  2. Servlets
  3. JavaServer pages
JAVA Platform Editions
  • Java Micro Edition (JAVA ME)
  • Java Standard Edition( JAVA SE)
  • Java Enterprise Edition(JAVA EE)

  • JVM (Java virtual machine) - 
JVM is a part of both the JDK and JRE that translates JAVA byte codes and execute them as the native code on the client machine.  

  • JRE(Java runtime Environment)
It is the environment provided for the JAVA programs to get executed.
  • JDK(Java development Kit)
JDK contains tools needed to develop the JAVA programs
ex-: javac , java ,javadoc etc..


  • JAVA SDK(Java software development kit)
SDK comprises a JDK an extra software such as application server ,  debuggers.


If you are  interesting to get more information about JAVA goto this link


Now I demonstrates you  how to write a simple JAVA program

Example 1

Create a folder on your desktop and name it as JAVA.
Then open a notepad and type this program.

class First{

         public static void main(String args[]){

                System.out.println("My first JAVA program");
         }
}


Save the program in your desktop JAVA folder as "First.java"

Now open your command prompt and type following commands to get into the JAVA folder you have created. 


Then Type javac First.java and press enter to compile your program. If you have compile errors recheck your coding. If you don't have any compile error it will display like this. 

Then the compiler would create java byte code. These files have an extension of   .class

To run your program you need to call java interpreter.
To call interpreter type    java First

 

Now you can see the output of your first java program.
Now you know how to display words.

  • In java everything must code in side a class
  • public static void main(String args[])  is the main method and the starting point of your program. (you have to remember this line )
  • { } these shows us scopes we have
  • ; indicates end of a statement. 
  • System.out.println(" "); print command in JAVA , whatever in quotations will be printed as it is.

Question 1

Write a program to print yourself.

Question 2

Write a program that draws the following figures 

                                                      **
                                                    *****
** ****************                     *********
******************                    ************   
******************                  ***************
******************                 *****************
******************                *******************
******************              **********************


Thank you 

-Tharindu Dilshan-

  •  






No comments:

Post a Comment