It is not simple as we compile and RUN the C/C++ program, to compile and run the java program, we have to follow some steps. Here I tell you how to Compile and Run the JAVA program in 3 easy steps. 1st step : write the java program 2nd step : how to compile java program 3rd step: how to run the java program So lets start!!
1st Step…
write the JAVA program!
Before this, read the above tutorial (2nd e-tutorial by GTUExam.in) for “how to download JAVA in Computer [JDK 7]”, if you have not installed the JDK in your computer else continue reading.
The 1st step is very simple, to write JAVA program, open you’re Notepad (start menu ⇒ accessories ⇒ Notepad. Or go to run ⇒ type Notepad ⇒ hit enter.), write a simple java program. For example, if I want to display my name, for that I have to write the following code:
The program code will looks like this:
// my first Java program!
class hello
{
public static void main(String[] args)
{
//this will display your name in terminal window
System.out.println ("My name is Vicky Sadhu!");
// you can write your own name too :)
}
}
Now save this file, the code you written in notepad. While you about to save this file kindly note that the file name must be same as the class name (i.e. hello) and the file extension must be “.java” (i.e. hello.java). The default extension in notepad is .txt, that file will not support by JDK.
Note: You can download and use Textpad (@ Textpad.com). By help of this editor, you can compile and run the java program in same editor (like we do in c/c++),else follow the step if you want to go with JDK 7.
2nd step…
how to compile the JAVA program?
In this step you will learn how to compile the java source code. To compile the java code, go to start menu and select “RUN” (or use windows key and press “r”). Here you will see you will see the "Run Dialog Box". Now type cmd and press “ok”. Like below screen shot shows.
RUN Terminal window |
Most of the programs that you run on your computer are windowed applications (i.e. they just show their window, ultimately they run on the windows terminal window). they work inside a window that you can move around on your desktop. The “Hello” program is an example of a console program. It does not run in its own window, so it has to be run through a terminal window instead. A terminal window is just another way of running programs stored on your hard drive.
Back to the point, by clicking on “ok” in Run, the JAVA compiler window will open.
So to compile the java program here, it bit confusing but I solve it for you. The compiler that compiles the java program is called the “javac” compiler. The “javac” will translate the code you written in notepad and convert it in java (machine) language.
3rd step…
How to Run the JAVA program?
To run the particular java file, you have to follow the following step:
1. Type “cd..” and hit enter on the terminal window.
2. Again type “cd..” and hit enter.
3. Type drive name, where you stored the java file (i.e. if you have stored it in D drive, write D: and enter, if you have stored file in D: drive’s any other folder, give the full path)
4. Now write javac filename.java (i.e. hello.java).
5. Now write java classname and hit the enter. (write the classname that you want to run, i.e hello.)
6. You can see the output of the above class is “My name is Vicky Sadhu!”.
(note: this will only for JDK, it will not work for any other java platform!)
That’s all, it is simple to compile and run the java program, if you follow the proper step. If you have any problem, write it to me by commenting bellow, I will help you best!
All the Best!!
via our partner site: GTUExam.in
{ 0 comments... read them below or add one }
Post a Comment