How to Write, Compile and Run Your First Java Program?

Before running Java programs you need to install and setup
java. For installation guide read: Java Installation: Downloading, Installing and Setting Path

How to write and run Java programs?

  • Open notepad and write below program.

 

class demo
{
                public
static void main(String…S)
                {
                                System.out.println(“Java
Programming”);
                }
}
First Java Program
  • Now save the file with name demo.java on desktop. Here you can replace demo with any other name that you want.
  • Then open command prompt (cmd) and type cd desktop and press enter to change current directory to desktop.
    We changed directory because our program is saved on desktop.
cd desktop
  • To compile java program type javac demo.java and hit enter. Type java demo to run the program. Remember that here we have to compile
    with program name and execute with class name that we have used in program. The
    java program name and class name can be different.
compile and run

 

Understand the Program

Understand the Program
 
 
System: Get reference id of the device on
which program is running. Here the device is cmd.
out: Store the reference id of device.
println: Throw the output on device.
A.java
A.java
A.java
class A
 {
}
class A
{
public static void main()
{
}
}
compile
Yes
Yes
Yes
.class file
Not created
Created
Created
execute
No
No
Yes

1 thought on “How to Write, Compile and Run Your First Java Program?”

Leave a Comment

Your email address will not be published. Required fields are marked *