Tuesday, August 2, 2011

Creating First Java Application

Basic steps to creating your first Java Application:

(1) Create a file name JavaProgramming.java. To do this, you can start by using Notepad and write your own source code or alternatively copy the source code below and save it. ( Note that the file name is case-sensitive)

(2) Sample source code:

/*
* Welcome to Java Programming
*/

//class definition
public class JavaProgramming {

//main method definition
public static void main(String args[])
{

//print out Welcome to Java Programming!! Big Achievement!!
System.out.println("Welcome to Java Programming!! Big Achievement!!");
}

}

(3) Before you run any Java Application, you would need to compile the source code by using javac command.For example at your operating system’s command prompt (such as the DOS prompt), type javac JavaProgramming.java


If you face any problems such as



'javac' is not recognised as an internal or external command, operable program or batch file. This is a commanly known issue as you may have not specify the PATH correctly during installation.Basically,you would have to find where you have installed the jdk(version no.) file and the bin directory and execute the command.

Eg:
C:\Java\jdk7.0.1\bin>javac JavaProgramming.java



Once completed, you have successfully converted your source code into Java byte code.The file extension for Java byte code is .class. Thus, you should see a new file named HelloWorld.class created by the Java compiler in the same directory as the source code file.

Final step is to run the file. To do this, just type java JavaProgramming

And you should be able to see the screen shot below:



Congratulations!! You have successfully created your first Java Program !!

No comments:

Post a Comment