Introduction to Java

Java is a programming language for the internet and was developed by Sun Microsystems. It’s completely object-oriented and more flexible than C/C++. You can perform two type of Programming work with java. First is general applications and the second applets. However, applications are not as much developed by using java. Programmers use java to design applets which can be transported via the internet. You can use java enabled browsers like Microsoft Internet Explorer or Netscape Navigator to View your applets.

In order to develop Java Applets and Applications you need a java compiler, and runtime environment which is called JDK (Java Development Kit) and can be downloaded from Sun’s website. You can download new versions from Sun’s site any time. Java programs can be run in Windows 98, Windows NT, Window XP, Window Vista, Windows 7 and Solaris 2.3 or higher machines.

According to Sun’s definition Java is Simple, Object-oriented, Distributed, Interpreted, Robust, Secure, Architecture neutral, Portable, High performance, Multithreaded, Dynamic language.

Basic theory behind every Java program

Programs source codes are written using editors, for example MS-DOS Editor which comes with Windows or Preferably Notepad. Once the source codes are written it is saved with an extension .java. The code is then compiled by using java compiler which will convert the java program into a byte code file with .class extension. Then the program is run using Java interpreter which is called java. The whole point will be clear to you after you understood your first program which is explained below:

Your First Java Program

Open your editor and enter the following code:

<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"><span style="color: #0000ff;">class</span> hello {
<span style="color: #0000ff;">public</span> <span style="color: #0000ff;">static</span> <span style="color: #0000ff;">void</span> main (String args[]) {
System.out.println("<span style="color: #8b0000;">Hello ,This is my first java program!</span>");
}
}

Save the file as Hello.java. Note that the file name and class name should be similar. Compile the program by using the command in the DOS prompt.

<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;">javac Hello.java
 

If you are having any errors the compiler will report the same otherwise a Dos prompt will be seen. A file name called Hello.class is created now. Now you can execute your java program by typing java Hello on the command line. The program displays the following output

<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;">Hello, This is my first java program!
 

Notes

The compile command varies from each machine. If you have set the correct path, then you should have no trouble in compiling and executing the Program. Please refer to the documentation (readme file) that comes with the JDK for installation instructions.

READ  5 Ways to Keep Visitors Coming Back

Leave a Reply

Your email address will not be published.