Example
Class = Simple
class Simple{
public static void main (String args[]){
System.out.println("Hello World");
}
}
Sketch
Copy the following java codes and replace data printed in green. Then run the java program.
class Simple{
public
static void main (String args[]){
System.out.println("Hello World");
}
}
How to compile and run the above program using command prompt
Copy the
above sketch into the notepad and save it with the extension .java instead of .txt
Then
open the command prompt and type,
cd
C:\Users\Inova\Desktop\new\Hello world
here
(C:\Users\Inova\Desktop\new\Hello world) is the path of the folder in which the
java file that you created before is saved.
Then
type,
javac Simple.java
and
enter. by typing 'javac' we compile the java file. A new file called CLASS file
will be created. Here 'Simple' is the name which the Java file is saved.
Then
type,
java Simple
and
enter. Then the compiled java file will run, giving the output "Hello
World".
|
Copy and paste the above sketch on the note pad |
|
Save with the extension .java insted of .txt. Also change the Save as type to All Files |
|
Text file is saved as a java file |
|
Copy the path of the folder. |
|
Open the command prompt |
|
Type "cd C:\Users\Inova\Desktop\new\Hello world" and press enter. (cd <space> <copied path> ) |
|
Type "javac Simple.java" and press enter. Here the java file compiles and creates a CLASS file. |
|
The CLASS file also saves in the same folder |
|
Type java Simple and enter |
|
Output : "Hello World" |
No comments:
Post a Comment