How To Compile And Run Java Programme Using Command Prompt
How To Compile And Run Java Programme Using Command Prompt
First of all you should install JDK (Java Development Kit) to your
computer.
What is command prompt?
In
windows O/S , it is a programme that emulates the input field in a text – based
user interface screen with the windows GUI. It can be used to execute entered
commands and perform advanced administrative functions.
Types of commands
Internal commands
Cls
- clear
screen
Mkdir - make a folder
Rmdir
- remove
a folder
Dir - how the list of files and folders in current
directory
C: or D: - change partitions
cd..
- go to parent directory
cd folder name - go to child directory
rename currentFolderName newFoderName - change folder name
d:\workingDirectory>FirstCode.java - enter path to open a file or
folder
External commands
Externally
installed software
Let’s see how to compile & run “hello world”
01) Open the command prompt (start >
command prompt)
02) Make a new folder (D:\>MKDIR FirstProject)
03) Enter your working
directory (D:\>cd FirstProject)
04) Request a text editor document via notepad (D:\FirstProject>notepadFirstcode.java)
05) Type and save your source
code in notepad
06) Compile your source code
file (D:\FirstProject>javac Firstcode.java)
07) Run your programme (D:\FirstProject>java Firstcode)
In Java, every application begins with a class name, and that
class must match the filename.
Let's create our first Java file, called Firstcode.java, which can
be done in any text editor (like Notepad).
When the text editor opens you can type your source code.
D:\FirstProject>javac Firstcode.java
This will compile your code. If there are no
errors in the code, the command prompt will take you to the next line. Now,
type "java Firstcode" to run the file
Then you can get output as Hello World.
Written by
Sachini Vinodya
Software Engineering Student,
(Content Writer at Learn with Panduza).




good
ReplyDelete