How to run 1st Java program.
Before starting,make sure you have running java on your pc.It is a suggestion use text editor and command prompt only to run your java programs at this level.
Once you have achieved grip on programming ,You can use tools like (Eclipse,Net beans etc) to create your program.
Suppose you want to run a java application.
following are general steps:
- Open Notepad
- Write your code
- Save file. File name will be classname.java (Class having main method)
- Open CMD
- Go to apporopriate directory
- Compile programe with command: javac filename.java
- Run programe with command: java filename
Now lets have above steps with example:
- Open Notepad:
- Write following code:
{
public static void main(String args[])
{
System.out.println("My first Java program.");
}
}
class aClass // Another class in same source file if required
{
}
- Save the file with name Example1.java
Suppose we have saved our java file at location D:\java
(You can choose location as per your convenience)
- open CMD(Command Prompt)
- Give command : d:
Will move to D drive.
Give command as per your drive in which you saved your example program.
- Give command : cd java
Give command as per your folder in which you saved your example programs.
- Give command : javac Example1.java
- Give command : java Example1
No comments:
Post a Comment